turbojpeg.h 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542
  1. /*
  2. * Copyright (C)2009-2015 D. R. Commander. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright notice,
  10. * this list of conditions and the following disclaimer in the documentation
  11. * and/or other materials provided with the distribution.
  12. * - Neither the name of the libjpeg-turbo Project nor the names of its
  13. * contributors may be used to endorse or promote products derived from this
  14. * software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  20. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. * POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #ifndef __TURBOJPEG_H__
  29. #define __TURBOJPEG_H__
  30. #if defined(_WIN32) && defined(DLLDEFINE)
  31. #define DLLEXPORT __declspec(dllexport)
  32. #else
  33. #define DLLEXPORT
  34. #endif
  35. #define DLLCALL
  36. /**
  37. * @addtogroup TurboJPEG
  38. * TurboJPEG API. This API provides an interface for generating, decoding, and
  39. * transforming planar YUV and JPEG images in memory.
  40. *
  41. * @anchor YUVnotes
  42. * YUV Image Format Notes
  43. * ----------------------
  44. * Technically, the JPEG format uses the YCbCr colorspace (which is technically
  45. * not a colorspace but a color transform), but per the convention of the
  46. * digital video community, the TurboJPEG API uses "YUV" to refer to an image
  47. * format consisting of Y, Cb, and Cr image planes.
  48. *
  49. * Each plane is simply a 2D array of bytes, each byte representing the value
  50. * of one of the components (Y, Cb, or Cr) at a particular location in the
  51. * image. The width and height of each plane are determined by the image
  52. * width, height, and level of chrominance subsampling. The luminance plane
  53. * width is the image width padded to the nearest multiple of the horizontal
  54. * subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of
  55. * 4:1:1, 1 in the case of 4:4:4 or grayscale.) Similarly, the luminance plane
  56. * height is the image height padded to the nearest multiple of the vertical
  57. * subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4
  58. * or grayscale.) This is irrespective of any additional padding that may be
  59. * specified as an argument to the various YUV functions. The chrominance
  60. * plane width is equal to the luminance plane width divided by the horizontal
  61. * subsampling factor, and the chrominance plane height is equal to the
  62. * luminance plane height divided by the vertical subsampling factor.
  63. *
  64. * For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is
  65. * used, then the luminance plane would be 36 x 35 bytes, and each of the
  66. * chrominance planes would be 18 x 35 bytes. If you specify a line padding of
  67. * 4 bytes on top of this, then the luminance plane would be 36 x 35 bytes, and
  68. * each of the chrominance planes would be 20 x 35 bytes.
  69. *
  70. * @{
  71. */
  72. /**
  73. * The number of chrominance subsampling options
  74. */
  75. #define TJ_NUMSAMP 6
  76. /**
  77. * Chrominance subsampling options.
  78. * When pixels are converted from RGB to YCbCr (see #TJCS_YCbCr) or from CMYK
  79. * to YCCK (see #TJCS_YCCK) as part of the JPEG compression process, some of
  80. * the Cb and Cr (chrominance) components can be discarded or averaged together
  81. * to produce a smaller image with little perceptible loss of image clarity
  82. * (the human eye is more sensitive to small changes in brightness than to
  83. * small changes in color.) This is called "chrominance subsampling".
  84. */
  85. enum TJSAMP
  86. {
  87. /**
  88. * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or
  89. * YUV image will contain one chrominance component for every pixel in the
  90. * source image.
  91. */
  92. TJSAMP_444=0,
  93. /**
  94. * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one
  95. * chrominance component for every 2x1 block of pixels in the source image.
  96. */
  97. TJSAMP_422,
  98. /**
  99. * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one
  100. * chrominance component for every 2x2 block of pixels in the source image.
  101. */
  102. TJSAMP_420,
  103. /**
  104. * Grayscale. The JPEG or YUV image will contain no chrominance components.
  105. */
  106. TJSAMP_GRAY,
  107. /**
  108. * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one
  109. * chrominance component for every 1x2 block of pixels in the source image.
  110. *
  111. * @note 4:4:0 subsampling is not fully accelerated in libjpeg-turbo.
  112. */
  113. TJSAMP_440,
  114. /**
  115. * 4:1:1 chrominance subsampling. The JPEG or YUV image will contain one
  116. * chrominance component for every 4x1 block of pixels in the source image.
  117. * JPEG images compressed with 4:1:1 subsampling will be almost exactly the
  118. * same size as those compressed with 4:2:0 subsampling, and in the
  119. * aggregate, both subsampling methods produce approximately the same
  120. * perceptual quality. However, 4:1:1 is better able to reproduce sharp
  121. * horizontal features.
  122. *
  123. * @note 4:1:1 subsampling is not fully accelerated in libjpeg-turbo.
  124. */
  125. TJSAMP_411
  126. };
  127. /**
  128. * MCU block width (in pixels) for a given level of chrominance subsampling.
  129. * MCU block sizes:
  130. * - 8x8 for no subsampling or grayscale
  131. * - 16x8 for 4:2:2
  132. * - 8x16 for 4:4:0
  133. * - 16x16 for 4:2:0
  134. * - 32x8 for 4:1:1
  135. */
  136. static const int tjMCUWidth[TJ_NUMSAMP] = {8, 16, 16, 8, 8, 32};
  137. /**
  138. * MCU block height (in pixels) for a given level of chrominance subsampling.
  139. * MCU block sizes:
  140. * - 8x8 for no subsampling or grayscale
  141. * - 16x8 for 4:2:2
  142. * - 8x16 for 4:4:0
  143. * - 16x16 for 4:2:0
  144. * - 32x8 for 4:1:1
  145. */
  146. static const int tjMCUHeight[TJ_NUMSAMP] = {8, 8, 16, 8, 16, 8};
  147. /**
  148. * The number of pixel formats
  149. */
  150. #define TJ_NUMPF 12
  151. /**
  152. * Pixel formats
  153. */
  154. enum TJPF
  155. {
  156. /**
  157. * RGB pixel format. The red, green, and blue components in the image are
  158. * stored in 3-byte pixels in the order R, G, B from lowest to highest byte
  159. * address within each pixel.
  160. */
  161. TJPF_RGB=0,
  162. /**
  163. * BGR pixel format. The red, green, and blue components in the image are
  164. * stored in 3-byte pixels in the order B, G, R from lowest to highest byte
  165. * address within each pixel.
  166. */
  167. TJPF_BGR,
  168. /**
  169. * RGBX pixel format. The red, green, and blue components in the image are
  170. * stored in 4-byte pixels in the order R, G, B from lowest to highest byte
  171. * address within each pixel. The X component is ignored when compressing
  172. * and undefined when decompressing.
  173. */
  174. TJPF_RGBX,
  175. /**
  176. * BGRX pixel format. The red, green, and blue components in the image are
  177. * stored in 4-byte pixels in the order B, G, R from lowest to highest byte
  178. * address within each pixel. The X component is ignored when compressing
  179. * and undefined when decompressing.
  180. */
  181. TJPF_BGRX,
  182. /**
  183. * XBGR pixel format. The red, green, and blue components in the image are
  184. * stored in 4-byte pixels in the order R, G, B from highest to lowest byte
  185. * address within each pixel. The X component is ignored when compressing
  186. * and undefined when decompressing.
  187. */
  188. TJPF_XBGR,
  189. /**
  190. * XRGB pixel format. The red, green, and blue components in the image are
  191. * stored in 4-byte pixels in the order B, G, R from highest to lowest byte
  192. * address within each pixel. The X component is ignored when compressing
  193. * and undefined when decompressing.
  194. */
  195. TJPF_XRGB,
  196. /**
  197. * Grayscale pixel format. Each 1-byte pixel represents a luminance
  198. * (brightness) level from 0 to 255.
  199. */
  200. TJPF_GRAY,
  201. /**
  202. * RGBA pixel format. This is the same as @ref TJPF_RGBX, except that when
  203. * decompressing, the X component is guaranteed to be 0xFF, which can be
  204. * interpreted as an opaque alpha channel.
  205. */
  206. TJPF_RGBA,
  207. /**
  208. * BGRA pixel format. This is the same as @ref TJPF_BGRX, except that when
  209. * decompressing, the X component is guaranteed to be 0xFF, which can be
  210. * interpreted as an opaque alpha channel.
  211. */
  212. TJPF_BGRA,
  213. /**
  214. * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when
  215. * decompressing, the X component is guaranteed to be 0xFF, which can be
  216. * interpreted as an opaque alpha channel.
  217. */
  218. TJPF_ABGR,
  219. /**
  220. * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when
  221. * decompressing, the X component is guaranteed to be 0xFF, which can be
  222. * interpreted as an opaque alpha channel.
  223. */
  224. TJPF_ARGB,
  225. /**
  226. * CMYK pixel format. Unlike RGB, which is an additive color model used
  227. * primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive
  228. * color model used primarily for printing. In the CMYK color model, the
  229. * value of each color component typically corresponds to an amount of cyan,
  230. * magenta, yellow, or black ink that is applied to a white background. In
  231. * order to convert between CMYK and RGB, it is necessary to use a color
  232. * management system (CMS.) A CMS will attempt to map colors within the
  233. * printer's gamut to perceptually similar colors in the display's gamut and
  234. * vice versa, but the mapping is typically not 1:1 or reversible, nor can it
  235. * be defined with a simple formula. Thus, such a conversion is out of scope
  236. * for a codec library. However, the TurboJPEG API allows for compressing
  237. * CMYK pixels into a YCCK JPEG image (see #TJCS_YCCK) and decompressing YCCK
  238. * JPEG images into CMYK pixels.
  239. */
  240. TJPF_CMYK
  241. };
  242. /**
  243. * Red offset (in bytes) for a given pixel format. This specifies the number
  244. * of bytes that the red component is offset from the start of the pixel. For
  245. * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
  246. * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>.
  247. */
  248. static const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1, -1};
  249. /**
  250. * Green offset (in bytes) for a given pixel format. This specifies the number
  251. * of bytes that the green component is offset from the start of the pixel.
  252. * For instance, if a pixel of format TJ_BGRX is stored in
  253. * <tt>char pixel[]</tt>, then the green component will be
  254. * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>.
  255. */
  256. static const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2, -1};
  257. /**
  258. * Blue offset (in bytes) for a given pixel format. This specifies the number
  259. * of bytes that the Blue component is offset from the start of the pixel. For
  260. * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
  261. * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>.
  262. */
  263. static const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3, -1};
  264. /**
  265. * Pixel size (in bytes) for a given pixel format.
  266. */
  267. static const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4};
  268. /**
  269. * The number of JPEG colorspaces
  270. */
  271. #define TJ_NUMCS 5
  272. /**
  273. * JPEG colorspaces
  274. */
  275. enum TJCS
  276. {
  277. /**
  278. * RGB colorspace. When compressing the JPEG image, the R, G, and B
  279. * components in the source image are reordered into image planes, but no
  280. * colorspace conversion or subsampling is performed. RGB JPEG images can be
  281. * decompressed to any of the extended RGB pixel formats or grayscale, but
  282. * they cannot be decompressed to YUV images.
  283. */
  284. TJCS_RGB=0,
  285. /**
  286. * YCbCr colorspace. YCbCr is not an absolute colorspace but rather a
  287. * mathematical transformation of RGB designed solely for storage and
  288. * transmission. YCbCr images must be converted to RGB before they can
  289. * actually be displayed. In the YCbCr colorspace, the Y (luminance)
  290. * component represents the black & white portion of the original image, and
  291. * the Cb and Cr (chrominance) components represent the color portion of the
  292. * original image. Originally, the analog equivalent of this transformation
  293. * allowed the same signal to drive both black & white and color televisions,
  294. * but JPEG images use YCbCr primarily because it allows the color data to be
  295. * optionally subsampled for the purposes of reducing bandwidth or disk
  296. * space. YCbCr is the most common JPEG colorspace, and YCbCr JPEG images
  297. * can be compressed from and decompressed to any of the extended RGB pixel
  298. * formats or grayscale, or they can be decompressed to YUV planar images.
  299. */
  300. TJCS_YCbCr,
  301. /**
  302. * Grayscale colorspace. The JPEG image retains only the luminance data (Y
  303. * component), and any color data from the source image is discarded.
  304. * Grayscale JPEG images can be compressed from and decompressed to any of
  305. * the extended RGB pixel formats or grayscale, or they can be decompressed
  306. * to YUV planar images.
  307. */
  308. TJCS_GRAY,
  309. /**
  310. * CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K
  311. * components in the source image are reordered into image planes, but no
  312. * colorspace conversion or subsampling is performed. CMYK JPEG images can
  313. * only be decompressed to CMYK pixels.
  314. */
  315. TJCS_CMYK,
  316. /**
  317. * YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but
  318. * rather a mathematical transformation of CMYK designed solely for storage
  319. * and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be
  320. * reversibly transformed into YCCK, and as with YCbCr, the chrominance
  321. * components in the YCCK pixels can be subsampled without incurring major
  322. * perceptual loss. YCCK JPEG images can only be compressed from and
  323. * decompressed to CMYK pixels.
  324. */
  325. TJCS_YCCK
  326. };
  327. /**
  328. * The uncompressed source/destination image is stored in bottom-up (Windows,
  329. * OpenGL) order, not top-down (X11) order.
  330. */
  331. #define TJFLAG_BOTTOMUP 2
  332. /**
  333. * When decompressing an image that was compressed using chrominance
  334. * subsampling, use the fastest chrominance upsampling algorithm available in
  335. * the underlying codec. The default is to use smooth upsampling, which
  336. * creates a smooth transition between neighboring chrominance components in
  337. * order to reduce upsampling artifacts in the decompressed image.
  338. */
  339. #define TJFLAG_FASTUPSAMPLE 256
  340. /**
  341. * Disable buffer (re)allocation. If passed to #tjCompress2() or
  342. * #tjTransform(), this flag will cause those functions to generate an error if
  343. * the JPEG image buffer is invalid or too small rather than attempting to
  344. * allocate or reallocate that buffer. This reproduces the behavior of earlier
  345. * versions of TurboJPEG.
  346. */
  347. #define TJFLAG_NOREALLOC 1024
  348. /**
  349. * Use the fastest DCT/IDCT algorithm available in the underlying codec. The
  350. * default if this flag is not specified is implementation-specific. For
  351. * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast
  352. * algorithm by default when compressing, because this has been shown to have
  353. * only a very slight effect on accuracy, but it uses the accurate algorithm
  354. * when decompressing, because this has been shown to have a larger effect.
  355. */
  356. #define TJFLAG_FASTDCT 2048
  357. /**
  358. * Use the most accurate DCT/IDCT algorithm available in the underlying codec.
  359. * The default if this flag is not specified is implementation-specific. For
  360. * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast
  361. * algorithm by default when compressing, because this has been shown to have
  362. * only a very slight effect on accuracy, but it uses the accurate algorithm
  363. * when decompressing, because this has been shown to have a larger effect.
  364. */
  365. #define TJFLAG_ACCURATEDCT 4096
  366. /**
  367. * The number of transform operations
  368. */
  369. #define TJ_NUMXOP 8
  370. /**
  371. * Transform operations for #tjTransform()
  372. */
  373. enum TJXOP
  374. {
  375. /**
  376. * Do not transform the position of the image pixels
  377. */
  378. TJXOP_NONE=0,
  379. /**
  380. * Flip (mirror) image horizontally. This transform is imperfect if there
  381. * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.)
  382. */
  383. TJXOP_HFLIP,
  384. /**
  385. * Flip (mirror) image vertically. This transform is imperfect if there are
  386. * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.)
  387. */
  388. TJXOP_VFLIP,
  389. /**
  390. * Transpose image (flip/mirror along upper left to lower right axis.) This
  391. * transform is always perfect.
  392. */
  393. TJXOP_TRANSPOSE,
  394. /**
  395. * Transverse transpose image (flip/mirror along upper right to lower left
  396. * axis.) This transform is imperfect if there are any partial MCU blocks in
  397. * the image (see #TJXOPT_PERFECT.)
  398. */
  399. TJXOP_TRANSVERSE,
  400. /**
  401. * Rotate image clockwise by 90 degrees. This transform is imperfect if
  402. * there are any partial MCU blocks on the bottom edge (see
  403. * #TJXOPT_PERFECT.)
  404. */
  405. TJXOP_ROT90,
  406. /**
  407. * Rotate image 180 degrees. This transform is imperfect if there are any
  408. * partial MCU blocks in the image (see #TJXOPT_PERFECT.)
  409. */
  410. TJXOP_ROT180,
  411. /**
  412. * Rotate image counter-clockwise by 90 degrees. This transform is imperfect
  413. * if there are any partial MCU blocks on the right edge (see
  414. * #TJXOPT_PERFECT.)
  415. */
  416. TJXOP_ROT270
  417. };
  418. /**
  419. * This option will cause #tjTransform() to return an error if the transform is
  420. * not perfect. Lossless transforms operate on MCU blocks, whose size depends
  421. * on the level of chrominance subsampling used (see #tjMCUWidth
  422. * and #tjMCUHeight.) If the image's width or height is not evenly divisible
  423. * by the MCU block size, then there will be partial MCU blocks on the right
  424. * and/or bottom edges. It is not possible to move these partial MCU blocks to
  425. * the top or left of the image, so any transform that would require that is
  426. * "imperfect." If this option is not specified, then any partial MCU blocks
  427. * that cannot be transformed will be left in place, which will create
  428. * odd-looking strips on the right or bottom edge of the image.
  429. */
  430. #define TJXOPT_PERFECT 1
  431. /**
  432. * This option will cause #tjTransform() to discard any partial MCU blocks that
  433. * cannot be transformed.
  434. */
  435. #define TJXOPT_TRIM 2
  436. /**
  437. * This option will enable lossless cropping. See #tjTransform() for more
  438. * information.
  439. */
  440. #define TJXOPT_CROP 4
  441. /**
  442. * This option will discard the color data in the input image and produce
  443. * a grayscale output image.
  444. */
  445. #define TJXOPT_GRAY 8
  446. /**
  447. * This option will prevent #tjTransform() from outputting a JPEG image for
  448. * this particular transform (this can be used in conjunction with a custom
  449. * filter to capture the transformed DCT coefficients without transcoding
  450. * them.)
  451. */
  452. #define TJXOPT_NOOUTPUT 16
  453. /**
  454. * Scaling factor
  455. */
  456. typedef struct
  457. {
  458. /**
  459. * Numerator
  460. */
  461. int num;
  462. /**
  463. * Denominator
  464. */
  465. int denom;
  466. } tjscalingfactor;
  467. /**
  468. * Cropping region
  469. */
  470. typedef struct
  471. {
  472. /**
  473. * The left boundary of the cropping region. This must be evenly divisible
  474. * by the MCU block width (see #tjMCUWidth.)
  475. */
  476. int x;
  477. /**
  478. * The upper boundary of the cropping region. This must be evenly divisible
  479. * by the MCU block height (see #tjMCUHeight.)
  480. */
  481. int y;
  482. /**
  483. * The width of the cropping region. Setting this to 0 is the equivalent of
  484. * setting it to the width of the source JPEG image - x.
  485. */
  486. int w;
  487. /**
  488. * The height of the cropping region. Setting this to 0 is the equivalent of
  489. * setting it to the height of the source JPEG image - y.
  490. */
  491. int h;
  492. } tjregion;
  493. /**
  494. * Lossless transform
  495. */
  496. typedef struct tjtransform
  497. {
  498. /**
  499. * Cropping region
  500. */
  501. tjregion r;
  502. /**
  503. * One of the @ref TJXOP "transform operations"
  504. */
  505. int op;
  506. /**
  507. * The bitwise OR of one of more of the @ref TJXOPT_CROP "transform options"
  508. */
  509. int options;
  510. /**
  511. * Arbitrary data that can be accessed within the body of the callback
  512. * function
  513. */
  514. void *data;
  515. /**
  516. * A callback function that can be used to modify the DCT coefficients
  517. * after they are losslessly transformed but before they are transcoded to a
  518. * new JPEG image. This allows for custom filters or other transformations
  519. * to be applied in the frequency domain.
  520. *
  521. * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE:
  522. * this pointer is not guaranteed to be valid once the callback returns, so
  523. * applications wishing to hand off the DCT coefficients to another function
  524. * or library should make a copy of them within the body of the callback.)
  525. *
  526. * @param arrayRegion #tjregion structure containing the width and height of
  527. * the array pointed to by <tt>coeffs</tt> as well as its offset relative to
  528. * the component plane. TurboJPEG implementations may choose to split each
  529. * component plane into multiple DCT coefficient arrays and call the callback
  530. * function once for each array.
  531. *
  532. * @param planeRegion #tjregion structure containing the width and height of
  533. * the component plane to which <tt>coeffs</tt> belongs
  534. *
  535. * @param componentID ID number of the component plane to which
  536. * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1,
  537. * and 2 in typical JPEG images.)
  538. *
  539. * @param transformID ID number of the transformed image to which
  540. * <tt>coeffs</tt> belongs. This is the same as the index of the transform
  541. * in the <tt>transforms</tt> array that was passed to #tjTransform().
  542. *
  543. * @param transform a pointer to a #tjtransform structure that specifies the
  544. * parameters and/or cropping region for this transform
  545. *
  546. * @return 0 if the callback was successful, or -1 if an error occurred.
  547. */
  548. int (*customFilter)(short *coeffs, tjregion arrayRegion,
  549. tjregion planeRegion, int componentIndex, int transformIndex,
  550. struct tjtransform *transform);
  551. } tjtransform;
  552. /**
  553. * TurboJPEG instance handle
  554. */
  555. typedef void* tjhandle;
  556. /**
  557. * Pad the given width to the nearest 32-bit boundary
  558. */
  559. #define TJPAD(width) (((width)+3)&(~3))
  560. /**
  561. * Compute the scaled value of <tt>dimension</tt> using the given scaling
  562. * factor. This macro performs the integer equivalent of <tt>ceil(dimension *
  563. * scalingFactor)</tt>.
  564. */
  565. #define TJSCALED(dimension, scalingFactor) ((dimension * scalingFactor.num \
  566. + scalingFactor.denom - 1) / scalingFactor.denom)
  567. #ifdef __cplusplus
  568. extern "C" {
  569. #endif
  570. /**
  571. * Create a TurboJPEG compressor instance.
  572. *
  573. * @return a handle to the newly-created instance, or NULL if an error
  574. * occurred (see #tjGetErrorStr().)
  575. */
  576. DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
  577. /**
  578. * Compress an RGB, grayscale, or CMYK image into a JPEG image.
  579. *
  580. * @param handle a handle to a TurboJPEG compressor or transformer instance
  581. *
  582. * @param srcBuf pointer to an image buffer containing RGB, grayscale, or
  583. * CMYK pixels to be compressed
  584. *
  585. * @param width width (in pixels) of the source image
  586. *
  587. * @param pitch bytes per line in the source image. Normally, this should be
  588. * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
  589. * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
  590. * is padded to the nearest 32-bit boundary, as is the case for Windows
  591. * bitmaps. You can also be clever and use this parameter to skip lines, etc.
  592. * Setting this parameter to 0 is the equivalent of setting it to
  593. * <tt>width * #tjPixelSize[pixelFormat]</tt>.
  594. *
  595. * @param height height (in pixels) of the source image
  596. *
  597. * @param pixelFormat pixel format of the source image (see @ref TJPF
  598. * "Pixel formats".)
  599. *
  600. * @param jpegBuf address of a pointer to an image buffer that will receive the
  601. * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer
  602. * to accommodate the size of the JPEG image. Thus, you can choose to:
  603. * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
  604. * let TurboJPEG grow the buffer as needed,
  605. * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
  606. * for you, or
  607. * -# pre-allocate the buffer to a "worst case" size determined by calling
  608. * #tjBufSize(). This should ensure that the buffer never has to be
  609. * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
  610. * .
  611. * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
  612. * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
  613. * you should always check <tt>*jpegBuf</tt> upon return from this function, as
  614. * it may have changed.
  615. *
  616. * @param jpegSize pointer to an unsigned long variable that holds the size of
  617. * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated
  618. * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
  619. * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
  620. * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
  621. * reused from a previous call to one of the JPEG compression functions, then
  622. * <tt>*jpegSize</tt> is ignored.
  623. *
  624. * @param jpegSubsamp the level of chrominance subsampling to be used when
  625. * generating the JPEG image (see @ref TJSAMP
  626. * "Chrominance subsampling options".)
  627. *
  628. * @param jpegQual the image quality of the generated JPEG image (1 = worst,
  629. * 100 = best)
  630. *
  631. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  632. * "flags"
  633. *
  634. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  635. */
  636. DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf,
  637. int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf,
  638. unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags);
  639. /**
  640. * Compress a YUV planar image into a JPEG image.
  641. *
  642. * @param handle a handle to a TurboJPEG compressor or transformer instance
  643. *
  644. * @param srcBuf pointer to an image buffer containing a YUV planar image to be
  645. * compressed. The size of this buffer should match the value returned by
  646. * #tjBufSizeYUV2() for the given image width, height, padding, and level of
  647. * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be
  648. * stored sequentially in the source buffer (refer to @ref YUVnotes
  649. * "YUV Image Format Notes".)
  650. *
  651. * @param width width (in pixels) of the source image. If the width is not an
  652. * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate
  653. * buffer copy will be performed within TurboJPEG.
  654. *
  655. * @param pad the line padding used in the source image. For instance, if each
  656. * line in each plane of the YUV image is padded to the nearest multiple of 4
  657. * bytes, then <tt>pad</tt> should be set to 4.
  658. *
  659. * @param height height (in pixels) of the source image. If the height is not
  660. * an even multiple of the MCU block height (see #tjMCUHeight), then an
  661. * intermediate buffer copy will be performed within TurboJPEG.
  662. *
  663. * @param subsamp the level of chrominance subsampling used in the source
  664. * image (see @ref TJSAMP "Chrominance subsampling options".)
  665. *
  666. * @param jpegBuf address of a pointer to an image buffer that will receive the
  667. * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
  668. * accommodate the size of the JPEG image. Thus, you can choose to:
  669. * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
  670. * let TurboJPEG grow the buffer as needed,
  671. * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
  672. * for you, or
  673. * -# pre-allocate the buffer to a "worst case" size determined by calling
  674. * #tjBufSize(). This should ensure that the buffer never has to be
  675. * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
  676. * .
  677. * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
  678. * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
  679. * you should always check <tt>*jpegBuf</tt> upon return from this function, as
  680. * it may have changed.
  681. *
  682. * @param jpegSize pointer to an unsigned long variable that holds the size of
  683. * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated
  684. * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
  685. * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
  686. * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
  687. * reused from a previous call to one of the JPEG compression functions, then
  688. * <tt>*jpegSize</tt> is ignored.
  689. *
  690. * @param jpegQual the image quality of the generated JPEG image (1 = worst,
  691. * 100 = best)
  692. *
  693. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  694. * "flags"
  695. *
  696. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  697. */
  698. DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle,
  699. const unsigned char *srcBuf, int width, int pad, int height, int subsamp,
  700. unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags);
  701. /**
  702. * Compress a set of Y, U (Cb), and V (Cr) image planes into a JPEG image.
  703. *
  704. * @param handle a handle to a TurboJPEG compressor or transformer instance
  705. *
  706. * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
  707. * (or just a Y plane, if compressing a grayscale image) that contain a YUV
  708. * image to be compressed. These planes can be contiguous or non-contiguous in
  709. * memory. The size of each plane should match the value returned by
  710. * #tjPlaneSizeYUV() for the given image width, height, strides, and level of
  711. * chrominance subsampling. Refer to @ref YUVnotes "YUV Image Format Notes"
  712. * for more details.
  713. *
  714. * @param width width (in pixels) of the source image. If the width is not an
  715. * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate
  716. * buffer copy will be performed within TurboJPEG.
  717. *
  718. * @param strides an array of integers, each specifying the number of bytes per
  719. * line in the corresponding plane of the YUV source image. Setting the stride
  720. * for any plane to 0 is the same as setting it to the plane width (see
  721. * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then
  722. * the strides for all planes will be set to their respective plane widths.
  723. * You can adjust the strides in order to specify an arbitrary amount of line
  724. * padding in each plane or to create a JPEG image from a subregion of a larger
  725. * YUV planar image.
  726. *
  727. * @param height height (in pixels) of the source image. If the height is not
  728. * an even multiple of the MCU block height (see #tjMCUHeight), then an
  729. * intermediate buffer copy will be performed within TurboJPEG.
  730. *
  731. * @param subsamp the level of chrominance subsampling used in the source
  732. * image (see @ref TJSAMP "Chrominance subsampling options".)
  733. *
  734. * @param jpegBuf address of a pointer to an image buffer that will receive the
  735. * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
  736. * accommodate the size of the JPEG image. Thus, you can choose to:
  737. * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
  738. * let TurboJPEG grow the buffer as needed,
  739. * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
  740. * for you, or
  741. * -# pre-allocate the buffer to a "worst case" size determined by calling
  742. * #tjBufSize(). This should ensure that the buffer never has to be
  743. * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
  744. * .
  745. * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
  746. * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
  747. * you should always check <tt>*jpegBuf</tt> upon return from this function, as
  748. * it may have changed.
  749. *
  750. * @param jpegSize pointer to an unsigned long variable that holds the size of
  751. * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated
  752. * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
  753. * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
  754. * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
  755. * reused from a previous call to one of the JPEG compression functions, then
  756. * <tt>*jpegSize</tt> is ignored.
  757. *
  758. * @param jpegQual the image quality of the generated JPEG image (1 = worst,
  759. * 100 = best)
  760. *
  761. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  762. * "flags"
  763. *
  764. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  765. */
  766. DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle,
  767. const unsigned char **srcPlanes, int width, const int *strides, int height,
  768. int subsamp, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual,
  769. int flags);
  770. /**
  771. * The maximum size of the buffer (in bytes) required to hold a JPEG image with
  772. * the given parameters. The number of bytes returned by this function is
  773. * larger than the size of the uncompressed source image. The reason for this
  774. * is that the JPEG format uses 16-bit coefficients, and it is thus possible
  775. * for a very high-quality JPEG image with very high-frequency content to
  776. * expand rather than compress when converted to the JPEG format. Such images
  777. * represent a very rare corner case, but since there is no way to predict the
  778. * size of a JPEG image prior to compression, the corner case has to be
  779. * handled.
  780. *
  781. * @param width width (in pixels) of the image
  782. *
  783. * @param height height (in pixels) of the image
  784. *
  785. * @param jpegSubsamp the level of chrominance subsampling to be used when
  786. * generating the JPEG image (see @ref TJSAMP
  787. * "Chrominance subsampling options".)
  788. *
  789. * @return the maximum size of the buffer (in bytes) required to hold the
  790. * image, or -1 if the arguments are out of bounds.
  791. */
  792. DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height,
  793. int jpegSubsamp);
  794. /**
  795. * The size of the buffer (in bytes) required to hold a YUV planar image with
  796. * the given parameters.
  797. *
  798. * @param width width (in pixels) of the image
  799. *
  800. * @param pad the width of each line in each plane of the image is padded to
  801. * the nearest multiple of this number of bytes (must be a power of 2.)
  802. *
  803. * @param height height (in pixels) of the image
  804. *
  805. * @param subsamp level of chrominance subsampling in the image (see
  806. * @ref TJSAMP "Chrominance subsampling options".)
  807. *
  808. * @return the size of the buffer (in bytes) required to hold the image, or
  809. * -1 if the arguments are out of bounds.
  810. */
  811. DLLEXPORT unsigned long DLLCALL tjBufSizeYUV2(int width, int pad, int height,
  812. int subsamp);
  813. /**
  814. * The size of the buffer (in bytes) required to hold a YUV image plane with
  815. * the given parameters.
  816. *
  817. * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
  818. *
  819. * @param width width (in pixels) of the YUV image. NOTE: this is the width of
  820. * the whole image, not the plane width.
  821. *
  822. * @param stride bytes per line in the image plane. Setting this to 0 is the
  823. * equivalent of setting it to the plane width.
  824. *
  825. * @param height height (in pixels) of the YUV image. NOTE: this is the height
  826. * of the whole image, not the plane height.
  827. *
  828. * @param subsamp level of chrominance subsampling in the image (see
  829. * @ref TJSAMP "Chrominance subsampling options".)
  830. *
  831. * @return the size of the buffer (in bytes) required to hold the YUV image
  832. * plane, or -1 if the arguments are out of bounds.
  833. */
  834. DLLEXPORT unsigned long DLLCALL tjPlaneSizeYUV(int componentID, int width,
  835. int stride, int height, int subsamp);
  836. /**
  837. * The plane width of a YUV image plane with the given parameters. Refer to
  838. * @ref YUVnotes "YUV Image Format Notes" for a description of plane width.
  839. *
  840. * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
  841. *
  842. * @param width width (in pixels) of the YUV image
  843. *
  844. * @param subsamp level of chrominance subsampling in the image (see
  845. * @ref TJSAMP "Chrominance subsampling options".)
  846. *
  847. * @return the plane width of a YUV image plane with the given parameters, or
  848. * -1 if the arguments are out of bounds.
  849. */
  850. DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp);
  851. /**
  852. * The plane height of a YUV image plane with the given parameters. Refer to
  853. * @ref YUVnotes "YUV Image Format Notes" for a description of plane height.
  854. *
  855. * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
  856. *
  857. * @param height height (in pixels) of the YUV image
  858. *
  859. * @param subsamp level of chrominance subsampling in the image (see
  860. * @ref TJSAMP "Chrominance subsampling options".)
  861. *
  862. * @return the plane height of a YUV image plane with the given parameters, or
  863. * -1 if the arguments are out of bounds.
  864. */
  865. DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp);
  866. /**
  867. * Encode an RGB or grayscale image into a YUV planar image. This function
  868. * uses the accelerated color conversion routines in the underlying
  869. * codec but does not execute any of the other steps in the JPEG compression
  870. * process.
  871. *
  872. * @param handle a handle to a TurboJPEG compressor or transformer instance
  873. *
  874. * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels
  875. * to be encoded
  876. *
  877. * @param width width (in pixels) of the source image
  878. *
  879. * @param pitch bytes per line in the source image. Normally, this should be
  880. * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
  881. * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
  882. * is padded to the nearest 32-bit boundary, as is the case for Windows
  883. * bitmaps. You can also be clever and use this parameter to skip lines, etc.
  884. * Setting this parameter to 0 is the equivalent of setting it to
  885. * <tt>width * #tjPixelSize[pixelFormat]</tt>.
  886. *
  887. * @param height height (in pixels) of the source image
  888. *
  889. * @param pixelFormat pixel format of the source image (see @ref TJPF
  890. * "Pixel formats".)
  891. *
  892. * @param dstBuf pointer to an image buffer that will receive the YUV image.
  893. * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based
  894. * on the image width, height, padding, and level of chrominance subsampling.
  895. * The Y, U (Cb), and V (Cr) image planes will be stored sequentially in the
  896. * buffer (refer to @ref YUVnotes "YUV Image Format Notes".)
  897. *
  898. * @param pad the width of each line in each plane of the YUV image will be
  899. * padded to the nearest multiple of this number of bytes (must be a power of
  900. * 2.) To generate images suitable for X Video, <tt>pad</tt> should be set to
  901. * 4.
  902. *
  903. * @param subsamp the level of chrominance subsampling to be used when
  904. * generating the YUV image (see @ref TJSAMP
  905. * "Chrominance subsampling options".) To generate images suitable for X
  906. * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420. This produces an
  907. * image compatible with the I420 (AKA "YUV420P") format.
  908. *
  909. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  910. * "flags"
  911. *
  912. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  913. */
  914. DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle,
  915. const unsigned char *srcBuf, int width, int pitch, int height,
  916. int pixelFormat, unsigned char *dstBuf, int pad, int subsamp, int flags);
  917. /**
  918. * Encode an RGB or grayscale image into separate Y, U (Cb), and V (Cr) image
  919. * planes. This function uses the accelerated color conversion routines in the
  920. * underlying codec but does not execute any of the other steps in the JPEG
  921. * compression process.
  922. *
  923. * @param handle a handle to a TurboJPEG compressor or transformer instance
  924. *
  925. * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels
  926. * to be encoded
  927. *
  928. * @param width width (in pixels) of the source image
  929. *
  930. * @param pitch bytes per line in the source image. Normally, this should be
  931. * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
  932. * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
  933. * is padded to the nearest 32-bit boundary, as is the case for Windows
  934. * bitmaps. You can also be clever and use this parameter to skip lines, etc.
  935. * Setting this parameter to 0 is the equivalent of setting it to
  936. * <tt>width * #tjPixelSize[pixelFormat]</tt>.
  937. *
  938. * @param height height (in pixels) of the source image
  939. *
  940. * @param pixelFormat pixel format of the source image (see @ref TJPF
  941. * "Pixel formats".)
  942. *
  943. * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
  944. * (or just a Y plane, if generating a grayscale image) that will receive the
  945. * encoded image. These planes can be contiguous or non-contiguous in memory.
  946. * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based
  947. * on the image width, height, strides, and level of chrominance subsampling.
  948. * Refer to @ref YUVnotes "YUV Image Format Notes" for more details.
  949. *
  950. * @param strides an array of integers, each specifying the number of bytes per
  951. * line in the corresponding plane of the output image. Setting the stride for
  952. * any plane to 0 is the same as setting it to the plane width (see
  953. * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then
  954. * the strides for all planes will be set to their respective plane widths.
  955. * You can adjust the strides in order to add an arbitrary amount of line
  956. * padding to each plane or to encode an RGB or grayscale image into a
  957. * subregion of a larger YUV planar image.
  958. *
  959. * @param subsamp the level of chrominance subsampling to be used when
  960. * generating the YUV image (see @ref TJSAMP
  961. * "Chrominance subsampling options".) To generate images suitable for X
  962. * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420. This produces an
  963. * image compatible with the I420 (AKA "YUV420P") format.
  964. *
  965. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  966. * "flags"
  967. *
  968. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  969. */
  970. DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle,
  971. const unsigned char *srcBuf, int width, int pitch, int height,
  972. int pixelFormat, unsigned char **dstPlanes, int *strides, int subsamp,
  973. int flags);
  974. /**
  975. * Create a TurboJPEG decompressor instance.
  976. *
  977. * @return a handle to the newly-created instance, or NULL if an error
  978. * occurred (see #tjGetErrorStr().)
  979. */
  980. DLLEXPORT tjhandle DLLCALL tjInitDecompress(void);
  981. /**
  982. * Retrieve information about a JPEG image without decompressing it.
  983. *
  984. * @param handle a handle to a TurboJPEG decompressor or transformer instance
  985. *
  986. * @param jpegBuf pointer to a buffer containing a JPEG image
  987. *
  988. * @param jpegSize size of the JPEG image (in bytes)
  989. *
  990. * @param width pointer to an integer variable that will receive the width (in
  991. * pixels) of the JPEG image
  992. *
  993. * @param height pointer to an integer variable that will receive the height
  994. * (in pixels) of the JPEG image
  995. *
  996. * @param jpegSubsamp pointer to an integer variable that will receive the
  997. * level of chrominance subsampling used when the JPEG image was compressed
  998. * (see @ref TJSAMP "Chrominance subsampling options".)
  999. *
  1000. * @param jpegColorspace pointer to an integer variable that will receive one
  1001. * of the JPEG colorspace constants, indicating the colorspace of the JPEG
  1002. * image (see @ref TJCS "JPEG colorspaces".)
  1003. *
  1004. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  1005. */
  1006. DLLEXPORT int DLLCALL tjDecompressHeader3(tjhandle handle,
  1007. const unsigned char *jpegBuf, unsigned long jpegSize, int *width,
  1008. int *height, int *jpegSubsamp, int *jpegColorspace);
  1009. /**
  1010. * Returns a list of fractional scaling factors that the JPEG decompressor in
  1011. * this implementation of TurboJPEG supports.
  1012. *
  1013. * @param numscalingfactors pointer to an integer variable that will receive
  1014. * the number of elements in the list
  1015. *
  1016. * @return a pointer to a list of fractional scaling factors, or NULL if an
  1017. * error is encountered (see #tjGetErrorStr().)
  1018. */
  1019. DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors);
  1020. /**
  1021. * Decompress a JPEG image to an RGB, grayscale, or CMYK image.
  1022. *
  1023. * @param handle a handle to a TurboJPEG decompressor or transformer instance
  1024. *
  1025. * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
  1026. *
  1027. * @param jpegSize size of the JPEG image (in bytes)
  1028. *
  1029. * @param dstBuf pointer to an image buffer that will receive the decompressed
  1030. * image. This buffer should normally be <tt>pitch * scaledHeight</tt> bytes
  1031. * in size, where <tt>scaledHeight</tt> can be determined by calling
  1032. * #TJSCALED() with the JPEG image height and one of the scaling factors
  1033. * returned by #tjGetScalingFactors(). The <tt>dstBuf</tt> pointer may also be
  1034. * used to decompress into a specific region of a larger buffer.
  1035. *
  1036. * @param width desired width (in pixels) of the destination image. If this is
  1037. * different than the width of the JPEG image being decompressed, then
  1038. * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
  1039. * possible image that will fit within the desired width. If <tt>width</tt> is
  1040. * set to 0, then only the height will be considered when determining the
  1041. * scaled image size.
  1042. *
  1043. * @param pitch bytes per line in the destination image. Normally, this is
  1044. * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt> if the decompressed image
  1045. * is unpadded, else <tt>#TJPAD(scaledWidth * #tjPixelSize[pixelFormat])</tt>
  1046. * if each line of the decompressed image is padded to the nearest 32-bit
  1047. * boundary, as is the case for Windows bitmaps. (NOTE: <tt>scaledWidth</tt>
  1048. * can be determined by calling #TJSCALED() with the JPEG image width and one
  1049. * of the scaling factors returned by #tjGetScalingFactors().) You can also be
  1050. * clever and use the pitch parameter to skip lines, etc. Setting this
  1051. * parameter to 0 is the equivalent of setting it to
  1052. * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt>.
  1053. *
  1054. * @param height desired height (in pixels) of the destination image. If this
  1055. * is different than the height of the JPEG image being decompressed, then
  1056. * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
  1057. * possible image that will fit within the desired height. If <tt>height</tt>
  1058. * is set to 0, then only the width will be considered when determining the
  1059. * scaled image size.
  1060. *
  1061. * @param pixelFormat pixel format of the destination image (see @ref
  1062. * TJPF "Pixel formats".)
  1063. *
  1064. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  1065. * "flags"
  1066. *
  1067. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  1068. */
  1069. DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle,
  1070. const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
  1071. int width, int pitch, int height, int pixelFormat, int flags);
  1072. /**
  1073. * Decompress a JPEG image to a YUV planar image. This function performs JPEG
  1074. * decompression but leaves out the color conversion step, so a planar YUV
  1075. * image is generated instead of an RGB image.
  1076. *
  1077. * @param handle a handle to a TurboJPEG decompressor or transformer instance
  1078. *
  1079. * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
  1080. *
  1081. * @param jpegSize size of the JPEG image (in bytes)
  1082. *
  1083. * @param dstBuf pointer to an image buffer that will receive the YUV image.
  1084. * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based
  1085. * on the image width, height, padding, and level of subsampling. The Y,
  1086. * U (Cb), and V (Cr) image planes will be stored sequentially in the buffer
  1087. * (refer to @ref YUVnotes "YUV Image Format Notes".)
  1088. *
  1089. * @param width desired width (in pixels) of the YUV image. If this is
  1090. * different than the width of the JPEG image being decompressed, then
  1091. * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
  1092. * possible image that will fit within the desired width. If <tt>width</tt> is
  1093. * set to 0, then only the height will be considered when determining the
  1094. * scaled image size. If the scaled width is not an even multiple of the MCU
  1095. * block width (see #tjMCUWidth), then an intermediate buffer copy will be
  1096. * performed within TurboJPEG.
  1097. *
  1098. * @param pad the width of each line in each plane of the YUV image will be
  1099. * padded to the nearest multiple of this number of bytes (must be a power of
  1100. * 2.) To generate images suitable for X Video, <tt>pad</tt> should be set to
  1101. * 4.
  1102. *
  1103. * @param height desired height (in pixels) of the YUV image. If this is
  1104. * different than the height of the JPEG image being decompressed, then
  1105. * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
  1106. * possible image that will fit within the desired height. If <tt>height</tt>
  1107. * is set to 0, then only the width will be considered when determining the
  1108. * scaled image size. If the scaled height is not an even multiple of the MCU
  1109. * block height (see #tjMCUHeight), then an intermediate buffer copy will be
  1110. * performed within TurboJPEG.
  1111. *
  1112. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  1113. * "flags"
  1114. *
  1115. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  1116. */
  1117. DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle,
  1118. const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
  1119. int width, int pad, int height, int flags);
  1120. /**
  1121. * Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image
  1122. * planes. This function performs JPEG decompression but leaves out the color
  1123. * conversion step, so a planar YUV image is generated instead of an RGB image.
  1124. *
  1125. * @param handle a handle to a TurboJPEG decompressor or transformer instance
  1126. *
  1127. * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
  1128. *
  1129. * @param jpegSize size of the JPEG image (in bytes)
  1130. *
  1131. * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
  1132. * (or just a Y plane, if decompressing a grayscale image) that will receive
  1133. * the YUV image. These planes can be contiguous or non-contiguous in memory.
  1134. * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based
  1135. * on the scaled image width, scaled image height, strides, and level of
  1136. * chrominance subsampling. Refer to @ref YUVnotes "YUV Image Format Notes"
  1137. * for more details.
  1138. *
  1139. * @param width desired width (in pixels) of the YUV image. If this is
  1140. * different than the width of the JPEG image being decompressed, then
  1141. * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
  1142. * possible image that will fit within the desired width. If <tt>width</tt> is
  1143. * set to 0, then only the height will be considered when determining the
  1144. * scaled image size. If the scaled width is not an even multiple of the MCU
  1145. * block width (see #tjMCUWidth), then an intermediate buffer copy will be
  1146. * performed within TurboJPEG.
  1147. *
  1148. * @param strides an array of integers, each specifying the number of bytes per
  1149. * line in the corresponding plane of the output image. Setting the stride for
  1150. * any plane to 0 is the same as setting it to the scaled plane width (see
  1151. * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then
  1152. * the strides for all planes will be set to their respective scaled plane
  1153. * widths. You can adjust the strides in order to add an arbitrary amount of
  1154. * line padding to each plane or to decompress the JPEG image into a subregion
  1155. * of a larger YUV planar image.
  1156. *
  1157. * @param height desired height (in pixels) of the YUV image. If this is
  1158. * different than the height of the JPEG image being decompressed, then
  1159. * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
  1160. * possible image that will fit within the desired height. If <tt>height</tt>
  1161. * is set to 0, then only the width will be considered when determining the
  1162. * scaled image size. If the scaled height is not an even multiple of the MCU
  1163. * block height (see #tjMCUHeight), then an intermediate buffer copy will be
  1164. * performed within TurboJPEG.
  1165. *
  1166. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  1167. * "flags"
  1168. *
  1169. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  1170. */
  1171. DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle,
  1172. const unsigned char *jpegBuf, unsigned long jpegSize,
  1173. unsigned char **dstPlanes, int width, int *strides, int height, int flags);
  1174. /**
  1175. * Decode a YUV planar image into an RGB or grayscale image. This function
  1176. * uses the accelerated color conversion routines in the underlying
  1177. * codec but does not execute any of the other steps in the JPEG decompression
  1178. * process.
  1179. *
  1180. * @param handle a handle to a TurboJPEG decompressor or transformer instance
  1181. *
  1182. * @param srcBuf pointer to an image buffer containing a YUV planar image to be
  1183. * decoded. The size of this buffer should match the value returned by
  1184. * #tjBufSizeYUV2() for the given image width, height, padding, and level of
  1185. * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be
  1186. * stored sequentially in the source buffer (refer to @ref YUVnotes
  1187. * "YUV Image Format Notes".)
  1188. *
  1189. * @param pad Use this parameter to specify that the width of each line in each
  1190. * plane of the YUV source image is padded to the nearest multiple of this
  1191. * number of bytes (must be a power of 2.)
  1192. *
  1193. * @param subsamp the level of chrominance subsampling used in the YUV source
  1194. * image (see @ref TJSAMP "Chrominance subsampling options".)
  1195. *
  1196. * @param dstBuf pointer to an image buffer that will receive the decoded
  1197. * image. This buffer should normally be <tt>pitch * height</tt> bytes in
  1198. * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a
  1199. * specific region of a larger buffer.
  1200. *
  1201. * @param width width (in pixels) of the source and destination images
  1202. *
  1203. * @param pitch bytes per line in the destination image. Normally, this should
  1204. * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is
  1205. * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line
  1206. * of the destination image should be padded to the nearest 32-bit boundary, as
  1207. * is the case for Windows bitmaps. You can also be clever and use the pitch
  1208. * parameter to skip lines, etc. Setting this parameter to 0 is the equivalent
  1209. * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
  1210. *
  1211. * @param height height (in pixels) of the source and destination images
  1212. *
  1213. * @param pixelFormat pixel format of the destination image (see @ref TJPF
  1214. * "Pixel formats".)
  1215. *
  1216. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  1217. * "flags"
  1218. *
  1219. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  1220. */
  1221. DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf,
  1222. int pad, int subsamp, unsigned char *dstBuf, int width, int pitch,
  1223. int height, int pixelFormat, int flags);
  1224. /**
  1225. * Decode a set of Y, U (Cb), and V (Cr) image planes into an RGB or grayscale
  1226. * image. This function uses the accelerated color conversion routines in the
  1227. * underlying codec but does not execute any of the other steps in the JPEG
  1228. * decompression process.
  1229. *
  1230. * @param handle a handle to a TurboJPEG decompressor or transformer instance
  1231. *
  1232. * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
  1233. * (or just a Y plane, if decoding a grayscale image) that contain a YUV image
  1234. * to be decoded. These planes can be contiguous or non-contiguous in memory.
  1235. * The size of each plane should match the value returned by #tjPlaneSizeYUV()
  1236. * for the given image width, height, strides, and level of chrominance
  1237. * subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" for more
  1238. * details.
  1239. *
  1240. * @param strides an array of integers, each specifying the number of bytes per
  1241. * line in the corresponding plane of the YUV source image. Setting the stride
  1242. * for any plane to 0 is the same as setting it to the plane width (see
  1243. * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then
  1244. * the strides for all planes will be set to their respective plane widths.
  1245. * You can adjust the strides in order to specify an arbitrary amount of line
  1246. * padding in each plane or to decode a subregion of a larger YUV planar image.
  1247. *
  1248. * @param subsamp the level of chrominance subsampling used in the YUV source
  1249. * image (see @ref TJSAMP "Chrominance subsampling options".)
  1250. *
  1251. * @param dstBuf pointer to an image buffer that will receive the decoded
  1252. * image. This buffer should normally be <tt>pitch * height</tt> bytes in
  1253. * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a
  1254. * specific region of a larger buffer.
  1255. *
  1256. * @param width width (in pixels) of the source and destination images
  1257. *
  1258. * @param pitch bytes per line in the destination image. Normally, this should
  1259. * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is
  1260. * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line
  1261. * of the destination image should be padded to the nearest 32-bit boundary, as
  1262. * is the case for Windows bitmaps. You can also be clever and use the pitch
  1263. * parameter to skip lines, etc. Setting this parameter to 0 is the equivalent
  1264. * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
  1265. *
  1266. * @param height height (in pixels) of the source and destination images
  1267. *
  1268. * @param pixelFormat pixel format of the destination image (see @ref TJPF
  1269. * "Pixel formats".)
  1270. *
  1271. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  1272. * "flags"
  1273. *
  1274. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  1275. */
  1276. DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle,
  1277. const unsigned char **srcPlanes, const int *strides, int subsamp,
  1278. unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat,
  1279. int flags);
  1280. /**
  1281. * Create a new TurboJPEG transformer instance.
  1282. *
  1283. * @return a handle to the newly-created instance, or NULL if an error
  1284. * occurred (see #tjGetErrorStr().)
  1285. */
  1286. DLLEXPORT tjhandle DLLCALL tjInitTransform(void);
  1287. /**
  1288. * Losslessly transform a JPEG image into another JPEG image. Lossless
  1289. * transforms work by moving the raw DCT coefficients from one JPEG image
  1290. * structure to another without altering the values of the coefficients. While
  1291. * this is typically faster than decompressing the image, transforming it, and
  1292. * re-compressing it, lossless transforms are not free. Each lossless
  1293. * transform requires reading and performing Huffman decoding on all of the
  1294. * coefficients in the source image, regardless of the size of the destination
  1295. * image. Thus, this function provides a means of generating multiple
  1296. * transformed images from the same source or applying multiple
  1297. * transformations simultaneously, in order to eliminate the need to read the
  1298. * source coefficients multiple times.
  1299. *
  1300. * @param handle a handle to a TurboJPEG transformer instance
  1301. *
  1302. * @param jpegBuf pointer to a buffer containing the JPEG source image to
  1303. * transform
  1304. *
  1305. * @param jpegSize size of the JPEG source image (in bytes)
  1306. *
  1307. * @param n the number of transformed JPEG images to generate
  1308. *
  1309. * @param dstBufs pointer to an array of n image buffers. <tt>dstBufs[i]</tt>
  1310. * will receive a JPEG image that has been transformed using the parameters in
  1311. * <tt>transforms[i]</tt>. TurboJPEG has the ability to reallocate the JPEG
  1312. * buffer to accommodate the size of the JPEG image. Thus, you can choose to:
  1313. * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
  1314. * let TurboJPEG grow the buffer as needed,
  1315. * -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the buffer
  1316. * for you, or
  1317. * -# pre-allocate the buffer to a "worst case" size determined by calling
  1318. * #tjBufSize() with the transformed or cropped width and height. This should
  1319. * ensure that the buffer never has to be re-allocated (setting
  1320. * #TJFLAG_NOREALLOC guarantees this.)
  1321. * .
  1322. * If you choose option 1, <tt>dstSizes[i]</tt> should be set to the size of
  1323. * your pre-allocated buffer. In any case, unless you have set
  1324. * #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt> upon return
  1325. * from this function, as it may have changed.
  1326. *
  1327. * @param dstSizes pointer to an array of n unsigned long variables that will
  1328. * receive the actual sizes (in bytes) of each transformed JPEG image. If
  1329. * <tt>dstBufs[i]</tt> points to a pre-allocated buffer, then
  1330. * <tt>dstSizes[i]</tt> should be set to the size of the buffer. Upon return,
  1331. * <tt>dstSizes[i]</tt> will contain the size of the JPEG image (in bytes.)
  1332. *
  1333. * @param transforms pointer to an array of n #tjtransform structures, each of
  1334. * which specifies the transform parameters and/or cropping region for the
  1335. * corresponding transformed output image.
  1336. *
  1337. * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  1338. * "flags"
  1339. *
  1340. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  1341. */
  1342. DLLEXPORT int DLLCALL tjTransform(tjhandle handle,
  1343. const unsigned char *jpegBuf, unsigned long jpegSize, int n,
  1344. unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms,
  1345. int flags);
  1346. /**
  1347. * Destroy a TurboJPEG compressor, decompressor, or transformer instance.
  1348. *
  1349. * @param handle a handle to a TurboJPEG compressor, decompressor or
  1350. * transformer instance
  1351. *
  1352. * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
  1353. */
  1354. DLLEXPORT int DLLCALL tjDestroy(tjhandle handle);
  1355. /**
  1356. * Allocate an image buffer for use with TurboJPEG. You should always use
  1357. * this function to allocate the JPEG destination buffer(s) for #tjCompress2()
  1358. * and #tjTransform() unless you are disabling automatic buffer
  1359. * (re)allocation (by setting #TJFLAG_NOREALLOC.)
  1360. *
  1361. * @param bytes the number of bytes to allocate
  1362. *
  1363. * @return a pointer to a newly-allocated buffer with the specified number of
  1364. * bytes.
  1365. *
  1366. * @sa tjFree()
  1367. */
  1368. DLLEXPORT unsigned char* DLLCALL tjAlloc(int bytes);
  1369. /**
  1370. * Free an image buffer previously allocated by TurboJPEG. You should always
  1371. * use this function to free JPEG destination buffer(s) that were automatically
  1372. * (re)allocated by #tjCompress2() or #tjTransform() or that were manually
  1373. * allocated using #tjAlloc().
  1374. *
  1375. * @param buffer address of the buffer to free
  1376. *
  1377. * @sa tjAlloc()
  1378. */
  1379. DLLEXPORT void DLLCALL tjFree(unsigned char *buffer);
  1380. /**
  1381. * Returns a descriptive error message explaining why the last command failed.
  1382. *
  1383. * @return a descriptive error message explaining why the last command failed.
  1384. */
  1385. DLLEXPORT char* DLLCALL tjGetErrorStr(void);
  1386. /* Deprecated functions and macros */
  1387. #define TJFLAG_FORCEMMX 8
  1388. #define TJFLAG_FORCESSE 16
  1389. #define TJFLAG_FORCESSE2 32
  1390. #define TJFLAG_FORCESSE3 128
  1391. /* Backward compatibility functions and macros (nothing to see here) */
  1392. #define NUMSUBOPT TJ_NUMSAMP
  1393. #define TJ_444 TJSAMP_444
  1394. #define TJ_422 TJSAMP_422
  1395. #define TJ_420 TJSAMP_420
  1396. #define TJ_411 TJSAMP_420
  1397. #define TJ_GRAYSCALE TJSAMP_GRAY
  1398. #define TJ_BGR 1
  1399. #define TJ_BOTTOMUP TJFLAG_BOTTOMUP
  1400. #define TJ_FORCEMMX TJFLAG_FORCEMMX
  1401. #define TJ_FORCESSE TJFLAG_FORCESSE
  1402. #define TJ_FORCESSE2 TJFLAG_FORCESSE2
  1403. #define TJ_ALPHAFIRST 64
  1404. #define TJ_FORCESSE3 TJFLAG_FORCESSE3
  1405. #define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE
  1406. #define TJ_YUV 512
  1407. DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height);
  1408. DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height,
  1409. int jpegSubsamp);
  1410. DLLEXPORT unsigned long DLLCALL tjBufSizeYUV(int width, int height,
  1411. int subsamp);
  1412. DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf,
  1413. int width, int pitch, int height, int pixelSize, unsigned char *dstBuf,
  1414. unsigned long *compressedSize, int jpegSubsamp, int jpegQual, int flags);
  1415. DLLEXPORT int DLLCALL tjEncodeYUV(tjhandle handle,
  1416. unsigned char *srcBuf, int width, int pitch, int height, int pixelSize,
  1417. unsigned char *dstBuf, int subsamp, int flags);
  1418. DLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle,
  1419. unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat,
  1420. unsigned char *dstBuf, int subsamp, int flags);
  1421. DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle handle,
  1422. unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height);
  1423. DLLEXPORT int DLLCALL tjDecompressHeader2(tjhandle handle,
  1424. unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height,
  1425. int *jpegSubsamp);
  1426. DLLEXPORT int DLLCALL tjDecompress(tjhandle handle,
  1427. unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
  1428. int width, int pitch, int height, int pixelSize, int flags);
  1429. DLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle handle,
  1430. unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
  1431. int flags);
  1432. /**
  1433. * @}
  1434. */
  1435. #ifdef __cplusplus
  1436. }
  1437. #endif
  1438. #endif