Statistics
| Branch: | Tag: | Revision:

root / Imaging / ImagingTypes.pas @ 0:95bd93c28625

History | View | Annotate | Download (21.3 kB)

1
{
2
  $Id: ImagingTypes.pas 112 2007-12-11 19:43:15Z galfar $
3
  Vampyre Imaging Library
4
  by Marek Mauder 
5
  http://imaginglib.sourceforge.net
6
7
  The contents of this file are used with permission, subject to the Mozilla
8
  Public License Version 1.1 (the "License"); you may not use this file except
9
  in compliance with the License. You may obtain a copy of the License at
10
  http://www.mozilla.org/MPL/MPL-1.1.html
11
12
  Software distributed under the License is distributed on an "AS IS" basis,
13
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14
  the specific language governing rights and limitations under the License.
15
16
  Alternatively, the contents of this file may be used under the terms of the
17
  GNU Lesser General Public License (the  "LGPL License"), in which case the
18
  provisions of the LGPL License are applicable instead of those above.
19
  If you wish to allow use of your version of this file only under the terms
20
  of the LGPL License and not to allow others to use your version of this file
21
  under the MPL, indicate your decision by deleting  the provisions above and
22
  replace  them with the notice and other provisions required by the LGPL
23
  License.  If you do not delete the provisions above, a recipient may use
24
  your version of this file under either the MPL or the LGPL License.
25
26
  For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
27
}
28
29
{ This unit contains basic types and constants used by Imaging library.}
30
unit ImagingTypes;
31
32
{$I ImagingOptions.inc}
33
34
interface
35
36
const
37
  { Current Major version of Imaging.}
38
  ImagingVersionMajor = 0;
39
  { Current Minor version of Imaging.}
40
  ImagingVersionMinor = 24;
41
  { Current patch of Imaging.}
42
  ImagingVersionPatch = 2;
43
44
  { Imaging Option Ids whose values can be set/get by SetOption/
45
    GetOption functions.}
46
47
  { Defines Jpeg compression quality, ranges from 1 (ugly/small) to 100 (nice/large).
48
    Default value is 90.}
49
  ImagingJpegQuality           = 10;
50
  { Specifies whether Jpeg images are saved in progressive format,
51
    can be 0 or 1. Default value is 0.}
52
  ImagingJpegProgressive       = 11;
53
54
  { Specifies whether Windows Bitmaps are saved using RLE compression
55
    (only for 1/4/8 bit images), can be 0 or 1. Default value is 1.}
56
  ImagingBitmapRLE             = 12;
57
58
  { Specifies whether Targa images are saved using RLE compression,
59
    can be 0 or 1. Default value is 0.}
60
  ImagingTargaRLE              = 13;
61
62
  { Value of this option is non-zero if last loaded DDS file was cube map.}
63
  ImagingDDSLoadedCubeMap      = 14;
64
  { Value of this option is non-zero if last loaded DDS file was volume texture.}
65
  ImagingDDSLoadedVolume       = 15;
66
  { Value of this option is number of mipmap levels of last loaded DDS image.}
67
  ImagingDDSLoadedMipMapCount  = 16;
68
  { Value of this option is depth (slices of volume texture or faces of
69
    cube map) of last loaded DDS image.}
70
  ImagingDDSLoadedDepth        = 17;
71
  { If it is non-zero next saved DDS file should be stored as cube map.}
72
  ImagingDDSSaveCubeMap        = 18;
73
  { If it is non-zero next saved DDS file should be stored as volume texture.}
74
  ImagingDDSSaveVolume         = 19;
75
  { Sets the number of mipmaps which should be stored in the next saved DDS file.
76
    Only applies to cube maps and volumes, ordinary 2D textures save all
77
    levels present in input.}
78
  ImagingDDSSaveMipMapCount    = 20;
79
  { Sets the depth (slices of volume texture or faces of cube map)
80
    of the next saved DDS file.}
81
  ImagingDDSSaveDepth          = 21;
