📄 libjasper.pas
字号:
unit LibJasper;
{ Quick, dirty and ugly conversion of some header files of the JasPer JPEG-2000
library.
Only those declarations needed by the Advanced Image Coding application
are converted.
Based on the JasPer JPEG-2000 library version 1.701.0.
Note: The JasPer library doen't come in a DLL, so I took the liberty of
exporting some symbols in the JasPer source code to build a DLL. }
interface
{$ALIGN 8}
{$MINENUMSIZE 4}
const
JAS_STREAM_MAXPUTBACK = 16;
JAS_STREAM_READ = $0001;
JAS_STREAM_WRITE = $0002; JAS_STREAM_APPEND = $0004; JAS_STREAM_BINARY = $0008; JAS_STREAM_CREATE = $0010;
JAS_STREAM_UNBUF = $0000;
JAS_STREAM_LINEBUF = $0001; JAS_STREAM_FULLBUF = $0002; JAS_STREAM_BUFMODEMASK =$000f;
JAS_CMPROF_NUMPXFORMSEQS = 13;
JAS_IMAGE_CS_GRAY = 769;
JAS_IMAGE_CS_RGB = 1025;
JAS_CLRSPC_CHANIND_RGB_R = 0;
JAS_CLRSPC_CHANIND_RGB_G = 1; JAS_CLRSPC_CHANIND_RGB_B = 2; JAS_CLRSPC_CHANIND_GRAY_Y = 0;
type
int = Integer;
uint = Cardinal;
uchar = Byte;
ushort = Word;
ulonglong = Int64;
long = Longint;
bool = Boolean; // or int or longbool
puchar = ^uchar;
type
int_fast32_t = int;
uint_fast32_t = uint;
uint_fast16_t = ushort;
uint_fast64_t = ulonglong;
uint_fast8_t = uchar;
jas_image_coord_t = int_fast32_t;
jas_image_cmpttype_t = int_fast32_t;
jas_clrspc_t = int;
jas_iccuint32_t = uint_fast32_t;
jas_iccsig_t = uint_fast32_t;
jas_iccuint16_t = uint_fast16_t;
jas_iccuint64_t = uint_fast64_t;
jas_iccs15fixed16_t = int_fast32_t;
jas_iccuint8_t = uint_fast8_t;
jas_iccsint32_t = int_fast32_t;
jas_align_t = Double;
jas_cmreal_t = Double;
jas_seqent_t = int_fast32_t;
type
pjas_iccuint16_t = ^jas_iccuint16_t;
ppjas_iccuint16_t = ^pjas_iccuint16_t;
pjas_iccuint8_t = ^jas_iccuint8_t;
ppjas_iccuint8_t = ^pjas_iccuint8_t;
type
JASMethod = procedure; cdecl;
type
pjas_stream_obj_t = Pointer;
pjas_stream_ops_t = ^jas_stream_ops_t;
pjas_stream_t = ^jas_stream_t;
pjas_image_t = ^jas_image_t;
pjas_image_cmpt_t = ^jas_image_cmpt_t;
ppjas_image_cmpt_t = ^pjas_image_cmpt_t;
pjas_cmprof_t = ^jas_cmprof_t;
pjas_iccprof_t = ^jas_iccprof_t;
pjas_icchdr_t = ^jas_icchdr_t;
pjas_icctime_t = ^jas_icctime_t;
pjas_iccxyz_t = ^jas_iccxyz_t;
pjas_icctagtab_t = ^jas_icctagtab_t;
pjas_icctagtabent_t = ^jas_icctagtabent_t;
pjas_iccattrtab_t = ^jas_iccattrtab_t;
pjas_iccattr_t = ^jas_iccattr_t;
pjas_iccattrval_t = ^jas_iccattrval_t;
pjas_iccattrvalops_t = ^jas_iccattrvalops_t;
pjas_icccurv_t = ^jas_icccurv_t;
pjas_icctxtdesc_t = ^jas_icctxtdesc_t;
pjas_icctxt_t = ^jas_icctxt_t;
pjas_icclut8_t = ^jas_icclut8_t;
pjas_icclut16_t = ^jas_icclut16_t;
pjas_cmpxformseq_t = ^jas_cmpxformseq_t;
pjas_cmpxform_t = ^jas_cmpxform_t;
ppjas_cmpxform_t = ^pjas_cmpxform_t;
pjas_cmpxformops_t = ^jas_cmpxformops_t;
pjas_cmshapmat_t = ^jas_cmshapmat_t;
pjas_cmshapmatlut_t = ^jas_cmshapmatlut_t;
pjas_align_t = ^jas_align_t;
pjas_cmreal_t = ^jas_cmreal_t;
pjas_cmshaplut_t = ^jas_cmshaplut_t;
pjas_cmclrspcconv_t = ^jas_cmclrspcconv_t;
pjas_matrix_t = ^jas_matrix_t;
pjas_seqent_t = ^jas_seqent_t;
ppjas_seqent_t = ^pjas_seqent_t;
pjas_image_cmptparm_t = ^jas_image_cmptparm_t;
jas_stream_ops_t = record
(* Read characters from a file object. *)
read_: function(obj: pjas_stream_obj_t; buf: pchar; cnt: int): int; cdecl;
(* Write characters to a file object. *) write_: function(obj: pjas_stream_obj_t; buf: pchar; cnt: int): int; cdecl; (* Set the position for a file object. *) seek_: function(obj: pjas_stream_obj_t; offset: long; origin: int): long; cdecl; (* Close a file object. *) close_: function(obj: pjas_stream_obj_t): int; cdecl; end; jas_stream_t = record
(* The mode in which the stream was opened. *)
openmode_: int; (* The buffering mode. *) bufmode_: int; (* The stream status. *) flags_: int; (* The start of the buffer area to use for reading/writing. *) bufbase_: puchar; (* The start of the buffer area excluding the extra initial space for character putback. *) bufstart_: puchar; (* The buffer size. *) bufsize_: int; (* The current position in the buffer. *) ptr_: puchar; (* The number of characters that must be read/written before the buffer needs to be filled/flushed. *) cnt_: int; (* A trivial buffer to be used for unbuffered operation. *) tinybuf_: array [0..JAS_STREAM_MAXPUTBACK] of uchar; (* The operations for the underlying stream file object. *) ops_: pjas_stream_ops_t; (* The underlying stream file object. *) obj_: pjas_stream_obj_t; (* The number of characters read/written. *) rwcnt_: long; (* The maximum number of characters that may be read/written. *) rwlimit_: long; end; jas_image_cmpt_t = record tlx_: jas_image_coord_t; (* The x-coordinate of the top-left corner of the component. *) tly_: jas_image_coord_t; (* The y-coordinate of the top-left corner of the component. *) hstep_: jas_image_coord_t; (* The horizontal sampling period in units of the reference grid. *) vstep_: jas_image_coord_t; (* The vertical sampling period in units of the reference grid. *) width_: jas_image_coord_t; (* The component width in samples. *) height_: jas_image_coord_t; (* The component height in samples. *) prec_: int; (* The precision of the sample data (i.e., the number of bits per sample). If the samples are signed values, this quantity includes the sign bit. *) sgnd_: int; (* The signedness of the sample data. *) stream_: pjas_stream_t; (* The stream containing the component data. *) cps_: int; (* The number of characters per sample in the stream. *) type_: jas_image_cmpttype_t; (* The type of component (e.g., opacity, red, green, blue, luma). *) end; jas_icctime_t = record year: jas_iccuint16_t; month: jas_iccuint16_t; day: jas_iccuint16_t; hour: jas_iccuint16_t; min: jas_iccuint16_t; sec: jas_iccuint16_t; end; jas_iccxyz_t = record x: jas_iccs15fixed16_t; y: jas_iccs15fixed16_t; z: jas_iccs15fixed16_t; end; jas_icchdr_t = record size: jas_iccuint32_t; (* profile size *) cmmtype: jas_iccsig_t; (* CMM type signature *) version: jas_iccuint32_t; (* profile version *) clas: jas_iccsig_t; (* profile/device class signature *) colorspc: jas_iccsig_t; (* color space of data *) refcolorspc: jas_iccsig_t; (* profile connection space *) ctime: jas_icctime_t; (* creation time *) magic: jas_iccsig_t; (* profile file signature *) platform_: jas_iccsig_t; (* primary platform *) flags: jas_iccuint32_t; (* profile flags *) maker: jas_iccsig_t; (* device manufacturer signature *) model: jas_iccsig_t; (* device model signature *) attr: jas_iccuint64_t; (* device setup attributes *) intent: jas_iccsig_t; (* rendering intent *) illum: jas_iccxyz_t; (* illuminant *) creator: jas_iccsig_t; (* profile creator signature *) end; jas_icctagtabent_t = record tag: jas_iccuint32_t; off: jas_iccuint32_t; len: jas_iccuint32_t; data: Pointer; first: pjas_icctagtabent_t; end; jas_icctagtab_t = record numents: jas_iccuint32_t; ents: pjas_icctagtabent_t; end; jas_iccattrvalops_t = record destroy: JASMethod; copy: JASMethod; input: JASMethod; output: JASMethod; getsize: JASMethod; dump: JASMethod; end; jas_icccurv_t = record numents: jas_iccuint32_t; ents: pjas_iccuint16_t; end; jas_icctxtdesc_t = record asclen: jas_iccuint32_t; ascdata: pchar; (* ASCII invariant description *) uclangcode: jas_iccuint32_t; (* Unicode language code *) uclen: jas_iccuint32_t; (* Unicode localizable description count *) ucdata: puchar; (* Unicode localizable description *) sccode: jas_iccuint16_t; (* ScriptCode code *) maclen: jas_iccuint8_t; (* Localizable Macintosh description count *) macdata: array [0..68] of uchar; (* Localizable Macintosh description *) end; jas_icctxt_t = record string_: pchar; end; jas_icclut8_t = record numinchans: jas_iccuint8_t; numoutchans: jas_iccuint8_t; e: array [0..2,0..2] of jas_iccsint32_t; clutlen: jas_iccuint8_t; clut: pjas_iccuint8_t; numintabents: jas_iccuint16_t; intabs: ppjas_iccuint8_t; intabsbuf: pjas_iccuint8_t; numouttabents: jas_iccuint16_t; outtabs: ppjas_iccuint8_t; outtabsbuf: pjas_iccuint8_t; end; jas_icclut16_t = record numinchans: jas_iccuint8_t; numoutchans: jas_iccuint8_t; e: array [0..2,0..2] of jas_iccsint32_t; clutlen: jas_iccuint8_t; clut: pjas_iccuint16_t; numintabents: jas_iccuint16_t; intabs: ppjas_iccuint16_t; intabsbuf: pjas_iccuint16_t; numouttabents: jas_iccuint16_t; outtabs: ppjas_iccuint16_t; outtabsbuf: pjas_iccuint16_t; end; jas_iccattrval_t = record refcnt: int; (* reference count *) type_: jas_iccsig_t; (* type *) ops: pjas_iccattrvalops_t; (* type-dependent operations *) case Integer of 0: (xyz: jas_iccxyz_t); 1: (curv: jas_icccurv_t); 2: (txtdesc: jas_icctxtdesc_t); 3: (txt: jas_icctxt_t); 4: (lut8: jas_icclut8_t); 5: (lut16: jas_icclut16_t); end; jas_iccattr_t = record name: jas_iccsig_t; val: pjas_iccattrval_t; end; jas_iccattrtab_t = record numattrs: int; maxattrs: int; attrs: pjas_iccattr_t; end; jas_iccprof_t = record hdr: jas_icchdr_t; tagtab: jas_icctagtab_t; attrtab: pjas_iccattrtab_t; end; jas_cmpxformops_t = record destroy: JASMethod; apply: JASMethod; dump: JASMethod; end; jas_cmshapmatlut_t = record data: pjas_cmreal_t; size: int; end; jas_cmshapmat_t = record mono: int; order: int; useluts: int; usemat: int; luts: array [0..2] of jas_cmshapmatlut_t; mat: array [0..2,0..3] of jas_cmreal_t; end; jas_cmshaplut_t = record order: int; end; jas_cmclrspcconv_t = record inclrspc: int; outclrspc: int; end; jas_cmpxform_t = record refcnt: int; ops: pjas_cmpxformops_t; numinchans: int; numoutchans: int; case Integer of 0: (dummy: jas_align_t); 1: (shapmat: jas_cmshapmat_t); 2: (shaplut: jas_cmshaplut_t); 3: (clrspcconv: jas_cmclrspcconv_t); end; jas_cmpxformseq_t = record numpxforms: int; maxpxforms: int; pxforms: ppjas_cmpxform_t; end; jas_cmprof_t = record clrspc: int; numchans: int; refclrspc: int; numrefchans: int; iccprof: pjas_iccprof_t; pxformseqs: array [0..JAS_CMPROF_NUMPXFORMSEQS-1] of pjas_cmpxformseq_t; end; jas_image_t = record tlx_: jas_image_coord_t;
(* The x-coordinate of the top-left corner of the image bounding box. *) tly_: jas_image_coord_t; (* The y-coordinate of the top-left corner of the image bounding box. *) brx_: jas_image_coord_t; (* The x-coordinate of the bottom-right corner of the image bounding box (plus one). *) bry_: jas_image_coord_t; (* The y-coordinate of the bottom-right corner of the image bounding box (plus one). *) numcmpts_: int; (* The number of components. *) maxcmpts_: int; (* The maximum number of components that this image can have (i.e., the allocated size of the components array). *) cmpts_: ppjas_image_cmpt_t; (* Per-component information. *) clrspc_: jas_clrspc_t; cmprof_: pjas_cmprof_t; inmem_: bool; end; jas_matrix_t = record (* Additional state information. *) flags_: int; (* The starting horizontal index. *) xstart_: int_fast32_t; (* The starting vertical index. *) ystart_: int_fast32_t; (* The ending horizontal index. *) xend_: int_fast32_t; (* The ending vertical index. *) yend_: int_fast32_t; (* The number of rows in the matrix. *) numrows_: int_fast32_t; (* The number of columns in the matrix. *) numcols_: int_fast32_t; (* Pointers to the start of each row. *) rows_: ppjas_seqent_t; (* The allocated size of the rows array. *) maxrows_: int_fast32_t; (* The matrix data buffer. *) data_: pjas_seqent_t; (* The allocated size of the data array. *) datasize_: int_fast32_t; end; jas_image_cmptparm_t = record tlx: jas_image_coord_t; (* The x-coordinate of the top-left corner of the component. *) tly: jas_image_coord_t; (* The y-coordinate of the top-left corner of the component. *) hstep: jas_image_coord_t; (* The horizontal sampling period in units of the reference grid. *) vstep: jas_image_coord_t; (* The vertical sampling period in units of the reference grid. *) width: jas_image_coord_t; (* The width of the component in samples. *) height: jas_image_coord_t; (* The height of the component in samples. *) prec: int; (* The precision of the component sample data. *) sgnd: int; (* The signedness of the component sample data. *) end;const JasperLib = 'libjasper.dll';
function jas_init: int; cdecl; external JasperLib;
function jas_image_decode(var in_: jas_stream_t; fmt: int; optstr: pchar): pjas_image_t; cdecl; external JasperLib;
function jas_matrix_create(numrows: int; numcols: int): pjas_matrix_t; cdecl; external JasperLib;
function jas_image_readcmpt(image: pjas_image_t; cmptno: int;
x: jas_image_coord_t; y: jas_image_coord_t; width: jas_image_coord_t;
height: jas_image_coord_t; data: pjas_matrix_t): int; cdecl; external JasperLib;
procedure jas_matrix_destroy(matrix: pjas_matrix_t); cdecl; external JasperLib;
procedure jas_image_destroy(image: pjas_image_t); cdecl; external JasperLib;
function jas_image_create(numcmpts: int; cmptparms: pjas_image_cmptparm_t; clrspc: jas_clrspc_t): pjas_image_t; cdecl; external JasperLib;
function jas_image_writecmpt(image: pjas_image_t; cmptno: int;
x: jas_image_coord_t; y: jas_image_coord_t; width: jas_image_coord_t;
height: jas_image_coord_t; data: pjas_matrix_t): int; cdecl; external JasperLib;
function jas_image_strtofmt(s: pchar): int; cdecl; external JasperLib;
function jas_image_encode(image: pjas_image_t; var out_: jas_stream_t; fmt: int; optstr: pchar): int; cdecl; external JasperLib;
function jas_stream_close(var stream: jas_stream_t): int;
implementation
function jas_stream_flush(var stream: jas_stream_t): int; cdecl; external JasperLib;
function jas_stream_close(var stream: jas_stream_t): int;
begin
{ Custom implementation. The default implementation frees the stream object
in a Delphi incompatible way, leading to an access violation }
jas_stream_flush(stream);
stream.ops_.close_(stream.obj_);
// Do not call jas_stream_destroy Result := 0;end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -