TJ.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*
  2. * Copyright (C)2011-2013, 2017-2018 D. R. Commander. All Rights Reserved.
  3. * Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * - Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * - Neither the name of the libjpeg-turbo Project nor the names of its
  14. * contributors may be used to endorse or promote products derived from this
  15. * software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  21. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. * POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. package org.libjpegturbo.turbojpeg;
  30. /**
  31. * TurboJPEG utility class (cannot be instantiated)
  32. */
  33. public final class TJ {
  34. private TJ() {}
  35. /**
  36. * The number of chrominance subsampling options
  37. */
  38. public static final int NUMSAMP = 6;
  39. /**
  40. * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG
  41. * or YUV image will contain one chrominance component for every pixel in the
  42. * source image.
  43. */
  44. public static final int SAMP_444 = 0;
  45. /**
  46. * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one
  47. * chrominance component for every 2x1 block of pixels in the source image.
  48. */
  49. public static final int SAMP_422 = 1;
  50. /**
  51. * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one
  52. * chrominance component for every 2x2 block of pixels in the source image.
  53. */
  54. public static final int SAMP_420 = 2;
  55. /**
  56. * Grayscale. The JPEG or YUV image will contain no chrominance components.
  57. */
  58. public static final int SAMP_GRAY = 3;
  59. /**
  60. * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one
  61. * chrominance component for every 1x2 block of pixels in the source image.
  62. * Note that 4:4:0 subsampling is not fully accelerated in libjpeg-turbo.
  63. */
  64. public static final int SAMP_440 = 4;
  65. /**
  66. * 4:1:1 chrominance subsampling. The JPEG or YUV image will contain one
  67. * chrominance component for every 4x1 block of pixels in the source image.
  68. * JPEG images compressed with 4:1:1 subsampling will be almost exactly the
  69. * same size as those compressed with 4:2:0 subsampling, and in the
  70. * aggregate, both subsampling methods produce approximately the same
  71. * perceptual quality. However, 4:1:1 is better able to reproduce sharp
  72. * horizontal features. Note that 4:1:1 subsampling is not fully accelerated
  73. * in libjpeg-turbo.
  74. */
  75. public static final int SAMP_411 = 5;
  76. /**
  77. * Returns the MCU block width for the given level of chrominance
  78. * subsampling.
  79. *
  80. * @param subsamp the level of chrominance subsampling (one of
  81. * <code>SAMP_*</code>)
  82. *
  83. * @return the MCU block width for the given level of chrominance
  84. * subsampling.
  85. */
  86. public static int getMCUWidth(int subsamp) {
  87. checkSubsampling(subsamp);
  88. return MCU_WIDTH[subsamp];
  89. }
  90. private static final int[] MCU_WIDTH = {
  91. 8, 16, 16, 8, 8, 32
  92. };
  93. /**
  94. * Returns the MCU block height for the given level of chrominance
  95. * subsampling.
  96. *
  97. * @param subsamp the level of chrominance subsampling (one of
  98. * <code>SAMP_*</code>)
  99. *
  100. * @return the MCU block height for the given level of chrominance
  101. * subsampling.
  102. */
  103. public static int getMCUHeight(int subsamp) {
  104. checkSubsampling(subsamp);
  105. return MCU_HEIGHT[subsamp];
  106. }
  107. private static final int[] MCU_HEIGHT = {
  108. 8, 8, 16, 8, 16, 8
  109. };
  110. /**
  111. * The number of pixel formats
  112. */
  113. public static final int NUMPF = 12;
  114. /**
  115. * RGB pixel format. The red, green, and blue components in the image are
  116. * stored in 3-byte pixels in the order R, G, B from lowest to highest byte
  117. * address within each pixel.
  118. */
  119. public static final int PF_RGB = 0;
  120. /**
  121. * BGR pixel format. The red, green, and blue components in the image are
  122. * stored in 3-byte pixels in the order B, G, R from lowest to highest byte
  123. * address within each pixel.
  124. */
  125. public static final int PF_BGR = 1;
  126. /**
  127. * RGBX pixel format. The red, green, and blue components in the image are
  128. * stored in 4-byte pixels in the order R, G, B from lowest to highest byte
  129. * address within each pixel. The X component is ignored when compressing
  130. * and undefined when decompressing.
  131. */
  132. public static final int PF_RGBX = 2;
  133. /**
  134. * BGRX pixel format. The red, green, and blue components in the image are
  135. * stored in 4-byte pixels in the order B, G, R from lowest to highest byte
  136. * address within each pixel. The X component is ignored when compressing
  137. * and undefined when decompressing.
  138. */
  139. public static final int PF_BGRX = 3;
  140. /**
  141. * XBGR pixel format. The red, green, and blue components in the image are
  142. * stored in 4-byte pixels in the order R, G, B from highest to lowest byte
  143. * address within each pixel. The X component is ignored when compressing
  144. * and undefined when decompressing.
  145. */
  146. public static final int PF_XBGR = 4;
  147. /**
  148. * XRGB pixel format. The red, green, and blue components in the image are
  149. * stored in 4-byte pixels in the order B, G, R from highest to lowest byte
  150. * address within each pixel. The X component is ignored when compressing
  151. * and undefined when decompressing.
  152. */
  153. public static final int PF_XRGB = 5;
  154. /**
  155. * Grayscale pixel format. Each 1-byte pixel represents a luminance
  156. * (brightness) level from 0 to 255.
  157. */
  158. public static final int PF_GRAY = 6;
  159. /**
  160. * RGBA pixel format. This is the same as {@link #PF_RGBX}, except that when
  161. * decompressing, the X byte is guaranteed to be 0xFF, which can be
  162. * interpreted as an opaque alpha channel.
  163. */
  164. public static final int PF_RGBA = 7;
  165. /**
  166. * BGRA pixel format. This is the same as {@link #PF_BGRX}, except that when
  167. * decompressing, the X byte is guaranteed to be 0xFF, which can be
  168. * interpreted as an opaque alpha channel.
  169. */
  170. public static final int PF_BGRA = 8;
  171. /**
  172. * ABGR pixel format. This is the same as {@link #PF_XBGR}, except that when
  173. * decompressing, the X byte is guaranteed to be 0xFF, which can be
  174. * interpreted as an opaque alpha channel.
  175. */
  176. public static final int PF_ABGR = 9;
  177. /**
  178. * ARGB pixel format. This is the same as {@link #PF_XRGB}, except that when
  179. * decompressing, the X byte is guaranteed to be 0xFF, which can be
  180. * interpreted as an opaque alpha channel.
  181. */
  182. public static final int PF_ARGB = 10;
  183. /**
  184. * CMYK pixel format. Unlike RGB, which is an additive color model used
  185. * primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive
  186. * color model used primarily for printing. In the CMYK color model, the
  187. * value of each color component typically corresponds to an amount of cyan,
  188. * magenta, yellow, or black ink that is applied to a white background. In
  189. * order to convert between CMYK and RGB, it is necessary to use a color
  190. * management system (CMS.) A CMS will attempt to map colors within the
  191. * printer's gamut to perceptually similar colors in the display's gamut and
  192. * vice versa, but the mapping is typically not 1:1 or reversible, nor can it
  193. * be defined with a simple formula. Thus, such a conversion is out of scope
  194. * for a codec library. However, the TurboJPEG API allows for compressing
  195. * CMYK pixels into a YCCK JPEG image (see {@link #CS_YCCK}) and
  196. * decompressing YCCK JPEG images into CMYK pixels.
  197. */
  198. public static final int PF_CMYK = 11;
  199. /**
  200. * Returns the pixel size (in bytes) for the given pixel format.
  201. *
  202. * @param pixelFormat the pixel format (one of <code>PF_*</code>)
  203. *
  204. * @return the pixel size (in bytes) for the given pixel format.
  205. */
  206. public static int getPixelSize(int pixelFormat) {
  207. checkPixelFormat(pixelFormat);
  208. return PIXEL_SIZE[pixelFormat];
  209. }
  210. private static final int[] PIXEL_SIZE = {
  211. 3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4
  212. };
  213. /**
  214. * For the given pixel format, returns the number of bytes that the red
  215. * component is offset from the start of the pixel. For instance, if a pixel
  216. * of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
  217. * then the red component will be
  218. * <code>pixel[TJ.getRedOffset(TJ.PF_BGRX)]</code>.
  219. *
  220. * @param pixelFormat the pixel format (one of <code>PF_*</code>)
  221. *
  222. * @return the red offset for the given pixel format, or -1 if the pixel
  223. * format does not have a red component.
  224. */
  225. public static int getRedOffset(int pixelFormat) {
  226. checkPixelFormat(pixelFormat);
  227. return RED_OFFSET[pixelFormat];
  228. }
  229. private static final int[] RED_OFFSET = {
  230. 0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1
  231. };
  232. /**
  233. * For the given pixel format, returns the number of bytes that the green
  234. * component is offset from the start of the pixel. For instance, if a pixel
  235. * of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
  236. * then the green component will be
  237. * <code>pixel[TJ.getGreenOffset(TJ.PF_BGRX)]</code>.
  238. *
  239. * @param pixelFormat the pixel format (one of <code>PF_*</code>)
  240. *
  241. * @return the green offset for the given pixel format, or -1 if the pixel
  242. * format does not have a green component.
  243. */
  244. public static int getGreenOffset(int pixelFormat) {
  245. checkPixelFormat(pixelFormat);
  246. return GREEN_OFFSET[pixelFormat];
  247. }
  248. private static final int[] GREEN_OFFSET = {
  249. 1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1
  250. };
  251. /**
  252. * For the given pixel format, returns the number of bytes that the blue
  253. * component is offset from the start of the pixel. For instance, if a pixel
  254. * of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
  255. * then the blue component will be
  256. * <code>pixel[TJ.getBlueOffset(TJ.PF_BGRX)]</code>.
  257. *
  258. * @param pixelFormat the pixel format (one of <code>PF_*</code>)
  259. *
  260. * @return the blue offset for the given pixel format, or -1 if the pixel
  261. * format does not have a blue component.
  262. */
  263. public static int getBlueOffset(int pixelFormat) {
  264. checkPixelFormat(pixelFormat);
  265. return BLUE_OFFSET[pixelFormat];
  266. }
  267. private static final int[] BLUE_OFFSET = {
  268. 2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1
  269. };
  270. /**
  271. * For the given pixel format, returns the number of bytes that the alpha
  272. * component is offset from the start of the pixel. For instance, if a pixel
  273. * of format <code>TJ.PF_BGRA</code> is stored in <code>char pixel[]</code>,
  274. * then the alpha component will be
  275. * <code>pixel[TJ.getAlphaOffset(TJ.PF_BGRA)]</code>.
  276. *
  277. * @param pixelFormat the pixel format (one of <code>PF_*</code>)
  278. *
  279. * @return the alpha offset for the given pixel format, or -1 if the pixel
  280. * format does not have a alpha component.
  281. */
  282. public static int getAlphaOffset(int pixelFormat) {
  283. checkPixelFormat(pixelFormat);
  284. return ALPHA_OFFSET[pixelFormat];
  285. }
  286. private static final int[] ALPHA_OFFSET = {
  287. -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
  288. };
  289. /**
  290. * The number of JPEG colorspaces
  291. */
  292. public static final int NUMCS = 5;
  293. /**
  294. * RGB colorspace. When compressing the JPEG image, the R, G, and B
  295. * components in the source image are reordered into image planes, but no
  296. * colorspace conversion or subsampling is performed. RGB JPEG images can be
  297. * decompressed to any of the extended RGB pixel formats or grayscale, but
  298. * they cannot be decompressed to YUV images.
  299. */
  300. public static final int CS_RGB = 0;
  301. /**
  302. * YCbCr colorspace. YCbCr is not an absolute colorspace but rather a
  303. * mathematical transformation of RGB designed solely for storage and
  304. * transmission. YCbCr images must be converted to RGB before they can
  305. * actually be displayed. In the YCbCr colorspace, the Y (luminance)
  306. * component represents the black & white portion of the original image, and
  307. * the Cb and Cr (chrominance) components represent the color portion of the
  308. * original image. Originally, the analog equivalent of this transformation
  309. * allowed the same signal to drive both black & white and color televisions,
  310. * but JPEG images use YCbCr primarily because it allows the color data to be
  311. * optionally subsampled for the purposes of reducing bandwidth or disk
  312. * space. YCbCr is the most common JPEG colorspace, and YCbCr JPEG images
  313. * can be compressed from and decompressed to any of the extended RGB pixel
  314. * formats or grayscale, or they can be decompressed to YUV planar images.
  315. */
  316. @SuppressWarnings("checkstyle:ConstantName")
  317. public static final int CS_YCbCr = 1;
  318. /**
  319. * Grayscale colorspace. The JPEG image retains only the luminance data (Y
  320. * component), and any color data from the source image is discarded.
  321. * Grayscale JPEG images can be compressed from and decompressed to any of
  322. * the extended RGB pixel formats or grayscale, or they can be decompressed
  323. * to YUV planar images.
  324. */
  325. public static final int CS_GRAY = 2;
  326. /**
  327. * CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K
  328. * components in the source image are reordered into image planes, but no
  329. * colorspace conversion or subsampling is performed. CMYK JPEG images can
  330. * only be decompressed to CMYK pixels.
  331. */
  332. public static final int CS_CMYK = 3;
  333. /**
  334. * YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but
  335. * rather a mathematical transformation of CMYK designed solely for storage
  336. * and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be
  337. * reversibly transformed into YCCK, and as with YCbCr, the chrominance
  338. * components in the YCCK pixels can be subsampled without incurring major
  339. * perceptual loss. YCCK JPEG images can only be compressed from and
  340. * decompressed to CMYK pixels.
  341. */
  342. public static final int CS_YCCK = 4;
  343. /**
  344. * The uncompressed source/destination image is stored in bottom-up (Windows,
  345. * OpenGL) order, not top-down (X11) order.
  346. */
  347. public static final int FLAG_BOTTOMUP = 2;
  348. @SuppressWarnings("checkstyle:JavadocVariable")
  349. @Deprecated
  350. public static final int FLAG_FORCEMMX = 8;
  351. @SuppressWarnings("checkstyle:JavadocVariable")
  352. @Deprecated
  353. public static final int FLAG_FORCESSE = 16;
  354. @SuppressWarnings("checkstyle:JavadocVariable")
  355. @Deprecated
  356. public static final int FLAG_FORCESSE2 = 32;
  357. @SuppressWarnings("checkstyle:JavadocVariable")
  358. @Deprecated
  359. public static final int FLAG_FORCESSE3 = 128;
  360. /**
  361. * When decompressing an image that was compressed using chrominance
  362. * subsampling, use the fastest chrominance upsampling algorithm available in
  363. * the underlying codec. The default is to use smooth upsampling, which
  364. * creates a smooth transition between neighboring chrominance components in
  365. * order to reduce upsampling artifacts in the decompressed image.
  366. */
  367. public static final int FLAG_FASTUPSAMPLE = 256;
  368. /**
  369. * Use the fastest DCT/IDCT algorithm available in the underlying codec. The
  370. * default if this flag is not specified is implementation-specific. For
  371. * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast
  372. * algorithm by default when compressing, because this has been shown to have
  373. * only a very slight effect on accuracy, but it uses the accurate algorithm
  374. * when decompressing, because this has been shown to have a larger effect.
  375. */
  376. public static final int FLAG_FASTDCT = 2048;
  377. /**
  378. * Use the most accurate DCT/IDCT algorithm available in the underlying
  379. * codec. The default if this flag is not specified is
  380. * implementation-specific. For example, the implementation of TurboJPEG for
  381. * libjpeg[-turbo] uses the fast algorithm by default when compressing,
  382. * because this has been shown to have only a very slight effect on accuracy,
  383. * but it uses the accurate algorithm when decompressing, because this has
  384. * been shown to have a larger effect.
  385. */
  386. public static final int FLAG_ACCURATEDCT = 4096;
  387. /**
  388. * Immediately discontinue the current compression/decompression/transform
  389. * operation if the underlying codec throws a warning (non-fatal error). The
  390. * default behavior is to allow the operation to complete unless a fatal
  391. * error is encountered.
  392. * <p>
  393. * NOTE: due to the design of the TurboJPEG Java API, only certain methods
  394. * (specifically, {@link TJDecompressor TJDecompressor.decompress*()} methods
  395. * with a void return type) will complete and leave the output image in a
  396. * fully recoverable state after a non-fatal error occurs.
  397. */
  398. public static final int FLAG_STOPONWARNING = 8192;
  399. /**
  400. * Use progressive entropy coding in JPEG images generated by compression and
  401. * transform operations. Progressive entropy coding will generally improve
  402. * compression relative to baseline entropy coding (the default), but it will
  403. * reduce compression and decompression performance considerably.
  404. */
  405. public static final int FLAG_PROGRESSIVE = 16384;
  406. /**
  407. * The number of error codes
  408. */
  409. public static final int NUMERR = 2;
  410. /**
  411. * The error was non-fatal and recoverable, but the image may still be
  412. * corrupt.
  413. * <p>
  414. * NOTE: due to the design of the TurboJPEG Java API, only certain methods
  415. * (specifically, {@link TJDecompressor TJDecompressor.decompress*()} methods
  416. * with a void return type) will complete and leave the output image in a
  417. * fully recoverable state after a non-fatal error occurs.
  418. */
  419. public static final int ERR_WARNING = 0;
  420. /**
  421. * The error was fatal and non-recoverable.
  422. */
  423. public static final int ERR_FATAL = 1;
  424. /**
  425. * Returns the maximum size of the buffer (in bytes) required to hold a JPEG
  426. * image with the given width, height, and level of chrominance subsampling.
  427. *
  428. * @param width the width (in pixels) of the JPEG image
  429. *
  430. * @param height the height (in pixels) of the JPEG image
  431. *
  432. * @param jpegSubsamp the level of chrominance subsampling to be used when
  433. * generating the JPEG image (one of {@link TJ TJ.SAMP_*})
  434. *
  435. * @return the maximum size of the buffer (in bytes) required to hold a JPEG
  436. * image with the given width, height, and level of chrominance subsampling.
  437. */
  438. public static native int bufSize(int width, int height, int jpegSubsamp);
  439. /**
  440. * Returns the size of the buffer (in bytes) required to hold a YUV planar
  441. * image with the given width, height, and level of chrominance subsampling.
  442. *
  443. * @param width the width (in pixels) of the YUV image
  444. *
  445. * @param pad the width of each line in each plane of the image is padded to
  446. * the nearest multiple of this number of bytes (must be a power of 2.)
  447. *
  448. * @param height the height (in pixels) of the YUV image
  449. *
  450. * @param subsamp the level of chrominance subsampling used in the YUV
  451. * image (one of {@link TJ TJ.SAMP_*})
  452. *
  453. * @return the size of the buffer (in bytes) required to hold a YUV planar
  454. * image with the given width, height, and level of chrominance subsampling.
  455. */
  456. public static native int bufSizeYUV(int width, int pad, int height,
  457. int subsamp);
  458. /**
  459. * @deprecated Use {@link #bufSizeYUV(int, int, int, int)} instead.
  460. */
  461. @SuppressWarnings("checkstyle:JavadocMethod")
  462. @Deprecated
  463. public static native int bufSizeYUV(int width, int height, int subsamp);
  464. /**
  465. * Returns the size of the buffer (in bytes) required to hold a YUV image
  466. * plane with the given parameters.
  467. *
  468. * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb,
  469. * 2 = V/Cr)
  470. *
  471. * @param width width (in pixels) of the YUV image. NOTE: this is the width
  472. * of the whole image, not the plane width.
  473. *
  474. * @param stride bytes per line in the image plane.
  475. *
  476. * @param height height (in pixels) of the YUV image. NOTE: this is the
  477. * height of the whole image, not the plane height.
  478. *
  479. * @param subsamp the level of chrominance subsampling used in the YUV
  480. * image (one of {@link TJ TJ.SAMP_*})
  481. *
  482. * @return the size of the buffer (in bytes) required to hold a YUV planar
  483. * image with the given parameters.
  484. */
  485. public static native int planeSizeYUV(int componentID, int width, int stride,
  486. int height, int subsamp);
  487. /**
  488. * Returns the plane width of a YUV image plane with the given parameters.
  489. * Refer to {@link YUVImage YUVImage} for a description of plane width.
  490. *
  491. * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb,
  492. * 2 = V/Cr)
  493. *
  494. * @param width width (in pixels) of the YUV image
  495. *
  496. * @param subsamp the level of chrominance subsampling used in the YUV image
  497. * (one of {@link TJ TJ.SAMP_*})
  498. *
  499. * @return the plane width of a YUV image plane with the given parameters.
  500. */
  501. public static native int planeWidth(int componentID, int width, int subsamp);
  502. /**
  503. * Returns the plane height of a YUV image plane with the given parameters.
  504. * Refer to {@link YUVImage YUVImage} for a description of plane height.
  505. *
  506. * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb,
  507. * 2 = V/Cr)
  508. *
  509. * @param height height (in pixels) of the YUV image
  510. *
  511. * @param subsamp the level of chrominance subsampling used in the YUV image
  512. * (one of {@link TJ TJ.SAMP_*})
  513. *
  514. * @return the plane height of a YUV image plane with the given parameters.
  515. */
  516. public static native int planeHeight(int componentID, int height,
  517. int subsamp);
  518. /**
  519. * Returns a list of fractional scaling factors that the JPEG decompressor in
  520. * this implementation of TurboJPEG supports.
  521. *
  522. * @return a list of fractional scaling factors that the JPEG decompressor in
  523. * this implementation of TurboJPEG supports.
  524. */
  525. public static native TJScalingFactor[] getScalingFactors();
  526. static {
  527. TJLoader.load();
  528. }
  529. private static void checkPixelFormat(int pixelFormat) {
  530. if (pixelFormat < 0 || pixelFormat >= NUMPF)
  531. throw new IllegalArgumentException("Invalid pixel format");
  532. }
  533. private static void checkSubsampling(int subsamp) {
  534. if (subsamp < 0 || subsamp >= NUMSAMP)
  535. throw new IllegalArgumentException("Invalid subsampling type");
  536. }
  537. }