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

Tilman Hausherr commented on PDFBOX-6151:
-----------------------------------------

If anyone wants to work on this, here's the test code:
{code:java}
    @Test
    public void testSerenity() throws IOException, JBIG2Exception
    {
        String dir = "XXXXXXXX";
        File zipFile = new File(dir, "serenity-jbig2-files.zip");
        Bitmap expectedBitmap = getBitmap(zipFile);
        // alternatively:
        // 
https://github.com/user-attachments/files/24440663/serenity-jbig2-files.zip
        InputStream is = new FileInputStream(zipFile);
        ZipInputStream zis = new ZipInputStream(is);
        ZipEntry ze;
        while ((ze = zis.getNextEntry()) != null)
        {
            if (ze.isDirectory() || !ze.getName().endsWith(".jbig2"))
            {
                continue;
            }
            final ImageInputStream imageIIS = 
ImageIO.createImageInputStream(zis);
            try
            {
                String filename = ze.getName().substring(0, 
ze.getName().length() - 6) + ".png";
                File file = new File(dir, filename);
                file.delete();
                final JBIG2Document doc = new JBIG2Document(imageIIS);
                final JBIG2Page page = doc.getPage(1);
                Bitmap bitmap = page.getBitmap();
                if (!bitmap.equals(expectedBitmap))
                {
                    ImageIO.write(Bitmaps.asBufferedImage(bitmap), "png", file);
                    System.err.println("unequal: " + ze.getName());
                }
                else
                    System.out.println("equal  : " + ze.getName());
                // Assert.assertEquals(expectedBitmap, bitmap);
            }
            catch (Exception ex)
            {
                System.err.println("threw " + ex.getClass().getName() + ": " + 
ze.getName() + ": " + ex.getMessage());
                ex.printStackTrace();
            }
            imageIIS.close();
        }
        zis.close();
        is.close();
    }

    private Bitmap getBitmap(File file) throws IOException, JBIG2Exception
    {
        // get the "perfect" image
        ZipFile zipFile = new ZipFile(file);
        InputStream is = 
zipFile.getInputStream(zipFile.getEntry("bitmap.jbig2"));
        final ImageInputStream imageIIS = ImageIO.createImageInputStream(is);
        final JBIG2Document doc = new JBIG2Document(imageIIS);
        final JBIG2Page page = doc.getPage(1);
        Bitmap bitmap = page.getBitmap();
        is.close();
        zipFile.close();
        return bitmap;
    }
{code}

> Run serenity JBIG2 tests
> ------------------------
>
>                 Key: PDFBOX-6151
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6151
>             Project: PDFBox
>          Issue Type: Task
>          Components: JBIG2
>    Affects Versions: 3.0.4 JBIG2
>            Reporter: Tilman Hausherr
>            Priority: Minor
>
> Run the jbig2 files from the serenity tests to see what happens.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to