You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/05/09 07:44:29 UTC

[GitHub] [commons-imaging] kinow commented on a diff in pull request #163: IMAGING-310 JpegImageParser.getImageInfo() Refactor colorType logic to first look at numberOfComponents

kinow commented on code in PR #163:
URL: https://github.com/apache/commons-imaging/pull/163#discussion_r867723828


##########
src/main/java/org/apache/commons/imaging/formats/jpeg/JpegImageParser.java:
##########
@@ -824,44 +824,44 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Obj
 
         // See http://docs.oracle.com/javase/6/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html#color
         ImageInfo.ColorType colorType = ImageInfo.ColorType.UNKNOWN;
-        // Some images have both JFIF/APP0 and APP14.
-        // JFIF is meant to win but in them APP14 is clearly right, so make it win.
-        if (app14Segment != null && app14Segment.isAdobeJpegSegment()) {
-            final int colorTransform = app14Segment.getAdobeColorTransform();
-            switch (colorTransform) {
-            case App14Segment.ADOBE_COLOR_TRANSFORM_UNKNOWN:
-                if (numberOfComponents == 3) {
-                    colorType = ImageInfo.ColorType.RGB;
-                } else if (numberOfComponents == 4) {
-                    colorType = ImageInfo.ColorType.CMYK;
+        switch (numberOfComponents) {
+        case 1:
+            colorType = ImageInfo.ColorType.GRAYSCALE;
+            break;
+        case 2:
+            colorType = ImageInfo.ColorType.GRAYSCALE;
+            transparent = true;
+            break;
+        case 3:
+        case 4:
+            // Some images have both JFIF/APP0 and APP14.
+            // JFIF is meant to win but in them APP14 is clearly right, so make it win.
+            if (app14Segment != null && app14Segment.isAdobeJpegSegment()) {
+                final int colorTransform = app14Segment.getAdobeColorTransform();
+                switch (colorTransform) {
+                case App14Segment.ADOBE_COLOR_TRANSFORM_UNKNOWN:
+                    if (numberOfComponents == 3) {
+                        colorType = ImageInfo.ColorType.RGB;
+                    } else if (numberOfComponents == 4) {
+                        colorType = ImageInfo.ColorType.CMYK;
+                    }
+                    break;
+                case App14Segment.ADOBE_COLOR_TRANSFORM_YCbCr:
+                    colorType = ImageInfo.ColorType.YCbCr;
+                    break;
+                case App14Segment.ADOBE_COLOR_TRANSFORM_YCCK:
+                    colorType = ImageInfo.ColorType.YCCK;
+                    break;
+                default:
+                    break;
                 }
-                break;
-            case App14Segment.ADOBE_COLOR_TRANSFORM_YCbCr:
-                colorType = ImageInfo.ColorType.YCbCr;
-                break;
-            case App14Segment.ADOBE_COLOR_TRANSFORM_YCCK:
-                colorType = ImageInfo.ColorType.YCCK;
-                break;
-            default:
-                break;
-            }
-        } else if (jfifSegment != null) {
-            if (numberOfComponents == 1) {
-                colorType = ImageInfo.ColorType.GRAYSCALE;
-            } else if (numberOfComponents == 3) {
-                colorType = ImageInfo.ColorType.YCbCr;
-            }
-        } else {
-            switch (numberOfComponents) {
-            case 1:
-                colorType = ImageInfo.ColorType.GRAYSCALE;
-                break;
-            case 2:
-                colorType = ImageInfo.ColorType.GRAYSCALE;
-                transparent = true;
-                break;
-            case 3:
-            case 4:
+            } else if (jfifSegment != null) {
+                if (numberOfComponents == 1) {

Review Comment:
   Ping 2. Release going out soon :steam_locomotive: 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org