Page 1 of 1

density bugs in PNG and JP2 from TIF

Posted: 2016-08-03T23:18:52-07:00
by xmmxmm
Trying to do some conversions to JP2 and anything converted to JP2 comes out as 72x72 regardless of the source image. Furthermore PNG for my source image is coming out at a strange number.

% identify -format "%w x %h, %x x %y\n" source.tif
2551 x 3905, 400 x 400
% convert source.tif dest.jpg
% convert source.tif dest.jp2
% convert source.tif dest.png
% identify -format "%w x %h, %x x %y\n" dest.jpg dest.jp2 dest.png
2551 x 3905, 400 x 400
2551 x 3905, 72 x 72
2551 x 3905, 157.47999999999998977 x 157.47999999999998977
%

JPG in there as a control and seems to be working ok.

opj_compress also ignores the pixel density. Furthermore it doesn't even seem to be working properly as a parameter to convert. JPG though works.

% convert source.tif -density 800 -units PixelsPerInch dest.jpg
% convert source.tif -density 800 -units PixelsPerInch dest.jp2
% convert source.tif -density 800 -units PixelsPerInch dest.png
% identify -format "%w x %h, %x x %y\n" dest.jpg dest.png dest.jp2
2551 x 3905, 800 x 800
2551 x 3905, 314.95999999999997954 x 314.95999999999997954
2551 x 3905, 72 x 72
%

Using the created JPG file as a source doesn't help much either. The PNG conversion maybe is picking up some other tag to calculate the values as it's changing but not being set to the correct value.

% convert dest.jpg -density 1200 -units PixelsPerInch dest.png
% convert dest.jpg -density 1200 -units PixelsPerInch dest.jp2
% identify -format "%w x %h, %x x %y\n" dest.png dest.jp2
2551 x 3905, 472.43999999999999773 x 472.43999999999999773
2551 x 3905, 72 x 72
%

Expected behavior would be for all three formats to have the same density after conversion. JPG working as one would expect, the others not. JP2 problem as mentioned is mirrored in any conversion being done by opj_compress which if fixed would maybe fix imagemagick.

% opj_compress -i source.tif -o dest.jp2
[INFO] tile number 1 / 1
[INFO] Generated outfile dest.jp2

% identify -format "%w x %h, %x x %y\n" source.tif dest.jp2
2551 x 3905, 400 x 400
2551 x 3905, 72 x 72
%



% identify --version
Version: ImageMagick 6.9.5-4 Q16 x86_64 2016-08-04 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib freetype jng jp2 jpeg lcms ltdl lzma png tiff xml zlib
%

Re: density bugs in PNG and JP2 from TIF

Posted: 2016-08-03T23:24:02-07:00
by fmw42
Note that PNG only supports density of pixelspercentimeter.

Re: density bugs in PNG and JP2 from TIF

Posted: 2016-08-04T12:13:41-07:00
by dlemstra
And the OpenJPEG library that we use does not have support for density so it will always use the default value of 72 DPI.