#include <dvmpnm.h>
Header used for PBM, PGM, and PPM files.
typedef struct PnmHdr { int type; int width; int height; int maxVal; } PnmHdr;
- type
- The type of the image (see Constant section below).
- width
- The width of the image in number of pixels.
- height
- The height of the image in number of pixels.
- maxVal
- The maximum value any pixels in the image can have (typically 255). Note that this is not the maximum value any pixel in the image does have. Instead, it's an indication of the precision of the image.
The type of the image.
#define PBM_TEXT 1 #define PGM_TEXT 2 #define PPM_TEXT 3 #define PBM_BIN 4 #define PGM_BIN 5 #define PPM_BIN 6
Return code from various PNM primitives. DVM_PNM_OK indicates the primitive executed succesfully. DVM_PNM_INVALID_HDR indicates there is an error in the header. DVM_PNM_BS_UNDERFLOW indicates the bitstream does not contain enough bits for the complete file. DVM_PNM_IS_BYTE_ALIGN and DVM_PNM_NOT_BYTE_ALIGN are
#define DVM_PNM_OK 0 #define DVM_PNM_INVALID_HDR -1 #define DVM_PNM_BS_UNDERFLOW -2 #define DVM_PNM_IS_BYTE_ALIGN -3 #define DVM_PNM_NOT_BYTE_ALIGN -4
PnmHdr *PnmHdrNew ( )
Allocates a new PnmHdr, and return a handle to it.
void PnmHdrFree (PnmHdr *hdr)
index {PnmHdr, Freeing} index {Freeing PnmHdrs} Deallocates the PnmHdr hdr.
void PnmHdrCopy (PnmHdr *src, PnmHdr *dest)
Copy the contents of src to dest.
int PnmHdrParse (BitParser *bp, PnmHdr *hdr)
Parse the BitStream attached to bp, assuming that cursor of bp is at the beginning of an PNM file stream. The header information is parsed from the BitStream and stored into the hdr (a PnmHdr). Comments in the encoded header are skipped. This function returns the number of bytes parsed from bp if parsing is successful. Otherwise, return DVM_PNM_INVALID_HEADER if header is not formated correctly, or DVM_PNM_BS_UNDERFLOW if BitStream does not have enough data for parsing to complete. Underflow exception is checked after each element in the header is encountered and parsed.
void PnmHdrSetType (PnmHdr *hdr, int type)
void PnmHdrSetWidth (PnmHdr *hdr, int width)
void PnmHdrSetHeight (PnmHdr *hdr, int height)
void PnmHdrSetMaxVal (PnmHdr *hdr, int maxval)
Each of these functions sets the corresponding slot of hdr. For PnmSetHdrType, use one of the constants defined in the PnmHdr typesabove.
int PnmHdrGetType (PnmHdr *hdr)
int PnmHdrGetWidth (PnmHdr *hdr)
int PnmHdrGetHeight (PnmHdr *hdr)
int PnmHdrGetMaxVal (PnmHdr *hdr)
Return the value of the corresponding slot in the PnmHdr hdr. The type slot is one of the constants defined in the PnmHdr typesabove.
int PnmHdrEncode (PnmHdr *hdr, BitParser *bp)
Output hdr to the BitStream attached to bp. Returns the number of bytes encoded.
int PpmParse (BitParser *bp, ByteImage *r, ByteImage *g, ByteImage *b)
Parse PPM image data from bp into ByteImages r, g, and b (the red, green, and blue planes of the PPM image). Assumes the cursor of bp is just before the beginning of the PPM data. Return the number of bytes parsed from the BitStream.
int PpmEncode (ByteImage *r, ByteImage *g, ByteImage *b, BitParser *bp)
Write the three ByteImages r, g and b in PPM binary format to an output BitStream using bp. Assumes that the BitStream is large enough to hold the PPM data. Return the number of bytes written into the BitStream.
int PgmParse (BitParser *bp, ByteImage *byte)
Parse PGM image data bp into the ByteImage byte. This function assumes that bp's cursor is just before the beginning of the PGM data. Return the number of bytes parsed from the BitStream.
int PgmEncode (ByteImage *byte, BitParser *bp)
Write the contents of ByteImage byte in PGM binary format to a BitStream using bp. This function assumes that the BitStream is large enough to hold the PGM data. Returns the number of bytes written into the BitStream.
BitStream *ByteCastToBitStream (ByteImage *byte)
Cast a physical ByteImage byte into a virtual BitStream object of size w*h, where w, and h are the width and height of byte. A new, virtual BitStream object is returned. This function can be used to avoid copying data when encoding.
Byte *BitStreamCastToByte (BitStream *bs, PnmHdr *hdr, int offset)
Cast a physical BitStream object bs into a virtual ByteImage object of dimension w x h, where w and h are the width and height specified in the PnmHdr object hdr. The data of the ByteImage must start offset bytes from the first byte of bs. A handle to a new virtual ByteImage is returned. This function can be used to avoid copying the data when decoding.
int PbmParse (BitParser *bp, BitImage *bit)
This function parses a PBM image from an input stream using bp into the BitImage bit. It assumes that bp's cursor is just before the beginning of the PBM data. It returns the number of bytes parsed from the BitStream. DVM_PNM_IS_BYTE_ALIGN is returned and the BitStream is not modified if bit is byte-aligned. For byte-aligned BitImages, PbmParse8 should be used instead. The number of bytes needed to initialize the BitImage can be found with BitGetSize.
int PbmParse8 (BitParser *bp, BitImage *bit)
This function parses a bit image from an input stream using bp into the byte-aligned BitImage bit. It assumes that bp's cursor is just before the beginning of the PBM data. DVM_PNM_NOT_BYTE_ALIGN is returned and the BitStream is not modified if bit is not byte-aligned. For non-byte-aligned BitImages, PbmParse should be used instead.
int PbmEncode (BitImage *bit, BitParser *bp)
Write the contents of BitImage bit in PBM binary format to a BitStream using bp. This function assumes that the BitStream is large enough to hold the PBM data. DVM_PNM_IS_BYTE_ALIGN is returned and the BitStream is not modified if bit is byte-aligned. For byte-aligned BitImage, PbmEncode8 should be used instead.
int PbmEncode8 (BitImage *bit, BitParser *bp)
Write the contents of the byte-aligned BitImage bit in PBM binary format to an output BitStream using bp. This function assumes that the BitStream is large enough to hold the PBM data. DVM_PNM_NOT_BYTE_ALIGN is returned and the BitStream is not modified if bit is not byte-aligned. For non-byte-aligned BitImage, PbmEncode should be used instead.
BitStream *BitCastToBitStream (BitImage *bit)
Cast a physical left-byte-aligned BitImage bit into a virtual BitStream. The resulting BitStream is a PBM encoded image (without the header, of course) that has size of w x h, where w and h are the width and height of bit. A pointer to the new Bitstream is returned.
Bit *BitStreamCastToBit (BitStream *bs, PnmHdr *hdr, int offset)
Cast the physical BitStream bs into a virtual left-byte-aligned BitImage. Raw bytes from bs, starting from position offset bytes, is interpreted as the body of BitImage of size w x h, where w and h are specified by the PnmHdr hdr. A handle to the virtual BitImage is returned.
Last updated : Saturday, November 14, 1998, 07:50 PM