82
83
  { Sets precompression filter used when saving PNG images. Allowed values
84
    are: 0 (none), 1 (sub), 2 (up), 3 (average), 4 (paeth),
85
    5 (use 0 for indexed/gray images and 4 for RGB/ARGB images),
86
    6 (adaptive filtering - use best filter for each scanline - very slow).
87
    Note that filters 3 and 4 are much slower than filters 1 and 2.
88
    Default value is 5.}
89
  ImagingPNGPreFilter          = 25;
90
  { Sets ZLib compression level used when saving PNG images.
91
    Allowed values are in range 0 (no compresstion) to 9 (best compression).
92
    Default value is 5.}
93
  ImagingPNGCompressLevel      = 26;
94
95
  { Specifies whether MNG animation frames are saved with lossy or lossless
96
    compression. Lossless frames are saved as PNG images and lossy frames are
97
    saved as JNG images. Allowed values are 0 (False) and 1 (True).
98
    Default value is 0.}
99
  ImagingMNGLossyCompression   = 28;
100
  { Defines whether alpha channel of lossy compressed MNG frames
101
    (when ImagingMNGLossyCompression is 1) is lossy compressed too.
102
    Allowed values are 0 (False) and 1 (True). Default value is 0.}
103
  ImagingMNGLossyAlpha         = 29;
104
  { Sets precompression filter used when saving MNG frames as PNG images.
105
    For details look at ImagingPNGPreFilter.}
106
  ImagingMNGPreFilter          = 30;
107
  { Sets ZLib compression level used when saving MNG frames as PNG images.
108
    For details look at ImagingPNGCompressLevel.}
109
  ImagingMNGCompressLevel      = 31;
110
  { Specifies compression quality used when saving MNG frames as JNG images.
111
    For details look at ImagingJpegQuality.}
112
  ImagingMNGQuality            = 32;
113
  { Specifies whether images are saved in progressive format when saving MNG
114
    frames as JNG images. For details look at ImagingJpegProgressive.}
115
  ImagingMNGProgressive        = 33;
116
117
  { Specifies whether alpha channels of JNG images are lossy compressed.
118
    Allowed values are 0 (False) and 1 (True). Default value is 0.}
119
  ImagingJNGLossyAlpha         = 40;
120
  { Sets precompression filter used when saving lossless alpha channels.
121
    For details look at ImagingPNGPreFilter.}
122
  ImagingJNGAlphaPreFilter     = 41;
123
  { Sets ZLib compression level used when saving lossless alpha channels.
124
    For details look at ImagingPNGCompressLevel.}
125
  ImagingJNGAlphaCompressLevel = 42;
126
  { Defines compression quality used when saving JNG images (and lossy alpha channels).
127
    For details look at ImagingJpegQuality.}
128
  ImagingJNGQuality            = 43;
129
  { Specifies whether JNG images are saved in progressive format.
130
    For details look at ImagingJpegProgressive.}
131
  ImagingJNGProgressive        = 44;
132
  { Specifies whether PGM files are stored in text or in binary format.
133
    Allowed values are 0 (store as text - very! large files) and 1 (save binary).
134
    Default value is 1.}
135
  ImagingPGMSaveBinary         = 50;
136
  { Specifies whether PPM files are stored in text or in binary format.
137
    Allowed values are 0 (store as text - very! large files) and 1 (save binary).
138
    Default value is 1.}
139
  ImagingPPMSaveBinary         = 51;
140
141
142
  { This option is used when reducing number of colors used in
143
    image (mainly when converting from ARGB image to indexed
144
    format). Mask is 'anded' (bitwise AND) with every pixel's
145
    channel value when creating color histogram. If $FF is used
146
    all 8bits of color channels are used which can result in very
147
    slow proccessing of large images with many colors so you can
148
    use lower masks to speed it up (FC, F8 and F0 are good
149
    choices). Allowed values are in range <0, $FF> and default is
150
    $FE.                                                          }
151
  ImagingColorReductionMask   = 128;
152
  { This option can be used to override image data format during image
153
    loading. If set to format different from ifUnknown all loaded images
154
    are automaticaly converted to this format. Useful when you have
155
    many files in various formats but you want them all in one format for
156
    further proccessing. Allowed values are in
157
    range <Ord(Low(TImageFormat)), Ord(High(TImageFormat))> and
158
    default value is ifUnknown.}
159
  ImagingLoadOverrideFormat   = 129;
160
  { This option can be used to override image data format during image
161
    saving. If set to format different from ifUnknown all images
162
    to be saved are automaticaly internaly converted to this format.
163
    Note that image file formats support only a subset of Imaging data formats
164
    so final saved file may in different format than this override.
165
    Allowed values are in range <Ord(Low(TImageFormat)), Ord(High(TImageFormat))>
166
    and default value is ifUnknown.}
167
  ImagingSaveOverrideFormat   = 130;
168
  { Specifies resampling filter used when generating mipmaps. It is used
169
    in GenerateMipMaps low level function and Direct3D and OpenGL extensions.
170
    Allowed values are in range
171
    <Ord(Low(ImagingFormats.TSamplingFilter)), Ord(High(ImagingFormats.TSamplingFilter))>
172
    and default value is 1 (linear filter).}
173
  ImagingMipMapFilter         = 131;
174
175
  { Returned by GetOption if given Option Id is invalid.}
176
  InvalidOption = -$7FFFFFFF;
177
178
  { Indices that can be used to access channel values in array parts
179
    of structures like TColor32Rec. Note that this order can be
180
    used only for ARGB images. For ABGR image you must swap Red and Blue.}
181
  ChannelBlue  = 0;
182
  ChannelGreen = 1;
183
  ChannelRed   = 2;
184
  ChannelAlpha = 3;
185
186
type
187
  { Enum defining image data format. In formats with more channels,
188
    first channel after "if" is stored in the most significant bits and channel
189
    before end is stored in the least significant.}
190
  TImageFormat = (
191
    ifUnknown        = 0,
192
    ifDefault        = 1,
193
    { Indexed formats using palette.}
194
    ifIndex8         = 10,
195
    { Grayscale/Luminance formats.}
196
    ifGray8          = 40,
197
    ifA8Gray8        = 41,
198
    ifGray16         = 42,
199
    ifGray32         = 43,
200
    ifGray64         = 44,
201
    ifA16Gray16      = 45,
202
    { ARGB formats.}
203
    ifX5R1G1B1       = 80,
204
    ifR3G3B2         = 81,
205
    ifR5G6B5         = 82,
206
    ifA1R5G5B5       = 83,
207
    ifA4R4G4B4       = 84,
208
    ifX1R5G5B5       = 85,
209
    ifX4R4G4B4       = 86,
210
    ifR8G8B8         = 87,
211
    ifA8R8G8B8       = 88,
212
    ifX8R8G8B8       = 89,
213
    ifR16G16B16      = 90,
214
    ifA16R16G16B16   = 91,
215
    ifB16G16R16      = 92,
216
    ifA16B16G16R16   = 93,
217
    { Floating point formats.}
218
    ifR32F           = 170,
219
    ifA32R32G32B32F  = 171,
220
    ifA32B32G32R32F  = 172,
221
    ifR16F           = 173,
222
    ifA16R16G16B16F  = 174,
223
    ifA16B16G16R16F  = 175,
224
    { Special formats.}
225
    ifDXT1           = 220,
226
    ifDXT3           = 221,
227
    ifDXT5           = 222,
228
    ifBTC            = 223);
229
230
  { Color value for 32 bit images.}
231
  TColor32 = LongWord;
232
  PColor32 = ^TColor32;
233
234
  { Color value for 64 bit images.}
235
  TColor64 = type Int64;
236
  PColor64 = ^TColor64;
237
238
  { Color record for 24 bit images, which allows access to individual color
239
    channels.}
240
  TColor24Rec = packed record
241
    case LongInt of
242
      0: (B, G, R: Byte);
243
      1: (Channels: array[0..2] of Byte);
244
  end;
245
  PColor24Rec = ^TColor24Rec;
246
  TColor24RecArray = array[0..MaxInt div SizeOf(TColor24Rec) - 1] of TColor24Rec;
247
  PColor24RecArray = ^TColor24RecArray;
248
249
  { Color record for 32 bit images, which allows access to individual color
250
    channels.}
251
  TColor32Rec = packed record
252
    case LongInt of
253
      0: (Color: TColor32);
254
      1: (B, G, R, A: Byte);
255
      2: (Channels: array[0..3] of Byte);
256
      3: (Color24Rec: TColor24Rec);
257
  end;
258
  PColor32Rec = ^TColor32Rec;
259
  TColor32RecArray = array[0..MaxInt div SizeOf(TColor32Rec) - 1] of TColor32Rec;
260
  PColor32RecArray = ^TColor32RecArray;
261
262
  { Color record for 48 bit images, which allows access to individual color
263
    channels.}
264
  TColor48Rec = packed record
265
    case LongInt of
266
      0: (B, G, R: Word);
267
      1: (Channels: array[0..2] of Word);
268
  end;
269
  PColor48Rec = ^TColor48Rec;
270
  TColor48RecArray = array[0..MaxInt div SizeOf(TColor48Rec) - 1] of TColor48Rec;
271
  PColor48RecArray = ^TColor48RecArray;
272
273
  { Color record for 64 bit images, which allows access to individual color
274
    channels.}
275
  TColor64Rec = packed record
276
    case LongInt of
277
      0: (Color: TColor64);
278
      1: (B, G, R, A: Word);
279
      2: (Channels: array[0..3] of Word);
280
      3: (Color48Rec: TColor48Rec);
281
  end;
282
  PColor64Rec = ^TColor64Rec;
283
  TColor64RecArray = array[0..MaxInt div SizeOf(TColor64Rec) - 1] of TColor64Rec;
284
  PColor64RecArray = ^TColor64RecArray;
285
286
  { Color record for 128 bit floating point images, which allows access to
287
    individual color channels.}
288
  TColorFPRec = packed record
289
    case LongInt of
290
      0: (B, G, R, A: Single);
291
      1: (Channels: array[0..3] of Single);
292
  end;
293
  PColorFPRec = ^TColorFPRec;
294
  TColorFPRecArray = array[0..MaxInt div SizeOf(TColorFPRec) - 1] of TColorFPRec;
295
  PColorFPRecArray = ^TColorFPRecArray;
296
297
  { 16 bit floating-point value. It has 1 sign bit, 5 exponent bits,
298
    and 10 mantissa bits.}
299
  THalfFloat = type Word;
300
  PHalfFloat = ^THalfFloat;
301
302
  { Color record for 64 bit floating point images, which allows access to
303
    individual color channels.}
304
  TColorHFRec = packed record
305
    case LongInt of
306
      0: (B, G, R, A: THalfFloat);
307
      1: (Channels: array[0..3] of THalfFloat);
308
  end;
309
  PColorHFRec = ^TColorHFRec;
310
  TColorHFRecArray = array[0..MaxInt div SizeOf(TColorHFRec) - 1] of TColorHFRec;
311
  PColorHFRecArray = ^TColorHFRecArray;
312
313
  { Palette for indexed mode images with 32 bit colors.}
314
  TPalette32 = TColor32RecArray;
315
  TPalette32Size256 = array[0..255] of TColor32Rec;
316
  PPalette32 = ^TPalette32;
317
318
  { Palette for indexd mode images with 24 bit colors.}
319
  TPalette24 = TColor24RecArray;
320
  TPalette24Size256 = array[0..255] of TColor24Rec;
321
  PPalette24 = ^TPalette24;
322
323
  { Record that stores single image data and information describing it.}
324
  TImageData = packed record
325
    Width: LongInt;       // Width of image in pixels
326
    Height: LongInt;      // Height of image in pixels
327
    Format: TImageFormat; // Data format of image
328
    Size: LongInt;        // Size of image bits in Bytes
329
    Bits: Pointer;        // Pointer to memory containing image bits
330
    Palette: PPalette32;  // Image palette for indexed images
331
  end;
332
  PImageData = ^TImageData;
333
334
  { Pixel format information used in conversions to/from 16 and 8 bit ARGB
335
    image formats.}
336
  TPixelFormatInfo = packed record
337
    ABitCount, RBitCount, GBitCount, BBitCount: Byte;
338
    ABitMask, RBitMask, GBitMask, BBitMask: LongWord;
339
    AShift, RShift, GShift, BShift: Byte;
340
    ARecDiv, RRecDiv, GRecDiv, BRecDiv: Byte;
341
  end;
342
  PPixelFormatInfo = ^TPixelFormatInfo;
343
344
  PImageFormatInfo = ^TImageFormatInfo;
345
346
  { Look at TImageFormatInfo.GetPixelsSize for details.}
347
  TFormatGetPixelsSizeFunc = function(Format: TImageFormat; Width,
348
    Height: LongInt): LongInt;
349
  { Look at TImageFormatInfo.CheckDimensions for details.}
350
  TFormatCheckDimensionsProc = procedure(Format: TImageFormat; var Width,
351
    Height: LongInt);
352
  { Function for getting pixel colors. Native pixel is read from Image and
353
    then translated to 32 bit ARGB.}
354
  TGetPixel32Func = function(Bits: Pointer; Info: PImageFormatInfo;
355
    Palette: PPalette32): TColor32Rec;
356
  { Function for getting pixel colors. Native pixel is read from Image and
357
    then translated to FP ARGB.}
358
  TGetPixelFPFunc = function(Bits: Pointer; Info: PImageFormatInfo;
359
    Palette: PPalette32): TColorFPRec;
360
  { Procedure for setting pixel colors. Input 32 bit ARGB color is translated to
361
    native format and then written to Image.}
362
  TSetPixel32Proc = procedure(Bits: Pointer; Info: PImageFormatInfo;
363
    Palette: PPalette32;const Color: TColor32Rec);
364
  { Procedure for setting pixel colors. Input FP ARGB color is translated to
365
    native format and then written to Image.}
366
  TSetPixelFPProc = procedure(Bits: Pointer; Info: PImageFormatInfo; 
367
    Palette: PPalette32; const Color: TColorFPRec);
368
369
  { Additional information for each TImageFormat value.}
370
  TImageFormatInfo = packed record
371
    Format: TImageFormat;             // Format described by this record
372
    Name: array[0..15] of Char;       // Symbolic name of format
373
    BytesPerPixel: LongInt;           // Number of bytes per pixel (note: it is
374
                                      // 0 for formats where BitsPerPixel < 8 (e.g. DXT).
375
                                      // Use GetPixelsSize function to get size of
376
                                      // image data.
377
    ChannelCount: LongInt;            // Number of image channels (R, G, B, A, Gray)
378
    PaletteEntries: LongInt;          // Number of palette entries
379
    HasGrayChannel: Boolean;          // True if image has grayscale channel
380
    HasAlphaChannel: Boolean;         // True if image has alpha channel
381
    IsFloatingPoint: Boolean;         // True if image has floating point pixels
382
    UsePixelFormat: Boolean;          // True if image uses pixel format
383
    IsRBSwapped: Boolean;             // True if Red and Blue channels are swapped
384
                                      // e.g. A16B16G16R16 has IsRBSwapped True
385
    RBSwapFormat: TImageFormat;       // Indicates supported format with swapped
386
                                      // Red and Blue channels, ifUnknown if such
387
                                      // format does not exist
388
    IsIndexed: Boolean;               // True if image uses palette
389
    IsSpecial: Boolean;               // True if image is in special format
390
    PixelFormat: PPixelFormatInfo;    // Pixel format structure
391
    GetPixelsSize: TFormatGetPixelsSizeFunc; // Returns size in bytes of
392
                                      // Width * Height pixels of image
393
    CheckDimensions: TFormatCheckDimensionsProc; // some formats have limited
394
                                      // values of Width and Height. This
395
                                      // procedure checks and changes dimensions
396
                                      // to be valid for given format.
397
    GetPixel32: TGetPixel32Func;      // 32bit ARGB pixel get function
398
    GetPixelFP: TGetPixelFPFunc;      // FP ARGB pixel get function
399
    SetPixel32: TSetPixel32Proc;      // 32bit ARGB pixel set procedure
400
    SetPixelFP: TSetPixelFPProc;      // FP ARGB pixel set procedure
401
    SpecialNearestFormat: TImageFormat; // Regular image format used when
402
                                      // compressing/decompressing special images
403
                                      // as source/target
404
  end;
405
406
  { Handle to list of image data records.}
407
  TImageDataList = Pointer;
408
  PImageDataList = ^TImageDataList;
409
410
  { Handle to input/output.}
411
  TImagingHandle = Pointer;
412
413
  { Filters used in functions that resize images or their portions.}
414
  TResizeFilter = (
415
    rfNearest  = 0,
416
    rfBilinear = 1,
417
    rfBicubic  = 2);
418
419
  { Seek origin mode for IO function Seek.}
420
  TSeekMode = (
421
   smFromBeginning = 0,
422
   smFromCurrent   = 1,
423
   smFromEnd       = 2);
424
425
  { IO functions used for reading and writing images from/to input/output.}
426
  TOpenReadProc = function(Source: PChar): TImagingHandle; cdecl;
427
  TOpenWriteProc = function(Source: PChar): TImagingHandle; cdecl;
428
  TCloseProc = procedure(Handle: TImagingHandle); cdecl;
429
  TEofProc = function(Handle: TImagingHandle): Boolean; cdecl;
430
  TSeekProc = function(Handle: TImagingHandle; Offset: LongInt; Mode: TSeekMode): LongInt; cdecl;
431
  TTellProc = function(Handle: TImagingHandle): LongInt; cdecl;
432
  TReadProc = function(Handle: TImagingHandle; Buffer: Pointer; Count: LongInt): LongInt; cdecl;
433
  TWriteProc = function(Handle: TImagingHandle; Buffer: Pointer; Count: LongInt): LongInt; cdecl;
434
       
435
implementation
436
437
{
438
  File Notes:
439
440
  -- TODOS ----------------------------------------------------
441
    - add lookup tables to pixel formats for fast conversions
442
    - change TImageFormatInfo - add new fields that shoudl replace old chaos
443
      like not knowing whether it is RGB without checking all other fields for False
444
      (add something like FormatType = (ftIndexed, ftRGB, ftIntensity, ftCompressed,
445
      ftFloatingPoint, ftRGBBitFields) and additional infos like HasAlphaChannel,
446
      ChannelSize, ChannelCount, ...)
447
448
  -- 0.23 Changes/Bug Fixes -----------------------------------
449
    - Added ifBTC image format and SpecialNearestFormat field
450
      to TImageFormatInfo.
451
452
  -- 0.21 Changes/Bug Fixes -----------------------------------
453
    - Added option constants for PGM and PPM file formats.
454
    - Added TPalette32Size256 and TPalette24Size256 types.
455
456
  -- 0.19 Changes/Bug Fixes -----------------------------------
457
    - added ImagingVersionPatch constant so bug fix only releases
458
      can be distinguished from ordinary major/minor releases
459
    - renamed TPixelFormat to TPixelFormatInfo to avoid name collisions
460
      with Graphics.TPixelFormat
461
    - added new image data formats:  ifR16F, ifA16R16G16B16F,
462
      ifA16B16G16R16F
463
    - added pixel get/set function pointers to TImageFormatInfo
464
    - added 16bit half float type and color record
465
    - renamed TColorFRec to TColorFPRec (and related types too)
466
467
  -- 0.17 Changes/Bug Fixes -----------------------------------
468
    - added option ImagingMipMapFilter which now controls resampling filter
469
      used when generating mipmaps
470
    - added TResizeFilter type
471
    - added ChannelCount to TImageFormatInfo
472
    - added new option constants for MNG and JNG images
473
474
  -- 0.15 Changes/Bug Fixes -----------------------------------
475
    - added RBSwapFormat to TImageFormatInfo for faster conversions
476
      between swapped formats (it just calls SwapChannels now if
477
      RBSwapFormat is not ifUnknown)
478
    - moved TImageFormatInfo and required types from Imaging unit
479
      here, removed TImageFormatShortInfo
480
    - added new options: ImagingLoadOverrideFormat, ImagingSaveOverrideFormat
481
482
  -- 0.13 Changes/Bug Fixes -----------------------------------
483
    - new ImagingColorReductionMask option added
484
    - new image format added: ifA16Gray16
485
486
}
487
488
end.