Commit dedb7358 authored by virgile devaux's avatar virgile devaux Committed by Davis E. King
Browse files

Feature/upgrade libjpeg (#1769)

* Upgrades dlib's included libjpeg to version 8d

* Overloads load_jpeg to read from memory buffer

* Removes "__inline__" define in jconfig, broke VC build

* Changes buffer size type to size_t
parent f0e1d4e4
...@@ -504,50 +504,72 @@ if (NOT TARGET dlib) ...@@ -504,50 +504,72 @@ if (NOT TARGET dlib)
# If we can't find libjpeg then statically compile it in. # If we can't find libjpeg then statically compile it in.
add_definitions(-DDLIB_JPEG_STATIC) add_definitions(-DDLIB_JPEG_STATIC)
set(source_files ${source_files} set(source_files ${source_files}
external/libjpeg/jcomapi.cpp external/libjpeg/jaricom.c
external/libjpeg/jdapimin.cpp external/libjpeg/jcapimin.c
external/libjpeg/jdapistd.cpp external/libjpeg/jcapistd.c
external/libjpeg/jdatasrc.cpp external/libjpeg/jcarith.c
external/libjpeg/jdcoefct.cpp external/libjpeg/jccoefct.c
external/libjpeg/jdcolor.cpp external/libjpeg/jccolor.c
external/libjpeg/jddctmgr.cpp external/libjpeg/jcdctmgr.c
external/libjpeg/jdhuff.cpp external/libjpeg/jchuff.c
external/libjpeg/jdinput.cpp external/libjpeg/jcinit.c
external/libjpeg/jdmainct.cpp external/libjpeg/jcmainct.c
external/libjpeg/jdmarker.cpp external/libjpeg/jcmarker.c
external/libjpeg/jdmaster.cpp external/libjpeg/jcmaster.c
external/libjpeg/jdmerge.cpp external/libjpeg/jcomapi.c
external/libjpeg/jdphuff.cpp external/libjpeg/jcparam.c
external/libjpeg/jdpostct.cpp external/libjpeg/jcprepct.c
external/libjpeg/jdsample.cpp external/libjpeg/jcsample.c
external/libjpeg/jerror.cpp external/libjpeg/jctrans.c
external/libjpeg/jidctflt.cpp external/libjpeg/jdapimin.c
external/libjpeg/jidctfst.cpp external/libjpeg/jdapistd.c
external/libjpeg/jidctint.cpp external/libjpeg/jdarith.c
external/libjpeg/jidctred.cpp external/libjpeg/jdatadst.c
external/libjpeg/jmemmgr.cpp external/libjpeg/jdatasrc.c
external/libjpeg/jmemnobs.cpp external/libjpeg/jdcoefct.c
external/libjpeg/jquant1.cpp external/libjpeg/jdcolor.c
external/libjpeg/jquant2.cpp external/libjpeg/jddctmgr.c
external/libjpeg/jutils.cpp external/libjpeg/jdhuff.c
external/libjpeg/jcapimin.cpp external/libjpeg/jdinput.c
external/libjpeg/jdatadst.cpp external/libjpeg/jdmainct.c
external/libjpeg/jcparam.cpp external/libjpeg/jdmarker.c
external/libjpeg/jcapistd.cpp external/libjpeg/jdmaster.c
external/libjpeg/jcmarker.cpp external/libjpeg/jdmerge.c
external/libjpeg/jcinit.cpp external/libjpeg/jdpostct.c
external/libjpeg/jcmaster.cpp external/libjpeg/jdsample.c
external/libjpeg/jcdctmgr.cpp external/libjpeg/jdtrans.c
external/libjpeg/jccoefct.cpp external/libjpeg/jerror.c
external/libjpeg/jccolor.cpp external/libjpeg/jerror.h
external/libjpeg/jchuff.cpp external/libjpeg/jfdctflt.c
external/libjpeg/jcmainct.cpp external/libjpeg/jfdctfst.c
external/libjpeg/jcphuff.cpp external/libjpeg/jfdctint.c
external/libjpeg/jcprepct.cpp external/libjpeg/jidctflt.c
external/libjpeg/jcsample.cpp external/libjpeg/jidctfst.c
external/libjpeg/jfdctint.cpp external/libjpeg/jidctint.c
external/libjpeg/jfdctflt.cpp external/libjpeg/jinclude.h
external/libjpeg/jfdctfst.cpp external/libjpeg/jmemansi.c
external/libjpeg/jmemmgr.c
external/libjpeg/jmemname.c
external/libjpeg/jmemnobs.c
external/libjpeg/jpegtran.c
external/libjpeg/jquant1.c
external/libjpeg/jquant2.c
external/libjpeg/jutils.c
external/libjpeg/rdbmp.c
external/libjpeg/rdcolmap.c
external/libjpeg/rdgif.c
external/libjpeg/rdjpgcom.c
external/libjpeg/rdppm.c
external/libjpeg/rdrle.c
external/libjpeg/rdswitch.c
external/libjpeg/rdtarga.c
external/libjpeg/transupp.c
external/libjpeg/wrbmp.c
external/libjpeg/wrgif.c
external/libjpeg/wrjpgcom.c
external/libjpeg/wrppm.c
external/libjpeg/wrrle.c
external/libjpeg/wrtarga.c
) )
endif() endif()
set(source_files ${source_files} set(source_files ${source_files}
......
This diff is collapsed.
/*
* cderror.h
*
* Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file defines the error and message codes for the cjpeg/djpeg
* applications. These strings are not needed as part of the JPEG library
* proper.
* Edit this file to add new codes, or to translate the message strings to
* some other language.
*/
/*
* To define the enum list of message codes, include this file without
* defining macro JMESSAGE. To create a message string table, include it
* again with a suitable JMESSAGE definition (see jerror.c for an example).
*/
#ifndef JMESSAGE
#ifndef CDERROR_H
#define CDERROR_H
/* First time through, define the enum list */
#define JMAKE_ENUM_LIST
#else
/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
#define JMESSAGE(code,string)
#endif /* CDERROR_H */
#endif /* JMESSAGE */
#ifdef JMAKE_ENUM_LIST
typedef enum {
#define JMESSAGE(code,string) code ,
#endif /* JMAKE_ENUM_LIST */
JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */
#ifdef BMP_SUPPORTED
JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
JMESSAGE(JERR_BMP_EMPTY, "Empty BMP image")
JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
#endif /* BMP_SUPPORTED */
#ifdef GIF_SUPPORTED
JMESSAGE(JERR_GIF_BUG, "GIF output got confused")
JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d")
JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
JMESSAGE(JTRC_GIF_BADVERSION,
"Warning: unexpected GIF version number '%c%c%c'")
JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x")
JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input")
JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file")
JMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring")
JMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image")
JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
#endif /* GIF_SUPPORTED */
#ifdef PPM_SUPPORTED
JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
JMESSAGE(JTRC_PGM, "%ux%u PGM image")
JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
JMESSAGE(JTRC_PPM, "%ux%u PPM image")
JMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image")
#endif /* PPM_SUPPORTED */
#ifdef RLE_SUPPORTED
JMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library")
JMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB")
JMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE")
JMESSAGE(JERR_RLE_EMPTY, "Empty RLE file")
JMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header")
JMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header")
JMESSAGE(JERR_RLE_NOT, "Not an RLE file")
JMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE")
JMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup")
JMESSAGE(JTRC_RLE, "%ux%u full-color RLE file")
JMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d")
JMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file")
JMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d")
JMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d")
#endif /* RLE_SUPPORTED */
#ifdef TARGA_SUPPORTED
JMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format")
JMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file")
JMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB")
JMESSAGE(JTRC_TGA, "%ux%u RGB Targa image")
JMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image")
JMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image")
#else
JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled")
#endif /* TARGA_SUPPORTED */
JMESSAGE(JERR_BAD_CMAP_FILE,
"Color map file is invalid or of unsupported format")
JMESSAGE(JERR_TOO_MANY_COLORS,
"Output file format cannot handle %d colormap entries")
JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed")
#ifdef TARGA_SUPPORTED
JMESSAGE(JERR_UNKNOWN_FORMAT,
"Unrecognized input file format --- perhaps you need -targa")
#else
JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format")
#endif
JMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format")
#ifdef JMAKE_ENUM_LIST
JMSG_LASTADDONCODE
} ADDON_MESSAGE_CODE;
#undef JMAKE_ENUM_LIST
#endif /* JMAKE_ENUM_LIST */
/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
#undef JMESSAGE
/*
* cdjpeg.h
*
* Copyright (C) 1994-1997, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains common declarations for the sample applications
* cjpeg and djpeg. It is NOT used by the core JPEG library.
*/
#define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
#define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
#include "jinclude.h"
#include "jpeglib.h"
#include "jerror.h" /* get library error codes too */
#include "cderror.h" /* get application-specific error codes */
/*
* Object interface for cjpeg's source file decoding modules
*/
typedef struct cjpeg_source_struct * cjpeg_source_ptr;
struct cjpeg_source_struct {
JMETHOD(void, start_input, (j_compress_ptr cinfo,
cjpeg_source_ptr sinfo));
JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
cjpeg_source_ptr sinfo));
JMETHOD(void, finish_input, (j_compress_ptr cinfo,
cjpeg_source_ptr sinfo));
FILE *input_file;
JSAMPARRAY buffer;
JDIMENSION buffer_height;
};
/*
* Object interface for djpeg's output file encoding modules
*/
typedef struct djpeg_dest_struct * djpeg_dest_ptr;
struct djpeg_dest_struct {
/* start_output is called after jpeg_start_decompress finishes.
* The color map will be ready at this time, if one is needed.
*/
JMETHOD(void, start_output, (j_decompress_ptr cinfo,
djpeg_dest_ptr dinfo));
/* Emit the specified number of pixel rows from the buffer. */
JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,
djpeg_dest_ptr dinfo,
JDIMENSION rows_supplied));
/* Finish up at the end of the image. */
JMETHOD(void, finish_output, (j_decompress_ptr cinfo,
djpeg_dest_ptr dinfo));
/* Target file spec; filled in by djpeg.c after object is created. */
FILE * output_file;
/* Output pixel-row buffer. Created by module init or start_output.
* Width is cinfo->output_width * cinfo->output_components;
* height is buffer_height.
*/
JSAMPARRAY buffer;
JDIMENSION buffer_height;
};
/*
* cjpeg/djpeg may need to perform extra passes to convert to or from
* the source/destination file format. The JPEG library does not know
* about these passes, but we'd like them to be counted by the progress
* monitor. We use an expanded progress monitor object to hold the
* additional pass count.
*/
struct cdjpeg_progress_mgr {
struct jpeg_progress_mgr pub; /* fields known to JPEG library */
int completed_extra_passes; /* extra passes completed */
int total_extra_passes; /* total extra */
/* last printed percentage stored here to avoid multiple printouts */
int percent_done;
};
typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
/* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jinit_read_bmp jIRdBMP
#define jinit_write_bmp jIWrBMP
#define jinit_read_gif jIRdGIF
#define jinit_write_gif jIWrGIF
#define jinit_read_ppm jIRdPPM
#define jinit_write_ppm jIWrPPM
#define jinit_read_rle jIRdRLE
#define jinit_write_rle jIWrRLE
#define jinit_read_targa jIRdTarga
#define jinit_write_targa jIWrTarga
#define read_quant_tables RdQTables
#define read_scan_script RdScnScript
#define set_quality_ratings SetQRates
#define set_quant_slots SetQSlots
#define set_sample_factors SetSFacts
#define read_color_map RdCMap
#define enable_signal_catcher EnSigCatcher
#define start_progress_monitor StProgMon
#define end_progress_monitor EnProgMon
#define read_stdin RdStdin
#define write_stdout WrStdout
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Module selection routines for I/O modules. */
EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
boolean is_os2));
EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
/* cjpeg support routines (in rdswitch.c) */
EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
boolean force_baseline));
EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg,
boolean force_baseline));
EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
/* djpeg support routines (in rdcolmap.c) */
EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
/* common support routines (in cdjpeg.c) */
EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));
EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,
cd_progress_ptr progress));
EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));
EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));
EXTERN(FILE *) read_stdin JPP((void));
EXTERN(FILE *) write_stdout JPP((void));
/* miscellaneous useful macros */
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r"
#define WRITE_BINARY "w"
#else
#ifdef VMS /* VMS is very nonstandard */
#define READ_BINARY "rb", "ctx=stm"
#define WRITE_BINARY "wb", "ctx=stm"
#else /* standard ANSI-compliant case */
#define READ_BINARY "rb"
#define WRITE_BINARY "wb"
#endif
#endif
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
#define EXIT_FAILURE 1
#endif
#ifndef EXIT_SUCCESS
#ifdef VMS
#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
#else
#define EXIT_SUCCESS 0
#endif
#endif
#ifndef EXIT_WARNING
#ifdef VMS
#define EXIT_WARNING 1 /* VMS is very nonstandard */
#else
#define EXIT_WARNING 2
#endif
#endif
/*
* jaricom.c
*
* Developed 1997-2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains probability estimation tables for common use in
* arithmetic entropy encoding and decoding routines.
*
* This data represents Table D.3 in the JPEG spec (D.2 in the draft),
* ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81, and Table 24
* in the JBIG spec, ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82.
*/
#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglib.h"
/* The following #define specifies the packing of the four components
* into the compact INT32 representation.
* Note that this formula must match the actual arithmetic encoder
* and decoder implementation. The implementation has to be changed
* if this formula is changed.
* The current organization is leaned on Markus Kuhn's JBIG
* implementation (jbig_tab.c).
*/
#define V(i,a,b,c,d) (((INT32)a << 16) | ((INT32)c << 8) | ((INT32)d << 7) | b)
const INT32 jpeg_aritab[113+1] = {
/*
* Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS
*/
V( 0, 0x5a1d, 1, 1, 1 ),
V( 1, 0x2586, 14, 2, 0 ),
V( 2, 0x1114, 16, 3, 0 ),
V( 3, 0x080b, 18, 4, 0 ),
V( 4, 0x03d8, 20, 5, 0 ),
V( 5, 0x01da, 23, 6, 0 ),
V( 6, 0x00e5, 25, 7, 0 ),
V( 7, 0x006f, 28, 8, 0 ),
V( 8, 0x0036, 30, 9, 0 ),
V( 9, 0x001a, 33, 10, 0 ),
V( 10, 0x000d, 35, 11, 0 ),
V( 11, 0x0006, 9, 12, 0 ),
V( 12, 0x0003, 10, 13, 0 ),
V( 13, 0x0001, 12, 13, 0 ),
V( 14, 0x5a7f, 15, 15, 1 ),
V( 15, 0x3f25, 36, 16, 0 ),
V( 16, 0x2cf2, 38, 17, 0 ),
V( 17, 0x207c, 39, 18, 0 ),
V( 18, 0x17b9, 40, 19, 0 ),
V( 19, 0x1182, 42, 20, 0 ),
V( 20, 0x0cef, 43, 21, 0 ),
V( 21, 0x09a1, 45, 22, 0 ),
V( 22, 0x072f, 46, 23, 0 ),
V( 23, 0x055c, 48, 24, 0 ),
V( 24, 0x0406, 49, 25, 0 ),
V( 25, 0x0303, 51, 26, 0 ),
V( 26, 0x0240, 52, 27, 0 ),
V( 27, 0x01b1, 54, 28, 0 ),
V( 28, 0x0144, 56, 29, 0 ),
V( 29, 0x00f5, 57, 30, 0 ),
V( 30, 0x00b7, 59, 31, 0 ),
V( 31, 0x008a, 60, 32, 0 ),
V( 32, 0x0068, 62, 33, 0 ),
V( 33, 0x004e, 63, 34, 0 ),
V( 34, 0x003b, 32, 35, 0 ),
V( 35, 0x002c, 33, 9, 0 ),
V( 36, 0x5ae1, 37, 37, 1 ),
V( 37, 0x484c, 64, 38, 0 ),
V( 38, 0x3a0d, 65, 39, 0 ),
V( 39, 0x2ef1, 67, 40, 0 ),
V( 40, 0x261f, 68, 41, 0 ),
V( 41, 0x1f33, 69, 42, 0 ),
V( 42, 0x19a8, 70, 43, 0 ),
V( 43, 0x1518, 72, 44, 0 ),
V( 44, 0x1177, 73, 45, 0 ),
V( 45, 0x0e74, 74, 46, 0 ),
V( 46, 0x0bfb, 75, 47, 0 ),
V( 47, 0x09f8, 77, 48, 0 ),
V( 48, 0x0861, 78, 49, 0 ),
V( 49, 0x0706, 79, 50, 0 ),
V( 50, 0x05cd, 48, 51, 0 ),
V( 51, 0x04de, 50, 52, 0 ),
V( 52, 0x040f, 50, 53, 0 ),
V( 53, 0x0363, 51, 54, 0 ),
V( 54, 0x02d4, 52, 55, 0 ),
V( 55, 0x025c, 53, 56, 0 ),
V( 56, 0x01f8, 54, 57, 0 ),
V( 57, 0x01a4, 55, 58, 0 ),
V( 58, 0x0160, 56, 59, 0 ),
V( 59, 0x0125, 57, 60, 0 ),
V( 60, 0x00f6, 58, 61, 0 ),
V( 61, 0x00cb, 59, 62, 0 ),
V( 62, 0x00ab, 61, 63, 0 ),
V( 63, 0x008f, 61, 32, 0 ),
V( 64, 0x5b12, 65, 65, 1 ),
V( 65, 0x4d04, 80, 66, 0 ),
V( 66, 0x412c, 81, 67, 0 ),
V( 67, 0x37d8, 82, 68, 0 ),
V( 68, 0x2fe8, 83, 69, 0 ),
V( 69, 0x293c, 84, 70, 0 ),
V( 70, 0x2379, 86, 71, 0 ),
V( 71, 0x1edf, 87, 72, 0 ),
V( 72, 0x1aa9, 87, 73, 0 ),
V( 73, 0x174e, 72, 74, 0 ),
V( 74, 0x1424, 72, 75, 0 ),
V( 75, 0x119c, 74, 76, 0 ),
V( 76, 0x0f6b, 74, 77, 0 ),
V( 77, 0x0d51, 75, 78, 0 ),
V( 78, 0x0bb6, 77, 79, 0 ),
V( 79, 0x0a40, 77, 48, 0 ),
V( 80, 0x5832, 80, 81, 1 ),
V( 81, 0x4d1c, 88, 82, 0 ),
V( 82, 0x438e, 89, 83, 0 ),
V( 83, 0x3bdd, 90, 84, 0 ),
V( 84, 0x34ee, 91, 85, 0 ),
V( 85, 0x2eae, 92, 86, 0 ),
V( 86, 0x299a, 93, 87, 0 ),
V( 87, 0x2516, 86, 71, 0 ),
V( 88, 0x5570, 88, 89, 1 ),
V( 89, 0x4ca9, 95, 90, 0 ),
V( 90, 0x44d9, 96, 91, 0 ),
V( 91, 0x3e22, 97, 92, 0 ),
V( 92, 0x3824, 99, 93, 0 ),
V( 93, 0x32b4, 99, 94, 0 ),
V( 94, 0x2e17, 93, 86, 0 ),
V( 95, 0x56a8, 95, 96, 1 ),
V( 96, 0x4f46, 101, 97, 0 ),
V( 97, 0x47e5, 102, 98, 0 ),
V( 98, 0x41cf, 103, 99, 0 ),
V( 99, 0x3c3d, 104, 100, 0 ),
V( 100, 0x375e, 99, 93, 0 ),
V( 101, 0x5231, 105, 102, 0 ),
V( 102, 0x4c0f, 106, 103, 0 ),
V( 103, 0x4639, 107, 104, 0 ),
V( 104, 0x415e, 103, 99, 0 ),
V( 105, 0x5627, 105, 106, 1 ),
V( 106, 0x50e7, 108, 107, 0 ),
V( 107, 0x4b85, 109, 103, 0 ),
V( 108, 0x5597, 110, 109, 0 ),
V( 109, 0x504f, 111, 107, 0 ),
V( 110, 0x5a10, 110, 111, 1 ),
V( 111, 0x5522, 112, 109, 0 ),
V( 112, 0x59eb, 112, 111, 1 ),
/*
* This last entry is used for fixed probability estimate of 0.5
* as suggested in Section 10.3 Table 5 of ITU-T Rec. T.851.
*/
V( 113, 0x5a1d, 113, 113, 0 )
};
/* /*
* jcapimin.c * jcapimin.c
* *
* Copyright (C) 1994-1998, Thomas G. Lane. * Copyright (C) 1994-1998, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * Modified 2003-2010 by Guido Vollbeding.
* For conditions of distribution and use, see the accompanying README file. * This file is part of the Independent JPEG Group's software.
* * For conditions of distribution and use, see the accompanying README file.
* This file contains application interface code for the compression half *
* of the JPEG library. These are the "minimum" API routines that may be * This file contains application interface code for the compression half
* needed in either the normal full-compression case or the transcoding-only * of the JPEG library. These are the "minimum" API routines that may be
* case. * needed in either the normal full-compression case or the transcoding-only
* * case.
* Most of the routines intended to be called directly by an application *
* are in this file or in jcapistd.c. But also see jcparam.c for * Most of the routines intended to be called directly by an application
* parameter-setup helper routines, jcomapi.c for routines shared by * are in this file or in jcapistd.c. But also see jcparam.c for
* compression and decompression, and jctrans.c for the transcoding case. * parameter-setup helper routines, jcomapi.c for routines shared by
*/ * compression and decompression, and jctrans.c for the transcoding case.
*/
#define JPEG_INTERNALS
#include "jinclude.h" #define JPEG_INTERNALS
#include "jpeglib.h" #include "jinclude.h"
#include "jpeglib.h"
/*
* Initialization of a JPEG compression object. /*
* The error manager must already be set up (in case memory manager fails). * Initialization of a JPEG compression object.
*/ * The error manager must already be set up (in case memory manager fails).
*/
GLOBAL(void)
jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize) GLOBAL(void)
{ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
int i; {
int i;
/* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ /* Guard against version mismatches between library and caller. */
if (version != JPEG_LIB_VERSION) cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); if (version != JPEG_LIB_VERSION)
if (structsize != SIZEOF(struct jpeg_compress_struct)) ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, if (structsize != SIZEOF(struct jpeg_compress_struct))
(int) SIZEOF(struct jpeg_compress_struct), (int) structsize); ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
(int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
/* For debugging purposes, we zero the whole master structure.
* But the application has already set the err pointer, and may have set /* For debugging purposes, we zero the whole master structure.
* client_data, so we have to save and restore those fields. * But the application has already set the err pointer, and may have set
* Note: if application hasn't set client_data, tools like Purify may * client_data, so we have to save and restore those fields.
* complain here. * Note: if application hasn't set client_data, tools like Purify may
*/ * complain here.
{ */
struct jpeg_error_mgr * err = cinfo->err; {
void * client_data = cinfo->client_data; /* ignore Purify complaint here */ struct jpeg_error_mgr * err = cinfo->err;
MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct)); void * client_data = cinfo->client_data; /* ignore Purify complaint here */
cinfo->err = err; MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
cinfo->client_data = client_data; cinfo->err = err;
} cinfo->client_data = client_data;
cinfo->is_decompressor = FALSE; }
cinfo->is_decompressor = FALSE;
/* Initialize a memory manager instance for this object */
jinit_memory_mgr((j_common_ptr) cinfo); /* Initialize a memory manager instance for this object */
jinit_memory_mgr((j_common_ptr) cinfo);
/* Zero out pointers to permanent structures. */
cinfo->progress = NULL; /* Zero out pointers to permanent structures. */
cinfo->dest = NULL; cinfo->progress = NULL;
cinfo->dest = NULL;
cinfo->comp_info = NULL;
cinfo->comp_info = NULL;
for (i = 0; i < NUM_QUANT_TBLS; i++)
cinfo->quant_tbl_ptrs[i] = NULL; for (i = 0; i < NUM_QUANT_TBLS; i++) {
cinfo->quant_tbl_ptrs[i] = NULL;
for (i = 0; i < NUM_HUFF_TBLS; i++) { cinfo->q_scale_factor[i] = 100;
cinfo->dc_huff_tbl_ptrs[i] = NULL; }
cinfo->ac_huff_tbl_ptrs[i] = NULL;
} for (i = 0; i < NUM_HUFF_TBLS; i++) {
cinfo->dc_huff_tbl_ptrs[i] = NULL;
cinfo->script_space = NULL; cinfo->ac_huff_tbl_ptrs[i] = NULL;
}
cinfo->input_gamma = 1.0; /* in case application forgets */
/* Must do it here for emit_dqt in case jpeg_write_tables is used */
/* OK, I'm ready */ cinfo->block_size = DCTSIZE;
cinfo->global_state = CSTATE_START; cinfo->natural_order = jpeg_natural_order;
} cinfo->lim_Se = DCTSIZE2-1;
cinfo->script_space = NULL;
/*
* Destruction of a JPEG compression object cinfo->input_gamma = 1.0; /* in case application forgets */
*/
/* OK, I'm ready */
GLOBAL(void) cinfo->global_state = CSTATE_START;
jpeg_destroy_compress (j_compress_ptr cinfo) }
{
jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
} /*
* Destruction of a JPEG compression object
*/
/*
* Abort processing of a JPEG compression operation, GLOBAL(void)
* but don't destroy the object itself. jpeg_destroy_compress (j_compress_ptr cinfo)
*/ {
jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
GLOBAL(void) }
jpeg_abort_compress (j_compress_ptr cinfo)
{
jpeg_abort((j_common_ptr) cinfo); /* use common routine */ /*
} * Abort processing of a JPEG compression operation,
* but don't destroy the object itself.
*/
/*
* Forcibly suppress or un-suppress all quantization and Huffman tables. GLOBAL(void)
* Marks all currently defined tables as already written (if suppress) jpeg_abort_compress (j_compress_ptr cinfo)
* or not written (if !suppress). This will control whether they get emitted {
* by a subsequent jpeg_start_compress call. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
* }
* This routine is exported for use by applications that want to produce
* abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
* since it is called by jpeg_start_compress, we put it here --- otherwise /*
* jcparam.o would be linked whether the application used it or not. * Forcibly suppress or un-suppress all quantization and Huffman tables.
*/ * Marks all currently defined tables as already written (if suppress)
* or not written (if !suppress). This will control whether they get emitted
GLOBAL(void) * by a subsequent jpeg_start_compress call.
jpeg_suppress_tables (j_compress_ptr cinfo, int suppress) *
{ * This routine is exported for use by applications that want to produce
int i; * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
JQUANT_TBL * qtbl; * since it is called by jpeg_start_compress, we put it here --- otherwise
JHUFF_TBL * htbl; * jcparam.o would be linked whether the application used it or not.
*/
for (i = 0; i < NUM_QUANT_TBLS; i++) {
if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL) GLOBAL(void)
qtbl->sent_table = suppress; jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
} {
int i;
for (i = 0; i < NUM_HUFF_TBLS; i++) { JQUANT_TBL * qtbl;
if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL) JHUFF_TBL * htbl;
htbl->sent_table = suppress;
if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL) for (i = 0; i < NUM_QUANT_TBLS; i++) {
htbl->sent_table = suppress; if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
} qtbl->sent_table = suppress;
} }
for (i = 0; i < NUM_HUFF_TBLS; i++) {
/* if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
* Finish JPEG compression. htbl->sent_table = suppress;
* if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
* If a multipass operating mode was selected, this may do a great deal of htbl->sent_table = suppress;
* work including most of the actual output. }
*/ }
GLOBAL(void)
jpeg_finish_compress (j_compress_ptr cinfo) /*
{ * Finish JPEG compression.
JDIMENSION iMCU_row; *
* If a multipass operating mode was selected, this may do a great deal of
if (cinfo->global_state == CSTATE_SCANNING || * work including most of the actual output.
cinfo->global_state == CSTATE_RAW_OK) { */
/* Terminate first pass */
if (cinfo->next_scanline < cinfo->image_height) GLOBAL(void)
ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); jpeg_finish_compress (j_compress_ptr cinfo)
(*cinfo->master->finish_pass) (cinfo); {
} else if (cinfo->global_state != CSTATE_WRCOEFS) JDIMENSION iMCU_row;
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* Perform any remaining passes */ if (cinfo->global_state == CSTATE_SCANNING ||
while (! cinfo->master->is_last_pass) { cinfo->global_state == CSTATE_RAW_OK) {
(*cinfo->master->prepare_for_pass) (cinfo); /* Terminate first pass */
for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { if (cinfo->next_scanline < cinfo->image_height)
if (cinfo->progress != NULL) { ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
cinfo->progress->pass_counter = (long) iMCU_row; (*cinfo->master->finish_pass) (cinfo);
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; } else if (cinfo->global_state != CSTATE_WRCOEFS)
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
} /* Perform any remaining passes */
/* We bypass the main controller and invoke coef controller directly; while (! cinfo->master->is_last_pass) {
* all work is being done from the coefficient buffer. (*cinfo->master->prepare_for_pass) (cinfo);
*/ for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) if (cinfo->progress != NULL) {
ERREXIT(cinfo, JERR_CANT_SUSPEND); cinfo->progress->pass_counter = (long) iMCU_row;
} cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
(*cinfo->master->finish_pass) (cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
} }
/* Write EOI, do final cleanup */ /* We bypass the main controller and invoke coef controller directly;
(*cinfo->marker->write_file_trailer) (cinfo); * all work is being done from the coefficient buffer.
(*cinfo->dest->term_destination) (cinfo); */
/* We can use jpeg_abort to release memory and reset global_state */ if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
jpeg_abort((j_common_ptr) cinfo); ERREXIT(cinfo, JERR_CANT_SUSPEND);
} }
(*cinfo->master->finish_pass) (cinfo);
}
/* /* Write EOI, do final cleanup */
* Write a special marker. (*cinfo->marker->write_file_trailer) (cinfo);
* This is only recommended for writing COM or APPn markers. (*cinfo->dest->term_destination) (cinfo);
* Must be called after jpeg_start_compress() and before /* We can use jpeg_abort to release memory and reset global_state */
* first call to jpeg_write_scanlines() or jpeg_write_raw_data(). jpeg_abort((j_common_ptr) cinfo);
*/ }
GLOBAL(void)
jpeg_write_marker (j_compress_ptr cinfo, int marker, /*
const JOCTET *dataptr, unsigned int datalen) * Write a special marker.
{ * This is only recommended for writing COM or APPn markers.
JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val)); * Must be called after jpeg_start_compress() and before
* first call to jpeg_write_scanlines() or jpeg_write_raw_data().
if (cinfo->next_scanline != 0 || */
(cinfo->global_state != CSTATE_SCANNING &&
cinfo->global_state != CSTATE_RAW_OK && GLOBAL(void)
cinfo->global_state != CSTATE_WRCOEFS)) jpeg_write_marker (j_compress_ptr cinfo, int marker,
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); const JOCTET *dataptr, unsigned int datalen)
{
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen); JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
while (datalen--) { if (cinfo->next_scanline != 0 ||
(*write_marker_byte) (cinfo, *dataptr); (cinfo->global_state != CSTATE_SCANNING &&
dataptr++; cinfo->global_state != CSTATE_RAW_OK &&
} cinfo->global_state != CSTATE_WRCOEFS))
} ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* Same, but piecemeal. */ (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
GLOBAL(void) while (datalen--) {
jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen) (*write_marker_byte) (cinfo, *dataptr);
{ dataptr++;
if (cinfo->next_scanline != 0 || }
(cinfo->global_state != CSTATE_SCANNING && }
cinfo->global_state != CSTATE_RAW_OK &&
cinfo->global_state != CSTATE_WRCOEFS)) /* Same, but piecemeal. */
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
GLOBAL(void)
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen); jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
} {
if (cinfo->next_scanline != 0 ||
GLOBAL(void) (cinfo->global_state != CSTATE_SCANNING &&
jpeg_write_m_byte (j_compress_ptr cinfo, int val) cinfo->global_state != CSTATE_RAW_OK &&
{ cinfo->global_state != CSTATE_WRCOEFS))
(*cinfo->marker->write_marker_byte) (cinfo, val); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
}
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
}
/*
* Alternate compression function: just write an abbreviated table file. GLOBAL(void)
* Before calling this, all parameters and a data destination must be set up. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
* {
* To produce a pair of files containing abbreviated tables and abbreviated (*cinfo->marker->write_marker_byte) (cinfo, val);
* image data, one would proceed as follows: }
*
* initialize JPEG object
* set JPEG parameters /*
* set destination to table file * Alternate compression function: just write an abbreviated table file.
* jpeg_write_tables(cinfo); * Before calling this, all parameters and a data destination must be set up.
* set destination to image file *
* jpeg_start_compress(cinfo, FALSE); * To produce a pair of files containing abbreviated tables and abbreviated
* write data... * image data, one would proceed as follows:
* jpeg_finish_compress(cinfo); *
* * initialize JPEG object
* jpeg_write_tables has the side effect of marking all tables written * set JPEG parameters
* (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress * set destination to table file
* will not re-emit the tables unless it is passed write_all_tables=TRUE. * jpeg_write_tables(cinfo);
*/ * set destination to image file
* jpeg_start_compress(cinfo, FALSE);
GLOBAL(void) * write data...
jpeg_write_tables (j_compress_ptr cinfo) * jpeg_finish_compress(cinfo);
{ *
if (cinfo->global_state != CSTATE_START) * jpeg_write_tables has the side effect of marking all tables written
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
* will not re-emit the tables unless it is passed write_all_tables=TRUE.
/* (Re)initialize error mgr and destination modules */ */
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
(*cinfo->dest->init_destination) (cinfo); GLOBAL(void)
/* Initialize the marker writer ... bit of a crock to do it here. */ jpeg_write_tables (j_compress_ptr cinfo)
jinit_marker_writer(cinfo); {
/* Write them tables! */ if (cinfo->global_state != CSTATE_START)
(*cinfo->marker->write_tables_only) (cinfo); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* And clean up. */
(*cinfo->dest->term_destination) (cinfo); /* (Re)initialize error mgr and destination modules */
/* (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
* In library releases up through v6a, we called jpeg_abort() here to free (*cinfo->dest->init_destination) (cinfo);
* any working memory allocated by the destination manager and marker /* Initialize the marker writer ... bit of a crock to do it here. */
* writer. Some applications had a problem with that: they allocated space jinit_marker_writer(cinfo);
* of their own from the library memory manager, and didn't want it to go /* Write them tables! */
* away during write_tables. So now we do nothing. This will cause a (*cinfo->marker->write_tables_only) (cinfo);
* memory leak if an app calls write_tables repeatedly without doing a full /* And clean up. */
* compression cycle or otherwise resetting the JPEG object. However, that (*cinfo->dest->term_destination) (cinfo);
* seems less bad than unexpectedly freeing memory in the normal case. /*
* An app that prefers the old behavior can call jpeg_abort for itself after * In library releases up through v6a, we called jpeg_abort() here to free
* each call to jpeg_write_tables(). * any working memory allocated by the destination manager and marker
*/ * writer. Some applications had a problem with that: they allocated space
} * of their own from the library memory manager, and didn't want it to go
* away during write_tables. So now we do nothing. This will cause a
* memory leak if an app calls write_tables repeatedly without doing a full
* compression cycle or otherwise resetting the JPEG object. However, that
* seems less bad than unexpectedly freeing memory in the normal case.
* An app that prefers the old behavior can call jpeg_abort for itself after
* each call to jpeg_write_tables().
*/
}
/* /*
* jcapistd.c * jcapistd.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains application interface code for the compression half * This file contains application interface code for the compression half
* of the JPEG library. These are the "standard" API routines that are * of the JPEG library. These are the "standard" API routines that are
* used in the normal full-compression case. They are not used by a * used in the normal full-compression case. They are not used by a
* transcoding-only application. Note that if an application links in * transcoding-only application. Note that if an application links in
* jpeg_start_compress, it will end up linking in the entire compressor. * jpeg_start_compress, it will end up linking in the entire compressor.
* We thus must separate this file from jcapimin.c to avoid linking the * We thus must separate this file from jcapimin.c to avoid linking the
* whole compression library into a transcoder. * whole compression library into a transcoder.
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
/* /*
* Compression initialization. * Compression initialization.
* Before calling this, all parameters and a data destination must be set up. * Before calling this, all parameters and a data destination must be set up.
* *
* We require a write_all_tables parameter as a failsafe check when writing * We require a write_all_tables parameter as a failsafe check when writing
* multiple datastreams from the same compression object. Since prior runs * multiple datastreams from the same compression object. Since prior runs
* will have left all the tables marked sent_table=TRUE, a subsequent run * will have left all the tables marked sent_table=TRUE, a subsequent run
* would emit an abbreviated stream (no tables) by default. This may be what * would emit an abbreviated stream (no tables) by default. This may be what
* is wanted, but for safety's sake it should not be the default behavior: * is wanted, but for safety's sake it should not be the default behavior:
* programmers should have to make a deliberate choice to emit abbreviated * programmers should have to make a deliberate choice to emit abbreviated
* images. Therefore the documentation and examples should encourage people * images. Therefore the documentation and examples should encourage people
* to pass write_all_tables=TRUE; then it will take active thought to do the * to pass write_all_tables=TRUE; then it will take active thought to do the
* wrong thing. * wrong thing.
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_start_compress (j_compress_ptr cinfo, int write_all_tables) jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
{ {
if (cinfo->global_state != CSTATE_START) if (cinfo->global_state != CSTATE_START)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (write_all_tables) if (write_all_tables)
jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
/* (Re)initialize error mgr and destination modules */ /* (Re)initialize error mgr and destination modules */
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
(*cinfo->dest->init_destination) (cinfo); (*cinfo->dest->init_destination) (cinfo);
/* Perform master selection of active modules */ /* Perform master selection of active modules */
jinit_compress_master(cinfo); jinit_compress_master(cinfo);
/* Set up for the first pass */ /* Set up for the first pass */
(*cinfo->master->prepare_for_pass) (cinfo); (*cinfo->master->prepare_for_pass) (cinfo);
/* Ready for application to drive first pass through jpeg_write_scanlines /* Ready for application to drive first pass through jpeg_write_scanlines
* or jpeg_write_raw_data. * or jpeg_write_raw_data.
*/ */
cinfo->next_scanline = 0; cinfo->next_scanline = 0;
cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING); cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
} }
/* /*
* Write some scanlines of data to the JPEG compressor. * Write some scanlines of data to the JPEG compressor.
* *
* The return value will be the number of lines actually written. * The return value will be the number of lines actually written.
* This should be less than the supplied num_lines only in case that * This should be less than the supplied num_lines only in case that
* the data destination module has requested suspension of the compressor, * the data destination module has requested suspension of the compressor,
* or if more than image_height scanlines are passed in. * or if more than image_height scanlines are passed in.
* *
* Note: we warn about excess calls to jpeg_write_scanlines() since * Note: we warn about excess calls to jpeg_write_scanlines() since
* this likely signals an application programmer error. However, * this likely signals an application programmer error. However,
* excess scanlines passed in the last valid call are *silently* ignored, * excess scanlines passed in the last valid call are *silently* ignored,
* so that the application need not adjust num_lines for end-of-image * so that the application need not adjust num_lines for end-of-image
* when using a multiple-scanline buffer. * when using a multiple-scanline buffer.
*/ */
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
JDIMENSION num_lines) JDIMENSION num_lines)
{ {
JDIMENSION row_ctr, rows_left; JDIMENSION row_ctr, rows_left;
if (cinfo->global_state != CSTATE_SCANNING) if (cinfo->global_state != CSTATE_SCANNING)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (cinfo->next_scanline >= cinfo->image_height) if (cinfo->next_scanline >= cinfo->image_height)
WARNMS(cinfo, JWRN_TOO_MUCH_DATA); WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) cinfo->next_scanline; cinfo->progress->pass_counter = (long) cinfo->next_scanline;
cinfo->progress->pass_limit = (long) cinfo->image_height; cinfo->progress->pass_limit = (long) cinfo->image_height;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
} }
/* Give master control module another chance if this is first call to /* Give master control module another chance if this is first call to
* jpeg_write_scanlines. This lets output of the frame/scan headers be * jpeg_write_scanlines. This lets output of the frame/scan headers be
* delayed so that application can write COM, etc, markers between * delayed so that application can write COM, etc, markers between
* jpeg_start_compress and jpeg_write_scanlines. * jpeg_start_compress and jpeg_write_scanlines.
*/ */
if (cinfo->master->call_pass_startup) if (cinfo->master->call_pass_startup)
(*cinfo->master->pass_startup) (cinfo); (*cinfo->master->pass_startup) (cinfo);
/* Ignore any extra scanlines at bottom of image. */ /* Ignore any extra scanlines at bottom of image. */
rows_left = cinfo->image_height - cinfo->next_scanline; rows_left = cinfo->image_height - cinfo->next_scanline;
if (num_lines > rows_left) if (num_lines > rows_left)
num_lines = rows_left; num_lines = rows_left;
row_ctr = 0; row_ctr = 0;
(*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines); (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
cinfo->next_scanline += row_ctr; cinfo->next_scanline += row_ctr;
return row_ctr; return row_ctr;
} }
/* /*
* Alternate entry point to write raw data. * Alternate entry point to write raw data.
* Processes exactly one iMCU row per call, unless suspended. * Processes exactly one iMCU row per call, unless suspended.
*/ */
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION num_lines) JDIMENSION num_lines)
{ {
JDIMENSION lines_per_iMCU_row; JDIMENSION lines_per_iMCU_row;
if (cinfo->global_state != CSTATE_RAW_OK) if (cinfo->global_state != CSTATE_RAW_OK)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (cinfo->next_scanline >= cinfo->image_height) { if (cinfo->next_scanline >= cinfo->image_height) {
WARNMS(cinfo, JWRN_TOO_MUCH_DATA); WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
return 0; return 0;
} }
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) cinfo->next_scanline; cinfo->progress->pass_counter = (long) cinfo->next_scanline;
cinfo->progress->pass_limit = (long) cinfo->image_height; cinfo->progress->pass_limit = (long) cinfo->image_height;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
} }
/* Give master control module another chance if this is first call to /* Give master control module another chance if this is first call to
* jpeg_write_raw_data. This lets output of the frame/scan headers be * jpeg_write_raw_data. This lets output of the frame/scan headers be
* delayed so that application can write COM, etc, markers between * delayed so that application can write COM, etc, markers between
* jpeg_start_compress and jpeg_write_raw_data. * jpeg_start_compress and jpeg_write_raw_data.
*/ */
if (cinfo->master->call_pass_startup) if (cinfo->master->call_pass_startup)
(*cinfo->master->pass_startup) (cinfo); (*cinfo->master->pass_startup) (cinfo);
/* Verify that at least one iMCU row has been passed. */ /* Verify that at least one iMCU row has been passed. */
lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE; lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
if (num_lines < lines_per_iMCU_row) if (num_lines < lines_per_iMCU_row)
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Directly compress the row. */ /* Directly compress the row. */
if (! (*cinfo->coef->compress_data) (cinfo, data)) { if (! (*cinfo->coef->compress_data) (cinfo, data)) {
/* If compressor did not consume the whole row, suspend processing. */ /* If compressor did not consume the whole row, suspend processing. */
return 0; return 0;
} }
/* OK, we processed one iMCU row. */ /* OK, we processed one iMCU row. */
cinfo->next_scanline += lines_per_iMCU_row; cinfo->next_scanline += lines_per_iMCU_row;
return lines_per_iMCU_row; return lines_per_iMCU_row;
} }
This diff is collapsed.
/*
* jchuff.h
*
* Copyright (C) 1991-1997, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains declarations for Huffman entropy encoding routines
* that are shared between the sequential encoder (jchuff.c) and the
* progressive encoder (jcphuff.c). No other modules need to see these.
*/
/* The legal range of a DCT coefficient is
* -1024 .. +1023 for 8-bit data;
* -16384 .. +16383 for 12-bit data.
* Hence the magnitude should always fit in 10 or 14 bits respectively.
*/
#if BITS_IN_JSAMPLE == 8
#define MAX_COEF_BITS 10
#else
#define MAX_COEF_BITS 14
#endif
/* Derived data constructed for each Huffman table */
typedef struct {
unsigned int ehufco[256]; /* code for each symbol */
char ehufsi[256]; /* length of code for each symbol */
/* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */
} c_derived_tbl;
/* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_make_c_derived_tbl jMkCDerived
#define jpeg_gen_optimal_table jGenOptTbl
#endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Expand a Huffman table definition into the derived format */
EXTERN(void) jpeg_make_c_derived_tbl
JPP((j_compress_ptr cinfo, int isDC, int tblno,
c_derived_tbl ** pdtbl));
/* Generate an optimal table definition given the specified counts */
EXTERN(void) jpeg_gen_optimal_table
JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment