Two comments to my own diff.

1) Obviously you will want to remove the System.out.println call before
   committing.

2) The same change will likely apply to other codecs, which suffer
   from a similar (float->int) truncation problem, e.g. PngImage.

On Wed, Jun 27, 2007 at 03:16:23PM -0700, Chad Loder wrote:
> I believe the bitmap codec has a floating point truncation error that
> causes a 300 dpi bitmap to be processed as 299 dpi. A 300 dpi image
> specifies an xPelsPerMeter of 11811, which is multiplied by 0.0254
> (one inch in meters), yielding an effective DPI of 299.9994. I do
> not think it is correct to truncate this when converting to an integer.
> 
> The correct method IMHO is to convert the double to a float, then
> round the float to an integer. The following diff achieves the correct
> results.
> 
> Comments?
> 
> Index: com/lowagie/text/pdf/codec/BmpImage.java
> ===================================================================
> --- com/lowagie/text/pdf/codec/BmpImage.java  6 Jun 2007 23:09:56 -0000       
> 1.1.1.6
> +++ com/lowagie/text/pdf/codec/BmpImage.java  27 Jun 2007 21:36:32 -0000
> @@ -203,7 +203,10 @@
>          BmpImage bmp = new BmpImage(is, noHeader, size);
>          try {
>              Image img = bmp.getImage();
> -            img.setDpi((int)((double)bmp.xPelsPerMeter * 0.0254), 
> (int)((double)bmp.yPelsPerMeter * 0.0254));
> +            img.setDpi(
> +               Math.round((float)((double)bmp.xPelsPerMeter * 0.0254)),
> +               Math.round((float)((double)bmp.yPelsPerMeter * 0.0254)));
> +            System.out.println("bmp dpiX is " + img.getDpiX());
>              img.setOriginalType(Image.ORIGINAL_BMP);
>              return img;
>          }
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> Buy the iText book: http://itext.ugent.be/itext-in-action/
> 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to