ilconvert.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: ilconvert.h /main/3 1995/10/23 15:44:19 rswiston $ */
  24. /**---------------------------------------------------------------------
  25. ***
  26. *** (c)Copyright 1991 Hewlett-Packard Co.
  27. ***
  28. *** RESTRICTED RIGHTS LEGEND
  29. *** Use, duplication, or disclosure by the U.S. Government is subject to
  30. *** restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
  31. *** Technical Data and Computer Software clause in DFARS 252.227-7013.
  32. *** Hewlett-Packard Company
  33. *** 3000 Hanover Street
  34. *** Palo Alto, CA 94304 U.S.A.
  35. *** Rights for non-DOD U.S. Government Departments and Agencies are as set
  36. *** forth in FAR 52.227-19(c)(1,2).
  37. ***
  38. ***-------------------------------------------------------------------*/
  39. #ifndef ILCONVERT_H
  40. #define ILCONVERT_H
  41. #ifndef IL_H
  42. #include "il.h"
  43. #endif
  44. /* Include file for /ilc/ilconvert.c and conversion code referenced by it;
  45. only those files should include this file.
  46. */
  47. /* Values for ilConvertRec.srcFormatCode.
  48. Format converters (those which would have ilConvertRec.pDstDes null
  49. and ilConvertRec.pDstFormat non-null) MUST set IL_DONT_CHECK_STD_FORMAT.
  50. Descriptor converters must set another code, which identifies the
  51. required src format, as follows (fields not named are not checked):
  52. IL_STD_FORMAT_BIT src format is IL_FORMAT_BIT: rowBitAlign
  53. == 32; bitsPerSample[0] == 1.
  54. IL_STD_FORMAT_BYTE src format is IL_FORMAT_BYTE:
  55. bitsPerSample[0] == 8.
  56. IL_STD_FORMAT_3BYTE_PIXEL src format is IL_FORMAT_3BYTE_PIXEL:
  57. bitsPerSample[0,1,2] == 8; sampleOrder ==
  58. IL_SAMPLE_PIXELS
  59. */
  60. #define IL_DONT_CHECK_STD_FORMAT 0
  61. #define IL_STD_FORMAT_BIT 1
  62. #define IL_STD_FORMAT_BYTE 2
  63. #define IL_STD_FORMAT_3BYTE_PIXEL 3
  64. /* Standard definition for a conversion filter added by ilConvert().
  65. Basically the parameter values to be passed to ilAddPipeElement() to
  66. add a given pipe converter. Some basic rules:
  67. - the filter must take any stripHeight, and output the same
  68. - it must not change the height/width of the image
  69. - pDstDes and pDstFormat in the structure must point to the output
  70. des/format, or be null if the output des/format is the
  71. same as the input (can't both be null - that is no conversion!)
  72. "srcFormatCode" is a code for the required src (input) format to
  73. this element. See notes above.
  74. The function "AddElement()" if non-null is called after the pipe
  75. element is successfully added, as:
  76. (*AddElement) (<pPrivate from ilAddPipeElement>, pPalette);
  77. It can be used for example to init the private block with data
  78. other than what might be done by Init().
  79. */
  80. typedef struct {
  81. ilError (*CheckFormat)(); /* reserved: MUST BE IL_NPF! */
  82. unsigned int srcFormatCode; /* see above */
  83. ilError (*AddElement)(); /* see above */
  84. const ilImageDes *pDstDes; /* ptr to new des or null */
  85. const ilImageFormat *pDstFormat; /* ptr to new format or null */
  86. size_t nBytesPrivate;
  87. ilError (*Init)();
  88. ilError (*Cleanup)();
  89. ilError (*Destroy)();
  90. ilError (*Execute)();
  91. } ilConvertRec, *ilConvertPtr;
  92. /* Standard definition for a format filter added by ilConvert().
  93. Basically a subset of an ilConvertRec; see above.
  94. */
  95. typedef struct {
  96. ilError (*AddElement)(); /* see above */
  97. unsigned int nBytesPrivate;
  98. ilError (*Init)();
  99. ilError (*Cleanup)();
  100. ilError (*Destroy)();
  101. ilError (*Execute)();
  102. } ilFormatRec, *ilFormatPtr;
  103. /* In /ilc/ildither.c : */
  104. IL_EXTERN const unsigned int _ilDitherKernel[];
  105. IL_EXTERN const unsigned short _ilMul8[];
  106. IL_EXTERN const unsigned short _ilMul4[];
  107. /* Convert from source type (pDes->type) == RGB to Palette.
  108. pFormat points to the source format; on return, *pFormat is updated
  109. to the dst format. *pDes ->the src (pipe) des; on return *pDes is the new des.
  110. */
  111. IL_EXTERN ilBool _ilConvertRGBToPalette (
  112. ilPipe pipe,
  113. ilPipeInfo *pInfo,
  114. register ilImageDes *pDes,
  115. ilImageFormat *pFormat,
  116. int option,
  117. ilConvertToPaletteInfo *pData
  118. );
  119. /* Dithers using error diffusion to bitonal.
  120. Input image: IL_DES_GRAY, IL_FORMAT_BYTE.
  121. Output image: IL_DES_BITONAL, IL_FORMAT_BIT
  122. */
  123. IL_EXTERN ilConvertRec _ilDiffuseGrayToBitonal;
  124. /* Convert using a user-supplied threshold.
  125. Input image: IL_DES_GRAY (either form of blackIsZero), IL_FORMAT_BYTE.
  126. Output image: IL_DES_BITONAL, IL_FORMAT_BIT
  127. */
  128. IL_EXTERN ilConvertRec _ilThresholdGrayToBitonal;
  129. /* In /ilc/ilpalette.c :
  130. Converts byte palette image to RGB, each a byte
  131. Input image: uncompressed IL_PALETTE, any # of levels, IL_FORMAT_3BYTE_PIXEL.
  132. Output image: IL_DES_GRAY, IL_FORMAT_BYTE.
  133. */
  134. IL_EXTERN ilConvertRec _ilPaletteToRGBByte;
  135. /* In /ilc/iltruegray.c :
  136. Converts rgb image to gray scale.
  137. Input image: uncompressed IL_RGB, any # of levels, IL_FORMAT_3BYTE_PIXEL.
  138. Output image: IL_DES_GRAY, IL_FORMAT_BYTE.
  139. */
  140. IL_EXTERN ilConvertRec _ilRGBToGray;
  141. /* In /ilc/iltruegray.c :
  142. Converts gray scale image to rgb.
  143. Input image: uncompressed IL_GRAY, any # of levels, IL_FORMAT_BYTE.
  144. Output image: IL_DES_RGB, IL_FORMAT_3BYTE_PIXEL.
  145. */
  146. IL_EXTERN ilConvertRec _ilGrayToRGB;
  147. /* In /ilc/ilformat.c :
  148. Reformats image to change the rowBitAlign only.
  149. */
  150. IL_EXTERN ilFormatRec _ilFormatRowBitAlign;
  151. /* Convert 4 to 8 bit or 8 to 4 bit per sample.
  152. */
  153. IL_EXTERN ilFormatRec _ilFormat4To8Bit;
  154. IL_EXTERN ilFormatRec _ilFormat8To4Bit;
  155. /* Reformat an 8 bit/pixel 3 sample planar image to pixel format.
  156. */
  157. IL_EXTERN ilFormatRec _ilFormat8Bit3PlaneToPixel;
  158. /* Reformat an 8 bit/pixel 3 sample pixel image to planar format.
  159. */
  160. IL_EXTERN ilFormatRec _ilFormat8Bit3PixelToPlane;
  161. /* In /ilc/ilformat.c :
  162. Add a conversion filter to the given pipe which converts from the levels
  163. in "*pPipeDes" (i.e. the levels of the current pipe image) to those in
  164. "*pDes" (note - only nLevelsPerSample is reference from pDes).
  165. If failure, declares pipe invalid (which sets error code) and returns false;
  166. else returns true and "*pInfo", "*pPipeDes" and "*pFormat" are updated
  167. with the new pipe state info.
  168. */
  169. IL_EXTERN ilBool _ilAddLevelConversionFilter (
  170. ilPipe pipe,
  171. ilPipeInfo *pInfo,
  172. ilImageDes *pPipeDes,
  173. const ilImageDes *pDes,
  174. ilImageFormat *pFormat
  175. );
  176. /* In /ilc/ilinvert.c :
  177. Add a filter to invert a bitonal or gray image.
  178. */
  179. IL_EXTERN ilBool _ilAddInvertFilter (
  180. ilPipe pipe,
  181. ilImageDes *pPipedes,
  182. ilPipeInfo *pInfo
  183. );
  184. /* In /ilc/ilupsample.c : */
  185. /* Attempt to upsample and scale based on "scaleFactor" (0 = no scaling; 1 = double;
  186. 2 = 4x), or return false if it cannot be done with the given pipe image (in which
  187. case pipe->context->error == 0) or if error occurs (error != 0). Pipe image
  188. must be decompressed before calling this function.
  189. */
  190. IL_EXTERN ilBool _ilFastUpsample (
  191. ilPipe pipe,
  192. ilPipeInfo *pInfo,
  193. ilImageDes *pDes,
  194. ilImageFormat *pFormat,
  195. int scaleFactor
  196. );
  197. /* Upsample and / or convert to gray the pipe image which must be a YCbCr image.
  198. If "toGray" is true, the Y plane only will be upsampled (or copied) resulting
  199. in a gray image; else a planar YCbCr image will result.
  200. If "upSample" is true must upsample; "upSample" and/or "toGray" must be true.
  201. pFormat points to the source format; on return, *pFormat is updated
  202. to the dst format, *pDes to the dst descriptor.
  203. */
  204. IL_EXTERN ilBool _ilUpsampleYCbCr (
  205. ilPipe pipe,
  206. ilPipeInfo *pInfo,
  207. ilImageDes *pDes,
  208. ilImageFormat *pFormat,
  209. ilBool toGray,
  210. ilBool upSample
  211. );
  212. /* In /ilc/ilycbcr.c : */
  213. /* Subsample the pipe image which must be a fully upsampled YCbCr image.
  214. pFormat points to the source format; on return, *pFormat is updated
  215. to the dst format. *pDes to the _destination_ des, i.e. has subsample values.
  216. */
  217. IL_EXTERN ilBool _ilSubsampleYCbCr (
  218. ilPipe pipe,
  219. ilPipeInfo *pInfo,
  220. ilImageDes *pDes,
  221. ilImageFormat *pFormat
  222. );
  223. /* Convert from source type (pDes->type) == IL_YCBCR to RBB.
  224. The YCbCr image must already be upsampled.
  225. pFormat points to the source format; on return, *pFormat is updated
  226. to the dst format, *pDes to the dst descriptor.
  227. */
  228. IL_EXTERN ilBool _ilConvertYCbCrToRGB (
  229. ilPipe pipe,
  230. ilPipeInfo *pInfo,
  231. ilImageDes *pDes,
  232. ilImageFormat *pFormat
  233. );
  234. /* Convert from source type (pDes->type) == RGB to YCbCr.
  235. pFormat points to the source format; on return, *pFormat is updated
  236. to the dst format. pNewDes points to the dst dest; *pDes to the src (pipe) des;
  237. on return it is updated to the new descriptor.
  238. */
  239. IL_EXTERN ilBool _ilConvertRGBToYCbCr (
  240. ilPipe pipe,
  241. ilPipeInfo *pInfo,
  242. ilImageDes *pDes,
  243. register const ilImageDes *pNewDes,
  244. ilImageFormat *pFormat
  245. );
  246. /* Does conversions of some forms of YCbCr to dithered IL_PALETTE.
  247. Returns "true" if conversion handled, else "false" if not handled or if error.
  248. The pipe image must be an uncompressed YCbCr image.
  249. */
  250. IL_EXTERN ilBool _ilDitherYCbCr (
  251. ilPipe pipe,
  252. ilPipeInfo *pInfo,
  253. ilImageDes *pDes,
  254. ilImageFormat *pFormat,
  255. int option,
  256. ilConvertToPaletteInfo *pData
  257. );
  258. #endif