{
  $Id: ImagingTypes.pas,v 1.7 2005/06/22 13:53:21 galfar Exp $
  Vampyre Imaging Library
  by Marek Mauder (pentar@seznam.cz)
  http://imaginglib.sourceforge.net

  The contents of this file are used with permission, subject to the Mozilla
  Public License Version 1.1 (the "License"); you may not use this file except
  in compliance with the License. You may obtain a copy of the License at
  http://www.mozilla.org/MPL/MPL-1.1.html

  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  the specific language governing rights and limitations under the License.

  Alternatively, the contents of this file may be used under the terms of the
  GNU Lesser General Public License (the  "LGPL License"), in which case the
  provisions of the LGPL License are applicable instead of those above.
  If you wish to allow use of your version of this file only under the terms
  of the LGPL License and not to allow others to use your version of this file
  under the MPL, indicate your decision by deleting  the provisions above and
  replace  them with the notice and other provisions required by the LGPL
  License.  If you do not delete the provisions above, a recipient may use
  your version of this file under either the MPL or the LGPL License.

  For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
}

{ This unit contains basic types and constants used by Imaging library.}
unit ImagingTypes;

{$I ImagingOptions.inc}

interface

const
  {(*}
  { Current Major version of Imaging.}
  ImagingVersionMajor = 0;
  { Current Minor version of Imaging.}
  ImagingVersionMinor = 14;


  { Imaging Option Ids whose values can be set/get by SetOption/
    GetOption functions.}
  { Defines Jpeg Saving quality, ranges from 1 (ugly/small) to 100 (nice/large).}
  ImagingJpegQuality          = 10;
  { Specifies whether Jpeg images are saved in progressive format,
    can be 0 or 1.}
  ImagingJpegProgressive      = 11;
  { Specifies whether Windows Bitmaps are saved using RLE compression
    (only for 1/4/8 bit images), can be 0 or 1.}
  ImagingBitmapRLE            = 12;
  { Specifies whether Targa images are saved using RLE compression,
    can be 0 or 1.}
  ImagingTargaRLE             = 13;
  { Value of this option is non-zero if last loaded DDS file is cube map.}
  ImagingDDSLoadedCubeMap     = 14;
  { Value of this option is non-zero if last loaded DDS file is volume texture.}
  ImagingDDSLoadedVolume      = 15;
  { Value of this option is number of mipmap levels of last loaded DDS image.}
  ImagingDDSLoadedMipMapCount = 16;
  { Value of this option is depth (slices of volume texture or faces of
    cube map) of last loaded DDS image.}
  ImagingDDSLoadedDepth       = 17;
  { If it is non-zero next saved DDS file will be stored as cube map.}
  ImagingDDSSaveCubeMap       = 18;
  { If it is non-zero next saved DDS file will be stored as volume texture.}
  ImagingDDSSaveVolume        = 19;
  { Sets the number of mipmaps which will be stored in the next saved DDS file.}
  ImagingDDSSaveMipMapCount   = 20;
  { Sets the depth (slices of volume texture or faces of cube map)
    of the next saved DDS file.}
  ImagingDDSSaveDepth         = 21;
  { Sets precompression filter used when saving PNG images. Possible values
    are: 0 (none), 1 (sub), 2 (up), 3 (average), 4 (paeth),
    5 (use 0 for indexed/gray images and 4 for RGB/ARGB images),
    6 (adaptive filtering - use best filter for each scanline - very slow).
    Note that filters 3 and 4 are much slower than filters 1 and 2.
    The default value is 5.}
  ImagingPNGPreFilter         = 22;
  { Sets ZLib compression level used when saving PNG images.
    Possible values are in range 0 (no compresstion) to 9 (best compression).
    Default value is 5.}
  ImagingPNGCompressLevel     = 23;

  { This option is used when reducing number of colors used in
    image (mainly when converting from ARGB image to indexed
    format). Mask is 'anded' (bitwise AND) with every pixel's
    channel value when creating color histogram. If $FF is used
    all 8bits of color channels are used which can result in very
    slow proccessing of large images with many colors so you can
    use lower masks to speed it up (FC, F8 and F0 are good
    choices). Allowed values are in range <0, $FF> and default is
    $FE.                                                          }
  ImagingColorReductionMask   = 128;

  { Returned by GetOption if given Option Id is invalid.}
  InvalidOption = -$7FFFFFFF;

  { Indices that can be used to access channel values in array parts
    of structures like TColor32Rec. Note that this order can be
    used only for ARGB images. For ABGR image you must swap Red and Blue.}
  ChannelBlue  = 0;
  ChannelGreen = 1;
  ChannelRed   = 2;
  ChannelAlpha = 3;

type
  { Enum defining image data format. In formats with more channels,
    first channel after "if" is stored in the most significant bits and channel
    before end is stored in the least significant.}
//{$IF (not defined(FPC)) or (FPC_VERSION>1) or ((FPC_VERSION=1) and (FPC_RELEASE=9) and (FPC_PATCH>6))}
{  TImageFormat = (
    ifUnknown        = 0,
    ifDefault        = 1,
    // indexed formats using palette
    ifIndex8         = 10,
    // grayscale formats
    ifGray8          = 40,
    ifA8Gray8        = 41,
    ifGray16         = 42,
    ifGray32         = 43,
    ifGray64         = 44,
    ifA16Gray16      = 45,
    // ARGB formats
    ifX5R1G1B1       = 80,
    ifR3G3B2         = 81,
    ifR5G6B5         = 82,
    ifA1R5G5B5       = 83,
    ifA4R4G4B4       = 84,
    ifX1R5G5B5       = 85,
    ifX4R4G4B4       = 86,
    ifR8G8B8         = 87,
    ifA8R8G8B8       = 88,
    ifX8R8G8B8       = 89,
    ifR16G16B16      = 90,
    ifA16R16G16B16   = 91,
    ifB16G16R16      = 92,
    ifA16B16G16R16   = 93,
    // floating point formats
    ifR32F           = 170,
    ifA32R32G32B32F  = 171,
    ifA32B32G32R32F  = 172,
    // special formats
    ifDXT1           = 220,
    ifDXT3           = 221,
    ifDXT5           = 222);}
{ $ELSE}
  { Enum defining image data format. In formats with more channels,
    first channel after "if" is stored in the most significant bits and channel
    before end is stored in the least significant.}
  TImageFormat = (
    ifUnknown,
    ifDefault,
    ifIndex8,
    ifGray8,
    ifA8Gray8,
    ifGray16,
    ifGray32,
    ifGray64,
    ifA16Gray16,
    ifX5R1G1B1,
    ifR3G3B2,
    ifR5G6B5,
    ifA1R5G5B5,
    ifA4R4G4B4,
    ifX1R5G5B5,
    ifX4R4G4B4,
    ifR8G8B8,
    ifA8R8G8B8,
    ifX8R8G8B8,
    ifR16G16B16,
    ifA16R16G16B16,
    ifB16G16R16,
    ifA16B16G16R16,
    ifR32F,
    ifA32R32G32B32F,
    ifA32B32G32R32F,
    ifDXT1,
    ifDXT3,
    ifDXT5);
//{$IFEND}

  { Color value for 32 bit images.}
  TColor32 = LongWord;
  PColor32 = ^TColor32;

  { Color value for 64 bit images.}
  TColor64 = type Int64;
  PColor64 = ^TColor64;

  { Color record for 24 bit images, which allows access to individual color
    channels.}
  TColor24Rec = packed record
    case Integer of
      0: (B, G, R: Byte);
      1: (Channels: array[0..2] of Byte);
  end;
  PColor24Rec = ^TColor24Rec;
  TColor24RecArray = array[0..MaxInt div SizeOf(TColor24Rec) - 1] of TColor24Rec;
  PColor24RecArray = ^TColor24RecArray;

  { Color record for 32 bit images, which allows access to individual color
    channels.}
  TColor32Rec = packed record
    case Integer of
      0: (Color: TColor32);
      1: (B, G, R, A: Byte);
      2: (Channels: array[0..3] of Byte);
  end;
  PColor32Rec = ^TColor32Rec;
  TColor32RecArray = array[0..MaxInt div SizeOf(TColor32Rec) - 1] of TColor32Rec;
  PColor32RecArray = ^TColor32RecArray;

  { Color record for 48 bit images, which allows access to individual color
    channels.}
  TColor48Rec = packed record
    case Integer of
      0: (B, G, R: Word);
      1: (Channels: array[0..2] of Word);
  end;
  PColor48Rec = ^TColor48Rec;
  TColor48RecArray = array[0..MaxInt div SizeOf(TColor48Rec) - 1] of TColor48Rec;
  PColor48RecArray = ^TColor48RecArray;

  { Color record for 64 bit images, which allows access to individual color
    channels.}
  TColor64Rec = packed record
    case Integer of
      0: (Color: TColor64);
      1: (B, G, R, A: Word);
      2: (Channels: array[0..3] of Word);
  end;
  PColor64Rec = ^TColor64Rec;
  TColor64RecArray = array[0..MaxInt div SizeOf(TColor64Rec) - 1] of TColor64Rec;
  PColor64RecArray = ^TColor64RecArray;

  { Color record for 128 bit floating point images, which allows access to
    individual color channels.}
  TColorFRec = packed record
    case Integer of
      0: (B, G, R, A: Single);
      1: (Channels: array[0..3] of Single);
  end;
  PColorFRec = ^TColorFRec;
  TColorFRecArray = array[0..MaxInt div SizeOf(TColorFRec) - 1] of TColorFRec;
  PColorFRecArray = ^TColorFRecArray;

  { Palette for indexd mode images with 32 bit colors.}
  TPalette32 = TColor32RecArray;
  PPalette32 = ^TPalette32;
  PPPalette32 = ^PPalette32;

  { Palette for indexd mode images with 24 bit colors.}
  TPalette24 = TColor24RecArray;
  PPalette24 = ^TPalette24;

  { Record that stores single image data and information describing it.}
  TImageData = packed record
    Width: LongInt;       // Width of image in pixels
    Height: LongInt;      // Height of image in pixels
    Format: TImageFormat; // Data format of image
    Size: LongInt;        // Size of image bits in Bytes
    Bits: Pointer;        // Pointer to memory containing image bits
    Palette: PPalette32;  // Image palette for indexed images
  end;
  PImageData = ^TImageData;

  { Additional short information for each TImageFormat value.}
  TImageFormatShortInfo = packed record
    Format: TImageFormat;             // Format described by this record
    Name: array[0..15] of Char;       // Symbolic name of format
    BytesPerPixel: Byte;              // Number of Bytes per pixel
    PaletteEntries: LongInt;          // Number of palette entries
    HasGrayChannel: Boolean;          // True if image has grayscale channel
    HasAlphaChannel: Boolean;         // True if image has alpha channel
    IsFloatingPoint: Boolean;         // True if image has floating point pixels
    UsePixelFormat: Boolean;          // True if image uses pixel format
    IsRBSwapped: Boolean;             // True if Red and Blue channels are swapped
                                      // e.g. A16B16G16R16 has IsRBSwapped True
    IsIndexed: Boolean;               // True if image uses palette
    IsSpecial: Boolean;               // True if image is in special format
  end;
  PImageFormatShortInfo = ^TImageFormatShortInfo;

  { Handle to list of image data records.}
  TImageDataList = Pointer;
  PImageDataList = ^TImageDataList;

  { Handle to input/output.}
  TImagingHandle = Pointer;

  { Seek origin mode for IO function Seek.}
  TSeekMode = (
   smFromBeginning {= 0},
   smFromCurrent   {= 1},
   smFromEnd       {= 2});

  { IO functions used for reading and writing images from/to input/output.}
  TOpenReadProc = function(Source: PChar): TImagingHandle; cdecl;
  TOpenWriteProc = function(Source: PChar): TImagingHandle; cdecl;
  TCloseProc = procedure(Handle: TImagingHandle); cdecl;
  TEofProc = function(Handle: TImagingHandle): Boolean; cdecl;
  TSeekProc = function(Handle: TImagingHandle; Offset: LongInt; Mode: TSeekMode):
    LongInt; cdecl;
  TTellProc = function(Handle: TImagingHandle): LongInt; cdecl;
  TReadProc = function(Handle: TImagingHandle; Buffer: Pointer; Count: LongInt):
    LongInt; cdecl;
  TWriteProc = function(Handle: TImagingHandle; Buffer: Pointer; Count:
    LongInt): LongInt; cdecl;
  {*)}

implementation

{
  File Notes:
  
  -- TODOS ----------------------------------------------------
    - add ifIndex16 format - conversion to Index16 by median cut? 
    - add new format ifGray32F for heightmaps. Mixed float-gray?
    - create only one TImageFormatInfo - no short infos?

  -- 0.13 Changes/Bug Fixes -----------------------------------
    - new ImagingColorReductionMask option added
    - new image format added: ifA16Gray16

}

end.





