Leptonica  1.54
Файл src/jpegio.c
#include <string.h>
#include "allheaders.h"
#include <setjmp.h>
#include "jpeglib.h"

Классы

struct  callback_data

Макросы

#define DEBUG_INFO   0

Функции

static void jpeg_error_catch_all_1 (j_common_ptr cinfo)
static void jpeg_error_catch_all_2 (j_common_ptr cinfo)
static l_uint8 jpeg_getc (j_decompress_ptr cinfo)
static boolean jpeg_comment_callback (j_decompress_ptr cinfo)
PIXpixReadJpeg (const char *filename, l_int32 cmapflag, l_int32 reduction, l_int32 *pnwarn, l_int32 hint)
PIXpixReadStreamJpeg (FILE *fp, l_int32 cmapflag, l_int32 reduction, l_int32 *pnwarn, l_int32 hint)
l_int32 readHeaderJpeg (const char *filename, l_int32 *pw, l_int32 *ph, l_int32 *pspp, l_int32 *pycck, l_int32 *pcmyk)
l_int32 freadHeaderJpeg (FILE *fp, l_int32 *pw, l_int32 *ph, l_int32 *pspp, l_int32 *pycck, l_int32 *pcmyk)
l_int32 fgetJpegResolution (FILE *fp, l_int32 *pxres, l_int32 *pyres)
l_int32 fgetJpegComment (FILE *fp, l_uint8 **pcomment)
l_int32 pixWriteJpeg (const char *filename, PIX *pix, l_int32 quality, l_int32 progressive)
l_int32 pixWriteStreamJpeg (FILE *fp, PIX *pixs, l_int32 quality, l_int32 progressive)
FILE * open_memstream (char **data, size_t *size)
FILE * fmemopen (void *data, size_t size, const char *mode)
PIXpixReadMemJpeg (const l_uint8 *data, size_t size, l_int32 cmflag, l_int32 reduction, l_int32 *pnwarn, l_int32 hint)
l_int32 readHeaderMemJpeg (const l_uint8 *data, size_t size, l_int32 *pw, l_int32 *ph, l_int32 *pspp, l_int32 *pycck, l_int32 *pcmyk)
l_int32 pixWriteMemJpeg (l_uint8 **pdata, size_t *psize, PIX *pix, l_int32 quality, l_int32 progressive)
l_int32 pixSetChromaSampling (PIX *pix, l_int32 sampling)

Макросы

#define DEBUG_INFO   0

Функции

l_int32 fgetJpegComment ( FILE *  fp,
l_uint8 **  pcomment 
)
l_int32 fgetJpegResolution ( FILE *  fp,
l_int32 pxres,
l_int32 pyres 
)
FILE* fmemopen ( void *  data,
size_t  size,
const char *  mode 
)
l_int32 freadHeaderJpeg ( FILE *  fp,
l_int32 pw,
l_int32 ph,
l_int32 pspp,
l_int32 pycck,
l_int32 pcmyk 
)

freadHeaderJpeg()

Input: stream &w (<optional return>="">) &h (<optional return>="">) &spp (<optional return>="">, samples/pixel) &ycck (<optional return>="">, 1 if ycck color space; 0 otherwise) &cmyk (<optional return>="">, 1 if cmyk color space; 0 otherwise) Return: 0 if OK, 1 on error

static boolean jpeg_comment_callback ( j_decompress_ptr  cinfo) [static]

jpeg_comment_callback()

Notes: (1) This is used to read the jpeg comment (JPEG_COM). See the note above the declaration for why it returns a "boolean".

static void jpeg_error_catch_all_1 ( j_common_ptr  cinfo) [static]

jpeg_error_catch_all_1()

Notes: (1) The default jpeg error_exit() kills the process, but we never want a call to leptonica to kill a process. If you do want this behavior, remove the calls to these error handlers. (2) This is used where cinfo->client_data holds only jmpbuf.

static void jpeg_error_catch_all_2 ( j_common_ptr  cinfo) [static]

jpeg_error_catch_all_2()

Notes: (1) This is used where cinfo->client_data needs to hold both the jmpbuf and the jpeg comment data. (2) On error, the comment data will be freed by the caller.

static l_uint8 jpeg_getc ( j_decompress_ptr  cinfo) [static]
FILE* open_memstream ( char **  data,
size_t *  size 
)
PIX* pixReadJpeg ( const char *  filename,
l_int32  cmapflag,
l_int32  reduction,
l_int32 pnwarn,
l_int32  hint 
)

pixReadJpeg()

Input: filename cmapflag (0 for no colormap in returned pix; 1 to return an 8 bpp cmapped pix if spp = 3 or 4) reduction (scaling factor: 1, 2, 4 or 8) &nwarn (<optional return>=""> number of warnings about corrupted data) hint (a bitwise OR of L_JPEG_* values; 0 for default) Return: pix, or null on error

Notes: (1) This is a special function for reading jpeg files. (2) Use this if you want the jpeg library to create an 8 bpp colormapped image. (3) Images reduced by factors of 2, 4 or 8 can be returned significantly faster than full resolution images. (4) If the jpeg data is bad, the jpeg library will continue silently, or return warnings, or attempt to exit. Depending on the severity of the data corruption, there are two possible outcomes: (a) a possibly damaged pix can be generated, along with zero or more warnings, or (b) the library will attempt to exit (caught by our error handler) and no pix will be returned. If a pix is generated with at least one warning of data corruption, and if L_JPEG_FAIL_ON_BAD_DATA is included in , no pix will be returned. (5) The possible hint values are given in the enum in imageio.h: * L_JPEG_READ_LUMINANCE * L_JPEG_FAIL_ON_BAD_DATA Default (0) is to do neither.

