Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

I am having to deal with CMYK JPEGs extracted from a PDF source. The PDFs were created with Photoshop.

The problem is that Photoshop stores JPEG CMYK data in PDF/EPS using "normal" values, whereas in standalone JPEGs it stores inverted values. So, when the DCTDecode streams are extracted bytewise and written to disk, the resulting JPEG files appear inverted.

(The actual extraction is done by an in-house utility, which simply extracts the bytes from the DCTDecode stream and writes them, unmodified, to a file ending in .jpg It's basically a binary copy-and-paste. The PDFs are available to re-process, should that be required.)

As the images must remain in their JFIF format, is there any way to place a marker into the extracted .jpg file to make Photoshop open it with the proper encoding? The process must be lossless (not involve further entropy encoding).

The JPEGs already contain the APP14 marker, and removing it has no effect.

Below is a quote from the libjpeg docs:

"... it appears that Adobe Photoshop writes inverted data in CMYK JPEG files: 0 represents 100% ink coverage, rather than 0% ink as you'd expect. ... Photoshop 3.0 [and newer]... write uninverted YCCK in EPS/JPEG files... (But the data polarity used in bare JPEG files will not change...)"

share|improve this question
2  
Can't you just batch automate the conversion of the exported JPEGs back to regular CMYK encoding? Why do you need to flag the extracted files - you say all the PDFs werre created in Photoshop? –  e100 Nov 27 '12 at 19:03
    
@e100 ~ How exactly would that be batch automated? –  Unsigned Nov 27 '12 at 19:03
    
How are you extracting the JPEGs from the PDFs? Do you already have a folder containing many JPEGs which all need to be converted? It would be good to add this info into your original question. –  e100 Nov 27 '12 at 19:12
    
@e100 ~ The DCTDecode stream is extracted bytewise. I would presume the actual number of files to process is irrelevant. A process that works on one would work on all. –  Unsigned Nov 27 '12 at 19:19
2  
I am referring to the original JFIF standard which supports 1 or 3 color (24-bit). Lack of CMYK support was rectified in a later standard. It used to be a problem when people would create jpegs from CMYK sources and try and use them on web sites. As far as workflow, you objected to e100's suggestion of using batch automation. Photoshop supports this. If the colors are simply inverted, then Photoshop can run a batch process such as "open, invert, save as" on an arbitrary number of files. –  horatio Nov 28 '12 at 17:28

3 Answers 3

(Dislaimer: I have no image to test with - if you could share such an image by a file-sharing site I can test and make adjustments to answer if needed).

The problem is most likely related to missing ICC profile.

To embed (or convert) such a profile you can use f.ex. ImageMagick to do this loss-les without affecting the data.

ImageMagick:
http://imagemagick.org/script/index.php

The command line utility can be used as this to embed a ICC profile:

convert cmyk.jpg -profile USWebCoatedSWOP.icc cmyk_w_icc.jpg

Optionally convert it to native RGB color-space.

See here for more details:
http://www.imagemagick.org/Usage/formats/#color_profile

You can download ICC profiles from here:
http://www.adobe.com/support/downloads/detail.jsp?ftpID=4074

share|improve this answer
    
Great info, but unfortunately this is not an ICC issue. The image contains the proper ICC profile, the pixels are just reversed. –  Unsigned Jan 12 '13 at 6:09

Here on Adobe forums is a same problem with successful results: http://forums.adobe.com/message/4271028

Maybe the APP14 tag is not correct? Theres more to APP14 tags than it just being there. On JPEG tags: http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe

JPEG Adobe Tags

The "Adobe" APP14 segment stores image encoding information for DCT filters. This segment may be copied or deleted as a block using the Extra "Adobe" tag, but note that it is not deleted by default when deleting all metadata because it may affect the appearance of the image.

╔════════╦══════════════════╦══════════╦════════════════════════════════════════════╗
║ Index2 ║     Tag Name     ║ Writable ║               Values / Notes               ║
╠════════╬══════════════════╬══════════╬════════════════════════════════════════════╣
║      0 ║ DCTEncodeVersion ║ N        ║                                            ║
║      1 ║ APP14Flags0      ║ N        ║ Bit 15 = Encoded with Blend=1 downsampling ║
║      2 ║ APP14Flags1      ║ N        ║                                            ║
║      3 ║ ColorTransform   ║ N        ║ 0 = Unknown (RGB or CMYK)                  ║
║        ║                  ║          ║ 1 = YCbCr                                  ║
║        ║                  ║          ║ 2 = YCCK                                   ║
╚════════╩══════════════════╩══════════╩════════════════════════════════════════════╝

But that might not help, I recall someone stating that these private markers aren't intended to guide PDF-Readers but proper decode arrays should be.

The magic seems to be

/Decode 0 1 0 1 0 1 0 1

which would invert the color mapping. (I guess that's a flag in libjpeg, something similiar should be available in any similiar tool.) Decode arrays are common in PDFs according to the PDF Reference here: http://partners.adobe.com/public/developer/en/pdf/PDFReference.pdf

I have no clue if you can add these decode arrays into PDF JPEGs or do you need to add that to the stream processing of your in-house tool. I have no example PDF to work on, so I can't do any further research (also, the reference is huge - tl;dr - but you might have to..)

share|improve this answer
    
This is a great reference, thanks! –  Unsigned Apr 23 '13 at 18:09

Edit: This no longer appears to work in Photoshop CC 2014. Pixelwise comparison now shows differences. Re-opening question for a better answer.

Figured out how to extract them using Photoshop CS5. Possibly works on other versions too, though I didn't test.

  • Open the PDF in Photoshop, choosing the image you want
  • Save as... > JPEG
  • Use all the default values when saving, don't move any sliders
  • The saved JPEG will be a pixel-perfect copy, with correct colors

This seems to be the one instance where saving a JPEG does not result in quality loss. Photoshop is smart enough to figure out what's going on here.

To verify that the images are identical, open both the original PDF and the new JPEG in Photoshop and do a pixel-by-pixel comparison. They will be identical.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.