Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-5378

Slow rendering due to rescaling

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.0.25
    • None
    • None
    • None

    Description

      Due to changes for better image quality when images are scaled down in https://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?r1=1877290&r2=1877289&pathrev=1877290 the attached PDF renders much slower.

      I propose to replace image.gerScaledInstance by

      public BufferedImage getRescaledImage( BufferedImage image, int w, int h ) throws IOException {
       float scaleW = w / (( float )image.getWidth());
       float scaleH = h / (( float )image.getHeight());
       if(scaleW < .5f || scaleH < .5f){
        int nextW = scaleW <.5f ? ( int )Math.ceil( image.getWidth() / 2.0 ) : w;
        int nextH = scaleH <.5f ? ( int )Math.ceil( image.getHeight() / 2.0 ) : h;
        image = getRescaledImage( image, nextW, nextH );
       }
       int type = (image.getTransparency() == Transparency.OPAQUE) ?  BufferedImage.TYPE_INT_RGB
       : BufferedImage.TYPE_INT_ARGB;
       BufferedImage scaled = new BufferedImage( w, h, type );
       Graphics2D g = scaled.createGraphics();
       g.setRenderingHint( RenderingHints.KEY_INTERPOLATION,  RenderingHints.VALUE_INTERPOLATION_BILINEAR );
       g.drawImage( image, 0, 0, w, h, null );
       return scaled;
      }

      While this implementations seems to be a bit slower than getScaledInstance, the call to graphics.drawImage with the resulting BufferedImage seems to be significantly faster than drawing the ToolkitImage.

      Attachments

        1. PDFBOX-4516-new.png
          146 kB
          Tilman Hausherr
        2. PDFBOX-4516-old.png
          161 kB
          Tilman Hausherr
        3. Test_2.pdf
          1.21 MB
          Oliver Schmidtmer

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Schmidor Oliver Schmidtmer
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: