Test fast upsampling
"4:1:1 = 4:2:0"


git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@43 632fc199-4ca6-4c93-a231-07263d6284db
diff --git a/jpegut.c b/jpegut.c
index 777cd3d..3b02fba 100644
--- a/jpegut.c
+++ b/jpegut.c
@@ -21,8 +21,8 @@
 
 #define _catch(f) {if((f)==-1) {printf("TJPEG: %s\n", tjGetErrorStr());  goto finally;}}
 
-const char *_subnamel[NUMSUBOPT]={"4:4:4", "4:2:2", "4:1:1", "GRAY"};
-const char *_subnames[NUMSUBOPT]={"444", "422", "411", "GRAY"};
+const char *_subnamel[NUMSUBOPT]={"4:4:4", "4:2:2", "4:2:0", "GRAY"};
+const char *_subnames[NUMSUBOPT]={"444", "422", "420", "GRAY"};
 
 int pixels[9][3]=
 {
diff --git a/jpgtest.cxx b/jpgtest.cxx
index d0baea5..d6c4cb3 100644
--- a/jpgtest.cxx
+++ b/jpgtest.cxx
@@ -23,7 +23,7 @@
 
 #define _catch(f) {if((f)==-1) {printf("Error in %s:\n%s\n", #f, tjGetErrorStr());  goto bailout;}}
 
-int forcemmx=0, forcesse=0, forcesse2=0, forcesse3=0;
+int forcemmx=0, forcesse=0, forcesse2=0, forcesse3=0, fastupsample=0;
 const int _ps[BMPPIXELFORMATS]={3, 4, 3, 4, 4, 4};
 const int _flags[BMPPIXELFORMATS]={0, 0, TJ_BGR, TJ_BGR,
 	TJ_BGR|TJ_ALPHAFIRST, TJ_ALPHAFIRST};
@@ -31,8 +31,8 @@
 const int _gindex[BMPPIXELFORMATS]={1, 1, 1, 1, 2, 2};
 const int _bindex[BMPPIXELFORMATS]={2, 2, 0, 0, 1, 3};
 const char *_pfname[]={"RGB", "RGBA", "BGR", "BGRA", "ABGR", "ARGB"};
-const char *_subnamel[NUMSUBOPT]={"4:4:4", "4:2:2", "4:1:1", "GRAY"};
-const char *_subnames[NUMSUBOPT]={"444", "422", "411", "GRAY"};
+const char *_subnamel[NUMSUBOPT]={"4:4:4", "4:2:2", "4:2:0", "GRAY"};
+const char *_subnames[NUMSUBOPT]={"444", "422", "420", "GRAY"};
 
 void printsigfig(double val, int figs)
 {
@@ -62,7 +62,8 @@
 	int jpgbufsize=0, i, j, tilesizex, tilesizey, numtilesx, numtilesy, ITER;
 	unsigned long *comptilesize=NULL;
 	int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0)
-		|(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0);
+		|(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0)
+		|(fastupsample?TJ_FASTUPSAMPLE:0);
 	int ps=_ps[pf];
 	int pitch=w*ps;
 
@@ -294,6 +295,9 @@
 		printf("       Force MMX, SSE, or SSE2 code paths in Intel codec\n\n");
 		printf("       [-rgb | -bgr | -rgba | -bgra | -abgr | -argb]\n");
 		printf("       Test the specified color conversion path in the codec (default: BGR)\n\n");
+		printf("       [-fastupsample]\n");
+		printf("       Use fast, inaccurate upsampling code to perform 4:2:2 and 4:2:0\n\n");
+		printf("       YUV decoding in libjpeg decompressor\n");
 		printf("       [-quiet]\n");
 		printf("       Output in tabular rather than verbose format\n\n");
 		printf("       NOTE: If the quality is specified as a range, i.e. 90-100, a separate\n");
@@ -335,6 +339,11 @@
 				printf("Using MMX code in Intel compressor\n");
 				forcemmx=1;
 			}
+			if(!stricmp(argv[i], "-fastupsample"))
+			{
+				printf("Using fast upsampling code\n");
+				fastupsample=1;
+			}
 			if(!stricmp(argv[i], "-rgb")) pf=BMP_RGB;
 			if(!stricmp(argv[i], "-rgba")) pf=BMP_RGBA;
 			if(!stricmp(argv[i], "-bgr")) pf=BMP_BGR;
@@ -369,7 +378,7 @@
 		dotest(bmpbuf, w, h, pf, bu, TJ_GRAYSCALE, i, argv[1], dotile, useppm, quiet);
 	if(quiet) printf("\n");
 	for(i=hiqual; i>=qual; i--)
-		dotest(bmpbuf, w, h, pf, bu, TJ_411, i, argv[1], dotile, useppm, quiet);
+		dotest(bmpbuf, w, h, pf, bu, TJ_420, i, argv[1], dotile, useppm, quiet);
 	if(quiet) printf("\n");
 	for(i=hiqual; i>=qual; i--)
 		dotest(bmpbuf, w, h, pf, bu, TJ_422, i, argv[1], dotile, useppm, quiet);
diff --git a/turbojpeg.h b/turbojpeg.h
index 90f1278..808e2f3 100644
--- a/turbojpeg.h
+++ b/turbojpeg.h
@@ -1,5 +1,6 @@
 /* Copyright (C)2004 Landmark Graphics Corporation
  * Copyright (C)2005, 2006 Sun Microsystems, Inc.
+ * Copyright (C)2009 D. R. Commander
  *
  * This library is free software and may be redistributed and/or modified under
  * the terms of the wxWindows Library License, Version 3.1 or (at your option)
@@ -23,7 +24,7 @@
 /* Subsampling */
 #define NUMSUBOPT 4
 
-enum {TJ_444=0, TJ_422, TJ_411, TJ_GRAYSCALE};
+enum {TJ_444=0, TJ_422, TJ_420, TJ_GRAYSCALE};
 
 /* Flags */
 #define TJ_BGR       1
@@ -33,6 +34,7 @@
 #define TJ_FORCESSE2 32  /* Force IPP to use SSE2 code (useful if auto-detect is not working properly) */
 #define TJ_ALPHAFIRST 64 /* BGR buffer is ABGR and RGB buffer is ARGB */
 #define TJ_FORCESSE3 128 /* Force IPP to use SSE3 code (useful if auto-detect is not working properly) */
+#define TJ_FASTUPSAMPLE 256 /* Use fast, inaccurate 4:2:2 and 4:2:0 YUV upsampling routines in libjpeg decompressor */
 
 typedef void* tjhandle;
 
@@ -86,14 +88,14 @@
      the appropriate size for this buffer based on the image width and height.
   [OUTPUT] size = pointer to unsigned long which receives the size (in bytes)
      of the compressed image
-  [INPUT] jpegsubsamp = Specifies either 4:1:1, 4:2:2, or 4:4:4 subsampling.
+  [INPUT] jpegsubsamp = Specifies either 4:2:0, 4:2:2, or 4:4:4 subsampling.
      When the image is converted from the RGB to YCbCr colorspace as part of the
      JPEG compression process, every other Cb and Cr (chrominance) pixel can be
      discarded to produce a smaller image with little perceptible loss of
      image clarity (the human eye is more sensitive to small changes in
      brightness than small changes in color.)
 
-     TJ_411: 4:1:1 subsampling.  Discards every other Cb, Cr pixel in both
+     TJ_420: 4:2:0 subsampling.  Discards every other Cb, Cr pixel in both
         horizontal and vertical directions.
      TJ_422: 4:2:2 subsampling.  Discards every other Cb, Cr pixel only in
         the horizontal direction.
diff --git a/turbojpegl.c b/turbojpegl.c
index 3f03aed..82acf23 100644
--- a/turbojpegl.c
+++ b/turbojpegl.c
@@ -1,5 +1,6 @@
 /* Copyright (C)2004 Landmark Graphics Corporation
  * Copyright (C)2005 Sun Microsystems, Inc.
+ * Copyright (C)2009 D. R. Commander
  *
  * This library is free software and may be redistributed and/or modified under
  * the terms of the wxWindows Library License, Version 3.1 or (at your option)
@@ -320,6 +321,7 @@
 	#else
 	#error "TurboJPEG requires JPEG colorspace extensions"
 	#endif
+	if(flags&TJ_FASTUPSAMPLE) j->dinfo.do_fancy_upsampling=FALSE;
 
 	jpeg_start_decompress(&j->dinfo);
 	while(j->dinfo.output_scanline<j->dinfo.output_height)