Uploaded image for project: 'Commons Imaging'
  1. Commons Imaging
  2. IMAGING-310

JpegImageParser: Grayscale JPEG file with app14Segment returns ColorType.UNKNOWN

    XMLWordPrintableJSON

Details

    • Bug
    • Status: In Progress
    • Major
    • Resolution: Unresolved
    • 1.0-alpha2
    • 1.0.0-alpha5
    • Format: JPEG
    • None

    Description

      In org.apache.commons.imaging.formats.jpeg. the logic to determine colorType (lines 825-970) does not account for a Grayscale image when there is an app14 segment present.

      When the number of components is 1 or 2, the colorType should always be Grayscale. None of the other logic would change that.

      It seems to me that the switch (numberOfComponents) statement should be moved to the top of this bit of code, and the rest of the logic should handled under Case 3 & 4:

      // See http://docs.oracle.com/javase/6/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html#color
      ImageInfo.ColorType colorType = ImageInfo.ColorType.UNKNOWN;
      
      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()) {
      etc.
      

      Attached sample-grayscale-with-app14segment.jpg, which can be used to demonstrate the issue.
      I've modified the code locally, but I'm a newbie at submitting pull-requests....

      Attachments

        Issue Links

          Activity

            People

              kinow Bruno P. Kinoshita
              john.phillips@broadridge.com John Phillips
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h
                  2h