📄 jpg.pas
字号:
unit JPG;
interface
{$Z4} // Minimum enum size = dword
uses
Windows, SysUtils, Classes, Graphics;
type
TJPGColorDepth = (jpgAuto, jpgGray, jpg8Bit, jpg24Bit);
TJPEGPixelFormat = (jf24Bit, jf8Bit);
const
JPEG_SUSPENDED = 0; { Suspended due to lack of input data }
JPEG_HEADER_OK = 1; { Found valid image datastream }
JPEG_HEADER_TABLES_ONLY = 2; { Found valid table-specs-only datastream }
{ If you pass require_image = TRUE (normal case), you need not check for
a TABLES_ONLY return code; an abbreviated file will cause an error exit.
JPEG_SUSPENDED is only possible if you use a data source module that can
give a suspension return (the stdio source module doesn't). }
{ function jpeg_consume_input (cinfo : j_decompress_ptr) : Integer;
Return value is one of: }
JPEG_REACHED_SOS = 1; { Reached start of new scan }
JPEG_REACHED_EOI = 2; { Reached end of image }
JPEG_ROW_COMPLETED = 3; { Completed one iMCU row }
JPEG_SCAN_COMPLETED = 4; { Completed last iMCU row of a scan }
CSTATE_START = 100; { after create_compress }
CSTATE_SCANNING = 101; { start_compress done, write_scanlines OK }
CSTATE_RAW_OK = 102; { start_compress done, write_raw_data OK }
CSTATE_WRCOEFS = 103; { jpeg_write_coefficients done }
JPEG_LIB_VERSION = 61; { Version 6a }
JPEG_RST0 = $D0; { RST0 marker code }
JPEG_EOI = $D9; { EOI marker code }
JPEG_APP0 = $E0; { APP0 marker code }
JPEG_COM = $FE; { COM marker code }
DCTSIZE = 8; { The basic DCT block is 8x8 samples }
DCTSIZE2 = 64; { DCTSIZE squared; # of elements in a block }
NUM_QUANT_TBLS = 4; { Quantization tables are numbered 0..3 }
NUM_HUFF_TBLS = 4; { Huffman tables are numbered 0..3 }
NUM_ARITH_TBLS = 16; { Arith-coding tables are numbered 0..15 }
MAX_COMPS_IN_SCAN = 4; { JPEG limit on # of components in one scan }
MAX_SAMP_FACTOR = 4; { JPEG limit on sampling factors }
C_MAX_BLOCKS_IN_MCU = 10; { compressor's limit on blocks per MCU }
D_MAX_BLOCKS_IN_MCU = 10; { decompressor's limit on blocks per MCU }
MAX_COMPONENTS = 10; { maximum number of image components (color channels) }
MAXJSAMPLE = 255;
CENTERJSAMPLE = 128;
DSTATE_START = 200; { after create_decompress }
DSTATE_INHEADER = 201; { reading header markers, no SOS yet }
DSTATE_READY = 202; { found SOS, ready for start_decompress }
DSTATE_PRELOAD = 203; { reading multiscan file in start_decompress}
DSTATE_PRESCAN = 204; { performing dummy pass for 2-pass quant }
DSTATE_SCANNING = 205; { start_decompress done, read_scanlines OK }
DSTATE_RAW_OK = 206; { start_decompress done, read_raw_data OK }
DSTATE_BUFIMAGE = 207; { expecting jpeg_start_output }
DSTATE_BUFPOST = 208; { looking for SOS/EOI in jpeg_finish_output }
DSTATE_RDCOEFS = 209; { reading file in jpeg_read_coefficients }
DSTATE_STOPPING = 210; { looking for EOI in jpeg_finish_decompress }
{ Error handler }
JMSG_LENGTH_MAX = 200; { recommended size of format_message buffer }
JMSG_STR_PARM_MAX = 80;
JPOOL_PERMANENT = 0; // lasts until master record is destroyed
JPOOL_IMAGE = 1; // lasts until done with image/datastream
type
JSAMPLE = byte;
GETJSAMPLE = integer;
JCOEF = integer;
JCOEF_PTR = ^JCOEF;
UINT8 = byte;
UINT16 = Word;
UINT32 = Cardinal;
INT16 = SmallInt;
INT32 = Integer;
INT32PTR = ^INT32;
JDIMENSION = Cardinal;
JOCTET = Byte;
jTOctet = 0..(MaxInt div SizeOf(JOCTET))-1;
JOCTET_FIELD = array[jTOctet] of JOCTET;
JOCTET_FIELD_PTR = ^JOCTET_FIELD;
JOCTETPTR = ^JOCTET;
JSAMPLE_PTR = ^JSAMPLE;
JSAMPROW_PTR = ^JSAMPROW;
jTSample = 0..(MaxInt div SIZEOF(JSAMPLE))-1;
JSAMPLE_ARRAY = Array[jTSample] of JSAMPLE; {far}
JSAMPROW = ^JSAMPLE_ARRAY; { ptr to one image row of pixel samples. }
jTRow = 0..(MaxInt div SIZEOF(JSAMPROW))-1;
JSAMPROW_ARRAY = Array[jTRow] of JSAMPROW;
JSAMPARRAY = ^JSAMPROW_ARRAY; { ptr to some rows (a 2-D sample array) }
jTArray = 0..(MaxInt div SIZEOF(JSAMPARRAY))-1;
JSAMP_ARRAY = Array[jTArray] of JSAMPARRAY;
JSAMPIMAGE = ^JSAMP_ARRAY; { a 3-D sample array: top index is color }
{ Known color spaces. }
J_COLOR_SPACE = (
JCS_UNKNOWN, { error/unspecified }
JCS_GRAYSCALE, { monochrome }
JCS_RGB, { red/green/blue }
JCS_YCbCr, { Y/Cb/Cr (also known as YUV) }
JCS_CMYK, { C/M/Y/K }
JCS_YCCK { Y/Cb/Cr/K }
);
{ DCT/IDCT algorithm options. }
J_DCT_METHOD = (
JDCT_ISLOW, { slow but accurate integer algorithm }
JDCT_IFAST, { faster, less accurate integer method }
JDCT_FLOAT { floating-point: accurate, fast on fast HW (Pentium)}
);
{ Dithering options for decompression. }
J_DITHER_MODE = (
JDITHER_NONE, { no dithering }
JDITHER_ORDERED, { simple ordered dither }
JDITHER_FS { Floyd-Steinberg error diffusion dither }
);
// DCT coefficient quantization tables.
JQUANT_TBL_ptr = ^JQUANT_TBL;
JQUANT_TBL = record
// This array gives the coefficient quantizers in natural array order
// (not the zigzag order in which they are stored in a JPEG DQT marker).
// CAUTION: IJG versions prior to v6a kept this array in zigzag order.
quantval: array[0..DCTSIZE2 - 1] of Word; // quantization step for each coefficient
// This field is used only during compression. It's initialized FALSE when
// the table is created, and set TRUE when it's been output to the file.
// You could suppress output of a table by setting this to TRUE.
// (See jpeg_suppress_tables for an example.)
sent_table: LongBool; // TRUE when table has been output
end;
// Basic info about one component (color channel).
jpeg_component_info_ptr = ^jpeg_component_info;
jpeg_component_info = record
// These values are fixed over the whole image.
// For compression, they must be supplied by parameter setup;
// for decompression, they are read from the SOF marker.
component_id, // identifier for this component (0..255)
component_index, // its index in SOF or cinfo->comp_info[]
h_samp_factor, // horizontal sampling factor (1..4) */
v_samp_factor, // vertical sampling factor (1..4) */
quant_tbl_no: Integer; // quantization table selector (0..3) */
// These values may vary between scans.
// For compression, they must be supplied by parameter setup;
// for decompression, they are read from the SOS marker.
// The decompressor output side may not use these variables.
dc_tbl_no, // DC entropy table selector (0..3)
ac_tbl_no: Integer; // AC entropy table selector (0..3)
// Remaining fields should be treated as private by applications.
// These values are computed during compression or decompression startup:
// Component's size in DCT blocks.
// Any dummy blocks added to complete an MCU are not counted; therefore
// these values do not depend on whether a scan is interleaved or not.
width_in_blocks,
height_in_blocks: JDIMENSION;
// Size of a DCT block in samples. Always DCTSIZE for compression.
// For decompression this is the size of the output from one DCT block,
// reflecting any scaling we choose to apply during the IDCT step.
// Values of 1,2,4,8 are likely to be supported. Note that different
// components may receive different IDCT scalings.
DCT_scaled_size: Integer;
// The downsampled dimensions are the component's actual, unpadded number
// of samples at the main buffer (preprocessing/compression interface), thus
// downsampled_width = ceil(image_width * Hi/Hmax)
// and similarly for height. For decompression, IDCT scaling is included, so
// downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
downsampled_width, // actual width in samples
downsampled_height: JDIMENSION; // actual height in samples
// This flag is used only for decompression. In cases where some of the
// components will be ignored (eg grayscale output from YCbCr image),
// we can skip most computations for the unused components.
component_needed: LongBool; // do we need the value of this component?
// These values are computed before starting a scan of the component.
// The decompressor output side may not use these variables.
MCU_width, // number of blocks per MCU, horizontally
MCU_height, // number of blocks per MCU, vertically
MCU_blocks, // MCU_width * MCU_height
MCU_sample_width, // MCU width in samples, MCU_width*DCT_scaled_size
last_col_width, // # of non-dummy blocks across in last MCU
last_row_height: Integer; // # of non-dummy blocks down in last MCU
// Saved quantization table for component; NULL if none yet saved.
// See jdinput.c comments about the need for this information.
// This field is currently used only for decompression.
quant_table: JQUANT_TBL_ptr;
// Private per-component storage for DCT or IDCT subsystem.
dct_table: Pointer;
end;
jpeg_error_mgr_ptr = ^jpeg_error_mgr;
jpeg_progress_mgr_ptr = ^jpeg_progress_mgr;
j_common_ptr = ^jpeg_common_struct;
j_decompress_ptr = ^jpeg_decompress_struct;
{ Routine signature for application-supplied marker processing methods.
Need not pass marker code since it is stored in cinfo^.unread_marker. }
jpeg_marker_parser_method = function(cinfo : j_decompress_ptr) : LongBool;
{ Marker reading & parsing }
jpeg_marker_reader_ptr = ^jpeg_marker_reader;
jpeg_marker_reader = record
reset_marker_reader : procedure(cinfo : j_decompress_ptr);
{ Read markers until SOS or EOI.
Returns same codes as are defined for jpeg_consume_input:
JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. }
read_markers : function (cinfo : j_decompress_ptr) : Integer;
{ Read a restart marker --- exported for use by entropy decoder only }
read_restart_marker : jpeg_marker_parser_method;
{ Application-overridable marker processing methods }
process_COM : jpeg_marker_parser_method;
process_APPn : Array[0..16-1] of jpeg_marker_parser_method;
{ State of marker reader --- nominally internal, but applications
supplying COM or APPn handlers might like to know the state. }
saw_SOI : LongBool; { found SOI? }
saw_SOF : LongBool; { found SOF? }
next_restart_num : Integer; { next restart number expected (0-7) }
discarded_bytes : UINT32; { # of bytes skipped looking for a marker }
end;
{int8array = Array[0..8-1] of int;}
int8array = Array[0..8-1] of Integer;
jpeg_error_mgr = record
{ Error exit handler: does not return to caller }
error_exit : procedure (cinfo : j_common_ptr);
{ Conditionally emit a trace or warning message }
emit_message : procedure (cinfo : j_common_ptr; msg_level : Integer);
{ Routine that actually outputs a trace or error message }
output_message : procedure (cinfo : j_common_ptr);
{ Format a message string for the most recent JPEG error or message }
format_message : procedure (cinfo : j_common_ptr; buffer: PChar);
{ Reset error state variables at start of a new image }
reset_error_mgr : procedure (cinfo : j_common_ptr);
{ The message ID code and any parameters are saved here.
A message can have one string parameter or up to 8 int parameters. }
msg_code : Integer;
msg_parm : record
case byte of
0:(i : int8array);
1:(s : string[JMSG_STR_PARM_MAX]);
end;
trace_level : Integer; { max msg_level that will be displayed }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -