blob: b0c44ad8a945f9c59bf870a4d010106b28399d7b [file] [log] [blame]
DRC3bad53f2011-02-23 02:20:49 +00001/*
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
33import java.io.*;
34import java.util.*;
DRC84a1bcc2011-02-23 12:09:56 +000035import java.awt.image.*;
36import javax.imageio.*;
DRC3bad53f2011-02-23 02:20:49 +000037import org.libjpegturbo.turbojpeg.*;
38
39public class TJUnitTest {
40
DRCf7f3ea42011-03-01 20:03:32 +000041 private static final String classname =
42 new TJUnitTest().getClass().getName();
DRC3bad53f2011-02-23 02:20:49 +000043
DRCf7f3ea42011-03-01 20:03:32 +000044 private static void usage() {
45 System.out.println("\nUSAGE: java " + classname + " [options]\n");
46 System.out.println("Options:\n");
47 System.out.println("-yuv = test YUV encoding/decoding support\n");
48 System.out.println("-bi = test BufferedImage support\n");
49 System.exit(1);
50 }
DRC3bad53f2011-02-23 02:20:49 +000051
DRCf7f3ea42011-03-01 20:03:32 +000052 private final static String subNameLong[] = {
DRCd0a81362011-03-04 13:04:24 +000053 "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0"
DRCf7f3ea42011-03-01 20:03:32 +000054 };
55 private final static String subName[] = {
DRCd0a81362011-03-04 13:04:24 +000056 "444", "422", "420", "GRAY", "440"
DRCf7f3ea42011-03-01 20:03:32 +000057 };
DRC3bad53f2011-02-23 02:20:49 +000058
DRCf7f3ea42011-03-01 20:03:32 +000059 private final static String pixFormatStr[] = {
60 "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "Grayscale"
61 };
62 private final static int biType[] = {
63 0, BufferedImage.TYPE_3BYTE_BGR, BufferedImage.TYPE_INT_BGR,
64 BufferedImage.TYPE_INT_RGB, 0, 0, BufferedImage.TYPE_BYTE_GRAY
65 };
DRC3bad53f2011-02-23 02:20:49 +000066
DRCf7f3ea42011-03-01 20:03:32 +000067 private final static int _3byteFormats[] = {
68 TJ.PF_RGB, TJ.PF_BGR
69 };
70 private final static int _3byteFormatsBI[] = {
71 TJ.PF_BGR
72 };
73 private final static int _4byteFormats[] = {
74 TJ.PF_RGBX, TJ.PF_BGRX, TJ.PF_XBGR, TJ.PF_XRGB
75 };
76 private final static int _4byteFormatsBI[] = {
77 TJ.PF_RGBX, TJ.PF_BGRX
78 };
79 private final static int onlyGray[] = {
80 TJ.PF_GRAY
81 };
82 private final static int onlyRGB[] = {
83 TJ.PF_RGB
84 };
DRC3bad53f2011-02-23 02:20:49 +000085
DRCf7f3ea42011-03-01 20:03:32 +000086 private final static int YUVENCODE = 1;
87 private final static int YUVDECODE = 2;
88 private static int yuv = 0;
89 private static boolean bi = false;
DRC3bad53f2011-02-23 02:20:49 +000090
DRCf7f3ea42011-03-01 20:03:32 +000091 private static int exitStatus = 0;
DRC3bad53f2011-02-23 02:20:49 +000092
DRCf7f3ea42011-03-01 20:03:32 +000093 private static double getTime() {
94 return (double)System.nanoTime() / 1.0e9;
95 }
DRC3bad53f2011-02-23 02:20:49 +000096
DRCf7f3ea42011-03-01 20:03:32 +000097 private final static byte pixels[][] = {
98 {0, (byte)255, 0},
99 {(byte)255, 0, (byte)255},
DRCf7f3ea42011-03-01 20:03:32 +0000100 {0, (byte)255, (byte)255},
101 {(byte)255, 0, 0},
DRCf962fbb2011-05-23 05:49:08 +0000102 {(byte)255, (byte)255, 0},
103 {0, 0, (byte)255},
DRCf7f3ea42011-03-01 20:03:32 +0000104 {(byte)255, (byte)255, (byte)255},
105 {0, 0, 0},
DRCf962fbb2011-05-23 05:49:08 +0000106 {0, 0, (byte)255}
DRCf7f3ea42011-03-01 20:03:32 +0000107 };
DRC3bad53f2011-02-23 02:20:49 +0000108
DRCf7f3ea42011-03-01 20:03:32 +0000109 private static void initBuf(byte[] buf, int w, int pitch, int h, int pf,
110 int flags) throws Exception {
DRC2c74e512011-03-16 00:02:53 +0000111 int roffset = TJ.getRedOffset(pf);
112 int goffset = TJ.getGreenOffset(pf);
113 int boffset = TJ.getBlueOffset(pf);
DRCf7f3ea42011-03-01 20:03:32 +0000114 int ps = TJ.getPixelSize(pf);
DRCf962fbb2011-05-23 05:49:08 +0000115 int index, row, col, halfway = 16;
DRC3bad53f2011-02-23 02:20:49 +0000116
DRCf7f3ea42011-03-01 20:03:32 +0000117 Arrays.fill(buf, (byte)0);
118 if(pf == TJ.PF_GRAY) {
DRCf962fbb2011-05-23 05:49:08 +0000119 for(row = 0; row < h; row++) {
120 for(col = 0; col < w; col++) {
121 if((flags & TJ.FLAG_BOTTOMUP) != 0)
122 index = pitch * (h - row - 1) + col;
123 else index = pitch * row + col;
124 if(((row / 8) + (col / 8)) % 2 == 0)
125 buf[index] = (row < halfway) ? (byte)255 : 0;
126 else buf[index] = (row < halfway) ? 76 : (byte)226;
DRCf7f3ea42011-03-01 20:03:32 +0000127 }
128 }
129 return;
130 }
DRCf962fbb2011-05-23 05:49:08 +0000131 for(row = 0; row < h; row++) {
132 for(col = 0; col < w; col++) {
133 if((flags & TJ.FLAG_BOTTOMUP) != 0)
134 index = pitch * (h - row - 1) + col * ps;
135 else index = pitch * row + col * ps;
136 if(((row / 8) + (col / 8)) % 2 == 0) {
137 if(row < halfway) {
138 buf[index + roffset] = (byte)255;
139 buf[index + goffset] = (byte)255;
140 buf[index + boffset] = (byte)255;
141 }
DRCf7f3ea42011-03-01 20:03:32 +0000142 }
DRCf962fbb2011-05-23 05:49:08 +0000143 else {
144 buf[index + roffset] = (byte)255;
145 if(row >= halfway) buf[index + goffset] = (byte)255;
DRCf7f3ea42011-03-01 20:03:32 +0000146 }
147 }
148 }
149 }
DRC3bad53f2011-02-23 02:20:49 +0000150
DRCf7f3ea42011-03-01 20:03:32 +0000151 private static void initIntBuf(int[] buf, int w, int pitch, int h, int pf,
152 int flags) throws Exception {
DRC2c74e512011-03-16 00:02:53 +0000153 int rshift = TJ.getRedOffset(pf) * 8;
154 int gshift = TJ.getGreenOffset(pf) * 8;
155 int bshift = TJ.getBlueOffset(pf) * 8;
DRCf962fbb2011-05-23 05:49:08 +0000156 int index, row, col, halfway = 16;
DRC84a1bcc2011-02-23 12:09:56 +0000157
DRCf7f3ea42011-03-01 20:03:32 +0000158 Arrays.fill(buf, 0);
DRCf962fbb2011-05-23 05:49:08 +0000159 for(row = 0; row < h; row++) {
160 for(col = 0; col < w; col++) {
161 if((flags & TJ.FLAG_BOTTOMUP) != 0)
162 index = pitch * (h - row - 1) + col;
163 else index = pitch * row + col;
164 if(((row / 8) + (col / 8)) % 2 == 0) {
165 if(row < halfway) {
166 buf[index] |= (255 << rshift);
167 buf[index] |= (255 << gshift);
168 buf[index] |= (255 << bshift);
169 }
DRCf7f3ea42011-03-01 20:03:32 +0000170 }
DRCf962fbb2011-05-23 05:49:08 +0000171 else {
172 buf[index] |= (255 << rshift);
173 if(row >= halfway) buf[index] |= (255 << gshift);
DRCf7f3ea42011-03-01 20:03:32 +0000174 }
175 }
176 }
177 }
DRC84a1bcc2011-02-23 12:09:56 +0000178
DRCf7f3ea42011-03-01 20:03:32 +0000179 private static void initImg(BufferedImage img, int pf, int flags)
180 throws Exception {
181 WritableRaster wr = img.getRaster();
182 int imgtype = img.getType();
183 if(imgtype == BufferedImage.TYPE_INT_RGB
184 || imgtype == BufferedImage.TYPE_INT_BGR) {
185 SinglePixelPackedSampleModel sm =
186 (SinglePixelPackedSampleModel)img.getSampleModel();
187 int pitch = sm.getScanlineStride();
188 DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
189 int[] buf = db.getData();
190 initIntBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, flags);
191 }
192 else {
193 ComponentSampleModel sm = (ComponentSampleModel)img.getSampleModel();
194 int pitch = sm.getScanlineStride();
195 DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
196 byte[] buf = db.getData();
197 initBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, flags);
198 }
199 }
DRC3bad53f2011-02-23 02:20:49 +0000200
DRCf962fbb2011-05-23 05:49:08 +0000201 private static void checkVal(int row, int col, int v, String vname, int cv)
DRCf7f3ea42011-03-01 20:03:32 +0000202 throws Exception {
203 v = (v < 0) ? v + 256 : v;
204 if(v < cv - 1 || v > cv + 1) {
DRCf962fbb2011-05-23 05:49:08 +0000205 throw new Exception("\nComp. " + vname + " at " + row + "," + col
DRCf7f3ea42011-03-01 20:03:32 +0000206 + " should be " + cv + ", not " + v + "\n");
207 }
208 }
DRC3bad53f2011-02-23 02:20:49 +0000209
DRCf962fbb2011-05-23 05:49:08 +0000210 private static void checkVal0(int row, int col, int v, String vname)
DRCf7f3ea42011-03-01 20:03:32 +0000211 throws Exception {
212 v = (v < 0) ? v + 256 : v;
213 if(v > 1) {
DRCf962fbb2011-05-23 05:49:08 +0000214 throw new Exception("\nComp. " + vname + " at " + row + "," + col
DRCf7f3ea42011-03-01 20:03:32 +0000215 + " should be 0, not " + v + "\n");
216 }
217 }
DRC3bad53f2011-02-23 02:20:49 +0000218
DRCf962fbb2011-05-23 05:49:08 +0000219 private static void checkVal255(int row, int col, int v, String vname)
DRCf7f3ea42011-03-01 20:03:32 +0000220 throws Exception {
221 v = (v < 0) ? v + 256 : v;
222 if(v < 254) {
DRCf962fbb2011-05-23 05:49:08 +0000223 throw new Exception("\nComp. " + vname + " at " + row + "," + col
DRCf7f3ea42011-03-01 20:03:32 +0000224 + " should be 255, not " + v + "\n");
225 }
226 }
DRC3bad53f2011-02-23 02:20:49 +0000227
DRCf7f3ea42011-03-01 20:03:32 +0000228 private static int checkBuf(byte[] buf, int w, int pitch, int h, int pf,
DRCb2f94152011-04-02 02:09:03 +0000229 int subsamp, TJScalingFactor sf, int flags) throws Exception {
DRC2c74e512011-03-16 00:02:53 +0000230 int roffset = TJ.getRedOffset(pf);
231 int goffset = TJ.getGreenOffset(pf);
232 int boffset = TJ.getBlueOffset(pf);
DRCf7f3ea42011-03-01 20:03:32 +0000233 int ps = TJ.getPixelSize(pf);
DRCf962fbb2011-05-23 05:49:08 +0000234 int index, row, col, retval = 1;
DRCb2f94152011-04-02 02:09:03 +0000235 int halfway = 16 * sf.getNum() / sf.getDenom();
236 int blockSize = 8 * sf.getNum() / sf.getDenom();
DRC3bad53f2011-02-23 02:20:49 +0000237
DRCf7f3ea42011-03-01 20:03:32 +0000238 try {
DRCf962fbb2011-05-23 05:49:08 +0000239 for(row = 0; row < halfway; row++) {
240 for(col = 0; col < w; col++) {
241 if((flags & TJ.FLAG_BOTTOMUP) != 0)
242 index = pitch * (h - row - 1) + col * ps;
243 else index = pitch * row + col * ps;
244 byte r = buf[index + roffset];
245 byte g = buf[index + goffset];
246 byte b = buf[index + boffset];
247 if(((row / blockSize) + (col / blockSize)) % 2 == 0) {
248 if(row < halfway) {
249 checkVal255(row, col, r, "R");
250 checkVal255(row, col, g, "G");
251 checkVal255(row, col, b, "B");
252 }
253 else {
254 checkVal0(row, col, r, "R");
255 checkVal0(row, col, g, "G");
256 checkVal0(row, col, b, "B");
257 }
DRCf7f3ea42011-03-01 20:03:32 +0000258 }
259 else {
260 if(subsamp == TJ.SAMP_GRAY) {
DRCf962fbb2011-05-23 05:49:08 +0000261 if(row < halfway) {
262 checkVal(row, col, r, "R", 76);
263 checkVal(row, col, g, "G", 76);
264 checkVal(row, col, b, "B", 76);
265 }
266 else {
267 checkVal(row, col, r, "R", 226);
268 checkVal(row, col, g, "G", 226);
269 checkVal(row, col, b, "B", 226);
270 }
DRCf7f3ea42011-03-01 20:03:32 +0000271 }
272 else {
DRCf962fbb2011-05-23 05:49:08 +0000273 checkVal255(row, col, r, "R");
274 if(row < halfway) {
275 checkVal0(row, col, g, "G");
276 }
277 else {
278 checkVal255(row, col, g, "G");
279 }
280 checkVal0(row, col, b, "B");
DRCf7f3ea42011-03-01 20:03:32 +0000281 }
282 }
283 }
284 }
285 }
286 catch(Exception e) {
287 System.out.println(e);
288 retval = 0;
289 }
DRC4f1580c2011-02-25 06:11:03 +0000290
DRCf7f3ea42011-03-01 20:03:32 +0000291 if(retval == 0) {
292 System.out.print("\n");
DRCf962fbb2011-05-23 05:49:08 +0000293 for(row = 0; row < h; row++) {
294 for(col = 0; col < w; col++) {
295 int r = buf[pitch * row + col * ps + roffset];
296 int g = buf[pitch * row + col * ps + goffset];
297 int b = buf[pitch * row + col * ps + boffset];
DRCf7f3ea42011-03-01 20:03:32 +0000298 if(r < 0) r += 256; if(g < 0) g += 256; if(b < 0) b += 256;
299 System.out.format("%3d/%3d/%3d ", r, g, b);
300 }
301 System.out.print("\n");
302 }
303 }
304 return retval;
305 }
DRC4f1580c2011-02-25 06:11:03 +0000306
DRCf7f3ea42011-03-01 20:03:32 +0000307 private static int checkIntBuf(int[] buf, int w, int pitch, int h, int pf,
DRCb2f94152011-04-02 02:09:03 +0000308 int subsamp, TJScalingFactor sf, int flags) throws Exception {
DRC2c74e512011-03-16 00:02:53 +0000309 int rshift = TJ.getRedOffset(pf) * 8;
310 int gshift = TJ.getGreenOffset(pf) * 8;
311 int bshift = TJ.getBlueOffset(pf) * 8;
DRCf962fbb2011-05-23 05:49:08 +0000312 int index, row, col, retval = 1;
DRCb2f94152011-04-02 02:09:03 +0000313 int halfway = 16 * sf.getNum() / sf.getDenom();
314 int blockSize = 8 * sf.getNum() / sf.getDenom();
DRC4f1580c2011-02-25 06:11:03 +0000315
DRCf7f3ea42011-03-01 20:03:32 +0000316 try {
DRCf962fbb2011-05-23 05:49:08 +0000317 for(row = 0; row < halfway; row++) {
318 for(col = 0; col < w; col++) {
319 if((flags & TJ.FLAG_BOTTOMUP) != 0)
320 index = pitch * (h - row - 1) + col;
321 else index = pitch * row + col;
322 int r = (buf[index] >> rshift) & 0xFF;
323 int g = (buf[index] >> gshift) & 0xFF;
324 int b = (buf[index] >> bshift) & 0xFF;
325 if(((row / blockSize) + (col / blockSize)) % 2 == 0) {
326 if(row < halfway) {
327 checkVal255(row, col, r, "R");
328 checkVal255(row, col, g, "G");
329 checkVal255(row, col, b, "B");
330 }
331 else {
332 checkVal0(row, col, r, "R");
333 checkVal0(row, col, g, "G");
334 checkVal0(row, col, b, "B");
335 }
DRCf7f3ea42011-03-01 20:03:32 +0000336 }
337 else {
338 if(subsamp == TJ.SAMP_GRAY) {
DRCf962fbb2011-05-23 05:49:08 +0000339 if(row < halfway) {
340 checkVal(row, col, r, "R", 76);
341 checkVal(row, col, g, "G", 76);
342 checkVal(row, col, b, "B", 76);
343 }
344 else {
345 checkVal(row, col, r, "R", 226);
346 checkVal(row, col, g, "G", 226);
347 checkVal(row, col, b, "B", 226);
348 }
DRCf7f3ea42011-03-01 20:03:32 +0000349 }
350 else {
DRCf962fbb2011-05-23 05:49:08 +0000351 checkVal255(row, col, r, "R");
352 if(row < halfway) {
353 checkVal0(row, col, g, "G");
354 }
355 else {
356 checkVal255(row, col, g, "G");
357 }
358 checkVal0(row, col, b, "B");
DRCf7f3ea42011-03-01 20:03:32 +0000359 }
360 }
361 }
362 }
363 }
364 catch(Exception e) {
365 System.out.println(e);
366 retval = 0;
367 }
DRC4f1580c2011-02-25 06:11:03 +0000368
DRCf7f3ea42011-03-01 20:03:32 +0000369 if(retval == 0) {
370 System.out.print("\n");
DRCf962fbb2011-05-23 05:49:08 +0000371 for(row = 0; row < h; row++) {
372 for(col = 0; col < w; col++) {
373 int r = (buf[pitch * row + col] >> rshift) & 0xFF;
374 int g = (buf[pitch * row + col] >> gshift) & 0xFF;
375 int b = (buf[pitch * row + col] >> bshift) & 0xFF;
DRCf7f3ea42011-03-01 20:03:32 +0000376 if(r < 0) r += 256; if(g < 0) g += 256; if(b < 0) b += 256;
377 System.out.format("%3d/%3d/%3d ", r, g, b);
378 }
379 System.out.print("\n");
380 }
381 }
382 return retval;
383 }
DRC3bad53f2011-02-23 02:20:49 +0000384
DRCf7f3ea42011-03-01 20:03:32 +0000385 private static int checkImg(BufferedImage img, int pf,
DRCb2f94152011-04-02 02:09:03 +0000386 int subsamp, TJScalingFactor sf, int flags) throws Exception {
DRCf7f3ea42011-03-01 20:03:32 +0000387 WritableRaster wr = img.getRaster();
388 int imgtype = img.getType();
389 if(imgtype == BufferedImage.TYPE_INT_RGB
390 || imgtype == BufferedImage.TYPE_INT_BGR) {
391 SinglePixelPackedSampleModel sm =
392 (SinglePixelPackedSampleModel)img.getSampleModel();
393 int pitch = sm.getScanlineStride();
394 DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
395 int[] buf = db.getData();
396 return checkIntBuf(buf, img.getWidth(), pitch, img.getHeight(), pf,
DRCb2f94152011-04-02 02:09:03 +0000397 subsamp, sf, flags);
DRCf7f3ea42011-03-01 20:03:32 +0000398 }
399 else {
400 ComponentSampleModel sm = (ComponentSampleModel)img.getSampleModel();
401 int pitch = sm.getScanlineStride();
402 DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
403 byte[] buf = db.getData();
404 return checkBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, subsamp,
DRCb2f94152011-04-02 02:09:03 +0000405 sf, flags);
DRCf7f3ea42011-03-01 20:03:32 +0000406 }
407 }
DRC84a1bcc2011-02-23 12:09:56 +0000408
DRCf7f3ea42011-03-01 20:03:32 +0000409 private static int PAD(int v, int p) {
410 return ((v + (p) - 1) & (~((p) - 1)));
411 }
DRC3bad53f2011-02-23 02:20:49 +0000412
DRCf7f3ea42011-03-01 20:03:32 +0000413 private static int checkBufYUV(byte[] buf, int size, int w, int h,
DRCd0a81362011-03-04 13:04:24 +0000414 int subsamp) throws Exception {
DRC215aa8b2011-05-27 02:10:42 +0000415 int row, col;
DRCd0a81362011-03-04 13:04:24 +0000416 int hsf = TJ.getMCUWidth(subsamp)/8, vsf = TJ.getMCUHeight(subsamp)/8;
DRCf7f3ea42011-03-01 20:03:32 +0000417 int pw = PAD(w, hsf), ph = PAD(h, vsf);
418 int cw = pw / hsf, ch = ph / vsf;
419 int ypitch = PAD(pw, 4), uvpitch = PAD(cw, 4);
420 int retval = 1;
421 int correctsize = ypitch * ph
422 + (subsamp == TJ.SAMP_GRAY ? 0 : uvpitch * ch * 2);
DRC215aa8b2011-05-27 02:10:42 +0000423 int halfway = 16;
DRC3bad53f2011-02-23 02:20:49 +0000424
DRCf7f3ea42011-03-01 20:03:32 +0000425 try {
426 if(size != correctsize)
427 throw new Exception("\nIncorrect size " + size + ". Should be "
428 + correctsize);
DRC3bad53f2011-02-23 02:20:49 +0000429
DRC215aa8b2011-05-27 02:10:42 +0000430 for(row = 0; row < ph; row++) {
431 for(col = 0; col < pw; col++) {
432 byte y = buf[ypitch * row + col];
433 if(((row / 8) + (col / 8)) % 2 == 0) {
434 if(row < halfway) checkVal255(row, col, y, "Y");
435 else checkVal0(row, col, y, "Y");
436 }
437 else {
438 if(row < halfway) checkVal(row, col, y, "Y", 76);
439 else checkVal(row, col, y, "Y", 226);
440 }
DRCf7f3ea42011-03-01 20:03:32 +0000441 }
442 }
443 if(subsamp != TJ.SAMP_GRAY) {
DRC215aa8b2011-05-27 02:10:42 +0000444 halfway = 16 / vsf;
445 for(row = 0; row < ch; row++) {
446 for(col = 0; col < cw; col++) {
447 byte u = buf[ypitch * ph + (uvpitch * row + col)],
448 v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)];
449 if(((row * vsf / 8) + (col * hsf / 8)) % 2 == 0) {
450 checkVal(row, col, u, "U", 128);
451 checkVal(row, col, v, "V", 128);
DRCf7f3ea42011-03-01 20:03:32 +0000452 }
453 else {
DRC215aa8b2011-05-27 02:10:42 +0000454 if(row < halfway) {
455 checkVal(row, col, u, "U", 85);
456 checkVal255(row, col, v, "V");
457 }
458 else {
459 checkVal0(row, col, u, "U");
460 checkVal(row, col, v, "V", 149);
461 }
DRCf7f3ea42011-03-01 20:03:32 +0000462 }
463 }
464 }
465 }
466 }
467 catch(Exception e) {
468 System.out.println(e);
469 retval = 0;
470 }
DRC3bad53f2011-02-23 02:20:49 +0000471
DRCf7f3ea42011-03-01 20:03:32 +0000472 if(retval == 0) {
DRC215aa8b2011-05-27 02:10:42 +0000473 for(row = 0; row < ph; row++) {
474 for(col = 0; col < pw; col++) {
475 int y = buf[ypitch * row + col];
DRCf7f3ea42011-03-01 20:03:32 +0000476 if(y < 0) y += 256;
477 System.out.format("%3d ", y);
478 }
479 System.out.print("\n");
480 }
481 System.out.print("\n");
DRC215aa8b2011-05-27 02:10:42 +0000482 for(row = 0; row < ch; row++) {
483 for(col = 0; col < cw; col++) {
484 int u = buf[ypitch * ph + (uvpitch * row + col)];
DRCf7f3ea42011-03-01 20:03:32 +0000485 if(u < 0) u += 256;
486 System.out.format("%3d ", u);
487 }
488 System.out.print("\n");
489 }
490 System.out.print("\n");
DRC215aa8b2011-05-27 02:10:42 +0000491 for(row = 0; row < ch; row++) {
492 for(col = 0; col < cw; col++) {
493 int v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)];
DRCf7f3ea42011-03-01 20:03:32 +0000494 if(v < 0) v += 256;
495 System.out.format("%3d ", v);
496 }
497 System.out.print("\n");
498 }
499 System.out.print("\n");
500 }
DRC3bad53f2011-02-23 02:20:49 +0000501
DRCf7f3ea42011-03-01 20:03:32 +0000502 return retval;
503 }
DRC3bad53f2011-02-23 02:20:49 +0000504
DRCf7f3ea42011-03-01 20:03:32 +0000505 private static void writeJPEG(byte[] jpegBuf, int jpegBufSize,
506 String filename) throws Exception {
507 File file = new File(filename);
508 FileOutputStream fos = new FileOutputStream(file);
509 fos.write(jpegBuf, 0, jpegBufSize);
510 fos.close();
511 }
DRC3bad53f2011-02-23 02:20:49 +0000512
DRCf962fbb2011-05-23 05:49:08 +0000513 private static int compTest(TJCompressor tjc, byte[] dstBuf, int w,
514 int h, int pf, String baseName, int subsamp, int jpegQual,
DRCf7f3ea42011-03-01 20:03:32 +0000515 int flags) throws Exception {
516 String tempstr;
DRCf962fbb2011-05-23 05:49:08 +0000517 byte[] srcBuf = null;
DRCf7f3ea42011-03-01 20:03:32 +0000518 BufferedImage img = null;
519 String pfStr;
520 double t;
521 int size = 0, ps = TJ.getPixelSize(pf);
DRC3bad53f2011-02-23 02:20:49 +0000522
DRCf7f3ea42011-03-01 20:03:32 +0000523 pfStr = pixFormatStr[pf];
DRC3bad53f2011-02-23 02:20:49 +0000524
DRCf7f3ea42011-03-01 20:03:32 +0000525 System.out.print(pfStr + " ");
DRC92549de2011-03-15 20:52:02 +0000526 if((flags & TJ.FLAG_BOTTOMUP) != 0) System.out.print("Bottom-Up");
DRCf7f3ea42011-03-01 20:03:32 +0000527 else System.out.print("Top-Down ");
528 System.out.print(" -> " + subNameLong[subsamp] + " ");
529 if(yuv == YUVENCODE) System.out.print("YUV ... ");
DRCf962fbb2011-05-23 05:49:08 +0000530 else System.out.print("Q" + jpegQual + " ... ");
DRC3bad53f2011-02-23 02:20:49 +0000531
DRCf7f3ea42011-03-01 20:03:32 +0000532 if(bi) {
533 img = new BufferedImage(w, h, biType[pf]);
534 initImg(img, pf, flags);
DRCf962fbb2011-05-23 05:49:08 +0000535 tempstr = baseName + "_enc_" + pfStr + "_"
DRC92549de2011-03-15 20:52:02 +0000536 + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_"
DRCf962fbb2011-05-23 05:49:08 +0000537 + subName[subsamp] + "_Q" + jpegQual + ".png";
DRCf7f3ea42011-03-01 20:03:32 +0000538 File file = new File(tempstr);
539 ImageIO.write(img, "png", file);
540 }
541 else {
DRCf962fbb2011-05-23 05:49:08 +0000542 srcBuf = new byte[w * h * ps + 1];
543 initBuf(srcBuf, w, w * ps, h, pf, flags);
DRCf7f3ea42011-03-01 20:03:32 +0000544 }
DRCf962fbb2011-05-23 05:49:08 +0000545 Arrays.fill(dstBuf, (byte)0);
DRC3bad53f2011-02-23 02:20:49 +0000546
DRCf7f3ea42011-03-01 20:03:32 +0000547 t = getTime();
548 tjc.setSubsamp(subsamp);
DRCf962fbb2011-05-23 05:49:08 +0000549 tjc.setJPEGQuality(jpegQual);
DRCf7f3ea42011-03-01 20:03:32 +0000550 if(bi) {
DRCf962fbb2011-05-23 05:49:08 +0000551 if(yuv == YUVENCODE) tjc.encodeYUV(img, dstBuf, flags);
552 else tjc.compress(img, dstBuf, flags);
DRCf7f3ea42011-03-01 20:03:32 +0000553 }
554 else {
DRCf962fbb2011-05-23 05:49:08 +0000555 tjc.setSourceImage(srcBuf, w, 0, h, pf);
556 if(yuv == YUVENCODE) tjc.encodeYUV(dstBuf, flags);
557 else tjc.compress(dstBuf, flags);
DRCf7f3ea42011-03-01 20:03:32 +0000558 }
559 size = tjc.getCompressedSize();
560 t = getTime() - t;
DRC3bad53f2011-02-23 02:20:49 +0000561
DRCf7f3ea42011-03-01 20:03:32 +0000562 if(yuv == YUVENCODE)
DRCf962fbb2011-05-23 05:49:08 +0000563 tempstr = baseName + "_enc_" + pfStr + "_"
DRC92549de2011-03-15 20:52:02 +0000564 + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_"
DRCf7f3ea42011-03-01 20:03:32 +0000565 + subName[subsamp] + ".yuv";
566 else
DRCf962fbb2011-05-23 05:49:08 +0000567 tempstr = baseName + "_enc_" + pfStr + "_"
DRC92549de2011-03-15 20:52:02 +0000568 + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_"
DRCf962fbb2011-05-23 05:49:08 +0000569 + subName[subsamp] + "_Q" + jpegQual + ".jpg";
570 writeJPEG(dstBuf, size, tempstr);
DRC84a1bcc2011-02-23 12:09:56 +0000571
DRCf7f3ea42011-03-01 20:03:32 +0000572 if(yuv == YUVENCODE) {
DRCf962fbb2011-05-23 05:49:08 +0000573 if(checkBufYUV(dstBuf, size, w, h, subsamp) == 1)
DRCf7f3ea42011-03-01 20:03:32 +0000574 System.out.print("Passed.");
575 else {
576 System.out.print("FAILED!"); exitStatus = -1;
577 }
578 }
579 else System.out.print("Done.");
580 System.out.format(" %.6f ms\n", t * 1000.);
581 System.out.println(" Result in " + tempstr);
DRC3bad53f2011-02-23 02:20:49 +0000582
DRCf7f3ea42011-03-01 20:03:32 +0000583 return size;
584 }
DRC3bad53f2011-02-23 02:20:49 +0000585
DRCf962fbb2011-05-23 05:49:08 +0000586 private static void decompTest(TJDecompressor tjd, byte[] jpegBuf,
587 int jpegSize, int w, int h, int pf, String baseName, int subsamp,
DRCb2f94152011-04-02 02:09:03 +0000588 int flags, TJScalingFactor sf) throws Exception {
DRCf7f3ea42011-03-01 20:03:32 +0000589 String pfStr, tempstr;
590 double t;
DRCb2f94152011-04-02 02:09:03 +0000591 int scaledWidth = sf.getScaled(w);
592 int scaledHeight = sf.getScaled(h);
DRCf7f3ea42011-03-01 20:03:32 +0000593 int temp1, temp2;
594 BufferedImage img = null;
DRCf962fbb2011-05-23 05:49:08 +0000595 byte[] dstBuf = null;
DRC3bad53f2011-02-23 02:20:49 +0000596
DRCf7f3ea42011-03-01 20:03:32 +0000597 if(yuv == YUVENCODE) return;
DRC3bad53f2011-02-23 02:20:49 +0000598
DRCf7f3ea42011-03-01 20:03:32 +0000599 pfStr = pixFormatStr[pf];
600 System.out.print("JPEG -> ");
601 if(yuv == YUVDECODE)
602 System.out.print("YUV " + subName[subsamp] + " ... ");
603 else {
604 System.out.print(pfStr + " ");
DRC92549de2011-03-15 20:52:02 +0000605 if((flags & TJ.FLAG_BOTTOMUP) != 0) System.out.print("Bottom-Up ");
DRCf7f3ea42011-03-01 20:03:32 +0000606 else System.out.print("Top-Down ");
DRCb2f94152011-04-02 02:09:03 +0000607 if(!sf.isOne())
608 System.out.print(sf.getNum() + "/" + sf.getDenom() + " ... ");
DRCf7f3ea42011-03-01 20:03:32 +0000609 else System.out.print("... ");
610 }
DRC3bad53f2011-02-23 02:20:49 +0000611
DRCf7f3ea42011-03-01 20:03:32 +0000612 t = getTime();
DRCf962fbb2011-05-23 05:49:08 +0000613 tjd.setJPEGImage(jpegBuf, jpegSize);
DRCf7f3ea42011-03-01 20:03:32 +0000614 if(tjd.getWidth() != w || tjd.getHeight() != h
615 || tjd.getSubsamp() != subsamp)
616 throw new Exception("Incorrect JPEG header");
DRC3bad53f2011-02-23 02:20:49 +0000617
DRCf7f3ea42011-03-01 20:03:32 +0000618 temp1 = scaledWidth;
619 temp2 = scaledHeight;
620 temp1 = tjd.getScaledWidth(temp1, temp2);
621 temp2 = tjd.getScaledHeight(temp1, temp2);
622 if(temp1 != scaledWidth || temp2 != scaledHeight)
623 throw new Exception("Scaled size mismatch");
DRC3bad53f2011-02-23 02:20:49 +0000624
DRCf962fbb2011-05-23 05:49:08 +0000625 if(yuv == YUVDECODE) dstBuf = tjd.decompressToYUV(flags);
DRCf7f3ea42011-03-01 20:03:32 +0000626 else {
627 if(bi)
628 img = tjd.decompress(scaledWidth, scaledHeight, biType[pf], flags);
DRCf962fbb2011-05-23 05:49:08 +0000629 else dstBuf = tjd.decompress(scaledWidth, 0, scaledHeight, pf, flags);
DRCf7f3ea42011-03-01 20:03:32 +0000630 }
631 t = getTime() - t;
DRC3bad53f2011-02-23 02:20:49 +0000632
DRCf7f3ea42011-03-01 20:03:32 +0000633 if(bi) {
DRCf962fbb2011-05-23 05:49:08 +0000634 tempstr = baseName + "_dec_" + pfStr + "_"
DRC92549de2011-03-15 20:52:02 +0000635 + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_"
DRCb2f94152011-04-02 02:09:03 +0000636 + subName[subsamp] + "_" + (double)sf.getNum() / (double)sf.getDenom()
DRCf7f3ea42011-03-01 20:03:32 +0000637 + "x" + ".png";
638 File file = new File(tempstr);
639 ImageIO.write(img, "png", file);
640 }
DRC84a1bcc2011-02-23 12:09:56 +0000641
DRCf7f3ea42011-03-01 20:03:32 +0000642 if(yuv == YUVDECODE) {
DRCf962fbb2011-05-23 05:49:08 +0000643 if(checkBufYUV(dstBuf, dstBuf.length, w, h, subsamp) == 1)
DRCf7f3ea42011-03-01 20:03:32 +0000644 System.out.print("Passed.");
645 else {
646 System.out.print("FAILED!"); exitStatus = -1;
647 }
648 }
649 else {
DRCb2f94152011-04-02 02:09:03 +0000650 if((bi && checkImg(img, pf, subsamp, sf, flags) == 1)
DRCf962fbb2011-05-23 05:49:08 +0000651 || (!bi && checkBuf(dstBuf, scaledWidth, scaledWidth
DRCb2f94152011-04-02 02:09:03 +0000652 * TJ.getPixelSize(pf), scaledHeight, pf, subsamp, sf, flags) == 1))
DRCf7f3ea42011-03-01 20:03:32 +0000653 System.out.print("Passed.");
654 else {
655 System.out.print("FAILED!"); exitStatus = -1;
656 }
657 }
658 System.out.format(" %.6f ms\n", t * 1000.);
659 }
DRC3bad53f2011-02-23 02:20:49 +0000660
DRCf962fbb2011-05-23 05:49:08 +0000661 private static void decompTest(TJDecompressor tjd, byte[] jpegBuf,
662 int jpegSize, int w, int h, int pf, String baseName, int subsamp,
DRCf7f3ea42011-03-01 20:03:32 +0000663 int flags) throws Exception {
664 int i;
665 if((subsamp == TJ.SAMP_444 || subsamp == TJ.SAMP_GRAY) && yuv == 0) {
DRCb2f94152011-04-02 02:09:03 +0000666 TJScalingFactor sf[] = TJ.getScalingFactors();
DRCf7f3ea42011-03-01 20:03:32 +0000667 for(i = 0; i < sf.length; i++)
DRCf962fbb2011-05-23 05:49:08 +0000668 decompTest(tjd, jpegBuf, jpegSize, w, h, pf, baseName, subsamp,
DRCb2f94152011-04-02 02:09:03 +0000669 flags, sf[i]);
DRCf7f3ea42011-03-01 20:03:32 +0000670 }
671 else
DRCf962fbb2011-05-23 05:49:08 +0000672 decompTest(tjd, jpegBuf, jpegSize, w, h, pf, baseName, subsamp,
DRCb2f94152011-04-02 02:09:03 +0000673 flags, new TJScalingFactor(1, 1));
DRCf7f3ea42011-03-01 20:03:32 +0000674 System.out.print("\n");
675 }
DRC3bad53f2011-02-23 02:20:49 +0000676
DRCf7f3ea42011-03-01 20:03:32 +0000677 private static void doTest(int w, int h, int[] formats, int subsamp,
DRCf962fbb2011-05-23 05:49:08 +0000678 String baseName) throws Exception {
DRCf7f3ea42011-03-01 20:03:32 +0000679 TJCompressor tjc = null;
680 TJDecompressor tjd = null;
DRC4f8c2952011-03-31 10:06:17 +0000681 int size;
DRCf962fbb2011-05-23 05:49:08 +0000682 byte[] dstBuf;
DRC3bad53f2011-02-23 02:20:49 +0000683
DRCf962fbb2011-05-23 05:49:08 +0000684 if(yuv == YUVENCODE) dstBuf = new byte[TJ.bufSizeYUV(w, h, subsamp)];
DRC9b49f0e2011-07-12 03:17:23 +0000685 else dstBuf = new byte[TJ.bufSize(w, h, subsamp)];
DRC3bad53f2011-02-23 02:20:49 +0000686
DRCf7f3ea42011-03-01 20:03:32 +0000687 try {
688 tjc = new TJCompressor();
689 tjd = new TJDecompressor();
DRC3bad53f2011-02-23 02:20:49 +0000690
DRCf7f3ea42011-03-01 20:03:32 +0000691 for(int pf : formats) {
692 for(int i = 0; i < 2; i++) {
693 int flags = 0;
694 if(i == 1) {
695 if(yuv == YUVDECODE) {
696 tjc.close(); tjd.close(); return;
697 }
DRC92549de2011-03-15 20:52:02 +0000698 else flags |= TJ.FLAG_BOTTOMUP;
DRCf7f3ea42011-03-01 20:03:32 +0000699 }
DRCf962fbb2011-05-23 05:49:08 +0000700 size = compTest(tjc, dstBuf, w, h, pf, baseName, subsamp, 100,
DRCf7f3ea42011-03-01 20:03:32 +0000701 flags);
DRCf962fbb2011-05-23 05:49:08 +0000702 decompTest(tjd, dstBuf, size, w, h, pf, baseName, subsamp, flags);
DRCf7f3ea42011-03-01 20:03:32 +0000703 }
704 }
705 }
706 catch(Exception e) {
707 if(tjc != null) tjc.close();
708 if(tjd != null) tjd.close();
709 throw e;
710 }
711 if(tjc != null) tjc.close();
712 if(tjd != null) tjd.close();
713 }
DRC3bad53f2011-02-23 02:20:49 +0000714
DRCf7f3ea42011-03-01 20:03:32 +0000715 private static void doTest1() throws Exception {
DRCf962fbb2011-05-23 05:49:08 +0000716 int w, h, i;
717 byte[] srcBuf, jpegBuf;
DRCf7f3ea42011-03-01 20:03:32 +0000718 TJCompressor tjc = null;
DRC3bad53f2011-02-23 02:20:49 +0000719
DRCf7f3ea42011-03-01 20:03:32 +0000720 try {
721 tjc = new TJCompressor();
722 System.out.println("Buffer size regression test");
DRCf962fbb2011-05-23 05:49:08 +0000723 for(w = 1; w < 48; w++) {
724 int maxh = (w == 1) ? 2048 : 48;
725 for(h = 1; h < maxh; h++) {
726 if(h % 100 == 0)
727 System.out.format("%04d x %04d\b\b\b\b\b\b\b\b\b\b\b", w, h);
728 srcBuf = new byte[w * h * 4];
DRC9b49f0e2011-07-12 03:17:23 +0000729 jpegBuf = new byte[TJ.bufSize(w, h, TJ.SAMP_444)];
DRCf962fbb2011-05-23 05:49:08 +0000730 Arrays.fill(srcBuf, (byte)0);
731 for(i = 0; i < w * h; i++) {
732 srcBuf[i * 4] = pixels[i % 9][0];
733 srcBuf[i * 4 + 1] = pixels[i % 9][1];
734 srcBuf[i * 4 + 2] = pixels[i % 9][2];
DRCf7f3ea42011-03-01 20:03:32 +0000735 }
DRCf962fbb2011-05-23 05:49:08 +0000736 tjc.setSourceImage(srcBuf, w, 0, h, TJ.PF_BGRX);
DRCf7f3ea42011-03-01 20:03:32 +0000737 tjc.setSubsamp(TJ.SAMP_444);
738 tjc.setJPEGQuality(100);
739 tjc.compress(jpegBuf, 0);
DRC3bad53f2011-02-23 02:20:49 +0000740
DRCf962fbb2011-05-23 05:49:08 +0000741 srcBuf = new byte[h * w * 4];
DRC9b49f0e2011-07-12 03:17:23 +0000742 jpegBuf = new byte[TJ.bufSize(h, w, TJ.SAMP_444)];
DRCf962fbb2011-05-23 05:49:08 +0000743 for(i = 0; i < h * w; i++) {
744 if(i % 2 == 0) srcBuf[i * 4] =
745 srcBuf[i * 4 + 1] = srcBuf[i * 4 + 2] = (byte)0xFF;
746 else srcBuf[i * 4] = srcBuf[i * 4 + 1] = srcBuf[i * 4 + 2] = 0;
DRCf7f3ea42011-03-01 20:03:32 +0000747 }
DRCf962fbb2011-05-23 05:49:08 +0000748 tjc.setSourceImage(srcBuf, h, 0, w, TJ.PF_BGRX);
DRCf7f3ea42011-03-01 20:03:32 +0000749 tjc.compress(jpegBuf, 0);
750 }
751 }
752 System.out.println("Done. ");
753 }
754 catch(Exception e) {
755 if(tjc != null) tjc.close();
756 throw e;
757 }
758 if(tjc != null) tjc.close();
759 }
DRC3bad53f2011-02-23 02:20:49 +0000760
DRCf7f3ea42011-03-01 20:03:32 +0000761 public static void main(String argv[]) {
762 try {
DRCb6ed7d32011-03-31 20:58:03 +0000763 String testName = "javatest";
DRCf7f3ea42011-03-01 20:03:32 +0000764 boolean doyuv = false;
765 for(int i = 0; i < argv.length; i++) {
766 if(argv[i].equalsIgnoreCase("-yuv")) doyuv = true;
767 if(argv[i].substring(0, 1).equalsIgnoreCase("-h")
768 || argv[i].equalsIgnoreCase("-?"))
769 usage();
DRCb6ed7d32011-03-31 20:58:03 +0000770 if(argv[i].equalsIgnoreCase("-bi")) {
771 bi = true;
772 testName = "javabitest";
773 }
DRCf7f3ea42011-03-01 20:03:32 +0000774 }
775 if(doyuv) yuv = YUVENCODE;
DRCb6ed7d32011-03-31 20:58:03 +0000776 doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_444, testName);
777 doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_444, testName);
DRCf7f3ea42011-03-01 20:03:32 +0000778 if(doyuv) {
779 doTest(41, 35, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_422,
DRCb6ed7d32011-03-31 20:58:03 +0000780 testName);
DRCf7f3ea42011-03-01 20:03:32 +0000781 doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_422,
DRCb6ed7d32011-03-31 20:58:03 +0000782 testName);
DRCf7f3ea42011-03-01 20:03:32 +0000783 doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_420,
DRCb6ed7d32011-03-31 20:58:03 +0000784 testName);
DRCf7f3ea42011-03-01 20:03:32 +0000785 doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_420,
DRCb6ed7d32011-03-31 20:58:03 +0000786 testName);
DRCd0a81362011-03-04 13:04:24 +0000787 doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_440,
DRCb6ed7d32011-03-31 20:58:03 +0000788 testName);
DRCd0a81362011-03-04 13:04:24 +0000789 doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_440,
DRCb6ed7d32011-03-31 20:58:03 +0000790 testName);
DRCf7f3ea42011-03-01 20:03:32 +0000791 }
DRCb6ed7d32011-03-31 20:58:03 +0000792 doTest(35, 39, onlyGray, TJ.SAMP_GRAY, testName);
DRCf7f3ea42011-03-01 20:03:32 +0000793 doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_GRAY,
DRCb6ed7d32011-03-31 20:58:03 +0000794 testName);
DRCf7f3ea42011-03-01 20:03:32 +0000795 doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_GRAY,
DRCb6ed7d32011-03-31 20:58:03 +0000796 testName);
DRCf7f3ea42011-03-01 20:03:32 +0000797 if(!doyuv && !bi) doTest1();
798 if(doyuv && !bi) {
799 yuv = YUVDECODE;
DRCb6ed7d32011-03-31 20:58:03 +0000800 doTest(48, 48, onlyRGB, TJ.SAMP_444, "javatest_yuv0");
801 doTest(35, 39, onlyRGB, TJ.SAMP_444, "javatest_yuv1");
802 doTest(48, 48, onlyRGB, TJ.SAMP_422, "javatest_yuv0");
803 doTest(39, 41, onlyRGB, TJ.SAMP_422, "javatest_yuv1");
804 doTest(48, 48, onlyRGB, TJ.SAMP_420, "javatest_yuv0");
805 doTest(41, 35, onlyRGB, TJ.SAMP_420, "javatest_yuv1");
806 doTest(48, 48, onlyRGB, TJ.SAMP_440, "javatest_yuv0");
807 doTest(35, 39, onlyRGB, TJ.SAMP_440, "javatest_yuv1");
808 doTest(48, 48, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv0");
809 doTest(35, 39, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv1");
810 doTest(48, 48, onlyGray, TJ.SAMP_GRAY, "javatest_yuv0");
811 doTest(39, 41, onlyGray, TJ.SAMP_GRAY, "javatest_yuv1");
DRCf7f3ea42011-03-01 20:03:32 +0000812 }
813 }
814 catch(Exception e) {
DRC2e2358e2011-03-04 09:54:59 +0000815 e.printStackTrace();
DRCf7f3ea42011-03-01 20:03:32 +0000816 exitStatus = -1;
817 }
818 System.exit(exitStatus);
819 }
DRC3bad53f2011-02-23 02:20:49 +0000820}