bitmap.pp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. (******************************************************************************
  2. *
  3. * Copyright (c) 1994-2000 Palm, Inc. or its subsidiaries.
  4. * All rights reserved.
  5. *
  6. * File: Bitmap.h
  7. *
  8. * Release: Palm OS SDK 4.0 (63220)
  9. *
  10. * Description:
  11. * This file defines bitmap structures and routines.
  12. *
  13. * History:
  14. * September, 1999 Created by Bertrand Simon
  15. * Name Date Description
  16. * ---- ---- -----------
  17. * BS 9/99 Create
  18. * jmp 12/23/99 Fix <> vs. "" problem.
  19. *
  20. *****************************************************************************)
  21. unit bitmap;
  22. interface
  23. uses palmos, coretraps;
  24. //-----------------------------------------------
  25. // The Bitmap Structure.
  26. //-----------------------------------------------
  27. // bitmap version numbers
  28. const
  29. BitmapVersionZero = 0;
  30. BitmapVersionOne = 1;
  31. BitmapVersionTwo = 2;
  32. // Compression Types for BitmapVersionTwo.
  33. type
  34. BitmapCompressionType = Enum;
  35. const
  36. BitmapCompressionTypeScanLine = 0;
  37. BitmapCompressionTypeRLE = Succ(BitmapCompressionTypeScanLine);
  38. BitmapCompressionTypePackBits = Succ(BitmapCompressionTypeRLE);
  39. BitmapCompressionTypeEnd = Succ(BitmapCompressionTypePackBits);
  40. // must follow last compression algorithm
  41. BitmapCompressionTypeBest = $64;
  42. BitmapCompressionTypeNone = $FF;
  43. type
  44. BitmapFlagsType = record
  45. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_BITMAPS} // These fields will not be available in the next OS release!
  46. Bits: UInt16;
  47. {
  48. UInt16 compressed:1; // Data format: 0=raw; 1=compressed
  49. UInt16 hasColorTable:1; // if true, color table stored before bits[]
  50. UInt16 hasTransparency:1; // true if transparency is used
  51. UInt16 indirect:1; // true if bits are stored indirectly
  52. UInt16 forScreen:1; // system use only
  53. UInt16 directColor:1; // direct color bitmap
  54. UInt16 reserved:10
  55. }
  56. {$endif}
  57. end;
  58. // this definition correspond to the 'Tbmp' and 'tAIB' resource types
  59. BitmapType = record
  60. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_BITMAPS} // These fields will not be available in the next OS release!
  61. width: Int16;
  62. height: Int16;
  63. rowBytes: UInt16;
  64. flags: BitmapFlagsType;
  65. pixelSize: UInt8; // bits/pixel
  66. version: UInt8; // version of bitmap. This is vers 2
  67. nextDepthOffset: UInt16; // # of DWords to next BitmapType
  68. // from beginnning of this one
  69. transparentIndex: UInt8; // v2 only, if flags.hasTransparency is true,
  70. // index number of transparent color
  71. compressionType: UInt8; // v2 only, if flags.compressed is true, this is
  72. // the type, see BitmapCompressionType
  73. reserved: UInt16; // for future use, must be zero!
  74. // if (flags.hasColorTable)
  75. // ColorTableType colorTable // NOTE: Could have 0 entries (2 bytes long)
  76. //
  77. // if (flags.directColor)
  78. // BitmapDirectInfoType directInfo;
  79. //
  80. // if (flags.indirect)
  81. // void* bitsP; // pointer to actual bits
  82. // else
  83. // UInt8 bits[]; // or actual bits
  84. //
  85. {$endif}
  86. end;
  87. BitmapPtr = ^BitmapType;
  88. //-----------------------------------------------
  89. // This is the structure of a color table. It maps pixel values into
  90. // RGB colors. Each element in the table corresponds to the next
  91. // index, starting at 0.
  92. //-----------------------------------------------
  93. RGBColorType = record
  94. index: UInt8; // index of color or best match to cur CLUT or unused.
  95. r: UInt8; // amount of red, 0->255
  96. g: UInt8; // amount of green, 0->255
  97. b: UInt8; // amount of blue, 0->255
  98. end;
  99. RGBColorPtr = ^RGBColorType;
  100. // -----------------------------------------------
  101. // For direct color bitmaps (flags.directColor set), this structure follows
  102. // the color table if one is present, or immediately follows the BitmapType if a
  103. // color table is not present.
  104. // The only type of direct color bitmap that is currently supported in version 3
  105. // of the Window Manager (feature: sysFtrCreator, #sysFtrNumWinVersion) are
  106. // 16 bits/pixel with redBits=5, greenBits=6, blueBits=5.
  107. // -----------------------------------------------
  108. BitmapDirectInfoType = record
  109. redBits: UInt8; // # of red bits in each pixel
  110. greenBits: UInt8; // # of green bits in each pixel
  111. blueBits: UInt8; // # of blue bits in each pixel
  112. reserved: UInt8; // must be zero
  113. transparentColor: RGBColorType; // transparent color (index field ignored)
  114. end;
  115. // -----------------------------------------------
  116. // Color Table
  117. // -----------------------------------------------
  118. ColorTableType = record
  119. // high bits (numEntries > 256) reserved
  120. numEntries: UInt16; // number of entries in table
  121. // RGBColorType entry[]; // array 0..numEntries-1 of colors
  122. // starts immediately after numEntries
  123. end;
  124. ColorTablePtr = ^ColorTableType;
  125. // get start of color table entries aray given pointer to ColorTableType
  126. function ColorTableEntries(ctP: ColorTablePtr): RGBColorPtr;
  127. //-----------------------------------------------
  128. // Routines relating to bitmap management
  129. //-----------------------------------------------
  130. function BmpCreate(width, height: Coord; depth: UInt8; var colortableP: ColorTableType; var error: UInt16): BitmapPtr; syscall sysTrapBmpCreate;
  131. function BmpDelete(bitmapP: BitmapPtr): Err; syscall sysTrapBmpDelete;
  132. function BmpCompress(bitmapP: BitmapPtr; compType: BitmapCompressionType): Err; syscall sysTrapBmpCompress;
  133. function BmpGetBits(bitmapP: BitmapPtr): Pointer; syscall sysTrapBmpGetBits;
  134. function BmpGetColortable(bitmapP: BitmapPtr): ColorTablePtr; syscall sysTrapBmpGetColortable;
  135. function BmpSize(bitmapP: BitmapPtr): UInt16; syscall sysTrapBmpSize;
  136. function BmpBitsSize(bitmapP: BitmapPtr): UInt16; syscall sysTrapBmpBitsSize;
  137. procedure BmpGetSizes(bitmapP: BitmapPtr; var dataSizeP: UInt32; var headerSizeP: UInt32); syscall sysTrapBmpGetSizes;
  138. function BmpColortableSize(bitmapP: BitmapPtr): UInt16; syscall sysTrapBmpColortableSize;
  139. procedure BmpGetDimensions(bitmapP: BitmapPtr; var widthP, heightP: Coord; var rowBytesP: UInt16); syscall sysTrapBmpGetDimensions;
  140. function BmpGetBitDepth(bitmapP: BitmapPtr): UInt8; syscall sysTrapBmpGetBitDepth;
  141. function BmpGetNextBitmap(bitmapP: BitmapPtr): BitmapPtr; syscall sysTrapBmpGetNextBitmap;
  142. implementation
  143. function ColorTableEntries(ctP: ColorTablePtr): RGBColorPtr;
  144. begin
  145. ColorTableEntries := RGBColorPtr(PChar(ctP) + SizeOf(ctP^));
  146. end;
  147. end.