CmPixelUtil.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef _PixelFormat_H__
  25. #define _PixelFormat_H__
  26. #include "CmPrerequisitesUtil.h"
  27. #include "CmBox.h"
  28. namespace CamelotEngine {
  29. /** \addtogroup Core
  30. * @{
  31. */
  32. /** \addtogroup Image
  33. * @{
  34. */
  35. /** The pixel format used for images, textures, and render surfaces */
  36. enum PixelFormat
  37. {
  38. /// Unknown pixel format.
  39. PF_UNKNOWN = 0,
  40. /// 8-bit pixel format, all bits luminace.
  41. PF_L8 = 1,
  42. PF_BYTE_L = PF_L8,
  43. /// 16-bit pixel format, all bits luminace.
  44. PF_L16 = 2,
  45. PF_SHORT_L = PF_L16,
  46. /// 8-bit pixel format, all bits alpha.
  47. PF_A8 = 3,
  48. PF_BYTE_A = PF_A8,
  49. /// 8-bit pixel format, 4 bits alpha, 4 bits luminance.
  50. PF_A4L4 = 4,
  51. /// 2 byte pixel format, 1 byte luminance, 1 byte alpha
  52. PF_BYTE_LA = 5,
  53. /// 16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
  54. PF_R5G6B5 = 6,
  55. /// 16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
  56. PF_B5G6R5 = 7,
  57. /// 8-bit pixel format, 2 bits blue, 3 bits green, 3 bits red.
  58. PF_R3G3B2 = 31,
  59. /// 16-bit pixel format, 4 bits for alpha, red, green and blue.
  60. PF_A4R4G4B4 = 8,
  61. /// 16-bit pixel format, 5 bits for blue, green, red and 1 for alpha.
  62. PF_A1R5G5B5 = 9,
  63. /// 24-bit pixel format, 8 bits for red, green and blue.
  64. PF_R8G8B8 = 10,
  65. /// 24-bit pixel format, 8 bits for blue, green and red.
  66. PF_B8G8R8 = 11,
  67. /// 32-bit pixel format, 8 bits for alpha, red, green and blue.
  68. PF_A8R8G8B8 = 12,
  69. /// 32-bit pixel format, 8 bits for blue, green, red and alpha.
  70. PF_A8B8G8R8 = 13,
  71. /// 32-bit pixel format, 8 bits for blue, green, red and alpha.
  72. PF_B8G8R8A8 = 14,
  73. /// 32-bit pixel format, 8 bits for red, green, blue and alpha.
  74. PF_R8G8B8A8 = 28,
  75. /// 32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue
  76. /// like PF_A8R8G8B8, but alpha will get discarded
  77. PF_X8R8G8B8 = 26,
  78. /// 32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red
  79. /// like PF_A8B8G8R8, but alpha will get discarded
  80. PF_X8B8G8R8 = 27,
  81. #if CM_ENDIAN == CM_ENDIAN_BIG
  82. /// 3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue
  83. PF_BYTE_RGB = PF_R8G8B8,
  84. /// 3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red
  85. PF_BYTE_BGR = PF_B8G8R8,
  86. /// 4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha
  87. PF_BYTE_BGRA = PF_B8G8R8A8,
  88. /// 4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
  89. PF_BYTE_RGBA = PF_R8G8B8A8,
  90. #else
  91. /// 3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue
  92. PF_BYTE_RGB = PF_B8G8R8,
  93. /// 3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red
  94. PF_BYTE_BGR = PF_R8G8B8,
  95. /// 4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha
  96. PF_BYTE_BGRA = PF_A8R8G8B8,
  97. /// 4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
  98. PF_BYTE_RGBA = PF_A8B8G8R8,
  99. #endif
  100. /// 32-bit pixel format, 2 bits for alpha, 10 bits for red, green and blue.
  101. PF_A2R10G10B10 = 15,
  102. /// 32-bit pixel format, 10 bits for blue, green and red, 2 bits for alpha.
  103. PF_A2B10G10R10 = 16,
  104. /// DDS (DirectDraw Surface) DXT1 format
  105. PF_DXT1 = 17,
  106. /// DDS (DirectDraw Surface) DXT2 format
  107. PF_DXT2 = 18,
  108. /// DDS (DirectDraw Surface) DXT3 format
  109. PF_DXT3 = 19,
  110. /// DDS (DirectDraw Surface) DXT4 format
  111. PF_DXT4 = 20,
  112. /// DDS (DirectDraw Surface) DXT5 format
  113. PF_DXT5 = 21,
  114. // 16-bit pixel format, 16 bits (float) for red
  115. PF_FLOAT16_R = 32,
  116. // 48-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue
  117. PF_FLOAT16_RGB = 22,
  118. // 64-bit pixel format, 16 bits (float) for red, 16 bits (float) for green, 16 bits (float) for blue, 16 bits (float) for alpha
  119. PF_FLOAT16_RGBA = 23,
  120. // 32-bit pixel format, 32 bits (float) for red
  121. PF_FLOAT32_R = 33,
  122. // 96-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue
  123. PF_FLOAT32_RGB = 24,
  124. // 128-bit pixel format, 32 bits (float) for red, 32 bits (float) for green, 32 bits (float) for blue, 32 bits (float) for alpha
  125. PF_FLOAT32_RGBA = 25,
  126. // 32-bit, 2-channel s10e5 floating point pixel format, 16-bit green, 16-bit red
  127. PF_FLOAT16_GR = 35,
  128. // 64-bit, 2-channel floating point pixel format, 32-bit green, 32-bit red
  129. PF_FLOAT32_GR = 36,
  130. // Depth texture format
  131. PF_DEPTH = 29,
  132. // 64-bit pixel format, 16 bits for red, green, blue and alpha
  133. PF_SHORT_RGBA = 30,
  134. // 32-bit pixel format, 16-bit green, 16-bit red
  135. PF_SHORT_GR = 34,
  136. // 48-bit pixel format, 16 bits for red, green and blue
  137. PF_SHORT_RGB = 37,
  138. /// PVRTC (PowerVR) RGB 2 bpp
  139. PF_PVRTC_RGB2 = 38,
  140. /// PVRTC (PowerVR) RGBA 2 bpp
  141. PF_PVRTC_RGBA2 = 39,
  142. /// PVRTC (PowerVR) RGB 4 bpp
  143. PF_PVRTC_RGB4 = 40,
  144. /// PVRTC (PowerVR) RGBA 4 bpp
  145. PF_PVRTC_RGBA4 = 41,
  146. // Number of pixel formats currently defined
  147. PF_COUNT = 42
  148. };
  149. typedef vector<PixelFormat>::type PixelFormatList;
  150. /**
  151. * Flags defining some on/off properties of pixel formats
  152. */
  153. enum PixelFormatFlags {
  154. // This format has an alpha channel
  155. PFF_HASALPHA = 0x00000001,
  156. // This format is compressed. This invalidates the values in elemBytes,
  157. // elemBits and the bit counts as these might not be fixed in a compressed format.
  158. PFF_COMPRESSED = 0x00000002,
  159. // This is a floating point format
  160. PFF_FLOAT = 0x00000004,
  161. // This is a depth format (for depth textures)
  162. PFF_DEPTH = 0x00000008,
  163. // Format is in native endian. Generally true for the 16, 24 and 32 bits
  164. // formats which can be represented as machine integers.
  165. PFF_NATIVEENDIAN = 0x00000010,
  166. // This is an intensity format instead of a RGB one. The luminance
  167. // replaces R,G and B. (but not A)
  168. PFF_LUMINANCE = 0x00000020
  169. };
  170. /** Pixel component format */
  171. enum PixelComponentType
  172. {
  173. PCT_BYTE = 0, /// Byte per component (8 bit fixed 0.0..1.0)
  174. PCT_SHORT = 1, /// Short per component (16 bit fixed 0.0..1.0))
  175. PCT_FLOAT16 = 2, /// 16 bit float per component
  176. PCT_FLOAT32 = 3, /// 32 bit float per component
  177. PCT_COUNT = 4 /// Number of pixel types
  178. };
  179. /** A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
  180. In case of a rectangle, depth must be 1.
  181. Pixels are stored as a succession of "depth" slices, each containing "height" rows of
  182. "width" pixels.
  183. */
  184. class CM_UTILITY_EXPORT PixelData: public Box {
  185. public:
  186. /// Parameter constructor for setting the members manually
  187. PixelData() {}
  188. ~PixelData() {}
  189. /** Constructor providing extents in the form of a Box object. This constructor
  190. assumes the pixel data is laid out consecutively in memory. (this
  191. means row after row, slice after slice, with no space in between)
  192. @param extents Extents of the region defined by data
  193. @param pixelFormat Format of this buffer
  194. @param pixelData Pointer to the actual data
  195. */
  196. PixelData(const Box &extents, PixelFormat pixelFormat, void *pixelData=0):
  197. Box(extents), data(pixelData), format(pixelFormat)
  198. {
  199. setConsecutive();
  200. }
  201. /** Constructor providing width, height and depth. This constructor
  202. assumes the pixel data is laid out consecutively in memory. (this
  203. means row after row, slice after slice, with no space in between)
  204. @param width Width of the region
  205. @param height Height of the region
  206. @param depth Depth of the region
  207. @param pixelFormat Format of this buffer
  208. @param pixelData Pointer to the actual data
  209. */
  210. PixelData(size_t width, size_t height, size_t depth, PixelFormat pixelFormat, void *pixelData=0):
  211. Box(0, 0, 0, width, height, depth),
  212. data(pixelData), format(pixelFormat)
  213. {
  214. setConsecutive();
  215. }
  216. /// The data pointer
  217. void *data;
  218. /// The pixel format
  219. PixelFormat format;
  220. /** Number of elements between the leftmost pixel of one row and the left
  221. pixel of the next. This value must always be equal to getWidth() (consecutive)
  222. for compressed formats.
  223. */
  224. size_t rowPitch;
  225. /** Number of elements between the top left pixel of one (depth) slice and
  226. the top left pixel of the next. This can be a negative value. Must be a multiple of
  227. rowPitch. This value must always be equal to getWidth()*getHeight() (consecutive)
  228. for compressed formats.
  229. */
  230. size_t slicePitch;
  231. /** Set the rowPitch and slicePitch so that the buffer is laid out consecutive
  232. in memory.
  233. */
  234. void setConsecutive()
  235. {
  236. rowPitch = getWidth();
  237. slicePitch = getWidth()*getHeight();
  238. }
  239. /** Get the number of elements between one past the rightmost pixel of
  240. one row and the leftmost pixel of the next row. (IE this is zero if rows
  241. are consecutive).
  242. */
  243. size_t getRowSkip() const { return rowPitch - getWidth(); }
  244. /** Get the number of elements between one past the right bottom pixel of
  245. one slice and the left top pixel of the next slice. (IE this is zero if slices
  246. are consecutive).
  247. */
  248. size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
  249. /** Return whether this buffer is laid out consecutive in memory (ie the pitches
  250. are equal to the dimensions)
  251. */
  252. bool isConsecutive() const
  253. {
  254. return rowPitch == getWidth() && slicePitch == getWidth()*getHeight();
  255. }
  256. /** Return the size (in bytes) this image would take if it was
  257. laid out consecutive in memory
  258. */
  259. size_t getConsecutiveSize() const;
  260. /** Return a subvolume of this PixelBox.
  261. @param def Defines the bounds of the subregion to return
  262. @returns A pixel box describing the region and the data in it
  263. @remarks This function does not copy any data, it just returns
  264. a PixelBox object with a data pointer pointing somewhere inside
  265. the data of object.
  266. @throws Exception(ERR_INVALIDPARAMS) if def is not fully contained
  267. */
  268. PixelData getSubVolume(const Box &def) const;
  269. /**
  270. * Get colour value from a certain location in the PixelBox. The z coordinate
  271. * is only valid for cubemaps and volume textures. This uses the first (largest)
  272. * mipmap.
  273. */
  274. Color getColourAt(size_t x, size_t y, size_t z);
  275. /**
  276. * Set colour value at a certain location in the PixelBox. The z coordinate
  277. * is only valid for cubemaps and volume textures. This uses the first (largest)
  278. * mipmap.
  279. */
  280. void setColourAt(Color const &cv, size_t x, size_t y, size_t z);
  281. };
  282. /**
  283. * Some utility functions for packing and unpacking pixel data
  284. */
  285. class CM_UTILITY_EXPORT PixelUtil {
  286. public:
  287. /** Returns the size in bytes of an element of the given pixel format.
  288. @returns
  289. The size in bytes of an element. See Remarks.
  290. @remarks
  291. Passing PF_UNKNOWN will result in returning a size of 0 bytes.
  292. */
  293. static size_t getNumElemBytes( PixelFormat format );
  294. /** Returns the size in bits of an element of the given pixel format.
  295. @returns
  296. The size in bits of an element. See Remarks.
  297. @remarks
  298. Passing PF_UNKNOWN will result in returning a size of 0 bits.
  299. */
  300. static size_t getNumElemBits( PixelFormat format );
  301. /** Returns the size in memory of a region with the given extents and pixel
  302. format with consecutive memory layout.
  303. @param width
  304. The width of the area
  305. @param height
  306. The height of the area
  307. @param depth
  308. The depth of the area
  309. @param format
  310. The format of the area
  311. @returns
  312. The size in bytes
  313. @remarks
  314. In case that the format is non-compressed, this simply returns
  315. width*height*depth*PixelUtil::getNumElemBytes(format). In the compressed
  316. case, this does serious magic.
  317. */
  318. static size_t getMemorySize(size_t width, size_t height, size_t depth, PixelFormat format);
  319. /** Returns the property flags for this pixel format
  320. @returns
  321. A bitfield combination of PFF_HASALPHA, PFF_ISCOMPRESSED,
  322. PFF_FLOAT, PFF_DEPTH, PFF_NATIVEENDIAN, PFF_LUMINANCE
  323. @remarks
  324. This replaces the seperate functions for formatHasAlpha, formatIsFloat, ...
  325. */
  326. static unsigned int getFlags( PixelFormat format );
  327. /** Shortcut method to determine if the format has an alpha component */
  328. static bool hasAlpha(PixelFormat format);
  329. /** Shortcut method to determine if the format is floating point */
  330. static bool isFloatingPoint(PixelFormat format);
  331. /** Shortcut method to determine if the format is compressed */
  332. static bool isCompressed(PixelFormat format);
  333. /** Shortcut method to determine if the format is a depth format. */
  334. static bool isDepth(PixelFormat format);
  335. /** Shortcut method to determine if the format is in native endian format. */
  336. static bool isNativeEndian(PixelFormat format);
  337. /** Shortcut method to determine if the format is a luminance format. */
  338. static bool isLuminance(PixelFormat format);
  339. /** Return wether a certain image extent is valid for this image format.
  340. @param width
  341. The width of the area
  342. @param height
  343. The height of the area
  344. @param depth
  345. The depth of the area
  346. @param format
  347. The format of the area
  348. @remarks For non-compressed formats, this is always true. For DXT formats,
  349. only sizes with a width and height multiple of 4 and depth 1 are allowed.
  350. */
  351. static bool isValidExtent(size_t width, size_t height, size_t depth, PixelFormat format);
  352. /** Gives the number of bits (RGBA) for a format. See remarks.
  353. @remarks For non-colour formats (dxt, depth) this returns [0,0,0,0].
  354. */
  355. static void getBitDepths(PixelFormat format, int rgba[4]);
  356. /** Gives the masks for the R, G, B and A component
  357. @note Only valid for native endian formats
  358. */
  359. static void getBitMasks(PixelFormat format, UINT32 rgba[4]);
  360. /** Gives the bit shifts for R, G, B and A component
  361. @note Only valid for native endian formats
  362. */
  363. static void getBitShifts(PixelFormat format, unsigned char rgba[4]);
  364. /** Gets the name of an image format
  365. */
  366. static String getFormatName(PixelFormat srcformat);
  367. /** Returns wether the format can be packed or unpacked with the packColour()
  368. and unpackColour() functions. This is generally not true for compressed and
  369. depth formats as they are special. It can only be true for formats with a
  370. fixed element size.
  371. @returns
  372. true if yes, otherwise false
  373. */
  374. static bool isAccessible(PixelFormat srcformat);
  375. /** Returns the component type for a certain pixel format. Returns PCT_BYTE
  376. in case there is no clear component type like with compressed formats.
  377. This is one of PCT_BYTE, PCT_SHORT, PCT_FLOAT16, PCT_FLOAT32.
  378. */
  379. static PixelComponentType getComponentType(PixelFormat fmt);
  380. /** Returns the component count for a certain pixel format. Returns 3(no alpha) or
  381. 4 (has alpha) in case there is no clear component type like with compressed formats.
  382. */
  383. static size_t getComponentCount(PixelFormat fmt);
  384. /** Gets the format from given name.
  385. @param name The string of format name
  386. @param accessibleOnly If true, non-accessible format will treat as invalid format,
  387. otherwise, all supported format are valid.
  388. @param caseSensitive Should be set true if string match should use case sensitivity.
  389. @returns The format match the format name, or PF_UNKNOWN if is invalid name.
  390. */
  391. static PixelFormat getFormatFromName(const String& name, bool accessibleOnly = false, bool caseSensitive = false);
  392. /** Gets the BNF expression of the pixel-formats.
  393. @note The string returned by this function is intented to use as a BNF expression
  394. to work with Compiler2Pass.
  395. @param accessibleOnly If true, only accessible pixel format will take into account, otherwise all
  396. pixel formats list in PixelFormat enumeration will being returned.
  397. @returns A string contains the BNF expression.
  398. */
  399. static String getBNFExpressionOfPixelFormats(bool accessibleOnly = false);
  400. /** Returns the similar format but acoording with given bit depths.
  401. @param fmt The original foamt.
  402. @param integerBits Preferred bit depth (pixel bits) for integer pixel format.
  403. Available values: 0, 16 and 32, where 0 (the default) means as it is.
  404. @param floatBits Preferred bit depth (channel bits) for float pixel format.
  405. Available values: 0, 16 and 32, where 0 (the default) means as it is.
  406. @returns The format that similar original format with bit depth according
  407. with preferred bit depth, or original format if no convertion occuring.
  408. */
  409. static PixelFormat getFormatForBitDepths(PixelFormat fmt, UINT16 integerBits, UINT16 floatBits);
  410. /** Pack a colour value to memory
  411. @param colour The colour
  412. @param pf Pixelformat in which to write the colour
  413. @param dest Destination memory location
  414. */
  415. static void packColour(const Color &colour, const PixelFormat pf, void* dest);
  416. /** Pack a colour value to memory
  417. @param r,g,b,a The four colour components, range 0x00 to 0xFF
  418. @param pf Pixelformat in which to write the colour
  419. @param dest Destination memory location
  420. */
  421. static void packColour(const UINT8 r, const UINT8 g, const UINT8 b, const UINT8 a, const PixelFormat pf, void* dest);
  422. /** Pack a colour value to memory
  423. @param r,g,b,a The four colour components, range 0.0f to 1.0f
  424. (an exception to this case exists for floating point pixel
  425. formats, which don't clamp to 0.0f..1.0f)
  426. @param pf Pixelformat in which to write the colour
  427. @param dest Destination memory location
  428. */
  429. static void packColour(const float r, const float g, const float b, const float a, const PixelFormat pf, void* dest);
  430. /** Unpack a colour value from memory
  431. @param colour The colour is returned here
  432. @param pf Pixelformat in which to read the colour
  433. @param src Source memory location
  434. */
  435. static void unpackColour(Color *colour, PixelFormat pf, const void* src);
  436. /** Unpack a colour value from memory
  437. @param r,g,b,a The colour is returned here (as byte)
  438. @param pf Pixelformat in which to read the colour
  439. @param src Source memory location
  440. @remarks This function returns the colour components in 8 bit precision,
  441. this will lose precision when coming from PF_A2R10G10B10 or floating
  442. point formats.
  443. */
  444. static void unpackColour(UINT8 *r, UINT8 *g, UINT8 *b, UINT8 *a, PixelFormat pf, const void* src);
  445. /** Unpack a colour value from memory
  446. @param r,g,b,a The colour is returned here (as float)
  447. @param pf Pixelformat in which to read the colour
  448. @param src Source memory location
  449. */
  450. static void unpackColour(float *r, float *g, float *b, float *a, PixelFormat pf, const void* src);
  451. /** Convert consecutive pixels from one format to another. No dithering or filtering is being done.
  452. Converting from RGB to luminance takes the R channel. In case the source and destination format match,
  453. just a copy is done.
  454. @param src Pointer to source region
  455. @param srcFormat Pixel format of source region
  456. @param dst Pointer to destination region
  457. @param dstFormat Pixel format of destination region
  458. */
  459. static void bulkPixelConversion(void *src, PixelFormat srcFormat, void *dest, PixelFormat dstFormat, unsigned int count);
  460. /** Convert pixels from one format to another. No dithering or filtering is being done. Converting
  461. from RGB to luminance takes the R channel.
  462. @param src PixelBox containing the source pixels, pitches and format
  463. @param dst PixelBox containing the destination pixels, pitches and format
  464. @remarks The source and destination boxes must have the same
  465. dimensions. In case the source and destination format match, a plain copy is done.
  466. */
  467. static void bulkPixelConversion(const PixelData &src, const PixelData &dst);
  468. enum Filter
  469. {
  470. FILTER_NEAREST,
  471. FILTER_LINEAR,
  472. FILTER_BILINEAR,
  473. FILTER_BOX,
  474. FILTER_TRIANGLE,
  475. FILTER_BICUBIC
  476. };
  477. /** Scale a 1D, 2D or 3D image volume.
  478. @param src PixelBox containing the source pointer, dimensions and format
  479. @param dst PixelBox containing the destination pointer, dimensions and format
  480. @param filter Which filter to use
  481. @remarks This function can do pixel format conversion in the process.
  482. @note dst and src can point to the same PixelBox object without any problem
  483. */
  484. static void scale(const PixelData &src, const PixelData &dst, Filter filter = FILTER_BILINEAR);
  485. /** Does gamma adjustment.
  486. @note
  487. Basic algo taken from Titan Engine, copyright (c) 2000 Ignacio
  488. Castano Iguado
  489. */
  490. static void applyGamma(UINT8 *buffer, float gamma, size_t size, UINT8 bpp);
  491. };
  492. /** @} */
  493. /** @} */
  494. }
  495. #endif