JBIG2 with SWT.image support

Help
Peter M
2014-05-12
2014-05-12
  • Peter M

    Peter M - 2014-05-12

    Hi, I noticed JBIG2 does'nt support SWT images? Could you add the following lines to "JBIG2Decoder.java" (i think the license permits it) for the next release?

    public Image getPageAsImage(int page) {
        page++;
        JBIG2Bitmap pageBitmap = streamDecoder.findPageSegement(page).getPageBitmap();
    
        byte[] bytes = pageBitmap.getData(true);
    
        if (bytes == null)
            return null;
    
        // make a a DEEP copy so we cant alter
        //int len = bytes.length;
        //byte[] copy = new byte[len];
        // memory inefficient on large images,
        // with several images it leads to poor performance
        // although it is fast if only for a few images. 
        //System.arraycopy(bytes, 0, copy, 0, len);
    
        byte[] copy = bytes.clone();
    
        int width = pageBitmap.getWidth();
        int height = pageBitmap.getHeight();
    
        PaletteData palette = new PaletteData(0xFF0000, 0x00FF00, 0x0000FF);
        ImageData imageData = new ImageData(width,height,24,palette); 
        imageData.setPixels(0, 0, width*height,copy, 0);
    
        return new Image(Display.getDefault(), imageData);;
    }
    

    I have not tested the code.

    Best, Peter

     
  • Elfi Heck

    Elfi Heck - 2014-05-12

    Uhm, no, sorry. For various reasons.

    • we don't want to modify 3rd party libraries if we don't absolutely have to (because of actual bugs)
    • we don't want to introduce dependencies on SWT into a decoder library
    • nothing we do in jPod renderer needs such a method

    You're free to add this method in your own copy of JBIG2 Image Decoder.

     
  • Peter M

    Peter M - 2014-05-12

    Ok, now i see (in JBIG2Filter). Thanks.

     

Log in to post a comment.