From d0a813632bc66e259aa457cb98ae2b5ff44a81a1 Mon Sep 17 00:00:00 2001 From: DRC Date: Fri, 4 Mar 2011 13:04:24 +0000 Subject: [PATCH] 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 --- java/TJUnitTest.java | 20 ++++++++++---------- java/org/libjpegturbo/turbojpeg/TJ.java | 25 +++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 12 deletions(-) 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 @@ public class TJUnitTest { } 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 @@ public class TJUnitTest { } 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 @@ public class TJUnitTest { "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 @@ public class TJUnitTest { 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 @@ final public class TJ { // 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 -- 2.40.0