TurboJPEG: Implement 4:4:1 chrominance subsampling

This allows losslessly transposed or rotated 4:1:1 JPEG images to be
losslessly cropped, partially decompressed, or decompressed to planar
YUV images.

Because tj3Transform() allows multiple lossless transformations to be
chained together, all subsampling options need to have a corresponding
transposed subsampling option.  (This is why 4:4:0 was originally
implemented as well.)  Otherwise, the documentation would be technically
incorrect.  It says that images with unknown subsampling types cannot be
losslessly cropped, partially decompressed, or decompressed to planar
YUV images, but it doesn't say anything about images with known
subsampling types whose subsampling type becomes unknown if the image is
rotated or transposed.  This is one of those situations in which it is
easier to implement a feature that works around the problem than to
document the problem.

Closes #659
This commit is contained in:
DRC
2023-03-09 20:55:43 -06:00
parent 58a3427ffc
commit fc881ebb21
42 changed files with 335 additions and 229 deletions

View File

@@ -42,7 +42,7 @@ public final class TJ {
/**
* The number of chrominance subsampling options
*/
public static final int NUMSAMP = 6;
public static final int NUMSAMP = 7;
/**
* 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG
* or YUV image will contain one chrominance component for every pixel in the
@@ -80,6 +80,17 @@ public final class TJ {
* in libjpeg-turbo.
*/
public static final int SAMP_411 = 5;
/**
* 4:4:1 chrominance subsampling. The JPEG or YUV image will contain one
* chrominance component for every 1x4 block of pixels in the source image.
* JPEG images compressed with 4:4:1 subsampling will be almost exactly the
* same size as those compressed with 4:2:0 subsampling, and in the
* aggregate, both subsampling methods produce approximately the same
* perceptual quality. However, 4:4:1 is better able to reproduce sharp
* vertical features. Note that 4:4:1 subsampling is not fully accelerated
* in libjpeg-turbo.
*/
public static final int SAMP_441 = 6;
/**
* Unknown subsampling. The JPEG image uses an unusual type of chrominance
* subsampling. Such images can be decompressed into packed-pixel images,
@@ -109,7 +120,7 @@ public final class TJ {
}
private static final int[] MCU_WIDTH = {
8, 16, 16, 8, 8, 32
8, 16, 16, 8, 8, 32, 8
};
@@ -129,7 +140,7 @@ public final class TJ {
}
private static final int[] MCU_HEIGHT = {
8, 8, 16, 8, 16, 8
8, 8, 16, 8, 16, 8, 32
};