Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMYK image loading with inverted colors #147

Closed
maciejhirsz opened this issue Jun 24, 2015 · 8 comments
Closed

CMYK image loading with inverted colors #147

maciejhirsz opened this issue Jun 24, 2015 · 8 comments
Assignees
Milestone

Comments

@maciejhirsz
Copy link

I've been using TwelveMonkeys for a while without much of an issue, but of course finally some client managed to fabricate an image that doesn't load quite right, it's the first CMYK image that I see load with inverted colors, and I'm a bit at a loss why...

The JPEG in question to be found here: http://terhix.com/inverted.jpg

ImageMagick identify -verbose dump:

Image: inverted.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 796x1194+0+0
  Resolution: 28.3465x28.3465
  Print size: 28.0811x42.1216
  Units: PixelsPerCentimeter
  Type: ColorSeparation
  Endianess: Undefined
  Colorspace: CMYK
  Depth: 8-bit
  Channel depth:
    cyan: 8-bit
    magenta: 8-bit
    yellow: 8-bit
    black: 8-bit
  Channel statistics:
    Pixels: 950424
    Cyan:
      min: 0 (0)
      max: 255 (1)
      mean: 77.9501 (0.305687)
      standard deviation: 52.9279 (0.207561)
      kurtosis: -0.987192
      skewness: 0.00923395
      entropy: 0.882891
    Magenta:
      min: 0 (0)
      max: 255 (1)
      mean: 87.5529 (0.343345)
      standard deviation: 58.1934 (0.228209)
      kurtosis: -0.841658
      skewness: -0.150388
      entropy: 0.867921
    Yellow:
      min: 0 (0)
      max: 255 (1)
      mean: 131.115 (0.514175)
      standard deviation: 87.8883 (0.34466)
      kurtosis: -1.45162
      skewness: -0.131165
      entropy: 0.927241
    Black:
      min: 0 (0)
      max: 255 (1)
      mean: 55.7855 (0.218767)
      standard deviation: 60.2406 (0.236238)
      kurtosis: -0.661707
      skewness: 0.7945
      entropy: 0.775388
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 88.1008 (0.345493)
      standard deviation: 66.2214 (0.259692)
      kurtosis: 0.129288
      skewness: 0.564087
      entropy: 0.86336
  Total ink density: 372.157%
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: cmyk(255,255,255,0)
  Border color: cmyk(223,223,223,0)
  Matte color: cmyk(189,189,189,0)
  Transparent color: cmyk(0,0,0,0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 796x1194+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 78
  Orientation: TopLeft
  Properties:
    date:create: 2015-06-24T13:46:51+02:00
    date:modify: 2015-06-24T13:46:46+02:00
    exif:ApertureValue: 327680/65536
    exif:BitsPerSample: 8, 8, 8, 8
    exif:ColorSpace: 65535
    exif:Compression: 5
    exif:DateTime: 2015:02:12 10:13:55
    exif:DateTimeDigitized: 2016:07:12 08:37:36
    exif:DateTimeOriginal: 2016:07:12 08:37:36
    exif:ExifImageLength: 1194
    exif:ExifImageWidth: 796
    exif:ExifOffset: 312
    exif:ExifVersion: 48, 50, 50, 48
    exif:ExposureBiasValue: 0/1
    exif:ExposureMode: 1
    exif:ExposureProgram: 1
    exif:ExposureTime: 1/250
    exif:FileSource: 3
    exif:Flash: 16
    exif:FNumber: 56/10
    exif:FocalLength: 88/1
    exif:FocalPlaneResolutionUnit: 2
    exif:ImageLength: 6739
    exif:ImageWidth: 4493
    exif:ISOSpeedRatings: 200
    exif:Make: Canon
    exif:MeteringMode: 5
    exif:Model: Canon EOS-1Ds Mark III
    exif:Orientation: 1
    exif:PhotometricInterpretation: 5
    exif:PlanarConfiguration: 1
    exif:ResolutionUnit: 3
    exif:SamplesPerPixel: 4
    exif:SceneType: 1
    exif:ShutterSpeedValue: 524288/65536
    exif:Software: Adobe Photoshop CS5.1 Windows
    exif:SubjectDistance: 0/1
    exif:thumbnail:Compression: 6
    exif:thumbnail:JPEGInterchangeFormat: 806
    exif:thumbnail:JPEGInterchangeFormatLength: 7607
    exif:thumbnail:ResolutionUnit: 2
    exif:thumbnail:XResolution: 72/1
    exif:thumbnail:YResolution: 72/1
    exif:WhiteBalance: 0
    exif:XResolution: 283465/10000
    exif:YResolution: 283465/10000
    jpeg:colorspace: 4
    jpeg:sampling-factor: 2x2,1x1,1x1,2x2
    signature: f79ef5e4bdbc0d1b087a48b9f1c690ac172e2c30ae7370ec29aed49aa738a1df
  Profiles:
    Profile-8bim: 9904 bytes
    Profile-exif: 8419 bytes
    Profile-icc: 1052608 bytes
    Profile-iptc: 139 bytes
      unknown[1,0]: 
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      City[1,90]: 0x00000000: 254700                                        -%
      unknown[2,0]: 
      Created Date[2,55]: 20160712
      Created Time[2,60]: 083736+0200
    Profile-xmp: 5100 bytes
  Artifacts:
    filename: inverted.jpg
    verbose: true
  Tainted: False
  Filesize: 1.159MB
  Number pixels: 950K
  Pixels per second: 237.61GB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.9.1-1 Q16 x86_64 2015-04-15 http://www.imagemagick.org

Tested with TwelveMonkeys 3.1.1.

@haraldk
Copy link
Owner

haraldk commented Jun 24, 2015

Hi Maciej,

Thanks for reporting!

Could be something experimental I implemented for not inverting CMYK JPEGs extracted from PDFs... But I'll have to look into it in more detail. If it displays inverted, it's probably a bug, as it seems to display correctly in my browser (Safari/iPad).

Right now I'm on summer holiday, but I'll look into it as soon as possible.

Regards,

Harald K

@maciejhirsz
Copy link
Author

Hey!

Thanks for the update, enjoy the holidays, you deserve it :).

