diff --git a/imageio/imageio-jpeg/src/main/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReader.java b/imageio/imageio-jpeg/src/main/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReader.java
index d56df77e..70ecac9b 100644
--- a/imageio/imageio-jpeg/src/main/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReader.java
+++ b/imageio/imageio-jpeg/src/main/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReader.java
@@ -66,6 +66,7 @@ import java.util.List;
*
* Main features:
*
+ * - Support for YCbCr JPEGs without JFIF segment (converted to RGB, using the embedded ICC profile if applicable)
* - Support for CMYK JPEGs (converted to RGB by default or as CMYK, using the embedded ICC profile if applicable)
* - Support for Adobe YCCK JPEGs (converted to RGB by default or as CMYK, using the embedded ICC profile if applicable)
* - Support for JPEGs containing ICC profiles with interpretation other than 'Perceptual' (profile is assumed to be 'Perceptual' and used)
@@ -298,26 +299,25 @@ public class JPEGImageReader extends ImageReaderBase {
// }
// }
- // NOTE: We rely on the fact that unsupported images has no valid types. This is kind of hacky.
- // Might want to look into the metadata, to see if there's a better way to identify these.
- boolean unsupported = !delegate.getImageTypes(imageIndex).hasNext();
-
ICC_Profile profile = getEmbeddedICCProfile(false);
AdobeDCTSegment adobeDCT = getAdobeDCT();
+ SOFSegment sof = getSOF();
+ JPEGColorSpace sourceCSType = getSourceCSType(adobeDCT, sof);
// We need to apply ICC profile unless the profile is sRGB/default gray (whatever that is)
// - or only filter out the bad ICC profiles in the JPEGSegmentImageInputStream.
if (delegate.canReadRaster() && (
- unsupported ||
+ sourceCSType == JPEGColorSpace.CMYK ||
+ sourceCSType == JPEGColorSpace.YCCK ||
adobeDCT != null && adobeDCT.getTransform() == AdobeDCTSegment.YCCK ||
- profile != null && !ColorSpaces.isCS_sRGB(profile))) {
-// profile != null && (ColorSpaces.isOffendingColorProfile(profile) || profile.getColorSpaceType() == ColorSpace.TYPE_CMYK))) {
+ profile != null && !ColorSpaces.isCS_sRGB(profile)) ||
+ sourceCSType == JPEGColorSpace.YCbCr && getRawImageType(imageIndex) != null) { // TODO: Issue warning?
if (DEBUG) {
System.out.println("Reading using raster and extra conversion");
System.out.println("ICC color profile: " + profile);
}
- return readImageAsRasterAndReplaceColorProfile(imageIndex, param, ensureDisplayProfile(profile));
+ return readImageAsRasterAndReplaceColorProfile(imageIndex, param, sof, sourceCSType, adobeDCT, ensureDisplayProfile(profile));
}
if (DEBUG) {
@@ -327,14 +327,10 @@ public class JPEGImageReader extends ImageReaderBase {
return delegate.read(imageIndex, param);
}
- private BufferedImage readImageAsRasterAndReplaceColorProfile(int imageIndex, ImageReadParam param, ICC_Profile profile) throws IOException {
+ private BufferedImage readImageAsRasterAndReplaceColorProfile(int imageIndex, ImageReadParam param, SOFSegment startOfFrame, JPEGColorSpace csType, AdobeDCTSegment adobeDCT, ICC_Profile profile) throws IOException {
int origWidth = getWidth(imageIndex);
int origHeight = getHeight(imageIndex);
- AdobeDCTSegment adobeDCT = getAdobeDCT();
- SOFSegment startOfFrame = getSOF();
- JPEGColorSpace csType = getSourceCSType(adobeDCT, startOfFrame);
-
Iterator imageTypes = getImageTypes(imageIndex);
BufferedImage image = getDestination(param, imageTypes, origWidth, origHeight);
WritableRaster destination = image.getRaster();
diff --git a/imageio/imageio-jpeg/src/test/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReaderTest.java b/imageio/imageio-jpeg/src/test/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReaderTest.java
index 37a34f73..0a811122 100644
--- a/imageio/imageio-jpeg/src/test/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReaderTest.java
+++ b/imageio/imageio-jpeg/src/test/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImageReaderTest.java
@@ -600,6 +600,38 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase> 16) & 0xff, (expectedRGB[i] >> 16) & 0xff, 5);
+ assertEquals((actualRGB >> 8) & 0xff, (expectedRGB[i] >> 8) & 0xff, 5);
+ assertEquals((actualRGB) & 0xff, (expectedRGB[i]) & 0xff, 5);
+ }
+ }
+
// TODO: Test RGBA/YCbCrA handling
@Test
diff --git a/imageio/imageio-jpeg/src/test/resources/jpeg/no-jfif-ycbcr.jpg b/imageio/imageio-jpeg/src/test/resources/jpeg/no-jfif-ycbcr.jpg
new file mode 100644
index 00000000..7e31ea76
Binary files /dev/null and b/imageio/imageio-jpeg/src/test/resources/jpeg/no-jfif-ycbcr.jpg differ