### PGM Plain ASCII Format Example (P2) Source: https://github.com/nu774/jbigkit/blob/master/pbmtools/pgm.txt This example demonstrates the structure of a PGM file using the plain ASCII format (P2). It includes the magic number, dimensions, maximum gray value, and pixel data, with comments and whitespace. ```text P2 # feep.pgm 24 7 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0 0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0 0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0 0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ``` -------------------------------- ### Example of Setting Maximum Size Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Example call to jbg_dec_maxsize to set a maximum decoding resolution of 1024x768 pixels. ```c jbg_dec_maxsize(&sd, 1024, 768); ``` -------------------------------- ### PBM ASCII Format Example Source: https://github.com/nu774/jbigkit/blob/master/pbmtools/pbm.txt This example demonstrates the structure of a PBM file in its ASCII format (P1). It includes the magic number, dimensions, and pixel data represented by '0' for white and '1' for black. ```text P1 # feep.pbm 24 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ``` -------------------------------- ### Minimal JBIG Encoding Application Example Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt A basic C application demonstrating how to use the jbig.c library to compress a bitmap and send the resulting BIE data to standard output. It includes the necessary header and a custom data output function. ```c #include #include "jbig.h" void output_bie(unsigned char *start, size_t len, void *file) { fwrite(start, 1, len, (FILE *) file); return; } ``` -------------------------------- ### Start JBIG Encoding Process Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Call this function to initiate the compression and deliver the complete BIE data via the provided data_out callback. Ensure to call jbg_enc_free afterwards to release allocated memory. ```c void jbg_enc_out(struct jbg_enc_state *s); ``` -------------------------------- ### jbg_enc_out Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Starts the JBIG compression process. This function triggers the encoder to generate the compressed BIE data and deliver it via the provided data_out callback function. ```APIDOC ## jbg_enc_out ### Description Starts the JBIG compression process. This function triggers the encoder to generate the compressed BIE data and deliver it via the provided data_out callback function. ### Function Signature ```c void jbg_enc_out(struct jbg_enc_state *s); ``` ### Parameters - **s** (*struct jbg_enc_state * *) - Required - A pointer to the initialized jbg_enc_state structure. ``` -------------------------------- ### Get JBIG Image Dimensions Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Retrieve the width and height of the decoded JBIG image using these utility functions. ```c unsigned long jbg85_dec_getwidth(struct jbg85_dec_state *s); unsigned long jbg85_dec_getheight(struct jbg85_dec_state *s); ``` -------------------------------- ### Example Image Data in Hexadecimal Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt This hexadecimal representation shows the raw byte data for a 23x5 pixel single-plane image, where each byte corresponds to 8 pixels. Padding bits are included if the image width is not a multiple of eight. ```text 7c e2 38 04 92 40 04 e2 5c 44 92 44 38 e2 38 ``` -------------------------------- ### Get JBIG Error String Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Convert an error number returned by the JBIG decoder functions into a human-readable string. ```c const char *jbg_strerror(int errnum); ``` -------------------------------- ### Retrieve Decoded Image Data Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Get a pointer to the bitmap data for a specific plane of a decoded JBIG image. The memory for the bitmap is managed by the decoder state. ```c unsigned char *jbg_dec_getimage(struct jbg_dec_state *s, int plane); ``` -------------------------------- ### Get Merged Data Size Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Determine the total size of the data array that will be delivered by jbg_dec_merge_planes(). ```c unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s); ``` -------------------------------- ### Initializing JBIG Decoder State Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Include the 'jbig.h' header and link with libjbig.a. Define a jbg_dec_state structure variable and initialize it using jbg_dec_init before passing data to the decoder. ```c #include "jbig.h" ``` ```c struct jbg_dec_state sd; ``` ```c void jbg_dec_init(struct jbg_dec_state *s); ``` -------------------------------- ### Minimal JBIG85 Encoding Application Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt A sample C application demonstrating how to use the JBIG85 library to encode a small bitmap and send the compressed data to stdout. ```c #include #include "jbig85.h" void output_bie(unsigned char *start, size_t len, void *file) { fwrite(start, 1, len, (FILE *) file); return; } int main() { unsigned char bitmap[15] = { /* 23 x 5 pixels, "JBIG" */ 0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44, 0x92, 0x44, 0x38, 0xe2, 0x38 }; struct jbg85_enc_state se; int i; jbg85_enc_init(&se, 23, 5, output_bie, stdout); /* initialize encoder */ jbg85_enc_options(&se, JBG_TPBON, 0, -1); /* clear JBG_VLENGTH option */ for (i = 0; i < 5; i++) { /* encode line */ jbg85_enc_lineout(&se, bitmap+i*3, bitmap+(i-1)*3, bitmap+(i-2)*3); } return 0; } ``` -------------------------------- ### Get JBIG85 Error Message Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Retrieve a human-readable error message for a given JBIG85 decoder error code. This is useful for user feedback. ```c const char *jbg85_strerror(int errnum); ``` -------------------------------- ### Initialize, Encode, and Free JBIG Encoder State Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt This snippet demonstrates the basic workflow for encoding an image using the JBIG encoder. It initializes the encoder state, encodes the image data, and then frees the allocated resources. Ensure the 'output_bie' function is correctly defined elsewhere to handle the encoded output. ```c int main() { unsigned char bitmap[15] = { /* 23 x 5 pixels, "JBIG" */ 0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, 0x5c, 0x44, 0x92, 0x44, 0x38, 0xe2, 0x38 }; unsigned char *bitmaps[1] = { bitmap }; struct jbg_enc_state se; jbg_enc_init(&se, 23, 5, 1, bitmaps, output_bie, stdout); /* initialize encoder */ jbg_enc_out(&se); /* encode image */ jbg_enc_free(&se); /* release allocated resources */ return 0; } ``` -------------------------------- ### Initialize JBIG Encoder State Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Declare and initialize the encoder state structure before compression. The constructor function requires image dimensions, number of planes, bitmap pointers, a data output callback, and a user-defined file pointer. ```c struct jbg_enc_state s; void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y, int pl, unsigned char **p, void (*data_out)(unsigned char *start, size_t len, void *file), void *file); ``` -------------------------------- ### jbg85_enc_init Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Initializes the JBIG85 encoder state. This function sets up the encoder with image dimensions and a callback for compressed data output. ```APIDOC ## jbg85_enc_init ### Description Initializes the JBIG85 encoder state structure. ### Signature ```c void jbg85_enc_init(struct jbg85_enc_state *s, unsigned long x, unsigned long y, void (*data_out)(unsigned char *start, size_t len, void *file), void *file); ``` ### Parameters * **s** (*struct jbg85_enc_state ") - A pointer to the jbg85_enc_state structure to initialize. * **x** (*unsigned long*) - The width of the image in pixels. * **y** (*unsigned long*) - The height of the image in pixels. This can be a larger value than the actual height or -1 if the height is unknown. In such cases, the JBG_VLENGTH option should remain set, and jbg85_enc_newlen() should be called when the height is known. * **data_out** (*function pointer*) - A callback function that the encoder calls to deliver the compressed BIE data. It receives a pointer to the data block (`start`), the number of bytes (`len`), and a user-provided file pointer (`file`). * **file** (*void ") - A pointer passed transparently to the `data_out` callback function, useful for distinguishing compression tasks in multi-threaded applications. ``` -------------------------------- ### jbg_enc_init Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Initializes the JBIG encoder state. This function sets up the encoder with image dimensions, number of planes, bitmap data, and a callback for data output. ```APIDOC ## jbg_enc_init ### Description Initializes the JBIG encoder state. This function sets up the encoder with image dimensions, number of planes, bitmap data, and a callback for data output. ### Function Signature ```c void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y, int pl, unsigned char **p, void (*data_out)(unsigned char *start, size_t len, void *file), void *file); ``` ### Parameters - **s** (*struct jbg_enc_state * *) - Required - A pointer to the jbg_enc_state structure that you want to initialize. - **x** (*unsigned long*) - Required - The width of your image in pixels. - **y** (*unsigned long*) - Required - The height of your image in pixels (lines). - **pl** (*int*) - Required - The number of bitmap planes you want to encode. - **p** (*unsigned char ** *) - Required - A pointer to an array of pl pointers, where each is again pointing to the first byte of a bitmap. - **data_out** (*void (*)(unsigned char *, size_t, void *)* ) - Required - A call-back function that the encoder will call during the compression process by in order to deliver the BIE data to your application. The parameters of the function data_out are a pointer start to the new block of data being delivered, as well as the number len of delivered bytes. The pointer file is transparently delivered to data_out, as specified in jbg_enc_init(). Typically, data_out will write the BIE portion to a file, send it to a network connection, or append it to some memory buffer. - **file** (*void * *) - Required - A pointer parameter that is passed on to data_out() and can be used, for instance, to allow data_out() to distinguish by which compression task it has been called in multi-threaded applications. ``` -------------------------------- ### JBIG85 Encoder Initialization Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Initializes the JBIG85 encoder state. Set image dimensions and provide a callback function for outputting compressed data. ```c void jbg85_enc_init(struct jbg85_enc_state *s, unsigned long x, unsigned long y, void (*data_out)(unsigned char *start, size_t len, void *file), void *file); ``` -------------------------------- ### jbg85_dec_init Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Initializes the JBIG85 decoder state. This function must be called before processing any BIE data. It sets up the decoder with a buffer for decoded lines and a callback function for line output. ```APIDOC ## jbg85_dec_init ### Description Initializes the JBIG85 decoder state. This function must be called before processing any BIE data. It sets up the decoder with a buffer for decoded lines and a callback function for line output. ### Function Signature ```c void jbg85_dec_init(struct jbg85_dec_state *s, unsigned char *buf, size_t buflen, int (*line_out)(const struct jbg85_dec_state *s, unsigned char *start, size_t len, unsigned long y, void *file), void *file); ``` ### Parameters #### `s` (struct jbg85_dec_state *) - A pointer to the decoder state structure to be initialized. #### `buf` (unsigned char *) - A memory buffer for storing decoded lines. Must be large enough for up to three lines (or two if LRLTWO option is used). Minimum size: `((xmax >> 3) + !!(xmax & 7)) * 3` bytes. #### `buflen` (size_t) - The length in bytes of the buffer pointed to by `buf`. #### `line_out` (int (*)(const struct jbg85_dec_state *, unsigned char *, size_t, unsigned long, void *)) - A call-back function invoked when a line is decoded. It receives the decoded line data, its length, line number, and a user-provided file pointer. Returning non-zero requests an interrupt. #### `file` (void *) - A user-defined pointer passed to the `line_out` callback function, useful for multi-threaded applications or context identification. ``` -------------------------------- ### Configure JBIG85 Encoder Options Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Use jbg85_enc_options to set encoding parameters like template lines, typical prediction, and variable length encoding. Default options are JBG_TPBON | JBG_VLENGTH. ```c void jbg85_enc_options(struct jbg85_enc_state *s, int options, unsigned long l0, int mx) ``` -------------------------------- ### Activate Progressive Encoding Layers Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Use jbg_enc_layers to specify the number of differential resolution layers for progressive encoding. This allows for multi-resolution output, enabling different preview capabilities. ```c void jbg_enc_layers(struct jbg_enc_state *s, int d); ``` -------------------------------- ### Include JBIG85 Header Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Include the jbig85.h header file in your source code to use the library functions. ```c #include "jbig85.h" ``` -------------------------------- ### jbg_newlen() Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Scans a BIE for the first NEWLEN marker segment and updates the image-height value (YD) in the BIE header. This is a workaround for handling NEWLEN markers when the jbig.c decoder cannot process them directly. ```APIDOC ## jbg_newlen() ### Description This function scans a provided BIE (Bitstream Image Element) for the first NEWLEN marker segment. If found, it updates the image-height value (YD) in the BIE header with the value from the NEWLEN marker. This is particularly useful for handling JBIG streams where the image height is not known at the start of transmission, as suggested by ITU-T T.85. ### Method ```c int jbg_newlen(unsigned char *bie, size_t len); ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **bie** (`unsigned char *`): A pointer to the first byte of the BIE data. - **len** (`size_t`): The length of the BIE data in bytes. ### Request Example None ### Response #### Success Response (200) Returns an integer status code. #### Response Example ``` 0 // JBG_EOK ``` ### Error Handling - `JBG_EOK`: Success, the BIE header was updated. - `JBG_EAGAIN`: The provided data is too short to be a valid BIE. - `JBG_EINVAL`: A format error was encountered within the BIE. - `JBG_EABORT`: An ABORT marker segment was found within the BIE. ``` -------------------------------- ### Initialize JBIG Decoder State Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Declare and initialize a jbg85_dec_state structure before decoding an image. The line_out callback is essential for processing decoded lines. ```c struct jbg85_dec_state s; void jbg85_dec_init(struct jbg85_dec_state *s, unsigned char *buf, size_t buflen, int (*line_out)(const struct jbg85_dec_state *s, unsigned char *start, size_t len, unsigned long y, void *file), void *file); ``` -------------------------------- ### Query JBIG85 Decoder State Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Use these macros to query the state of the JBIG85 decoder. They help determine if the image dimensions are known and if decoding is complete. ```c int jbg85_dec_validwidth(struct jbg85_dec_state *s); int jbg85_dec_finalheight(struct jbg85_dec_state *s); int jbg85_dec_finished(struct jbg85_dec_state *s); ``` -------------------------------- ### JBIG85 Encoder Line Output Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Encodes a single line of the image. Pass pointers to the current line and the previous two lines for context. ```c void jbg85_enc_lineout(struct jbg85_enc_state *s, unsigned char *line, unsigned char *prevline, unsigned char *prevprevline); ``` -------------------------------- ### jbg_dec_free Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Releases any memory allocated by the JBIG decoder state. ```APIDOC ## jbg_dec_free ### Description Releases any memory allocated by the JBIG decoder state. This function should be called when an error occurs during decoding or when the decoded bitmap is no longer needed. ### Parameters - **s** (struct jbg_dec_state *) - Pointer to the decoder state structure. ### Return Value None. ``` -------------------------------- ### Set Advanced JBIG Encoder Options Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt The jbg_enc_options function allows modification of various advanced JBIG algorithm parameters, including SDE storage order and other optional features. This function should be called before jbg_enc_out. ```c void jbg_enc_options(struct jbg_enc_state *s, int order, int options, long l0, int mx, int my); ``` -------------------------------- ### Passing Data to JBIG Decoder Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt After initializing the decoder state, use jbg_dec_in to pass data from the BIE (Bitstream Input Engine) to the decoder. The function returns an integer status and updates the count of processed bytes. ```c int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len, size_t *cnt); ``` -------------------------------- ### jbg_strerror Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Returns a human-readable string representation of a JBIG decoder error code. ```APIDOC ## jbg_strerror ### Description Returns a human-readable string representation of a JBIG decoder error code. ### Parameters - **errnum** (int) - The error code returned by a JBIG decoder function. ### Return Value - **const char***: A string describing the error. ``` -------------------------------- ### Incremental JBIG Decoding Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Process data blocks incrementally for JBIG decoding. Call this function multiple times with fragmented data. The function returns JBG_EOK upon completion of a BIE, JBG_EAGAIN if more data is needed, or an error code. ```c int jbg_dec_in(struct jbg_dec_state *s, const unsigned char *pointer, unsigned long len, unsigned long *cnt); ``` -------------------------------- ### Free JBIG Encoder Resources Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Call this destructor function after jbg_enc_out has completed to release any heap memory allocated during the encoding process. ```c void jbg_enc_free(struct jbg_enc_state *s); ``` -------------------------------- ### Merge JBIG Bit Planes Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Merge individual bit planes into a byte-per-pixel format using a callback function for output. The 'use_graycode' parameter controls binary encoding. ```c void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode, void (*data_out)(unsigned char *start, size_t len, void *file), void *file); ``` -------------------------------- ### Set Maximum Resolution Layer Size Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Call jbg_enc_lrlmax to automatically determine the number of resolution layers so that the lowest resolution layer fits within a specified maximum width and height. This is useful when the target display size is known. ```c int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long mwidth, unsigned long mheight); ``` -------------------------------- ### Set Maximum Output Size for Progressive Decoding Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Specify an abort criterion for progressively encoded images to prevent decoding excessively large images. The decoder may stop at the largest resolution layer smaller than the specified maximum size. ```c void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax, unsigned long ymax); ``` -------------------------------- ### Set Range of Resolution Layers for BIE Output Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Use jbg_enc_lrange to control which resolution layers are included in the BIE (JBIG Encoded File). This function allows specifying the lowest (dl) and highest (dh) differential layers to be encoded. ```c int jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh); ``` -------------------------------- ### Free JBIG Decoder Resources Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Release any memory allocated by the JBIG decoder state. This function should be called when an error occurs or when the decoder is no longer needed. ```c void jbg_dec_free(struct jbg_dec_state *s); ``` -------------------------------- ### Image Retrieval Functions Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Functions to retrieve the dimensions, number of planes, and bitmap data of a decoded JBIG image. ```APIDOC ## Image Retrieval Functions ### Description Functions to retrieve the dimensions, number of planes, and bitmap data of a decoded JBIG image after `jbg_dec_in()` has returned `JBG_EOK` or `JBG_EOK_INTR`. ### Functions #### `jbg_dec_getwidth(struct jbg_dec_state *s)` - **Description**: Retrieves the width of the decoded image. - **Return Value**: Width of the image in pixels. #### `jbg_dec_getheight(struct jbg_dec_state *s)` - **Description**: Retrieves the height of the decoded image. - **Return Value**: Height of the image in pixels. #### `jbg_dec_getplanes(struct jbg_dec_state *s)` - **Description**: Retrieves the number of bit planes in the decoded image. - **Return Value**: Number of planes. #### `jbg_dec_getimage(struct jbg_dec_state *s, int plane)` - **Description**: Retrieves a pointer to a specific bitmap plane of the decoded image. - **Parameters**: - **s** (struct jbg_dec_state *) - Pointer to the decoder state structure. - **plane** (int) - The index of the plane to retrieve. - **Return Value**: Pointer to the bitmap data for the specified plane. #### `jbg_dec_getsize(struct jbg_dec_state *s)` - **Description**: Calculates the number of bytes required for one bitmap plane. - **Return Value**: Size of one bitmap plane in bytes. ``` -------------------------------- ### Clear JBG_VLENGTH Option in JBIG85 Encoder Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt If the initial image height is known and will not change, clear the JBG_VLENGTH option by calling jbg85_enc_options with only JBG_TPBON set. ```c jbg85_enc_options(&s, JBG_TPBON, 0, -1); ``` -------------------------------- ### jbg85_enc_lineout Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Encodes a single line of the image. This function should be called successively for each line of the image after initialization. ```APIDOC ## jbg85_enc_lineout ### Description Encodes a single line of the image and delivers the compressed data via the `data_out` callback. ### Signature ```c void jbg85_enc_lineout(struct jbg85_enc_state *s, unsigned char *line, unsigned char *prevline, unsigned char *prevprevline); ``` ### Parameters * **s** (*struct jbg85_enc_state ") - A pointer to the initialized encoder state. * **line** (*unsigned char ") - A pointer to the first byte of the current line to be encoded. * **prevline** (*unsigned char ") - A pointer to the data of the previous line. Ignored on the first call. * **prevprevline** (*unsigned char ") - A pointer to the data of the line before the previous line. Ignored on the first or second call. ``` -------------------------------- ### Patching BIE Header with jbg_newlen Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Use `jbg_newlen` to update the image height (Y_D) in a BIE header when the VLENGTH=1 option is set. This function scans the BIE for the first NEWLEN marker and overwrites the Y_D value. It can return error codes similar to `jbg_dec_in`. ```c int jbg_newlen(unsigned char *bie, size_t len); ``` -------------------------------- ### jbg_dec_merge_planes Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Merges individual bit planes into a multi-byte-per-pixel format using a callback function for output. ```APIDOC ## jbg_dec_merge_planes ### Description Merges the bit planes (accessible via `jbg_dec_getimage()`) into an array with one or more bytes per pixel, similar to the format provided to `jbg_split_planes()`. The output is delivered via a callback function. ### Parameters - **s** (const struct jbg_dec_state *) - Pointer to the decoder state structure. - **use_graycode** (int) - If zero, a binary encoding is used. Non-zero for graycode. - **data_out** (void (*)(unsigned char *start, size_t len, void *file)) - Callback function to receive the merged data. - **file** (void *) - User-defined data pointer passed to the callback function. ### Return Value None. ``` -------------------------------- ### Update JBIG85 Encoder Image Length Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Call jbg85_enc_newlen to announce the actual image height during encoding, especially when the initial estimate might change. This function can be called even after the last line is encoded. ```c void jbg85_enc_newlen(struct jbg85_enc_state *s, unsigned long newlen) ``` -------------------------------- ### jbg85_dec_getwidth Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Retrieves the width of the decoded JBIG image. ```APIDOC ## jbg85_dec_getwidth ### Description Retrieves the width of the decoded JBIG image. ### Function Signature ```c unsigned long jbg85_dec_getwidth(struct jbg85_dec_state *s); ``` ### Parameters #### `s` (struct jbg85_dec_state *) - A pointer to the initialized decoder state structure. ### Return Value - The width of the image in pixels. ``` -------------------------------- ### Feed Data to JBIG Decoder Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Pass data from the BIE to the decoder using jbg85_dec_in. Data can be fragmented across multiple calls. The cnt pointer receives the number of bytes read. ```c int jbg85_dec_in(struct jbg85_dec_state *s, unsigned char *data, size_t len, size_t *cnt); ``` -------------------------------- ### Retrieve Decoded Image Dimensions Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Query the width, height, and number of planes of a decoded JBIG image. These functions should be called after jbg_dec_in() returns JBG_EOK or JBG_EOK_INTR. ```c unsigned long jbg_dec_getwidth(struct jbg_dec_state *s); ``` ```c unsigned long jbg_dec_getheight(struct jbg_dec_state *s); ``` ```c int jbg_dec_getplanes(struct jbg_dec_state *s); ``` -------------------------------- ### Calculate Bitmap Size Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Calculate the number of bytes required for a single bitmap plane of the decoded image. This can be useful for memory allocation. ```c unsigned long jbg_dec_getsize(struct jbg_dec_state *s); ``` -------------------------------- ### jbg_strerror() Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Returns a pointer to a short single-line test message that explains the return value of jbg_dec_in(). This message can be used to provide the user with a brief informative message about what went wrong while decompressing a JBIG image. ```APIDOC ## jbg_strerror() ### Description Returns a human-readable error message corresponding to the return code from `jbg_dec_in()`. ### Usage ```c const char* jbg_strerror(int error_code); ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Returns a `const char*` pointing to an error message string. #### Response Example ``` "Input data stream uses unimplemented JBIG features" ``` ### Error Handling - `JBG_EOK`: Success. - Other codes indicate specific errors during decompression. ``` -------------------------------- ### jbg_enc_free Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Releases memory allocated by the JBIG encoder. This function should be called after compression is complete to free any heap memory used by the encoder. ```APIDOC ## jbg_enc_free ### Description Releases memory allocated by the JBIG encoder. This function should be called after compression is complete to free any heap memory used by the encoder. ### Function Signature ```c void jbg_enc_free(struct jbg_enc_state *s); ``` ### Parameters - **s** (*struct jbg_enc_state * *) - Required - A pointer to the jbg_enc_state structure to be freed. ``` -------------------------------- ### jbg_dec_maxsize Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Sets an abort criterion for progressively encoded images to prevent decoding excessively large images. ```APIDOC ## jbg_dec_maxsize ### Description Sets an abort criterion for progressively encoded images. If the decoded image exceeds the specified maximum dimensions, the decoding process will stop early. ### Parameters - **s** (struct jbg_dec_state *) - Pointer to the decoder state structure. - **xmax** (unsigned long) - The maximum allowed width in pixels. - **ymax** (unsigned long) - The maximum allowed height in pixels. ### Return Value None. ### Usage Call this function before starting the decoding process (i.e., before the first call to `jbg_dec_in()`). The application should still verify the actual image size after decoding, as the decoder does not automatically reduce resolution if no suitable layer is available. ``` -------------------------------- ### Splitting Image Planes for Grayscale Encoding Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Use this function to separate an image into individual bit planes for grayscale encoding. It handles images where pixels are represented by multiple bytes and allows extraction of specific bit planes. Ensure correct calculation of the source array length based on image dimensions and bits per pixel. ```c void jbg_split_planes(unsigned long x, unsigned long y, int has_planes, int encode_planes, const unsigned char *src, unsigned char **dest, int use_graycode); ``` -------------------------------- ### jbg85_dec_getheight Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Retrieves the height of the decoded JBIG image. ```APIDOC ## jbg85_dec_getheight ### Description Retrieves the height of the decoded JBIG image. ### Function Signature ```c unsigned long jbg85_dec_getheight(struct jbg85_dec_state *s); ``` ### Parameters #### `s` (struct jbg85_dec_state *) - A pointer to the initialized decoder state structure. ### Return Value - The height of the image in pixels. ``` -------------------------------- ### jbg_dec_in Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Processes a block of data for JBIG decoding. It can be called multiple times to handle fragmented data or multiple BIEs. It returns status codes indicating success, need for more data, or errors. ```APIDOC ## jbg_dec_in ### Description Processes a block of data for JBIG decoding. It can be called multiple times to handle fragmented data or multiple BIEs. It returns status codes indicating success, need for more data, or errors. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **s** (struct jbg_dec_state *) - Pointer to the decoder state structure. - **data** (const unsigned char *) - Pointer to the data block to be processed. - **len** (unsigned long) - The length of the data block in bytes. - **cnt** (unsigned long *) - Optional pointer to store the number of bytes actually read from the data block. ### Return Value - **JBG_EOK**: End of a BIE reached. - **JBG_EOK_INTR**: Largest resolution layer smaller than max size reached (progressive mode). - **JBG_EAGAIN**: More data is required to complete the current BIE. - **JBG_ENOCONT**: Error due to incompatible BIEs. - Other values indicate an error. ### Error Handling If any error occurs (return value other than JBG_EOK, JBG_EOK_INTR, or JBG_EAGAIN), call `jbg_dec_free()` to release allocated memory. ``` -------------------------------- ### jbg85_dec_in Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Feeds data from a BIE to the JBIG85 decoder. This function can be called multiple times to pass fragmented BIE data. It processes the input data and calls the `line_out` callback when lines are completed. ```APIDOC ## jbg85_dec_in ### Description Feeds data from a BIE to the JBIG85 decoder. This function can be called multiple times to pass fragmented BIE data. It processes the input data and calls the `line_out` callback when lines are completed. ### Function Signature ```c int jbg85_dec_in(struct jbg85_dec_state *s, unsigned char *data, size_t len, size_t *cnt); ``` ### Parameters #### `s` (struct jbg85_dec_state *) - A pointer to the initialized decoder state structure. #### `data` (unsigned char *) - A pointer to the first byte of the data block containing BIE data. #### `len` (size_t) - The length in bytes of the data block pointed to by `data`. #### `cnt` (size_t *) - Optional. If not NULL, the number of bytes actually read from the `data` block will be stored here. ### Return Value - **JBG_EAGAIN**: The decoder did not recognize the end of the BIE. `*cnt` will equal `len`. - **JBG_EOK**: The end of the BIE has been reached. - Non-zero value from `line_out` callback: Indicates an interrupt request. ``` -------------------------------- ### jbg_dec_getsize_merged Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig.txt Determines the total size of the data array that will be delivered by `jbg_dec_merge_planes()`. ```APIDOC ## jbg_dec_getsize_merged ### Description Determines the total size of the data array that will be delivered by the `jbg_dec_merge_planes()` function. ### Parameters - **s** (const struct jbg_dec_state *) - Pointer to the decoder state structure. ### Return Value - **unsigned long**: The size of the merged data array in bytes. ``` -------------------------------- ### Abort JBIG85 Encoding Process Source: https://github.com/nu774/jbigkit/blob/master/libjbig/jbig85.txt Use jbg85_enc_abort to send a special abort marker segment, typically used when no other method is available to signal the end of data to the decoder. ```c void jbg85_enc_abort(struct jbg85_enc_state *s); ```