📄 jpeglib.pas
字号:
Unit JPEGLib;
{ This file defines the application interface for the JPEG library.
Most applications using the library need only include this file,
and perhaps jerror.h if they want to know the exact error codes. }
{ Source:jpeglib.h+jpegint.h; Copyright (C) 1991-1996, Thomas G. Lane. }
interface
{$I jconfig.inc}
{ First we include the configuration files that record how this
installation of the JPEG library is set up. jconfig.h can be
generated automatically for many systems. jmorecfg.h contains
manual configuration options that most people need not worry about. }
uses
jdeferr,
jmorecfg; { seldom changed options }
{ Version ID for the JPEG library.
Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". }
Const
JPEG_LIB_VERSION = 61; { Version 6a }
{ These marker codes are exported since applications and data source modules
are likely to want to use them. }
const
JPEG_RST0 = $D0; { RST0 marker code }
JPEG_EOI = $D9; { EOI marker code }
JPEG_APP0 = $E0; { APP0 marker code }
JPEG_COM = $FE; { COM marker code }
{ Various constants determining the sizes of things.
All of these are specified by the JPEG standard, so don't change them
if you want to be compatible. }
const
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 }
{ Unfortunately, some bozo at Adobe saw no reason to be bound by the standard;
the PostScript DCT filter can emit files with many more than 10 blocks/MCU.
If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU
to handle it. We even let you do this from the jconfig.h file. However,
we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe
sometimes emits noncompliant files doesn't mean you should too. }
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 }
{ Data structures for images (arrays of samples and of DCT coefficients).
On 80x86 machines, the image arrays are too big for near pointers,
but the pointer arrays can fit in near memory. }
type
{ for typecasting }
JSAMPLE_PTR = ^JSAMPLE;
JSAMPROW_PTR = ^JSAMPROW;
JBLOCKROW_PTR = ^JBLOCKROW;
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 }
{ }
JBLOCK = Array[0..DCTSIZE2-1] of JCOEF; { one block of coefficients }
JBLOCK_PTR = ^JBLOCK;
jTBlockRow = 0..(MaxInt div SIZEOF(JBLOCK))-1;
JBLOCK_ROWS = Array[jTBlockRow] of JBLOCK;
JBLOCKROW = ^JBLOCK_ROWS; {far} { pointer to one row of coefficient blocks }
jTBlockArray = 0..(MaxInt div SIZEOF(JBLOCKROW))-1;
JBLOCK_ARRAY = Array[jTBlockArray] of JBLOCKROW;
JBLOCKARRAY = ^JBLOCK_ARRAY; { a 2-D array of coefficient blocks }
jTBlockImage = 0..(MaxInt div SIZEOF(JBLOCKARRAY))-1;
JBLOCK_IMAGE = Array[jTBlockImage] of JBLOCKARRAY;
JBLOCKIMAGE = ^JBLOCK_IMAGE; { a 3-D array of coefficient blocks }
jTCoef = 0..(MaxInt div SIZEOF(JCOEF))-1;
JCOEF_ROW = Array[jTCoef] of JCOEF;
JCOEFPTR = ^JCOEF_ROW; {far} { useful in a couple of places }
type
jTByte = 0..(MaxInt div SIZEOF(byte))-1;
JByteArray = Array[jTByte] of byte;
JBytePtr = ^JByteArray;
type
byteptr = ^byte;
{ Types for JPEG compression parameters and working tables. }
{ DCT coefficient quantization tables. }
type
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 UINT16;
{ 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 : boolean; { TRUE when table has been output }
end;
JQUANT_TBL_FIELD = Array[0..(MaxInt div SizeOf(JQUANT_TBL))-1] of JQUANT_TBL;
{ Huffman coding tables. }
type
JHUFF_TBL_PTR = ^JHUFF_TBL;
JHUFF_TBL = record
{ These two fields directly represent the contents of a JPEG DHT marker }
bits : Array[0..17-1] of UINT8; { bits[k] = # of symbols with codes of }
{ length k bits; bits[0] is unused }
huffval : Array[0..256-1] of UINT8;
{ The symbols, in order of incr code length }
{ 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 : boolean; { TRUE when table has been output }
end;
JHUFF_TBL_FIELD = Array[0..(MaxInt div SizeOf(JHUFF_TBL))-1] of JHUFF_TBL;
{ Declarations for both compression & decompression }
type
J_BUF_MODE = ( { Operating modes for buffer controllers }
JBUF_PASS_THRU, { Plain stripwise operation }
{ Remaining modes require a full-image buffer to have been created }
JBUF_SAVE_SOURCE, { Run source subobject only, save output }
JBUF_CRANK_DEST, { Run dest subobject only, using saved data }
JBUF_SAVE_AND_PASS { Run both subobjects, save output }
);
{ Values of global_state field (jdapi.c has some dependencies on ordering!) }
const
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 }
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 }
{ Basic info about one component (color channel). }
type
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 : int; { identifier for this component (0..255) }
component_index : int; { its index in SOF or cinfo->comp_info[] }
h_samp_factor : int; { horizontal sampling factor (1..4) }
v_samp_factor : int; { vertical sampling factor (1..4) }
quant_tbl_no : int; { 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 : int; { DC entropy table selector (0..3) }
ac_tbl_no : int; { 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 : JDIMENSION;
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 : int;
{ 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 : JDIMENSION; { 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 : boolean; { 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 : int; { number of blocks per MCU, horizontally }
MCU_height : int; { number of blocks per MCU, vertically }
MCU_blocks : int; { MCU_width * MCU_height }
MCU_sample_width : int; { MCU width in samples, MCU_width*DCT_scaled_size }
last_col_width : int; { # of non-dummy blocks across in last MCU }
last_row_height : int; { # of non-dummy blocks down in last MCU }
{ Saved quantization table for component; NIL 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; { record jpeg_component_info }
jTCinfo = 0..(MaxInt div SizeOf(jpeg_component_info))-1;
jpeg_component_info_array = array[jTCinfo] of jpeg_component_info;
jpeg_component_info_list_ptr = ^jpeg_component_info_array;
{ The script for encoding a multiple-scan file is an array of these: }
type
jpeg_scan_info_ptr = ^jpeg_scan_info;
jpeg_scan_info = record
comps_in_scan : int; { number of components encoded in this scan }
component_index : Array[0..MAX_COMPS_IN_SCAN-1] of int;
{ their SOF/comp_info[] indexes }
Ss, Se : int; { progressive JPEG spectral selection parms }
Ah, Al : int; { progressive JPEG successive approx. parms }
end;
{ Known color spaces. }
type
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. }
type
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 }
);
const
JDCT_DEFAULT = JDCT_ISLOW;
JDCT_FASTEST = JDCT_IFAST;
{ Dithering options for decompression. }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -