"convert" changes bitdepth

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
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

"convert" changes bitdepth

Post by naoliv »

Hi!

From http://bugs.debian.org/472699, the user is saying that with ImageMagick version 6.2.4-5, he converts a 8-bit JPEG to PNG, and he gets a 8-bit too PNG.
But with newer versions (including the latest beta version 6.4.0-5, tested here), he gets a 16-bit PNG file.

Using "-depth 8" works, but shouldn't convert keep the same bit depth when converting, unless -depth is specified?

Thank you!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: "convert" changes bitdepth

Post by magick »

Not a bug. ImageMagick, by design, promotes the image depth to the QuantumDepth (e.g. Q16) whenever pixels are modified. As you mentioned, the solution is to use the -depth command line option to set the desired depth. The user is encouraged to post an enhancement request to maintain the color depth of the original image, however, that would require a new option so that existing scripts do not break (e.g. convert image.png -depth original image.tif).
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

Re: "convert" changes bitdepth

Post by naoliv »

Right.
Where can users send enhancement requests, please?

Thank you again!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: "convert" changes bitdepth

Post by magick »

We have already added your enhancement request to our to-do list. We currently do not have an ETA but its simply to implement so we should have something in short order (i.e. a few weeks / a few months).
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Re: "convert" changes bitdepth

Post by broucaries »

I suppose this was fixed by :
2008-08-27 6.4.3-6 Cristy <quetzlzacatenango@image...>
Set image depth when -depth is fired.

Regards

Bastien
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Re: "convert" changes bitdepth

Post by broucaries »

Hi,

Could you either ACK or NACK that this was fixed by cited commit?

Regards

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

Re: "convert" changes bitdepth

Post by magick »

Not sure what you are asking for. The default behavior of ImageMagick is to increase the image depth if any pixels are modified. This makes sense to us because an 8-bit image when resized, for example, goes from 8-bits to 16-bits (assuming IM Q16) because of the blended colors. To force 8-bit output, simply add -depth 8 to the command line:
  • convert 8-bit.jpg 8-bit.png // output is 8-bit because no pixels were modified
    convert 8-bit.jpg -resize 50% 16-bit.png // output is 16-bit because IM is Q16 and the resize introduced blended colors
    convert 8-bit.jpg -resize 50% -depth 8 8-bit.png // output is 8-bit because we asked for 8-bit with -depth
Therefore we do not consider increasing the image depth a bug. Given the above discussion, how can we help?
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Re: "convert" changes bitdepth

Post by broucaries »

Thank you for your answer, I supposed it was fixed by the commit mentionned above.

Will maintain as a whislist item in our BTS with your answer copied.

Thank you for your time.

Regards

Bastien
Axaes

Re: "convert" changes bitdepth

Post by Axaes »

EDIT: Please ignore this post, I just discovered my mistake.

Aloha,

I apologize for raising this thread from the dead, but I need help how to place the depth command. I crop a master image into tiles, the tiles need to be 8bit for opensimulator.

The crop command for an 768pixel image into 9 tiles I use is:

convert -crop 256x256 me.png minime.png

Where do I add the 8bit depth command here so the minimi-tiles come out as 8bit?

Or, as an alternative, how do I convert a folder of tiles into 8bit in a separate step?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "convert" changes bitdepth

Post by fmw42 »

Axaes wrote:EDIT: Please ignore this post, I just discovered my mistake.

Aloha,

I apologize for raising this thread from the dead, but I need help how to place the depth command. I crop a master image into tiles, the tiles need to be 8bit for opensimulator.

The crop command for an 768pixel image into 9 tiles I use is:

convert -crop 256x256 me.png minime.png

Where do I add the 8bit depth command here so the minimi-tiles come out as 8bit?

Or, as an alternative, how do I convert a folder of tiles into 8bit in a separate step?

convert me.png -crop 256x256 -depth 8 +repage minime.png

see
http://www.imagemagick.org/Usage/basics/#cmdline

+repage is needed to remove the larger virtual canvas whenever you nominally use -crop

To process a folder, use mogrify in place of convert.

See
http://www.imagemagick.org/Usage/basics/#mogrify
Axaes

Re: "convert" changes bitdepth

Post by Axaes »

I was using that command as suggested, apart from the repage addition, hence the confusion. However I found the error:

My problem was that the master image needed to be exported in L3DT as 8 bit png as well. If that option is not _explicitly_ selected in that application, the master image png output would be 16bit, which oddly resulted in 24bit tiles *with* the 8 bit command.

Normally I wouldn't even notice such things, but opensimulator refuses anything above 8 bit relating to terraforms. My solution was to set the export standard of L3DT (which I'm using under Wine) for png's at 8 bit. This then has the desired result of the tiles being 8bit as well.

Why the IM turns a 16 bit into 24 bit image with the 8bit command included is beyond my technical understanding, luckily L3DT has the option to export png's as 8 bit.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "convert" changes bitdepth

Post by fmw42 »

Post Reply