DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C)2011 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 | |
| 29 | /* |
| 30 | * This program tests the various code paths in the TurboJPEG JNI Wrapper |
| 31 | */ |
| 32 | |
| 33 | import java.io.*; |
| 34 | import java.util.*; |
DRC | 84a1bcc | 2011-02-23 12:09:56 +0000 | [diff] [blame] | 35 | import java.awt.image.*; |
| 36 | import javax.imageio.*; |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 37 | import java.nio.*; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 38 | import org.libjpegturbo.turbojpeg.*; |
| 39 | |
| 40 | public class TJUnitTest { |
| 41 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 42 | private static final String classname = |
| 43 | new TJUnitTest().getClass().getName(); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 44 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 45 | private static void usage() { |
| 46 | System.out.println("\nUSAGE: java " + classname + " [options]\n"); |
| 47 | System.out.println("Options:\n"); |
| 48 | System.out.println("-yuv = test YUV encoding/decoding support\n"); |
| 49 | System.out.println("-bi = test BufferedImage support\n"); |
| 50 | System.exit(1); |
| 51 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 52 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 53 | private final static String subNameLong[] = { |
DRC | d0a8136 | 2011-03-04 13:04:24 +0000 | [diff] [blame] | 54 | "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0" |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 55 | }; |
| 56 | private final static String subName[] = { |
DRC | d0a8136 | 2011-03-04 13:04:24 +0000 | [diff] [blame] | 57 | "444", "422", "420", "GRAY", "440" |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 58 | }; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 59 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 60 | private final static String pixFormatStr[] = { |
| 61 | "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "Grayscale" |
| 62 | }; |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 63 | |
| 64 | private final static int alphaOffset[] = { |
| 65 | -1, -1, 3, 3, 0, 0, -1 |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 66 | }; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 67 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 68 | private final static int _3byteFormats[] = { |
| 69 | TJ.PF_RGB, TJ.PF_BGR |
| 70 | }; |
| 71 | private final static int _3byteFormatsBI[] = { |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 72 | BufferedImage.TYPE_3BYTE_BGR |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 73 | }; |
| 74 | private final static int _4byteFormats[] = { |
| 75 | TJ.PF_RGBX, TJ.PF_BGRX, TJ.PF_XBGR, TJ.PF_XRGB |
| 76 | }; |
| 77 | private final static int _4byteFormatsBI[] = { |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 78 | BufferedImage.TYPE_INT_BGR, BufferedImage.TYPE_INT_RGB, |
| 79 | BufferedImage.TYPE_4BYTE_ABGR, BufferedImage.TYPE_4BYTE_ABGR_PRE, |
| 80 | BufferedImage.TYPE_INT_ARGB, BufferedImage.TYPE_INT_ARGB_PRE |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 81 | }; |
| 82 | private final static int onlyGray[] = { |
| 83 | TJ.PF_GRAY |
| 84 | }; |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 85 | private final static int onlyGrayBI[] = { |
| 86 | BufferedImage.TYPE_BYTE_GRAY |
| 87 | }; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 88 | private final static int onlyRGB[] = { |
| 89 | TJ.PF_RGB |
| 90 | }; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 91 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 92 | private final static int YUVENCODE = 1; |
| 93 | private final static int YUVDECODE = 2; |
| 94 | private static int yuv = 0; |
| 95 | private static boolean bi = false; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 96 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 97 | private static int exitStatus = 0; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 98 | |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 99 | private static int biTypePF(int biType) { |
| 100 | ByteOrder byteOrder = ByteOrder.nativeOrder(); |
| 101 | switch(biType) { |
| 102 | case BufferedImage.TYPE_3BYTE_BGR: |
| 103 | return TJ.PF_BGR; |
| 104 | case BufferedImage.TYPE_4BYTE_ABGR: |
| 105 | case BufferedImage.TYPE_4BYTE_ABGR_PRE: |
| 106 | return TJ.PF_XBGR; |
| 107 | case BufferedImage.TYPE_BYTE_GRAY: |
| 108 | return TJ.PF_GRAY; |
| 109 | case BufferedImage.TYPE_INT_BGR: |
| 110 | if(byteOrder == ByteOrder.BIG_ENDIAN) |
| 111 | return TJ.PF_XBGR; |
| 112 | else |
| 113 | return TJ.PF_RGBX; |
| 114 | case BufferedImage.TYPE_INT_RGB: |
| 115 | case BufferedImage.TYPE_INT_ARGB: |
| 116 | case BufferedImage.TYPE_INT_ARGB_PRE: |
| 117 | if(byteOrder == ByteOrder.BIG_ENDIAN) |
| 118 | return TJ.PF_XRGB; |
| 119 | else |
| 120 | return TJ.PF_BGRX; |
| 121 | } |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | private static String biTypeStr(int biType) { |
| 126 | switch(biType) { |
| 127 | case BufferedImage.TYPE_3BYTE_BGR: |
| 128 | return "3BYTE_BGR"; |
| 129 | case BufferedImage.TYPE_4BYTE_ABGR: |
| 130 | return "4BYTE_ABGR"; |
| 131 | case BufferedImage.TYPE_4BYTE_ABGR_PRE: |
| 132 | return "4BYTE_ABGR_PRE"; |
| 133 | case BufferedImage.TYPE_BYTE_GRAY: |
| 134 | return "BYTE_GRAY"; |
| 135 | case BufferedImage.TYPE_INT_BGR: |
| 136 | return "INT_BGR"; |
| 137 | case BufferedImage.TYPE_INT_RGB: |
| 138 | return "INT_RGB"; |
| 139 | case BufferedImage.TYPE_INT_ARGB: |
| 140 | return "INT_ARGB"; |
| 141 | case BufferedImage.TYPE_INT_ARGB_PRE: |
| 142 | return "INT_ARGB_PRE"; |
| 143 | } |
| 144 | return "Unknown"; |
| 145 | } |
| 146 | |
| 147 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 148 | private static double getTime() { |
| 149 | return (double)System.nanoTime() / 1.0e9; |
| 150 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 151 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 152 | private static void initBuf(byte[] buf, int w, int pitch, int h, int pf, |
| 153 | int flags) throws Exception { |
DRC | 2c74e51 | 2011-03-16 00:02:53 +0000 | [diff] [blame] | 154 | int roffset = TJ.getRedOffset(pf); |
| 155 | int goffset = TJ.getGreenOffset(pf); |
| 156 | int boffset = TJ.getBlueOffset(pf); |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 157 | int aoffset = alphaOffset[pf]; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 158 | int ps = TJ.getPixelSize(pf); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 159 | int index, row, col, halfway = 16; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 160 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 161 | Arrays.fill(buf, (byte)0); |
| 162 | if(pf == TJ.PF_GRAY) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 163 | for(row = 0; row < h; row++) { |
| 164 | for(col = 0; col < w; col++) { |
| 165 | if((flags & TJ.FLAG_BOTTOMUP) != 0) |
| 166 | index = pitch * (h - row - 1) + col; |
| 167 | else index = pitch * row + col; |
| 168 | if(((row / 8) + (col / 8)) % 2 == 0) |
| 169 | buf[index] = (row < halfway) ? (byte)255 : 0; |
| 170 | else buf[index] = (row < halfway) ? 76 : (byte)226; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | return; |
| 174 | } |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 175 | for(row = 0; row < h; row++) { |
| 176 | for(col = 0; col < w; col++) { |
| 177 | if((flags & TJ.FLAG_BOTTOMUP) != 0) |
| 178 | index = pitch * (h - row - 1) + col * ps; |
| 179 | else index = pitch * row + col * ps; |
| 180 | if(((row / 8) + (col / 8)) % 2 == 0) { |
| 181 | if(row < halfway) { |
| 182 | buf[index + roffset] = (byte)255; |
| 183 | buf[index + goffset] = (byte)255; |
| 184 | buf[index + boffset] = (byte)255; |
| 185 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 186 | } |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 187 | else { |
| 188 | buf[index + roffset] = (byte)255; |
| 189 | if(row >= halfway) buf[index + goffset] = (byte)255; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 190 | } |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 191 | if (aoffset >= 0) buf[index + aoffset] = (byte)255; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 195 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 196 | private static void initIntBuf(int[] buf, int w, int pitch, int h, int pf, |
| 197 | int flags) throws Exception { |
DRC | 2c74e51 | 2011-03-16 00:02:53 +0000 | [diff] [blame] | 198 | int rshift = TJ.getRedOffset(pf) * 8; |
| 199 | int gshift = TJ.getGreenOffset(pf) * 8; |
| 200 | int bshift = TJ.getBlueOffset(pf) * 8; |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 201 | int ashift = alphaOffset[pf] * 8; |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 202 | int index, row, col, halfway = 16; |
DRC | 84a1bcc | 2011-02-23 12:09:56 +0000 | [diff] [blame] | 203 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 204 | Arrays.fill(buf, 0); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 205 | for(row = 0; row < h; row++) { |
| 206 | for(col = 0; col < w; col++) { |
| 207 | if((flags & TJ.FLAG_BOTTOMUP) != 0) |
| 208 | index = pitch * (h - row - 1) + col; |
| 209 | else index = pitch * row + col; |
| 210 | if(((row / 8) + (col / 8)) % 2 == 0) { |
| 211 | if(row < halfway) { |
| 212 | buf[index] |= (255 << rshift); |
| 213 | buf[index] |= (255 << gshift); |
| 214 | buf[index] |= (255 << bshift); |
| 215 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 216 | } |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 217 | else { |
| 218 | buf[index] |= (255 << rshift); |
| 219 | if(row >= halfway) buf[index] |= (255 << gshift); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 220 | } |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 221 | if (ashift >= 0) buf[index] |= (255 << ashift); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | } |
DRC | 84a1bcc | 2011-02-23 12:09:56 +0000 | [diff] [blame] | 225 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 226 | private static void initImg(BufferedImage img, int pf, int flags) |
| 227 | throws Exception { |
| 228 | WritableRaster wr = img.getRaster(); |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 229 | int imgType = img.getType(); |
| 230 | if(imgType == BufferedImage.TYPE_INT_RGB |
| 231 | || imgType == BufferedImage.TYPE_INT_BGR |
| 232 | || imgType == BufferedImage.TYPE_INT_ARGB |
| 233 | || imgType == BufferedImage.TYPE_INT_ARGB_PRE) { |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 234 | SinglePixelPackedSampleModel sm = |
| 235 | (SinglePixelPackedSampleModel)img.getSampleModel(); |
| 236 | int pitch = sm.getScanlineStride(); |
| 237 | DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); |
| 238 | int[] buf = db.getData(); |
| 239 | initIntBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, flags); |
| 240 | } |
| 241 | else { |
| 242 | ComponentSampleModel sm = (ComponentSampleModel)img.getSampleModel(); |
| 243 | int pitch = sm.getScanlineStride(); |
| 244 | DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); |
| 245 | byte[] buf = db.getData(); |
| 246 | initBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, flags); |
| 247 | } |
| 248 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 249 | |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 250 | private static void checkVal(int row, int col, int v, String vname, int cv) |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 251 | throws Exception { |
| 252 | v = (v < 0) ? v + 256 : v; |
| 253 | if(v < cv - 1 || v > cv + 1) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 254 | throw new Exception("\nComp. " + vname + " at " + row + "," + col |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 255 | + " should be " + cv + ", not " + v + "\n"); |
| 256 | } |
| 257 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 258 | |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 259 | private static void checkVal0(int row, int col, int v, String vname) |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 260 | throws Exception { |
| 261 | v = (v < 0) ? v + 256 : v; |
| 262 | if(v > 1) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 263 | throw new Exception("\nComp. " + vname + " at " + row + "," + col |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 264 | + " should be 0, not " + v + "\n"); |
| 265 | } |
| 266 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 267 | |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 268 | private static void checkVal255(int row, int col, int v, String vname) |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 269 | throws Exception { |
| 270 | v = (v < 0) ? v + 256 : v; |
| 271 | if(v < 254) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 272 | throw new Exception("\nComp. " + vname + " at " + row + "," + col |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 273 | + " should be 255, not " + v + "\n"); |
| 274 | } |
| 275 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 276 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 277 | private static int checkBuf(byte[] buf, int w, int pitch, int h, int pf, |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 278 | int subsamp, TJScalingFactor sf, int flags) throws Exception { |
DRC | 2c74e51 | 2011-03-16 00:02:53 +0000 | [diff] [blame] | 279 | int roffset = TJ.getRedOffset(pf); |
| 280 | int goffset = TJ.getGreenOffset(pf); |
| 281 | int boffset = TJ.getBlueOffset(pf); |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 282 | int aoffset = alphaOffset[pf]; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 283 | int ps = TJ.getPixelSize(pf); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 284 | int index, row, col, retval = 1; |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 285 | int halfway = 16 * sf.getNum() / sf.getDenom(); |
| 286 | int blockSize = 8 * sf.getNum() / sf.getDenom(); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 287 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 288 | try { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 289 | for(row = 0; row < halfway; row++) { |
| 290 | for(col = 0; col < w; col++) { |
| 291 | if((flags & TJ.FLAG_BOTTOMUP) != 0) |
| 292 | index = pitch * (h - row - 1) + col * ps; |
| 293 | else index = pitch * row + col * ps; |
| 294 | byte r = buf[index + roffset]; |
| 295 | byte g = buf[index + goffset]; |
| 296 | byte b = buf[index + boffset]; |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 297 | byte a = aoffset >= 0 ? buf[index + aoffset] : (byte)255; |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 298 | if(((row / blockSize) + (col / blockSize)) % 2 == 0) { |
| 299 | if(row < halfway) { |
| 300 | checkVal255(row, col, r, "R"); |
| 301 | checkVal255(row, col, g, "G"); |
| 302 | checkVal255(row, col, b, "B"); |
| 303 | } |
| 304 | else { |
| 305 | checkVal0(row, col, r, "R"); |
| 306 | checkVal0(row, col, g, "G"); |
| 307 | checkVal0(row, col, b, "B"); |
| 308 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 309 | } |
| 310 | else { |
| 311 | if(subsamp == TJ.SAMP_GRAY) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 312 | if(row < halfway) { |
| 313 | checkVal(row, col, r, "R", 76); |
| 314 | checkVal(row, col, g, "G", 76); |
| 315 | checkVal(row, col, b, "B", 76); |
| 316 | } |
| 317 | else { |
| 318 | checkVal(row, col, r, "R", 226); |
| 319 | checkVal(row, col, g, "G", 226); |
| 320 | checkVal(row, col, b, "B", 226); |
| 321 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 322 | } |
| 323 | else { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 324 | checkVal255(row, col, r, "R"); |
| 325 | if(row < halfway) { |
| 326 | checkVal0(row, col, g, "G"); |
| 327 | } |
| 328 | else { |
| 329 | checkVal255(row, col, g, "G"); |
| 330 | } |
| 331 | checkVal0(row, col, b, "B"); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 332 | } |
| 333 | } |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 334 | checkVal255(row, col, a, "A"); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | } |
| 338 | catch(Exception e) { |
| 339 | System.out.println(e); |
| 340 | retval = 0; |
| 341 | } |
DRC | 4f1580c | 2011-02-25 06:11:03 +0000 | [diff] [blame] | 342 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 343 | if(retval == 0) { |
| 344 | System.out.print("\n"); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 345 | for(row = 0; row < h; row++) { |
| 346 | for(col = 0; col < w; col++) { |
| 347 | int r = buf[pitch * row + col * ps + roffset]; |
| 348 | int g = buf[pitch * row + col * ps + goffset]; |
| 349 | int b = buf[pitch * row + col * ps + boffset]; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 350 | if(r < 0) r += 256; if(g < 0) g += 256; if(b < 0) b += 256; |
| 351 | System.out.format("%3d/%3d/%3d ", r, g, b); |
| 352 | } |
| 353 | System.out.print("\n"); |
| 354 | } |
| 355 | } |
| 356 | return retval; |
| 357 | } |
DRC | 4f1580c | 2011-02-25 06:11:03 +0000 | [diff] [blame] | 358 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 359 | private static int checkIntBuf(int[] buf, int w, int pitch, int h, int pf, |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 360 | int subsamp, TJScalingFactor sf, int flags) throws Exception { |
DRC | 2c74e51 | 2011-03-16 00:02:53 +0000 | [diff] [blame] | 361 | int rshift = TJ.getRedOffset(pf) * 8; |
| 362 | int gshift = TJ.getGreenOffset(pf) * 8; |
| 363 | int bshift = TJ.getBlueOffset(pf) * 8; |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 364 | int ashift = alphaOffset[pf] * 8; |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 365 | int index, row, col, retval = 1; |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 366 | int halfway = 16 * sf.getNum() / sf.getDenom(); |
| 367 | int blockSize = 8 * sf.getNum() / sf.getDenom(); |
DRC | 4f1580c | 2011-02-25 06:11:03 +0000 | [diff] [blame] | 368 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 369 | try { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 370 | for(row = 0; row < halfway; row++) { |
| 371 | for(col = 0; col < w; col++) { |
| 372 | if((flags & TJ.FLAG_BOTTOMUP) != 0) |
| 373 | index = pitch * (h - row - 1) + col; |
| 374 | else index = pitch * row + col; |
| 375 | int r = (buf[index] >> rshift) & 0xFF; |
| 376 | int g = (buf[index] >> gshift) & 0xFF; |
| 377 | int b = (buf[index] >> bshift) & 0xFF; |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 378 | int a = ashift >= 0 ? (buf[index] >> ashift) & 0xFF : 255; |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 379 | if(((row / blockSize) + (col / blockSize)) % 2 == 0) { |
| 380 | if(row < halfway) { |
| 381 | checkVal255(row, col, r, "R"); |
| 382 | checkVal255(row, col, g, "G"); |
| 383 | checkVal255(row, col, b, "B"); |
| 384 | } |
| 385 | else { |
| 386 | checkVal0(row, col, r, "R"); |
| 387 | checkVal0(row, col, g, "G"); |
| 388 | checkVal0(row, col, b, "B"); |
| 389 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 390 | } |
| 391 | else { |
| 392 | if(subsamp == TJ.SAMP_GRAY) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 393 | if(row < halfway) { |
| 394 | checkVal(row, col, r, "R", 76); |
| 395 | checkVal(row, col, g, "G", 76); |
| 396 | checkVal(row, col, b, "B", 76); |
| 397 | } |
| 398 | else { |
| 399 | checkVal(row, col, r, "R", 226); |
| 400 | checkVal(row, col, g, "G", 226); |
| 401 | checkVal(row, col, b, "B", 226); |
| 402 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 403 | } |
| 404 | else { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 405 | checkVal255(row, col, r, "R"); |
| 406 | if(row < halfway) { |
| 407 | checkVal0(row, col, g, "G"); |
| 408 | } |
| 409 | else { |
| 410 | checkVal255(row, col, g, "G"); |
| 411 | } |
| 412 | checkVal0(row, col, b, "B"); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 413 | } |
| 414 | } |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 415 | checkVal255(row, col, a, "A"); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | } |
| 419 | catch(Exception e) { |
| 420 | System.out.println(e); |
| 421 | retval = 0; |
| 422 | } |
DRC | 4f1580c | 2011-02-25 06:11:03 +0000 | [diff] [blame] | 423 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 424 | if(retval == 0) { |
| 425 | System.out.print("\n"); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 426 | for(row = 0; row < h; row++) { |
| 427 | for(col = 0; col < w; col++) { |
| 428 | int r = (buf[pitch * row + col] >> rshift) & 0xFF; |
| 429 | int g = (buf[pitch * row + col] >> gshift) & 0xFF; |
| 430 | int b = (buf[pitch * row + col] >> bshift) & 0xFF; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 431 | if(r < 0) r += 256; if(g < 0) g += 256; if(b < 0) b += 256; |
| 432 | System.out.format("%3d/%3d/%3d ", r, g, b); |
| 433 | } |
| 434 | System.out.print("\n"); |
| 435 | } |
| 436 | } |
| 437 | return retval; |
| 438 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 439 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 440 | private static int checkImg(BufferedImage img, int pf, |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 441 | int subsamp, TJScalingFactor sf, int flags) throws Exception { |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 442 | WritableRaster wr = img.getRaster(); |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 443 | int imgType = img.getType(); |
| 444 | if(imgType == BufferedImage.TYPE_INT_RGB |
| 445 | || imgType == BufferedImage.TYPE_INT_BGR |
| 446 | || imgType == BufferedImage.TYPE_INT_ARGB |
| 447 | || imgType == BufferedImage.TYPE_INT_ARGB_PRE) { |
| 448 | SinglePixelPackedSampleModel sm = |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 449 | (SinglePixelPackedSampleModel)img.getSampleModel(); |
| 450 | int pitch = sm.getScanlineStride(); |
| 451 | DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); |
| 452 | int[] buf = db.getData(); |
| 453 | return checkIntBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 454 | subsamp, sf, flags); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 455 | } |
| 456 | else { |
| 457 | ComponentSampleModel sm = (ComponentSampleModel)img.getSampleModel(); |
| 458 | int pitch = sm.getScanlineStride(); |
| 459 | DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); |
| 460 | byte[] buf = db.getData(); |
| 461 | return checkBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, subsamp, |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 462 | sf, flags); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 463 | } |
| 464 | } |
DRC | 84a1bcc | 2011-02-23 12:09:56 +0000 | [diff] [blame] | 465 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 466 | private static int PAD(int v, int p) { |
| 467 | return ((v + (p) - 1) & (~((p) - 1))); |
| 468 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 469 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 470 | private static int checkBufYUV(byte[] buf, int size, int w, int h, |
DRC | d0a8136 | 2011-03-04 13:04:24 +0000 | [diff] [blame] | 471 | int subsamp) throws Exception { |
DRC | 215aa8b | 2011-05-27 02:10:42 +0000 | [diff] [blame] | 472 | int row, col; |
DRC | d0a8136 | 2011-03-04 13:04:24 +0000 | [diff] [blame] | 473 | int hsf = TJ.getMCUWidth(subsamp)/8, vsf = TJ.getMCUHeight(subsamp)/8; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 474 | int pw = PAD(w, hsf), ph = PAD(h, vsf); |
| 475 | int cw = pw / hsf, ch = ph / vsf; |
| 476 | int ypitch = PAD(pw, 4), uvpitch = PAD(cw, 4); |
| 477 | int retval = 1; |
| 478 | int correctsize = ypitch * ph |
| 479 | + (subsamp == TJ.SAMP_GRAY ? 0 : uvpitch * ch * 2); |
DRC | 215aa8b | 2011-05-27 02:10:42 +0000 | [diff] [blame] | 480 | int halfway = 16; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 481 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 482 | try { |
| 483 | if(size != correctsize) |
| 484 | throw new Exception("\nIncorrect size " + size + ". Should be " |
| 485 | + correctsize); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 486 | |
DRC | 215aa8b | 2011-05-27 02:10:42 +0000 | [diff] [blame] | 487 | for(row = 0; row < ph; row++) { |
| 488 | for(col = 0; col < pw; col++) { |
| 489 | byte y = buf[ypitch * row + col]; |
| 490 | if(((row / 8) + (col / 8)) % 2 == 0) { |
| 491 | if(row < halfway) checkVal255(row, col, y, "Y"); |
| 492 | else checkVal0(row, col, y, "Y"); |
| 493 | } |
| 494 | else { |
| 495 | if(row < halfway) checkVal(row, col, y, "Y", 76); |
| 496 | else checkVal(row, col, y, "Y", 226); |
| 497 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | if(subsamp != TJ.SAMP_GRAY) { |
DRC | 215aa8b | 2011-05-27 02:10:42 +0000 | [diff] [blame] | 501 | halfway = 16 / vsf; |
| 502 | for(row = 0; row < ch; row++) { |
| 503 | for(col = 0; col < cw; col++) { |
| 504 | byte u = buf[ypitch * ph + (uvpitch * row + col)], |
| 505 | v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)]; |
| 506 | if(((row * vsf / 8) + (col * hsf / 8)) % 2 == 0) { |
| 507 | checkVal(row, col, u, "U", 128); |
| 508 | checkVal(row, col, v, "V", 128); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 509 | } |
| 510 | else { |
DRC | 215aa8b | 2011-05-27 02:10:42 +0000 | [diff] [blame] | 511 | if(row < halfway) { |
| 512 | checkVal(row, col, u, "U", 85); |
| 513 | checkVal255(row, col, v, "V"); |
| 514 | } |
| 515 | else { |
| 516 | checkVal0(row, col, u, "U"); |
| 517 | checkVal(row, col, v, "V", 149); |
| 518 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | catch(Exception e) { |
| 525 | System.out.println(e); |
| 526 | retval = 0; |
| 527 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 528 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 529 | if(retval == 0) { |
DRC | 215aa8b | 2011-05-27 02:10:42 +0000 | [diff] [blame] | 530 | for(row = 0; row < ph; row++) { |
| 531 | for(col = 0; col < pw; col++) { |
| 532 | int y = buf[ypitch * row + col]; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 533 | if(y < 0) y += 256; |
| 534 | System.out.format("%3d ", y); |
| 535 | } |
| 536 | System.out.print("\n"); |
| 537 | } |
| 538 | System.out.print("\n"); |
DRC | 215aa8b | 2011-05-27 02:10:42 +0000 | [diff] [blame] | 539 | for(row = 0; row < ch; row++) { |
| 540 | for(col = 0; col < cw; col++) { |
| 541 | int u = buf[ypitch * ph + (uvpitch * row + col)]; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 542 | if(u < 0) u += 256; |
| 543 | System.out.format("%3d ", u); |
| 544 | } |
| 545 | System.out.print("\n"); |
| 546 | } |
| 547 | System.out.print("\n"); |
DRC | 215aa8b | 2011-05-27 02:10:42 +0000 | [diff] [blame] | 548 | for(row = 0; row < ch; row++) { |
| 549 | for(col = 0; col < cw; col++) { |
| 550 | int v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)]; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 551 | if(v < 0) v += 256; |
| 552 | System.out.format("%3d ", v); |
| 553 | } |
| 554 | System.out.print("\n"); |
| 555 | } |
| 556 | System.out.print("\n"); |
| 557 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 558 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 559 | return retval; |
| 560 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 561 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 562 | private static void writeJPEG(byte[] jpegBuf, int jpegBufSize, |
| 563 | String filename) throws Exception { |
| 564 | File file = new File(filename); |
| 565 | FileOutputStream fos = new FileOutputStream(file); |
| 566 | fos.write(jpegBuf, 0, jpegBufSize); |
| 567 | fos.close(); |
| 568 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 569 | |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 570 | private static int compTest(TJCompressor tjc, byte[] dstBuf, int w, |
| 571 | int h, int pf, String baseName, int subsamp, int jpegQual, |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 572 | int flags) throws Exception { |
| 573 | String tempstr; |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 574 | byte[] srcBuf = null; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 575 | BufferedImage img = null; |
| 576 | String pfStr; |
| 577 | double t; |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 578 | int size = 0, ps, imgType = pf; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 579 | |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 580 | if (bi) { |
| 581 | pf = biTypePF(imgType); |
| 582 | pfStr = biTypeStr(imgType); |
| 583 | } |
| 584 | else pfStr = pixFormatStr[pf]; |
| 585 | ps = TJ.getPixelSize(pf); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 586 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 587 | System.out.print(pfStr + " "); |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 588 | if(bi) System.out.print("(" + pixFormatStr[pf] + ") "); |
DRC | 92549de | 2011-03-15 20:52:02 +0000 | [diff] [blame] | 589 | if((flags & TJ.FLAG_BOTTOMUP) != 0) System.out.print("Bottom-Up"); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 590 | else System.out.print("Top-Down "); |
| 591 | System.out.print(" -> " + subNameLong[subsamp] + " "); |
| 592 | if(yuv == YUVENCODE) System.out.print("YUV ... "); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 593 | else System.out.print("Q" + jpegQual + " ... "); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 594 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 595 | if(bi) { |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 596 | img = new BufferedImage(w, h, imgType); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 597 | initImg(img, pf, flags); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 598 | tempstr = baseName + "_enc_" + pfStr + "_" |
DRC | 92549de | 2011-03-15 20:52:02 +0000 | [diff] [blame] | 599 | + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_" |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 600 | + subName[subsamp] + "_Q" + jpegQual + ".png"; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 601 | File file = new File(tempstr); |
| 602 | ImageIO.write(img, "png", file); |
| 603 | } |
| 604 | else { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 605 | srcBuf = new byte[w * h * ps + 1]; |
| 606 | initBuf(srcBuf, w, w * ps, h, pf, flags); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 607 | } |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 608 | Arrays.fill(dstBuf, (byte)0); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 609 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 610 | t = getTime(); |
| 611 | tjc.setSubsamp(subsamp); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 612 | tjc.setJPEGQuality(jpegQual); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 613 | if(bi) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 614 | if(yuv == YUVENCODE) tjc.encodeYUV(img, dstBuf, flags); |
| 615 | else tjc.compress(img, dstBuf, flags); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 616 | } |
| 617 | else { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 618 | tjc.setSourceImage(srcBuf, w, 0, h, pf); |
| 619 | if(yuv == YUVENCODE) tjc.encodeYUV(dstBuf, flags); |
| 620 | else tjc.compress(dstBuf, flags); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 621 | } |
| 622 | size = tjc.getCompressedSize(); |
| 623 | t = getTime() - t; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 624 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 625 | if(yuv == YUVENCODE) |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 626 | tempstr = baseName + "_enc_" + pfStr + "_" |
DRC | 92549de | 2011-03-15 20:52:02 +0000 | [diff] [blame] | 627 | + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_" |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 628 | + subName[subsamp] + ".yuv"; |
| 629 | else |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 630 | tempstr = baseName + "_enc_" + pfStr + "_" |
DRC | 92549de | 2011-03-15 20:52:02 +0000 | [diff] [blame] | 631 | + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_" |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 632 | + subName[subsamp] + "_Q" + jpegQual + ".jpg"; |
| 633 | writeJPEG(dstBuf, size, tempstr); |
DRC | 84a1bcc | 2011-02-23 12:09:56 +0000 | [diff] [blame] | 634 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 635 | if(yuv == YUVENCODE) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 636 | if(checkBufYUV(dstBuf, size, w, h, subsamp) == 1) |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 637 | System.out.print("Passed."); |
| 638 | else { |
| 639 | System.out.print("FAILED!"); exitStatus = -1; |
| 640 | } |
| 641 | } |
| 642 | else System.out.print("Done."); |
| 643 | System.out.format(" %.6f ms\n", t * 1000.); |
| 644 | System.out.println(" Result in " + tempstr); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 645 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 646 | return size; |
| 647 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 648 | |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 649 | private static void decompTest(TJDecompressor tjd, byte[] jpegBuf, |
| 650 | int jpegSize, int w, int h, int pf, String baseName, int subsamp, |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 651 | int flags, TJScalingFactor sf) throws Exception { |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 652 | String pfStr, tempstr; |
| 653 | double t; |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 654 | int scaledWidth = sf.getScaled(w); |
| 655 | int scaledHeight = sf.getScaled(h); |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 656 | int temp1, temp2, imgType = pf; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 657 | BufferedImage img = null; |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 658 | byte[] dstBuf = null; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 659 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 660 | if(yuv == YUVENCODE) return; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 661 | |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 662 | if (bi) { |
| 663 | pf = biTypePF(imgType); |
| 664 | pfStr = biTypeStr(imgType); |
| 665 | } |
| 666 | else pfStr = pixFormatStr[pf]; |
| 667 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 668 | System.out.print("JPEG -> "); |
| 669 | if(yuv == YUVDECODE) |
| 670 | System.out.print("YUV " + subName[subsamp] + " ... "); |
| 671 | else { |
| 672 | System.out.print(pfStr + " "); |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 673 | if(bi) System.out.print("(" + pixFormatStr[pf] + ") "); |
DRC | 92549de | 2011-03-15 20:52:02 +0000 | [diff] [blame] | 674 | if((flags & TJ.FLAG_BOTTOMUP) != 0) System.out.print("Bottom-Up "); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 675 | else System.out.print("Top-Down "); |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 676 | if(!sf.isOne()) |
| 677 | System.out.print(sf.getNum() + "/" + sf.getDenom() + " ... "); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 678 | else System.out.print("... "); |
| 679 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 680 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 681 | t = getTime(); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 682 | tjd.setJPEGImage(jpegBuf, jpegSize); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 683 | if(tjd.getWidth() != w || tjd.getHeight() != h |
| 684 | || tjd.getSubsamp() != subsamp) |
| 685 | throw new Exception("Incorrect JPEG header"); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 686 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 687 | temp1 = scaledWidth; |
| 688 | temp2 = scaledHeight; |
| 689 | temp1 = tjd.getScaledWidth(temp1, temp2); |
| 690 | temp2 = tjd.getScaledHeight(temp1, temp2); |
| 691 | if(temp1 != scaledWidth || temp2 != scaledHeight) |
| 692 | throw new Exception("Scaled size mismatch"); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 693 | |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 694 | if(yuv == YUVDECODE) dstBuf = tjd.decompressToYUV(flags); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 695 | else { |
| 696 | if(bi) |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 697 | img = tjd.decompress(scaledWidth, scaledHeight, imgType, flags); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 698 | else dstBuf = tjd.decompress(scaledWidth, 0, scaledHeight, pf, flags); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 699 | } |
| 700 | t = getTime() - t; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 701 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 702 | if(bi) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 703 | tempstr = baseName + "_dec_" + pfStr + "_" |
DRC | 92549de | 2011-03-15 20:52:02 +0000 | [diff] [blame] | 704 | + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_" |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 705 | + subName[subsamp] + "_" + (double)sf.getNum() / (double)sf.getDenom() |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 706 | + "x" + ".png"; |
| 707 | File file = new File(tempstr); |
| 708 | ImageIO.write(img, "png", file); |
| 709 | } |
DRC | 84a1bcc | 2011-02-23 12:09:56 +0000 | [diff] [blame] | 710 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 711 | if(yuv == YUVDECODE) { |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 712 | if(checkBufYUV(dstBuf, dstBuf.length, w, h, subsamp) == 1) |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 713 | System.out.print("Passed."); |
| 714 | else { |
| 715 | System.out.print("FAILED!"); exitStatus = -1; |
| 716 | } |
| 717 | } |
| 718 | else { |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 719 | if((bi && checkImg(img, pf, subsamp, sf, flags) == 1) |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 720 | || (!bi && checkBuf(dstBuf, scaledWidth, scaledWidth |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 721 | * TJ.getPixelSize(pf), scaledHeight, pf, subsamp, sf, flags) == 1)) |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 722 | System.out.print("Passed."); |
| 723 | else { |
| 724 | System.out.print("FAILED!"); exitStatus = -1; |
| 725 | } |
| 726 | } |
| 727 | System.out.format(" %.6f ms\n", t * 1000.); |
| 728 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 729 | |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 730 | private static void decompTest(TJDecompressor tjd, byte[] jpegBuf, |
| 731 | int jpegSize, int w, int h, int pf, String baseName, int subsamp, |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 732 | int flags) throws Exception { |
| 733 | int i; |
| 734 | if((subsamp == TJ.SAMP_444 || subsamp == TJ.SAMP_GRAY) && yuv == 0) { |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 735 | TJScalingFactor sf[] = TJ.getScalingFactors(); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 736 | for(i = 0; i < sf.length; i++) |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 737 | decompTest(tjd, jpegBuf, jpegSize, w, h, pf, baseName, subsamp, |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 738 | flags, sf[i]); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 739 | } |
| 740 | else |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 741 | decompTest(tjd, jpegBuf, jpegSize, w, h, pf, baseName, subsamp, |
DRC | b2f9415 | 2011-04-02 02:09:03 +0000 | [diff] [blame] | 742 | flags, new TJScalingFactor(1, 1)); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 743 | System.out.print("\n"); |
| 744 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 745 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 746 | private static void doTest(int w, int h, int[] formats, int subsamp, |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 747 | String baseName) throws Exception { |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 748 | TJCompressor tjc = null; |
| 749 | TJDecompressor tjd = null; |
DRC | 4f8c295 | 2011-03-31 10:06:17 +0000 | [diff] [blame] | 750 | int size; |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 751 | byte[] dstBuf; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 752 | |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 753 | if(yuv == YUVENCODE) dstBuf = new byte[TJ.bufSizeYUV(w, h, subsamp)]; |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 754 | else dstBuf = new byte[TJ.bufSize(w, h, subsamp)]; |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 755 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 756 | try { |
| 757 | tjc = new TJCompressor(); |
| 758 | tjd = new TJDecompressor(); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 759 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 760 | for(int pf : formats) { |
| 761 | for(int i = 0; i < 2; i++) { |
| 762 | int flags = 0; |
| 763 | if(i == 1) { |
| 764 | if(yuv == YUVDECODE) { |
| 765 | tjc.close(); tjd.close(); return; |
| 766 | } |
DRC | 92549de | 2011-03-15 20:52:02 +0000 | [diff] [blame] | 767 | else flags |= TJ.FLAG_BOTTOMUP; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 768 | } |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 769 | size = compTest(tjc, dstBuf, w, h, pf, baseName, subsamp, 100, |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 770 | flags); |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 771 | decompTest(tjd, dstBuf, size, w, h, pf, baseName, subsamp, flags); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | } |
| 775 | catch(Exception e) { |
| 776 | if(tjc != null) tjc.close(); |
| 777 | if(tjd != null) tjd.close(); |
| 778 | throw e; |
| 779 | } |
| 780 | if(tjc != null) tjc.close(); |
| 781 | if(tjd != null) tjd.close(); |
| 782 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 783 | |
DRC | 724c56b | 2011-07-12 06:22:06 +0000 | [diff] [blame] | 784 | private static void bufSizeTest() throws Exception { |
| 785 | int w, h, i, subsamp; |
DRC | f962fbb | 2011-05-23 05:49:08 +0000 | [diff] [blame] | 786 | byte[] srcBuf, jpegBuf; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 787 | TJCompressor tjc = null; |
DRC | 724c56b | 2011-07-12 06:22:06 +0000 | [diff] [blame] | 788 | Random r = new Random(); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 789 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 790 | try { |
| 791 | tjc = new TJCompressor(); |
| 792 | System.out.println("Buffer size regression test"); |
DRC | 724c56b | 2011-07-12 06:22:06 +0000 | [diff] [blame] | 793 | for(subsamp = 0; subsamp < TJ.NUMSAMP; subsamp++) { |
| 794 | for(w = 1; w < 48; w++) { |
| 795 | int maxh = (w == 1) ? 2048 : 48; |
| 796 | for(h = 1; h < maxh; h++) { |
| 797 | if(h % 100 == 0) |
| 798 | System.out.format("%04d x %04d\b\b\b\b\b\b\b\b\b\b\b", w, h); |
| 799 | srcBuf = new byte[w * h * 4]; |
| 800 | jpegBuf = new byte[TJ.bufSize(w, h, subsamp)]; |
| 801 | for(i = 0; i < w * h * 4; i++) { |
| 802 | srcBuf[i] = (byte)(r.nextInt(2) * 255); |
| 803 | } |
| 804 | tjc.setSourceImage(srcBuf, w, 0, h, TJ.PF_BGRX); |
| 805 | tjc.setSubsamp(subsamp); |
| 806 | tjc.setJPEGQuality(100); |
| 807 | tjc.compress(jpegBuf, 0); |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 808 | |
DRC | 724c56b | 2011-07-12 06:22:06 +0000 | [diff] [blame] | 809 | srcBuf = new byte[h * w * 4]; |
| 810 | jpegBuf = new byte[TJ.bufSize(h, w, subsamp)]; |
| 811 | for(i = 0; i < h * w * 4; i++) { |
| 812 | srcBuf[i] = (byte)(r.nextInt(2) * 255); |
| 813 | } |
| 814 | tjc.setSourceImage(srcBuf, h, 0, w, TJ.PF_BGRX); |
| 815 | tjc.compress(jpegBuf, 0); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 816 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | System.out.println("Done. "); |
| 820 | } |
| 821 | catch(Exception e) { |
| 822 | if(tjc != null) tjc.close(); |
| 823 | throw e; |
| 824 | } |
| 825 | if(tjc != null) tjc.close(); |
| 826 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 827 | |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 828 | public static void main(String argv[]) { |
| 829 | try { |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 830 | String testName = "javatest"; |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 831 | boolean doyuv = false; |
| 832 | for(int i = 0; i < argv.length; i++) { |
| 833 | if(argv[i].equalsIgnoreCase("-yuv")) doyuv = true; |
| 834 | if(argv[i].substring(0, 1).equalsIgnoreCase("-h") |
| 835 | || argv[i].equalsIgnoreCase("-?")) |
| 836 | usage(); |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 837 | if(argv[i].equalsIgnoreCase("-bi")) { |
| 838 | bi = true; |
| 839 | testName = "javabitest"; |
| 840 | } |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 841 | } |
| 842 | if(doyuv) yuv = YUVENCODE; |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 843 | doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_444, testName); |
| 844 | doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_444, testName); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 845 | if(doyuv) { |
| 846 | doTest(41, 35, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_422, |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 847 | testName); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 848 | doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_422, |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 849 | testName); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 850 | doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_420, |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 851 | testName); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 852 | doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_420, |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 853 | testName); |
DRC | d0a8136 | 2011-03-04 13:04:24 +0000 | [diff] [blame] | 854 | doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_440, |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 855 | testName); |
DRC | d0a8136 | 2011-03-04 13:04:24 +0000 | [diff] [blame] | 856 | doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_440, |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 857 | testName); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 858 | } |
DRC | c08e8c1 | 2011-09-08 23:54:40 +0000 | [diff] [blame] | 859 | doTest(35, 39, bi ? onlyGrayBI : onlyGray, TJ.SAMP_GRAY, testName); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 860 | doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_GRAY, |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 861 | testName); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 862 | doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_GRAY, |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 863 | testName); |
DRC | 724c56b | 2011-07-12 06:22:06 +0000 | [diff] [blame] | 864 | if(!doyuv && !bi) bufSizeTest(); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 865 | if(doyuv && !bi) { |
| 866 | yuv = YUVDECODE; |
DRC | b6ed7d3 | 2011-03-31 20:58:03 +0000 | [diff] [blame] | 867 | doTest(48, 48, onlyRGB, TJ.SAMP_444, "javatest_yuv0"); |
| 868 | doTest(35, 39, onlyRGB, TJ.SAMP_444, "javatest_yuv1"); |
| 869 | doTest(48, 48, onlyRGB, TJ.SAMP_422, "javatest_yuv0"); |
| 870 | doTest(39, 41, onlyRGB, TJ.SAMP_422, "javatest_yuv1"); |
| 871 | doTest(48, 48, onlyRGB, TJ.SAMP_420, "javatest_yuv0"); |
| 872 | doTest(41, 35, onlyRGB, TJ.SAMP_420, "javatest_yuv1"); |
| 873 | doTest(48, 48, onlyRGB, TJ.SAMP_440, "javatest_yuv0"); |
| 874 | doTest(35, 39, onlyRGB, TJ.SAMP_440, "javatest_yuv1"); |
| 875 | doTest(48, 48, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv0"); |
| 876 | doTest(35, 39, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv1"); |
| 877 | doTest(48, 48, onlyGray, TJ.SAMP_GRAY, "javatest_yuv0"); |
| 878 | doTest(39, 41, onlyGray, TJ.SAMP_GRAY, "javatest_yuv1"); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | catch(Exception e) { |
DRC | 2e2358e | 2011-03-04 09:54:59 +0000 | [diff] [blame] | 882 | e.printStackTrace(); |
DRC | f7f3ea4 | 2011-03-01 20:03:32 +0000 | [diff] [blame] | 883 | exitStatus = -1; |
| 884 | } |
| 885 | System.exit(exitStatus); |
| 886 | } |
DRC | 3bad53f | 2011-02-23 02:20:49 +0000 | [diff] [blame] | 887 | } |