📄 jpegfilt.pas
字号:
procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
begin
{$ifdef IEPROFILE} try IEProfileBegin('_memset'); {$endif}
FillChar(P^, count, B);
{$ifdef IEPROFILE} finally IEProfileEnd; end; {$endif}
end;
procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
begin
{$ifdef IEPROFILE} try IEProfileBegin('_memcpy'); {$endif}
Move(source^, dest^, count);
{$ifdef IEPROFILE} finally IEProfileEnd; end; {$endif}
end;
function __ftol: Integer;
var
f: double;
begin
{$ifdef IEPROFILE} try IEProfileBegin('__ftol'); {$endif}
asm
lea eax, f // BC++ passes floats on the FPU stack
fstp qword ptr [eax] // Delphi passes floats on the CPU stack
end;
Result := Trunc(f);
{$ifdef IEPROFILE} finally IEProfileEnd; end; {$endif}
end;
{$L jdapimin.obj}
{$L jmemmgr.obj}
{$L jmemnobs.obj}
{$L jdinput.obj}
{$L jdapistd.obj}
{$L jdmaster.obj}
{$L jdphuff.obj}
{$L jdhuff.obj}
{$L jdmerge.obj}
{$L jdcolor.obj}
{$L jquant1.obj}
{$L jquant2.obj}
{$L jdmainct.obj}
{$L jdcoefct.obj}
{$L jdpostct.obj}
{$L jddctmgr.obj}
{$L jdsample.obj}
{$L jidctflt.obj}
{$L jidctfst.obj}
{$L jidctint.obj}
{$L jidctred.obj}
{$L jdmarker.obj}
{$L jutils.obj}
{$L jcomapi.obj}
{$L transupp.obj}
{$L jdtrans.obj}
{$L jctrans.obj}
procedure jpeg_CreateDecompress(var cinfo: jpeg_decompress_struct; version: integer; structsize: integer); external;
procedure jpeg_read_header(var cinfo: jpeg_decompress_struct; RequireImage: LongBool); external;
procedure jpeg_calc_output_dimensions(var cinfo: jpeg_decompress_struct); external;
function jpeg_start_decompress(var cinfo: jpeg_decompress_struct): Longbool; external;
function jpeg_read_scanlines(var cinfo: jpeg_decompress_struct; scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; external;
function jpeg_finish_decompress(var cinfo: jpeg_decompress_struct): Longbool; external;
procedure jpeg_destroy_decompress(var cinfo: jpeg_decompress_struct); external;
function jpeg_has_multiple_scans(var cinfo: jpeg_decompress_struct): Longbool; external;
function jpeg_consume_input(var cinfo: jpeg_decompress_struct): Integer; external;
function jpeg_start_output(var cinfo: jpeg_decompress_struct; scan_number: Integer): Longbool; external;
function jpeg_finish_output(var cinfo: jpeg_decompress_struct): LongBool; external;
procedure jpeg_destroy(var cinfo: jpeg_common_struct); external;
procedure jpeg_save_markers(var cinfo: jpeg_decompress_struct; marker_code: integer; length_limit: UINT); external;
function jpeg_resync_to_restart(cinfo: j_decompress_ptr; desired: Integer): LongBool; external;
// transforms
type
JXFORM_CODE = integer;
const
JXFORM_NONE = 0; // no transformation
const
JXFORM_CUT = 1; // cut out part of the image
const
JXFORM_FLIP_H = 2; // horizontal flip
const
JXFORM_FLIP_V = 3; // vertical flip
const
JXFORM_TRANSPOSE = 4; // transpose across UL-to-LR axis
const
JXFORM_TRANSVERSE = 5; // transpose across UR-to-LL axis
const
JXFORM_ROT_90 = 6; // 90-degree clockwise rotation
const
JXFORM_ROT_180 = 7; // 180-degree rotation
const
JXFORM_ROT_270 = 8; // 270-degree clockwise (or 90 ccw)
type
jpeg_transform_info = record
// Options: set by caller */
transform: JXFORM_CODE; // image transform operator
trim: integer; // if TRUE, trim partial MCUs as needed
force_grayscale: integer; // if TRUE, convert color image to grayscale
xoffs, yoffs, newwidth, newheight: dword;
// Internal workspace: caller should not touch these
num_components: integer; // # of components in workspace
workspace_coef_arrays: pointer; // workspace for transformations
end;
type
JCOPY_OPTION = integer;
const
JCOPYOPT_NONE = 0; // copy no optional markers
const
JCOPYOPT_COMMENTS = 1; // copy only comment (COM) markers
const
JCOPYOPT_ALL = 2; // copy all optional markers
procedure jtransform_request_workspace(var srcinfo: jpeg_decompress_struct; var info: jpeg_transform_info); external;
function jtransform_adjust_parameters(var srcinfo: jpeg_decompress_struct; var dstinfo: jpeg_compress_struct;
src_coef_arrays: pointer;
var info: jpeg_transform_info): pointer; external;
procedure jtransform_execute_transformation(var srcinfo: jpeg_decompress_struct; var dstinfo: jpeg_compress_struct;
src_coef_arrays: pointer;
var info: jpeg_transform_info); external;
procedure jcopy_markers_setup(var srcinfo: jpeg_decompress_struct; option: JCOPY_OPTION); external;
procedure jcopy_markers_execute(var srcinfo: jpeg_decompress_struct; var dstinfo: jpeg_compress_struct;
option: JCOPY_OPTION); external;
function jpeg_read_coefficients(var cinfo: jpeg_decompress_struct): pointer; external;
procedure jpeg_write_coefficients(var dstinfo: jpeg_compress_struct; coef: pointer); external;
procedure jpeg_copy_critical_parameters(var srcinfo: jpeg_decompress_struct; var dstinfo: jpeg_compress_struct); external;
{$L jcparam.obj}
{$L jcapistd.obj}
{$L jcapimin.obj}
{$L jcinit.obj}
{$L jcmarker.obj}
{$L jcmaster.obj}
{$L jcmainct.obj}
{$L jcprepct.obj}
{$L jccoefct.obj}
{$L jccolor.obj}
{$L jcsample.obj}
{$L jcdctmgr.obj}
{$L jcphuff.obj}
{$L jfdctint.obj}
{$L jfdctfst.obj}
{$L jfdctflt.obj}
{$L jchuff.obj}
procedure jpeg_CreateCompress(var cinfo: jpeg_compress_struct; version: integer; structsize: integer); external;
procedure jpeg_set_defaults(var cinfo: jpeg_compress_struct); external;
procedure jpeg_set_quality(var cinfo: jpeg_compress_struct; Quality: Integer; Baseline: Longbool); external;
procedure jpeg_set_colorspace(var cinfo: jpeg_compress_struct; colorspace: J_COLOR_SPACE); external;
procedure jpeg_simple_progression(var cinfo: jpeg_compress_struct); external;
procedure jpeg_start_compress(var cinfo: jpeg_compress_struct; WriteAllTables: LongBool); external;
function jpeg_write_scanlines(var cinfo: jpeg_compress_struct; scanlines: JSAMPARRAY; max_lines: JDIMENSION): JDIMENSION; external;
procedure jpeg_finish_compress(var cinfo: jpeg_compress_struct); external;
procedure jpeg_destroy_compress(var cinfo: jpeg_compress_struct); external;
procedure jpeg_write_marker(var cinfo: jpeg_compress_struct; marker: integer; dataptr: pbyte; datalen: dword); external;
procedure JpegError(cinfo: j_common_ptr);
var
ss: string;
c: integer;
begin
{$ifdef IEPROFILE} try IEProfileBegin('JpegError'); {$endif}
if assigned(cinfo.err^.aborting) then
cinfo.err^.aborting^ := True;
c := cinfo.err^.msg_code + 1;
case c of
1: ss := 'Bogus message code ?';
2: ss := 'Sorry, there are legal restrictions on arithmetic coding';
3: ss := 'ALIGN_TYPE is wrong, please fix';
4: ss := 'MAX_ALLOC_CHUNK is wrong, please fix';
5: ss := 'Bogus buffer control mode';
6: ss := 'Invalid component ID ? in SOS';
7: ss := 'DCT coefficient out of range';
8: ss := 'IDCT output block size ? not supported';
9: ss := 'Bogus Huffman table definition';
10: ss := 'Bogus input colorspace';
11: ss := 'Bogus JPEG colorspace';
12: ss := 'Bogus marker length';
13: ss := 'Wrong JPEG library version: library is ?, caller expects ?';
14: ss := 'Sampling factors too large for interleaved scan';
15: ss := 'Invalid memory pool code ?';
16: ss := 'Unsupported JPEG data precision ?';
17: ss := 'Invalid progressive parameters Ss=? Se=? Ah=? Al=?';
18: ss := 'Invalid progressive parameters at scan script entry ?';
19: ss := 'Bogus sampling factors';
20: ss := 'Invalid scan script at entry ?';
21: ss := 'Improper call to JPEG library in state ?';
22: ss := 'JPEG parameter struct mismatch: library thinks size is ?, caller expects ?';
23: ss := 'Bogus virtual array access';
24: ss := 'Buffer passed to JPEG library is too small';
25: ss := 'Suspension not allowed here';
26: ss := 'CCIR601 sampling not implemented yet';
27: ss := 'Too many color components: ?, max ?';
28: ss := 'Unsupported color conversion request';
29: ss := 'Bogus DAC index ?';
30: ss := 'Bogus DAC value 0x?';
31: ss := 'Bogus DHT index ?';
32: ss := 'Bogus DQT index ?';
33: ss := 'Empty JPEG image (DNL not supported)';
34: ss := 'Read from EMS failed';
35: ss := 'Write to EMS failed';
36: ss := 'Didn''t expect more than one scan';
37: ss := 'Input file read error';
38: ss := 'Output file write error --- out of disk space?';
39: ss := 'Fractional sampling not implemented yet';
40: ss := 'Huffman code size table overflow';
41: ss := 'Missing Huffman code table entry';
42: ss := 'Maximum supported image dimension is ? pixels';
43: ss := 'Empty input file';
44: ss := 'Premature end of input file';
45: ss := 'Cannot transcode due to multiple use of quantization table ?';
46: ss := 'Scan script does not transmit all data';
47: ss := 'Invalid color quantization mode change';
48: ss := 'Not implemented yet';
49: ss := 'Requested feature was omitted at compile time';
50: ss := 'Backing store not supported';
51: ss := 'Huffman table was not defined';
52: ss := 'JPEG datastream contains no image';
53: ss := 'Quantization table was not defined';
54: ss := 'Not a JPEG file: starts with ?';
55: ss := 'Insufficient memory (case ?)';
56: ss := 'Cannot quantize more than ? color components';
57: ss := 'Cannot quantize to fewer than ? colors';
58: ss := 'Cannot quantize to more than ? colors';
59: ss := 'Invalid JPEG file structure: two SOF markers';
60: ss := 'Invalid JPEG file structure: missing SOS marker';
61: ss := 'Unsupported JPEG process: SOF type ?';
62: ss := 'Invalid JPEG file structure: two SOI markers';
63: ss := 'Invalid JPEG file structure: SOS before SOF';
64: ss := 'Failed to create temporary file ?';
65: ss := 'Read failed on temporary file';
66: ss := 'Seek failed on temporary file';
67: ss := 'Write failed on temporary file --- out of disk space?';
68: ss := 'Application transferred too few scanlines';
69: ss := 'Unsupported marker type ?';
70: ss := 'Virtual array controller messed up';
71: ss := 'Image too wide for this implementation';
72: ss := 'Read from XMS failed';
73: ss := 'Write to XMS failed';
74: ss := '';
75: ss := '';
76: ss := 'Caution: quantization tables are too coarse for baseline JPEG';
77: ss := 'Adobe APP14 marker: version ?, flags ?, transform ?';
78: ss := 'Unknown APP0 marker (not JFIF), length ?';
79: ss := 'Unknown APP14 marker (not Adobe), length ?';
80: ss := 'Define Arithmetic Table ?';
81: ss := 'Define Huffman Table ?';
82: ss := 'Define Quantization Table ? precision ?';
83: ss := 'Define Restart Interval ?';
84: ss := 'Freed EMS handle ?';
85: ss := 'Obtained EMS handle ?';
86: ss := 'End Of Image';
87: ss := '?';
88: ss := 'JFIF APP0 marker: version ?, density ?';
89: ss := 'Warning: thumbnail image size does not match data length ?';
90: ss := 'JFIF extension marker: type ?, length ?';
91: ss := 'with ? x ? thumbnail image';
92: ss := 'Miscellaneous marker ?, length ?';
93: ss := 'Unexpected marker ?';
94: ss := '?';
95: ss := 'Quantizing to ? = ?*?*? colors';
96: ss := 'Quantizing to ? colors';
97: ss := 'Selected ? colors for quantization';
98: ss := 'At marker ?, recovery action ?';
99: ss := 'RST?';
100: ss := 'Smoothing not supported with nonstandard sampling ratios';
101: ss := 'Start Of Frame ?: width=?, height=?, components=?';
102: ss := 'Component ?: ?hx?v q=?';
103: ss := 'Start of Image';
104: ss := 'Start Of Scan: ? components';
105: ss := 'Component ?: dc=? ac=?';
106: ss := 'Ss=?, Se=?, Ah=?, Al=?';
107: ss := 'Closed temporary file ?';
108: ss := 'Opened temporary file ?';
109: ss := 'JFIF extension marker: JPEG-compressed thumbnail image, length ?';
110: ss := 'JFIF extension marker: palette thumbnail image, length ?';
111: ss := 'JFIF extension marker: RGB thumbnail image, length ?';
112: ss := 'Unrecognized component IDs ? ? ?, assuming YCbCr';
113: ss := 'Freed XMS handle ?';
114: ss := 'Obtained XMS handle ?';
115: ss := 'Unknown Adobe color transform code ?';
116: ss := 'Inconsistent progression sequence for component ? coefficient ?';
117: ss := 'Corrupt JPEG data: ? extraneous bytes before marker ?';
118: ss := 'Corrupt JPEG data: premature end of data segment';
119: ss := 'Corrupt JPEG data: bad Huffman code';
120: ss := 'Warning: unknown JFIF revision number ?';
121: ss := 'Premature end of JPEG file';
122: ss := 'Corrupt JPEG data: found marker ? instead of RST?';
123: ss := 'Invalid SOS parameters for sequential JPEG';
124: ss := 'Application transferred too many scanlines';
else
ss := 'Corrupted';
end;
if c<>68 then
raise EIEJpegException.Create(ss);
{$ifdef IEPROFILE} finally IEProfileEnd; end; {$endif}
end;
procedure EmitMessage(cinfo: j_common_ptr; msg_level: Integer);
begin
{$ifdef IEPROFILE} try IEProfileBegin('EmitMessage'); {$endif}
if msg_level = -1 then
inc(cinfo^.err^.num_warnings);
{$ifdef IEPROFILE} finally IEProfileEnd; end; {$endif}
end;
procedure OutputMessage(cinfo: j_common_ptr);
begin
//
end;
procedure FormatMessage(cinfo: j_common_ptr; buffer: PChar);
begin
//
end;
procedure ResetErrorMgr(cinfo: j_common_ptr);
begin
{$ifdef IEPROFILE} try IEProfileBegin('ResetErrorMgr'); {$endif}
cinfo^.err^.num_warnings := 0;
cinfo^.err^.msg_code := 0;
{$ifdef IEPROFILE} finally IEProfileEnd; end; {$endif}
end;
const
jpeg_std_error: jpeg_error_mgr = (
error_exit: JpegError;
emit_message: EmitMessage;
output_message: OutputMessage;
format_message: FormatMessage;
reset_error_mgr: ResetErrorMgr);
/////////////////////////////////////////////////////////////////////////////////////
// destination manager
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -