read() does not maintain depth

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
personalrobert
Posts: 11
Joined: 2012-12-20T12:49:30-07:00
Authentication code: 6789

read() does not maintain depth

Post by personalrobert »

Obviously I am relatively new to Magick++. I read in a 16-bit TIF file, but its depth prints as 8, and the resultant JPEG2000 file is also only 8 bpp. Can you tell me what I'm doing wrong? Thank you.

Version: ImageMagick 6.6.9-7 2012-08-17 Q16

Code: Select all

$ identify fullres.tif
fullres.tif TIFF 2560x3328 2560x3328+0+0 16-bit Grayscale DirectClass 5.893MB 0.000u 0:00.000

Code: Select all

#include <iostream>
#include <Magick++.h>

int main(int argc, char **argv)
{
    Magick::InitializeMagick(*argv);

    Magick::Image
        image;

    try
    {
        image.read("fullres.tif");
        std::cout << "Depth: " << image.depth() << std::endl;
        image.write("test.jp2");
    }
    catch(Magick::Exception &ex)
    {
        std::cerr << "Exception: " << ex.what() << std::endl;
    }
    return 0;
}

Code: Select all

$ identify test.jp2
test.jp2 JP2 2560x3328 2560x3328+0+0 8-bit DirectClass 519KB 0.380u 0:00.390
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: read() does not maintain depth

Post by snibgo »

Do you get the same result from a command?

Code: Select all

convert fullres.tif test.jp2
If so, I suspect the input file has only 8 or fewer significant bits of data. IM generally tries to shrink files when it can.

Your IM version is also very old.
snibgo's IM pages: im.snibgo.com
personalrobert
Posts: 11
Joined: 2012-12-20T12:49:30-07:00
Authentication code: 6789

Re: read() does not maintain depth

Post by personalrobert »

No. When I run the command

Code: Select all

convert fullres.tif test.jp2
it generates a proper 16-bit JP2 file!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: read() does not maintain depth

Post by snibgo »

Okay. Sorry, I can't help with Magic++. All I can suggest is upgrading to a more recent version. JP2 is a relatively new format, and IM v6.6.9 is very old.
snibgo's IM pages: im.snibgo.com
personalrobert
Posts: 11
Joined: 2012-12-20T12:49:30-07:00
Authentication code: 6789

Re: read() does not maintain depth

Post by personalrobert »

6.6.9-7 is dated Aug 17, 2012. That may be "old", but "very old" is a stretch. :wink:
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: read() does not maintain depth

Post by glennrp »

personalrobert wrote:6.6.9-7 is dated Aug 17, 2012. That may be "old", but "very old" is a stretch. :wink:
That would probably be the date it was compiled on your platform. My copy of the source for 6.6.9-7 is from around the end of April 2011.
Somewhere between "old" and "very old".
personalrobert
Posts: 11
Joined: 2012-12-20T12:49:30-07:00
Authentication code: 6789

Re: read() does not maintain depth

Post by personalrobert »

I believe my problem is that the version of the Magick++ library I am using is 8-bit, and therefore the 16-bit image being read is converted to 8-bit when I call read(). Does this sound like a reasonable conclusion?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: read() does not maintain depth

Post by snibgo »

You said it was "Version: ImageMagick 6.6.9-7 2012-08-17 Q16", which is 16-bit. But your library might be a different version, I suppose. If it is 8-bit, then all files it writes will be 8-bit.
snibgo's IM pages: im.snibgo.com
personalrobert
Posts: 11
Joined: 2012-12-20T12:49:30-07:00
Authentication code: 6789

Re: read() does not maintain depth

Post by personalrobert »

The version output was from "convert -version", but Magick::Quantum is 1 (byte) and MaxRGB is 255, so I think you are right that my command line utilities are 16-bit and my library is 8.
Post Reply