Problem converting to TXT format

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Problem converting to TXT format

Post by GeeMack »

Using IM7 beta ImageMagick 7.0.0-0 Q16 x64 2016-02-21 (installed from ImageMagick-7.0.0-0~beta20160221-Q16-HDRI-x64-static.exe) on Windows 7 64, and running this command...

Code: Select all

magick rose: output.txt
... I get a text file that starts out like this...

Code: Select all

# ImageMagick pixel enumeration: 70,46,255,srgb
0,0: (12336,12079,11565)  #302F2D  srgb(48,47,45)
1,0: (12850,12336,11822)  #32302E  srgb(50,48,46)
2,0: (13878,12850,12079)  #36322F  srgb(54,50,47)
...
...
On the first line of the output text, the size of the image is specified by the "70" and "46". The "255" is supposed to specify a range for each color from "0" to "255". However, in the first parentheses of all the following lines the color descriptors are in the range of "0" to "65535". So when trying to reassemble the text file into an image with this command...

Code: Select all

magick output.txt rose.png
... the result is an all white image. The problem seems to be the color descriptors in the first parentheses of each line should be shown as 8 bit, or in a range of "0" to "255".

I can force that first line of the text file to 16 bit color descriptors by running this command...

Code: Select all

magick rose: -depth 16 output.txt
... which creates a text file that starts like this...

Code: Select all

# ImageMagick pixel enumeration: 70,46,65535,srgb
0,0: (12336,12079,11565)  #30302F2F2D2D  srgb(48,47,45)
1,0: (12850,12336,11822)  #323230302E2E  srgb(50,48,46)
2,0: (13878,12850,12079)  #363632322F2F  srgb(54,50,47)
...
...
... and easily reassembles into the rose image. But I can't seem to get those color descriptors in the parentheses to use 8 bit notation, "0" through "255", even if I use "-depth 8" in my command. That means the TXT file can't be reconstructed into an image unless it's created with "-depth 16" in the command.

I wonder if this is something should be brought to the attention of the developers.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem converting to TXT format

Post by fmw42 »

The number is parenthesis are in the range of your IM install. Q16 means 16 bit values (0 to 65535). A Q8 install means 8 bit values (0 to 255). The rose image shows 70,46,255,srgb, because it is an 8 bit depth per channel image, but you are running on a Q16 install of Imagemagick. So the numbers in parenthesis will always be shown in the range 0 to 65535. But the rgb color values at the ends of the line will always be shown in 8 bit range (0 to 255).

When you convert with -depth 16, you are telling IM to convert the rose image from 8 to 16 bits, since Q16 supports 16 bits.

If you run:

convert -version

you will likely see that your IM compile is Q16.


However, even on IM 6.9.3.5 Q16 Mac OSX, I can reproduce your bug. I do get a totally white image from

Code: Select all

convert rose: rose.txt
convert rose.txt rose.png

Code: Select all

Image: rose.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: PseudoClass
  Geometry: 70x46+0+0
  Units: Undefined
  Type: Bilevel
  Base type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8/1-bit
  Channel depth:
    gray: 1-bit
  Channel statistics:
    Pixels: 3220
    Gray:
      min: 255 (1)
      max: 255 (1)
      mean: 255 (1)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
      entropy: nan
  Colors: 1
  Histogram:
      3220: (255,255,255) #FFFFFF gray(255)
  Colormap entries: 2
  Colormap:
         0: (  0,  0,  0) #000000 gray(0)
         1: (255,255,255) #FFFFFF gray(255)
  Rendering intent: Undefined
  Gamma: 0.45455
  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: gray(255)
  Border color: gray(223)
  Matte color: gray(189)
  Transparent color: gray(0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 70x46+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2016-02-24T21:10:05-08:00
    date:modify: 2016-02-24T21:10:05-08:00
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.45455 (See Gamma, above)
    png:IHDR.bit-depth-orig: 1
    png:IHDR.bit_depth: 1
    png:IHDR.color-type-orig: 0
    png:IHDR.color_type: 0 (Grayscale)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 70, 46
    png:text: 2 tEXt/zTXt/iTXt chunks were found
    png:tIME: 2016-02-24T21:09:57Z
    signature: d01dd224cfd7715a4f45afa6b47fbb642061fdede5ca1d1270122b117f7b10e6
  Artifacts:
    filename: rose.png
    verbose: true
  Tainted: False
  Filesize: 266B
  Number pixels: 3.22K
  Pixels per second: 3.22EB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.9.3-5 Q16 x86_64 2016-02-21 http://www.imagemagick.org
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem converting to TXT format

Post by snibgo »

I agree this is a bug. The round-trip...

Code: Select all

convert rose: r.txt
convert r.txt r.png
... should result in an image that looks like the rose.

The problem is that IM is writing the first line with a certain meaning, but reading it with a different meaning.

I think the best workaround is to put "+depth" before the text write. Then the write can be done with any Q-number IM, and is correctly read with any Q-number IM.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Problem converting to TXT format

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.

In the mean-time, use this command:
  • magick rose: -define txt:compliance=SVG rose.txt
Post Reply