PIX* pixReadMemJpeg ( const l_uint8 data,
size_t  size,
l_int32  cmflag,
l_int32  reduction,
l_int32 pnwarn,
l_int32  hint 
)

pixReadMemJpeg()

Input: data (const; jpeg-encoded) size (of data) colormap flag (0 means return RGB image if color; 1 means create a colormap and return an 8 bpp colormapped image if color) reduction (scaling factor: 1, 2, 4 or 8) &nwarn (<optional return>=""> number of warnings) hint (a bitwise OR of L_JPEG_* values; 0 for default) Return: pix, or null on error

Notes: (1) The byte of must be a null character. (2) The only hint flag so far is L_JPEG_READ_LUMINANCE, given in the enum in imageio.h. (3) See pixReadJpeg() for usage.

PIX* pixReadStreamJpeg ( FILE *  fp,
l_int32  cmapflag,
l_int32  reduction,
l_int32 pnwarn,
l_int32  hint 
)

pixReadStreamJpeg()

Input: stream cmapflag (0 for no colormap in returned pix; 1 to return an 8 bpp cmapped pix if spp = 3 or 4) reduction (scaling factor: 1, 2, 4 or 8) &nwarn (<optional return>=""> number of warnings) hint (a bitwise OR of L_JPEG_* values; 0 for default) Return: pix, or null on error

Usage: see pixReadJpeg() Notes: (1) The jpeg comment, if it exists, is not stored in the pix.

l_int32 pixSetChromaSampling ( PIX pix,
l_int32  sampling 
)

pixSetChromaSampling()

Input: pix sampling (1 for subsampling; 0 for no subsampling) Return: 0 if OK, 1 on error

Notes: (1) The default is for 2x2 chroma subsampling because the files are considerably smaller and the appearance is typically satisfactory. To get full resolution output in the chroma channels for jpeg writing, call this with == 0.

l_int32 pixWriteJpeg ( const char *  filename,
PIX pix,
l_int32  quality,
l_int32  progressive 
)

pixWriteJpeg()

Input: filename pix (any depth; cmap is OK) quality (1 - 100; 75 is default) progressive (0 for baseline sequential; 1 for progressive) Return: 0 if OK; 1 on error

l_int32 pixWriteMemJpeg ( l_uint8 **  pdata,
size_t *  psize,
PIX pix,
l_int32  quality,
l_int32  progressive 
)

pixWriteMemJpeg()

Input: &data (<return> data of jpeg compressed image) &size (<return> size of returned data) pix (any depth; cmap is OK) quality (1 - 100; 75 is default value; 0 is also default) progressive (0 for baseline sequential; 1 for progressive) Return: 0 if OK, 1 on error

Notes: (1) See pixWriteStreamJpeg() for usage. This version writes to memory instead of to a file stream.

l_int32 pixWriteStreamJpeg ( FILE *  fp,
PIX pixs,
l_int32  quality,
l_int32  progressive 
)

pixWriteStreamJpeg()

Input: stream pixs (any depth; cmap is OK) quality (1 - 100; 75 is default value; 0 is also default) progressive (0 for baseline sequential; 1 for progressive) Return: 0 if OK, 1 on error

Notes: (1) Progressive encoding gives better compression, at the expense of slower encoding and decoding. (2) Standard chroma subsampling is 2x2 on both the U and V channels. For highest quality, use no subsampling; this option is set by pixSetChromaSampling(pix, 0). (3) The only valid pixel depths in leptonica are 1, 2, 4, 8, 16 and 32 bpp. However, it is possible, and in some cases desirable, to write out a jpeg file using an rgb pix that has 24 bpp. This can be created by appending the raster data for a 24 bpp image (with proper scanline padding) directly to a 24 bpp pix that was created without a data array. (4) There are two compression paths in this function: * Grayscale image, no colormap: compress as 8 bpp image. * rgb full color image: copy each line into the color line buffer, and compress as three 8 bpp images. (5) Under the covers, the jpeg library transforms rgb to a luminance-chromaticity triple, each component of which is also 8 bits, and compresses that. It uses 2 Huffman tables, a higher resolution one (with more quantization levels) for luminosity and a lower resolution one for the chromas.

l_int32 readHeaderJpeg ( const char *  filename,
l_int32 pw,
l_int32 ph,
l_int32 pspp,
l_int32 pycck,
l_int32 pcmyk 
)

readHeaderJpeg()

Input: filename &w (<optional return>="">) &h (<optional return>="">) &spp (<optional return>="">, samples/pixel) &ycck (<optional return>="">, 1 if ycck color space; 0 otherwise) &cmyk (<optional return>="">, 1 if cmyk color space; 0 otherwise) Return: 0 if OK, 1 on error

l_int32 readHeaderMemJpeg ( const l_uint8 data,
size_t  size,
l_int32 pw,
l_int32 ph,
l_int32 pspp,
l_int32 pycck,
l_int32 pcmyk 
)

readHeaderMemJpeg()

Input: data (const; jpeg-encoded) size (of data) &w (<optional return>="">) &h (<optional return>="">) &spp (<optional return>="">, samples/pixel) &ycck (<optional return>="">, 1 if ycck color space; 0 otherwise) &cmyk (<optional return>="">, 1 if cmyk color space; 0 otherwise) Return: 0 if OK, 1 on error