Handle 4:4:0 (transposed 4:2:2 subsampling)


git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@503 632fc199-4ca6-4c93-a231-07263d6284db
diff --git a/java/TJUnitTest.java b/java/TJUnitTest.java
index 0819d33..f09d861 100644
--- a/java/TJUnitTest.java
+++ b/java/TJUnitTest.java
@@ -50,16 +50,10 @@
   }
 
   private final static String subNameLong[] = {
-    "4:4:4", "4:2:2", "4:2:0", "GRAY"
+    "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0"
   };
   private final static String subName[] = {
-    "444", "422", "420", "GRAY"
-  };
-  private final static int horizSampFactor[] = {
-    1, 2, 2, 1
-  };
-  private final static int vertSampFactor[] = {
-    1, 1, 2, 1
+    "444", "422", "420", "GRAY", "440"
   };
 
   private final static String pixFormatStr[] = {
@@ -439,9 +433,9 @@
   }
 
   private static int checkBufYUV(byte[] buf, int size, int w, int h,
-    int subsamp) {
+    int subsamp) throws Exception {
     int i, j;
-    int hsf = horizSampFactor[subsamp], vsf = vertSampFactor[subsamp];
+    int hsf = TJ.getMCUWidth(subsamp)/8, vsf = TJ.getMCUHeight(subsamp)/8;
     int pw = PAD(w, hsf), ph = PAD(h, vsf);
     int cw = pw / hsf, ch = ph / vsf;
     int ypitch = PAD(pw, 4), uvpitch = PAD(cw, 4);
@@ -814,6 +808,10 @@
           "test");
         doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_420,
           "test");
+        doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_440,
+          "test");
+        doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_440,
+          "test");
       }
       doTest(35, 39, onlyGray, TJ.SAMP_GRAY, "test");
       doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_GRAY,
@@ -829,6 +827,8 @@
         doTest(39, 41, onlyRGB, TJ.SAMP_422, "test");
         doTest(48, 48, onlyRGB, TJ.SAMP_420, "test");
         doTest(41, 35, onlyRGB, TJ.SAMP_420, "test");
+        doTest(48, 48, onlyRGB, TJ.SAMP_440, "test");
+        doTest(35, 39, onlyRGB, TJ.SAMP_440, "test");
         doTest(48, 48, onlyRGB, TJ.SAMP_GRAY, "test");
         doTest(35, 39, onlyRGB, TJ.SAMP_GRAY, "test");
         doTest(48, 48, onlyGray, TJ.SAMP_GRAY, "test");
diff --git a/java/org/libjpegturbo/turbojpeg/TJ.java b/java/org/libjpegturbo/turbojpeg/TJ.java
index be8fe5e..fd8fb1c 100644
--- a/java/org/libjpegturbo/turbojpeg/TJ.java
+++ b/java/org/libjpegturbo/turbojpeg/TJ.java
@@ -37,11 +37,32 @@
 
   // Chrominance subsampling options
   final public static int
-    NUMSAMPOPT = 4,
+    NUMSAMPOPT = 5,
     SAMP_444   = 0,
     SAMP_422   = 1,
     SAMP_420   = 2,
-    SAMP_GRAY  = 3;
+    SAMP_GRAY  = 3,
+    SAMP_440   = 4;
+
+  final private static int mcuWidth[] = {
+    8, 16, 16, 8, 8
+  };
+
+  public static int getMCUWidth(int subsamp) throws Exception {
+    if(subsamp < 0 || subsamp >= NUMSAMPOPT)
+      throw new Exception("Invalid subsampling type");
+    return mcuWidth[subsamp];
+  }
+
+  final private static int mcuHeight[] = {
+    8, 8, 16, 8, 16
+  };
+
+  public static int getMCUHeight(int subsamp) throws Exception {
+    if(subsamp < 0 || subsamp >= NUMSAMPOPT)
+      throw new Exception("Invalid subsampling type");
+    return mcuHeight[subsamp];
+  }
 
   // Bitmap pixel formats
   final public static int