The Cartesian Perceptual Compression (CPC) method and its implementation are designed to be inter-operable across a wide spectrum of application environments, ranging from standalone office equipment to Internet Browser add-on modules. For most applications, however, the core API provides more freedom than is necessary, thereby requiring greater complexity in the application. To facilitate rapid application development, an alternative API, known as the Rapid Deployment API, is provided. Although the Rapid Deployment API does not have the flexibility of the core API, it is sufficient for the overwhelming majority of applications, providing a fast path to incorporating CPC compression into existing applications. This document describes the Rapid Deployment Application Programming Interface to the CPC programming library.
The portion of the API described in this document requires the use of files for the underlying storage of the raw CPC data. The document, Rapid Deployment Data Streams, describes an extension of the API, which allows an application to utilize arbitray storage mechanisms for the raw CPC data.
The Rapid Deployment API provides two objects for interacting with documents:
Type Definition: ImRow | |
Specifies a row coordinate in CPC. | |
|
Type Definition: ImCol | |
Specifies a column coordinate in CPC. | |
|
Type Definition: ImDim | |
Describes the dimensions of a pattern. The field num_rows specifies the pattern height (in pixels); the field num_cols specifies the pattern width (in pixels). | |
|
Type Definition: ImResolution | |
Specifies the resolution of an image. Separate resolutions are specified for the x and y axes. The field xDpi specifies the resolution of the x-axis in pixels per inch; the field yDpi specifies the resolution of the y-axis in pixels per inch. If the resolution of an axis is not known, the corresponding field (xDpi or yDpi) is set to zero. | |
|
Multiple pixels are packed together, as densely as possible, into a single word of memory. Within a long-word, bitmap data is stored in most-significant to least-significant (big-endian) order. That is, column 0 is the most significant bit of the long-word; column 1 is the next most significant bit, etc.
Bit-maps are organized into rows of pixels. For efficiency reasons, it is useful to insure that each row of the map begins on a long-word boundary. Hence, the width of a row is rounded up to a multiple of the number of bits in a long-word (i.e., 32). A bit-map, therefore, has two dimensions:
Type Definition: ImBitMap | |
Describes the bit-map representation of a pattern. The image dimensions of the pattern are stored in img_dim, and the memory dimensions of the pattern are stored in mem_dim. pixels points to the memory buffer that stores the pattern bit-map. | |
The memory width is always a multiple of the number of bits in a long-word, and hence, each image row in pixels starts on a long-word boundary. | |
|
Function Definition: ibm_create | |
Create a bitmap with the image dimensions, imgDim. If initializePixels is non-zero, the pixels of the bitmap are initialized to zero (white). Otherwise, the pixels are not initialized. | |
Returns a pointer to the bitmap, or 0 if the bitmap could not be allocated. | |
|
Function Definition: ibm_getRow | |
Returns a pointer to the pixel longword that contains column 0 of the row, rowNum, within the bit-map, ibm. Rows are numbered from zero. | |
If rowNum is greater than or equal to the height of the bit-map, the returned pointer is not valid. | |
|
Function Definition: ibm_destroy | |
Destroy the bitmap, ibm, de-allocating its memory. | |
On return from this function, ibm is no longer valid, and the application should not use it on any subsequent interaction with the CPC library. | |
|
Opaque Type: CpcEncoder | |
The opaque data type used to represent a CPC encoder. | |
|
When the application is done with the encoder, it should call cpcEnc_destroy to deallocate it.
Function Definition: cpcEnc_createFromFile | |
Create a CPC encoder that sends its compressed CPC data to the file, sink, starting at the file's current seek position. If progressive is non-zero, the document is encoded using the CPC-Progressive format. Otherwise, it is encoded using the CPC-Normal format. | |
Returns a pointer to the encoder, or 0 if the encoder could not be created. The only reason for failure is that memory could not be allocated. | |
sink must be a seekable file (i.e., it must not be a pipe), and it must be opened in binary mode. | |
|
Function Definition: cpcEnc_addPage | |
Add the page described by ibm as the next page in the document that cpc is encoding. | |
|
Function Definition: cpcEnc_destroy | |
Flush all document data to the output file and destroy the encoder, cpc. If closeOutput is non-zero, the output file is also closed. Otherwise, the encoder is detached from the output file, and on return, the output file's seek pointer is positioned immediately after the compressed document data. (On an error, the position of the output file's seek pointer is undefined.) | |
If an application is using Rapid Deployment Data Streams, the closeOutput parameter determines whether or not the output Data Stream is also closed. | |
Returns 0 if the encoder successfully compressed the document. Otherwise, returns a pointer to a zero-terminated ASCII string describing the nature of the error. | |
On return from this function, cpc is no longer valid, and the application should not use it on any subsequent interaction with the CPC library. | |
The returned string is owned by the CPC library. It should not be modified or deallocated by the application. | |
|
This example is for expository purposes only; in a real-world application, it would be inefficient to buffer all of the page bitmaps for a document.
char const *Encode(ImBitMap *pages[], unsigned pageCnt) { unsigned i; CpcEncoder *cpc; FILE *fp; fp = fopen("out.cpi", "wb"); if(!fp) { return "Unable to create output file"; } cpc = cpcEnc_createFromFile(fp, 0/*CPC-Normal*/); if(!cpc) { fclose(fp); return "Unable to create decoder"; } for(i=0; i<pageCnt; i++) { cpcEnc_addPage(cpc, pages[i]); } return cpcEnc_destroy(cpc, 1/*closeOutput*/); } |
Opaque Type: CpcDecoder | |
The opaque data type used to represent a CPC decoder. | |
|
Function Definition: cpcDec_createFromFile | |
Create a CPC decoder that reads its compressed CPC data from the file, data, starting at the file's current seek position. If sequential is non-zero, the decoder is configured for sequential access to the pages. Otherwise, the decoder is configured for random access. (Random access uses an additional 750k of memory.) | |
Returns a pointer to the decoder, or 0 if the decoder could not be created. The only reason for failure is that memory could not be allocated. | |
data must be a seekable file (i.e., it must not be a pipe), and it must be opened in binary mode. | |
|
Function Definition: cpcDec_getPageCount | |
Returns the number of pages contained in the document that the decoder, cpc, is reading. | |
|
Function Definition: cpcDec_getPage | |
Retrieve the bit-map for page, pageNum, from the decoder, cpc. Pages are numbered from zero. | |
Returns a pointer to the bitmap, or 0 if an error occurred. The caller is responsible for deallocating the bitmap (using ibm_destroy) when it is done with it. | |
|
Function Definition: cpcDec_getPageRes | |
Retrieve the image resolution for page, pageNum, from the decoder, cpc. The resolution is returned in the output parameter, res. Pages are numbered from zero. | |
|
Function Definition: cpcDec_getError | |
Returns 0 if the decoder, cpc, has not encountered any errors. Otherwise, returns a pointer to a zero-terminated ASCII string describing the nature of the error. | |
The returned string is owned by the CPC library. It should not be modified or deallocated by the application. | |
|
Function Definition: cpcDec_destroy | |
Closes the CPC decoder, cpc. If closeInput is non-zero, the underlying input file will also be closed. Otherwise, the decoder is detached from the input file. On return, the position of the input file's seek pointer is undefined. | |
If an application is using Rapid Deployment Data Streams, the closeInput parameter determines whether or not the input Data Stream is also closed. | |
Returns 0 if the decoder has not encountered any errors. Otherwise, returns a pointer to a zero-terminated ASCII string describing the nature of the error. | |
On return from this function, cpc is no longer valid, and the application should not use it on any subsequent interaction with the CPC library. | |
The returned string is owned by the CPC library. It should not be modified or deallocated by the application. | |
|
char const *Decode(FILE *fp) { unsigned i, pageCnt; CpcDecoder *cpc; cpc = cpcDec_createFromFile(fp, 1/*sequential*/); if(!cpc) { return "Unable to create decoder"; } for(i=0, pageCnt=cpcDec_getPageCount(cpc); i<pageCount; i++) { ImBitMap *ibm = cpcDec_getPage(cpc,i); if(!ibm) { break; } ibm_destroy(ibm); } return cpcDec_destroy(cpc, 0/*do not close file*/); } |
extern "C" { # include "RapidCpc.h" }; |
Type Definition: CpcMemAllocator | |
Defines the functions to use for memory management. Allocate has the same semantics as the ANSI C malloc function. Reallocate has the same semantics as the ANSI C realloc function. Free has the same semantics as the ANSI C free function. | |
|
The following interface is used to set the memory allocator for the calling process.
Function Definition: cpcMem_setAllocator | |
Set the CPC memory allocator to the allocator, cpcMem. The CPC library copies the CpcMemAllocator, so the application may pass a pointer to temporary memory. | |
This function, if it is called, must be called prior to calling any other CPC library functions. | |
|