Cheers.

@haraldk
Copy link
Owner

haraldk commented Jul 3, 2015

Okay, found the issue (it was the experimental code I expected). I'll have to revert some code for this to display correctly (and it will break some other images).

The main problem here is that CMYK JPEG isn't very strictly defined AFAIK. The "de facto" way is to treat stand-alone CMYK JPEGs as stored inverted, while CMYK JPEG streams inside PDFs are normally stored non-inverted. However this is not always correct...

Do you know what software created this image? Is it extracted from a PDF?

Regards,

Harald K

@photopcf
Copy link

photopcf commented Jul 4, 2015

Hi
I also had this problem and decided to replace imageio-jpeg-3.1.1.jar by twelvemonkeys-imageio-jpeg-3.0-SNAPSHOT.jar
This problem also occurs in version 3.1.0

Sérgio

@haraldk
Copy link
Owner

haraldk commented Jul 7, 2015

Hi Sérgio,

Thanks. Do you have the issue with Maciej's image on 3.0?

Please keep in mind that there's (AFAIK) no way to accurately determine if the CMYK JPEG is inverted or not, so some images will be inverted, regardless of version and applying the proposed fix.

If you are extracting JPEGs from PDFs, the PDF does contain the necessary information.

Harald K

@haraldk haraldk self-assigned this Jul 8, 2015
@haraldk haraldk added this to the 3.2 milestone Jul 8, 2015
@haraldk
Copy link
Owner

haraldk commented Jul 13, 2015

Fixed in lastest commit.

Now all CMYK JPEGs are inverted when read.

If someone would like the non-inverted values, they will have to use the readRaster method.

I'm planning to add a setting to the JPEGReadParam that will allow specifying non-inversion of CMYK data, or ideally, allow specifying a PDF decode array that will determine if the data is to be inverted. This is not implemented yet.

Harald K

@haraldk haraldk closed this as completed Jul 13, 2015
@maciejhirsz
Copy link
Author

Late to the party, but I'm afraid I wouldn't be able to help you - no idea how the client made the jpeg nor have any contact to them.

@haraldk
Copy link
Owner

haraldk commented Jul 14, 2015

@maciejhirsz Ok. Latest master is back to the original code, treating all images the same. The image you attached looks good using this approach. If an image comes out as inverted, it's because the JPEG is stored non-inverted, which should not happen for standalone CMYK JPEGs.

Harald K

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants