Delphi: Быстрое (де)кодирование JPEG с помощью libjpeg-turbo
{ Known color spaces. } J_COLOR_SPACE = ( JCS_UNKNOWN, { error/unspecified } JCS_GRAYSCALE, //* monochrome */ JCS_RGB, //* red/green/blue as specified by the RGB_RED, RGB_GREEN, //RGB_BLUE, and RGB_PIXELSIZE macros */ JCS_YCbCr, //* Y/Cb/Cr (also known as YUV) */ JCS_CMYK, //* C/M/Y/K */ JCS_YCCK, //* Y/Cb/Cr/K */ JCS_EXT_RGB, //* red/green/blue */ JCS_EXT_RGBX, //* red/green/blue/x */ JCS_EXT_BGR, //* blue/green/red */ JCS_EXT_BGRX, //* blue/green/red/x */ JCS_EXT_XBGR, //* x/blue/green/red */ JCS_EXT_XRGB, //* x/red/green/blue */ // When out_color_space it set to JCS_EXT_RGBX, JCS_EXT_BGRX, // JCS_EXT_XBGR, or JCS_EXT_XRGB during decompression, the X byte is // undefined, and in order to ensure the best performance, // libjpeg-turbo can set that byte to whatever value it wishes. Use // the following colorspace constants to ensure that the X byte is set // to 0xFF, so that it can be interpreted as an opaque alpha // channel. JCS_EXT_RGBA, ///* red/green/blue/alpha */ JCS_EXT_BGRA, //* blue/green/red/alpha */ JCS_EXT_ABGR, //* alpha/blue/green/red */ JCS_EXT_ARGB //* alpha/red/green/blue */ ); … { Standard data source and destination managers: stdio streams. } { Caller is responsible for opening the file before and closing after. } // jpeg_stdio_dest: procedure (cinfo: j_compress_ptr; FILE * outfile); cdecl; // jpeg_stdio_src: procedure (cinfo: j_decompress_ptr; FILE * infile); cdecl; jpeg_mem_src: procedure (cinfo: j_decompress_ptr; inbuffer: Pointer; insize: LongWord); cdecl; jpeg_mem_dest: procedure (cinfo: j_decompress_ptr; outbuffer: Pointer; outsize: PLongWord); cdecl; … Function init_libJPEG (): boolean; … @jpeg_mem_src:= GetProcAddress (libJPEG_Handle, 'jpeg_mem_src'); @jpeg_mem_dest:= GetProcAddress (libJPEG_Handle, 'jpeg_mem_dest'); … {$DEFINE JPEG_LIB_VERSION = 62} //Version 6b type J_MESSAGE_CODE = ( JMSG_NOMESSAGE, {$IF Declared (JPEG_LIB_VERSION) and (JPEG_LIB_VERSION < 70)} JERR_ARITH_NOTIMPL, {$IFEND} JERR_BAD_ALIGN_TYPE, JERR_BAD_ALLOC_CHUNK, JERR_BAD_BUFFER_MODE, JERR_BAD_COMPONENT_ID, {$IF Declared(JPEG_LIB_VERSION) and (JPEG_LIB_VERSION >= 70)} JERR_BAD_CROP_SPEC, {$IFEND} JERR_BAD_DCT_COEF, JERR_BAD_DCTSIZE, {$IF Declared (JPEG_LIB_VERSION) and (JPEG_LIB_VERSION >= 70)} JERR_BAD_DROP_SAMPLING, {$IFEND} JERR_BAD_HUFF_TABLE, JERR_BAD_IN_COLORSPACE, JERR_BAD_J_COLORSPACE, JERR_BAD_LENGTH, JERR_BAD_LIB_VERSION, JERR_BAD_MCU_SIZE, JERR_BAD_POOL_ID, JERR_BAD_PRECISION, JERR_BAD_PROGRESSION, JERR_BAD_PROG_SCRIPT, JERR_BAD_SAMPLING, JERR_BAD_SCAN_SCRIPT, JERR_BAD_STATE, JERR_BAD_STRUCT_SIZE, JERR_BAD_VIRTUAL_ACCESS, JERR_BUFFER_SIZE, JERR_CANT_SUSPEND, JERR_CCIR601_NOTIMPL, JERR_COMPONENT_COUNT, JERR_CONVERSION_NOTIMPL, JERR_DAC_INDEX, JERR_DAC_VALUE, JERR_DHT_INDEX, JERR_DQT_INDEX, JERR_EMPTY_IMAGE, JERR_EMS_READ, JERR_EMS_WRITE, JERR_EOI_EXPECTED, JERR_FILE_READ, JERR_FILE_WRITE, JERR_FRACT_SAMPLE_NOTIMPL, JERR_HUFF_CLEN_OVERFLOW, JERR_HUFF_MISSING_CODE, JERR_IMAGE_TOO_BIG, JERR_INPUT_EMPTY, JERR_INPUT_EOF, JERR_MISMATCHED_QUANT_TABLE, JERR_MISSING_DATA, JERR_MODE_CHANGE, JERR_NOTIMPL, JERR_NOT_COMPILED, {$IF Declared (JPEG_LIB_VERSION) and (JPEG_LIB_VERSION >= 70)} JERR_NO_ARITH_TABLE, {$IFEND} JERR_NO_BACKING_STORE, JERR_NO_HUFF_TABLE, JERR_NO_IMAGE, JERR_NO_QUANT_TABLE, JERR_NO_SOI, JERR_OUT_OF_MEMORY, JERR_QUANT_COMPONENTS, JERR_QUANT_FEW_COLORS, JERR_QUANT_MANY_COLORS, JERR_SOF_DUPLICATE, JERR_SOF_NO_SOS, JERR_SOF_UNSUPPORTED, JERR_SOI_DUPLICATE, JERR_SOS_NO_SOF, JERR_TFILE_CREATE, JERR_TFILE_READ, JERR_TFILE_SEEK, JERR_TFILE_WRITE, JERR_TOO_LITTLE_DATA, JERR_UNKNOWN_MARKER, JERR_VIRTUAL_BUG, JERR_WIDTH_OVERFLOW, JERR_XMS_READ, JERR_XMS_WRITE ); procedure ERREXIT (cinfo: j_common_ptr; code: J_MESSAGE_CODE); procedure ERREXIT1(cinfo: j_common_ptr; code: J_MESSAGE_CODE; p1: Integer); … //Макрос из jerror.h //Fatal errors (print message and exit) procedure ERREXIT (cinfo: j_common_ptr; code: J_MESSAGE_CODE); begin cinfo^.err^.msg_code:= Ord (code); cinfo^.err^.error_exit (j_common_ptr (cinfo)); end; procedure ERREXIT1(cinfo: j_common_ptr; code: J_MESSAGE_CODE; p1: Integer); begin cinfo^.err^.msg_code:= Ord (code); cinfo^.err^.msg_parm.i[0] := p1; cinfo^.err^.error_exit (j_common_ptr (cinfo)); end;