Missing K values from a CMYK TIFF image

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
sanderton

Missing K values from a CMYK TIFF image

Post by sanderton »

I need to extract the pixel data and write it to a Postscript file in ASCII format. The problem is that the K values are 00 for all the pixels, and the image now looks almost black.

I'm using this line of code:

Code: Select all

MagickLib::PixelPacket* pImageData = m_pIMImage->setPixels( 0, 0, nCols, nRows );
and the following output (from the memory window) is the contents of pImageData (from the file CMYK.tif)

Code: Select all

0x04F50000  02 01 00 00 01 00 00 00 04 01 01 00 08 02 02 00  ................
0x04F50010  04 01 01 00 04 01 01 00 04 01 01 00 04 01 01 00  ................
0x04F50020  04 01 01 00 02 01 00 00 01 00 00 00 04 01 01 00  ................
0x04F50030  04 01 01 00 04 01 01 00 01 00 00 00 04 01 01 00  ................
0x04F50040  04 01 01 00 09 03 02 00 06 02 01 00 04 01 01 00  ................
0x04F50050  04 01 01 00 02 01 00 00 06 02 02 00 01 00 00 00  ................
0x04F50060  04 01 01 00 06 02 01 00 02 01 00 00 01 00 00 00  ................
0x04F50070  04 01 01 00 04 01 01 00 06 02 02 00 04 01 01 00  ................
0x04F50080  04 01 01 00 08 02 04 00 07 09 0c 00 35 5b 2a 00  ............5[*.
0x04F50090  23 61 b0 00 28 59 b1 00 24 66 af 00 20 69 ac 00  #a°.(Y±.$f¯. i¬.
0x04F500A0  11 73 c7 00 19 6c b0 00 29 57 af 00 13 7a ba 00  .sÇ..l°.)W¯..zº.
0x04F500B0  16 6c c5 00 37 51 a3 00 20 67 b4 00 1d 67 b4 00  .lÅ.7Q£. g´..g´.
0x04F500C0  24 66 b7 00 23 66 aa 00 15 69 cb 00 12 7d c5 00  $f·.#fª..iË..}Å.
0x04F500D0  1a 63 ba 00 15 7b c3 00 1d 71 b9 00 25 5c b3 00  .cº..{Ã..q..%\..
0x04F500E0  1f 64 b6 00 25 5e bb 00 27 55 b9 00 12 7f c6 00  .d¶.%^».'U....Æ.
0x04F500F0  12 69 bb 00 27 5e a9 00 1e 6e b5 00 13 70 c8 00  .i».'^©..nµ..pÈ.
Every 4th item is 00 when it should be a K value. IM correctly identifies the image as CMYK but throws the following warning exception during the read operation:

Code: Select all

Coder Warning: ImageMagick: incorrect count for field "MaxSampleValue" (1, expecting 4); tag ignored.
However, when I run the following on the command line I do get the K values (and the same warnings):

Code: Select all

convert CMYK.tif txt:-

# ImageMagick pixel enumeration: 799,633,255,CMYK
0,0: (  0,  1,  2,  0) #000102
1,0: (  0,  0,  1,  0) #000001
2,0: (  1,  1,  4,  0) #010104
3,0: (  2,  2,  8,  0) #020208
4,0: (  1,  1,  4,  0) #010104
5,0: (  1,  1,  4,  0) #010104
6,0: (  1,  1,  4,  0) #010104
7,0: (  1,  1,  4,  0) #010104
8,0: (  1,  1,  4,  0) #010104
9,0: (  0,  1,  2,  0) #000102
10,0: (  0,  0,  1,  0) #000001
11,0: (  1,  1,  4,  0) #010104
12,0: (  1,  1,  4,  0) #010104
13,0: (  1,  1,  4,  0) #010104
14,0: (  0,  0,  1,  0) #000001
15,0: (  1,  1,  4,  0) #010104
16,0: (  1,  1,  4,  0) #010104
17,0: (  2,  3,  9,  0) #020309
18,0: (  1,  2,  6,  0) #010206
19,0: (  1,  1,  4,  0) #010104
20,0: (  1,  1,  4,  0) #010104
21,0: (  0,  1,  2,  0) #000102
22,0: (  2,  2,  6,  0) #020206
23,0: (  0,  0,  1,  0) #000001
24,0: (  1,  1,  4,  0) #010104
25,0: (  1,  2,  6,  0) #010206
26,0: (  0,  1,  2,  0) #000102
27,0: (  0,  0,  1,  0) #000001
28,0: (  1,  1,  4,  0) #010104
29,0: (  1,  1,  4,  0) #010104
30,0: (  2,  2,  6,  0) #020206
31,0: (  1,  1,  4,  0) #010104
32,0: (  1,  1,  4,  0) #010104
33,0: (  4,  2,  8,  0) #040208
34,0: ( 12,  9,  7,  0) #0C0907
35,0: ( 42, 91, 53,  7) #2A5B35
36,0: (176, 97, 35, 39) #B06123
37,0: (177, 89, 40, 41) #B15928
38,0: (175,102, 36, 40) #AF6624
39,0: (172,105, 32, 35) #AC6920
40,0: (199,115, 17, 15) #C77311
41,0: (176,108, 25, 24) #B06C19
42,0: (175, 87, 41, 40) #AF5729
43,0: (186,122, 19, 18) #BA7A13
44,0: (197,108, 22, 21) #C56C16
45,0: (163, 81, 55, 40) #A35137
46,0: (180,103, 32, 37) #B46720
47,0: (180,103, 29, 31) #B4671D
48,0: (183,102, 36, 44) #B76624
49,0: (170,102, 35, 37) #AA6623
50,0: (203,105, 21, 19) #CB6915
51,0: (197,125, 18, 16) #C57D12
52,0: (186, 99, 26, 25) #BA631A
53,0: (195,123, 21, 19) #C37B15
54,0: (185,113, 29, 34) #B9711D
55,0: (179, 92, 37, 41) #B35C25
56,0: (182,100, 31, 34) #B6641F
57,0: (187, 94, 37, 45) #BB5E25
58,0: (185, 85, 39, 45) #B95527
59,0: (198,127, 18, 15) #C67F12
60,0: (187,105, 18, 15) #BB6912
61,0: (169, 94, 39, 37) #A95E27
62,0: (181,110, 30, 35) #B56E1E
63,0: (200,112, 19, 17) #C87013
...

convert: incorrect count for field "MinSampleValue" (1, expecting 4); tag ignored. `C:\testing\TIFF\CMYK.tif'.
convert: incorrect count for field "MaxSampleValue" (1, expecting 4); tag ignored. `C:\testing\TIFF\CMYK.tif'.
I've tried getPixels() and it's the same thing. I thought readPixels() would work, but am having trouble as I'm not sure what to put for the source parameter.

Does anyone have any ideas? Should I be using another function to access the pixels?

Thanks,
Stephanie
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

The 4th value of a pixel is the alpha value, not the K value. Grab CMY from the pixel then call getIndexes() to grab the K value.
sanderton

Post by sanderton »

Thanks! Worked like a charm.
I also found another of your replies very useful (another posting); it also uses the getIndexes() function in some sample code.
Post Reply