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

PDDeviceRGB.toRGBImage should return a RGB-Typed-Image

    XMLWordPrintableJSON

Details

    Description

      While converting a PDPage to a BufferedImage (using the PDFRenderer) Images-Resources located in the PDPage gets loaded in a WriteableRaster and a given Colorspace.

      These get converted to a BufferedImage (with PDDeviceRGB.toRGBImage()). But the Type of the returing BufferedImage is with the given Raster and Colorspace always from Type "BufferedImage.TYPE_CUSTOM" instead of the expected "BufferedImage.TYPE_INT_RGB" for example.

      Consequences:
      Image-Processing-Operations with/on BufferedImages with TYPE_CUSTOM are not optimized in Java (slower) and partialy runs through "Synchronized" Blocks.
      ==> Converting different Documents in different Threads are blocking each other.

      "Quick"-Fix for seeing a Performance-Improvement in a Multithreading Environment:

      PDDeviceRGB.java
      @Override
      public BufferedImage toRGBImage(WritableRaster raster) throws IOException {
      	init();
      	ColorModel colorModel = new ComponentColorModel(awtColorSpace, false, false, Transparency.OPAQUE,
      			raster.getDataBuffer().getDataType());
      
      	BufferedImage image = new BufferedImage(colorModel, raster, false, null);
      
      	BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
      	ColorConvertOp op = new ColorConvertOp(dest.getColorModel().getColorSpace(), null);
      	return op.filter(image, dest);
      }
      

      Attachments

        1. rgbImageExample0.pdf
          87 kB
          Yannick Haser
        2. Starter.java
          2 kB
          Yannick Haser
        3. Starter2.java
          2 kB
          Yannick Haser
        4. rgbImageSecondExample.pdf
          168 kB
          Yannick Haser

        Issue Links

          Activity

            People

              tilman Tilman Hausherr
              YaHa Yannick Haser
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: