[ 
https://issues.apache.org/jira/browse/IMAGING-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16887865#comment-16887865
 ] 

Bruno P. Kinoshita edited comment on IMAGING-231 at 7/19/19 2:58 AM:
---------------------------------------------------------------------

Issue reproduced. And indeed seems to be related to LZW. Code used to reproduce 
it:
{code:java}
package org.apache.commons.imaging;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TTT {

    public static void main(String[] args) throws Exception {
        File f = new File("/home/kinow/Downloads/imaging/image_pages/A4.tiff");
        ImageInfo imageInfo = Imaging.getImageInfo(f);
        Map<String, Object> params = new HashMap<>();
        if (imageInfo.getNumberOfImages() > 1) {

            List<BufferedImage> allBufferedImages = 
Imaging.getAllBufferedImages(f);

            for (BufferedImage bufferedImage : allBufferedImages) {
                //appendImagePage(bufferedImage);
                Imaging.writeImage(bufferedImage, new File(f.getParent(), "" + 
System.nanoTime()), ImageFormats.PNG,
                        new HashMap<>());
            }

        } else {
            //appendImagePage(Imaging.getBufferedImage(imageBytes));
            System.out.println("SINGLE PAGE!");
            BufferedImage bufferedImage = Imaging.getBufferedImage(f, params);
            Imaging.writeImage(bufferedImage, new File(f.getParent(), "" + 
System.nanoTime()), ImageFormats.TIFF,
                    new HashMap<>());
        }
    }
}
{code}
Tested with ImageIO.write with the result BufferedReader, and got the same 
issue. So the issue is not in our writer.

Tested with [ngageoint/tiff-java|[https://github.com/ngageoint/tiff-java]] 
using just their LZW decoder, and got exact same image... so our LZW is 
probably correct (or both incorrect).

Looked at the output of exiftool, and found nothing clearly wrong.

So it could still be something before the writer and decompressor, like the way 
we read the data.

Thanks for the good issue description and the attachments. Hopefully we will 
find what is wrong and include the fix in the next release.

Cheers

Bruno


was (Author: kinow):
Issue reproduced. And indeed seems to be related to LZW. Code used to reproduce 
it:
{code:java}
package org.apache.commons.imaging;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TTT {

    public static void main(String[] args) throws Exception {
        File f = new File("/home/kinow/Downloads/imaging/image_pages/A4.tiff");
        ImageInfo imageInfo = Imaging.getImageInfo(f);
        Map<String, Object> params = new HashMap<>();
        if (imageInfo.getNumberOfImages() > 1) {

            List<BufferedImage> allBufferedImages = 
Imaging.getAllBufferedImages(f);

            for (BufferedImage bufferedImage : allBufferedImages) {
                //appendImagePage(bufferedImage);
                Imaging.writeImage(bufferedImage, new File(f.getParent(), "" + 
System.nanoTime()), ImageFormats.PNG,
                        new HashMap<>());
            }

        } else {
            //appendImagePage(Imaging.getBufferedImage(imageBytes));
            System.out.println("SINGLE PAGE!");
            BufferedImage bufferedImage = Imaging.getBufferedImage(f, params);
            Imaging.writeImage(bufferedImage, new File(f.getParent(), "" + 
System.nanoTime()), ImageFormats.TIFF,
                    new HashMap<>());
        }
    }
}
{code}
Tested with ImageIO.write with the result BufferedReader, and got the same 
issue. So the issue is not in our writer.

Tested with [ngageoint/tiff-java|[https://github.com/ngageoint/tiff-java],] 
using just their LZW decoder, and got exact same image... so our LZW is 
probably correct (or both incorrect).

Looked at the output of exiftool, and found nothing clearly wrong.

So it could still be something before the writer and decompressor, like the way 
we read the data.

Thanks for the good issue description and the attachments. Hopefully we will 
find what is wrong and include the fix in the next release.

Cheers

Bruno

> Reading tiff with LZW compression results in mangled image
> ----------------------------------------------------------
>
>                 Key: IMAGING-231
>                 URL: https://issues.apache.org/jira/browse/IMAGING-231
>             Project: Commons Imaging
>          Issue Type: Bug
>          Components: Format: TIFF
>    Affects Versions: 1.0-alpha1
>            Reporter: Jimmy Merrild Krag
>            Priority: Major
>         Attachments: image_pages.zip, result.pdf
>
>
> I am trying to create a PDF using PDFbox with Commons Imaging for loading 
> images. Commons imaging fixes most of the issues I have with the 
> alternatives, but still cannot load my tiff files correctly.
> I have attached a resulting PDF as {{result.pdf}}.
>  The files I use for testing, are attached in {{image_pages.zip}}. The 
> tiff-files, which are not loaded correctly, are LZW-compressed, and that is 
> the only difference I can find in the format.
> All images look the same if I save them to separate image files in another 
> format, as they do in the PDF, so PDFbox does not seem to be the one to 
> blame. My code for reading the files is pretty straightforward:
>  
> {code:java}
> ImageInfo imageInfo = Imaging.getImageInfo(imageBytes);
> if (imageInfo.getNumberOfImages() > 1) {
>     List<BufferedImage> allBufferedImages = 
> Imaging.getAllBufferedImages(imageBytes);
>     for (BufferedImage bufferedImage : allBufferedImages) {
>         appendImagePage(bufferedImage);
>     }
> } else {
>     appendImagePage(Imaging.getBufferedImage(imageBytes));
> }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to