Uploaded image for project: 'XMLGraphicsCommons'
  1. XMLGraphicsCommons
  2. XGC-7

NullPointerException in TiffImageWriter if JPEG is chosen for compression

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Fixed
    • 1.2
    • None
    • image writer
    • None
    • Operating System: other
      Platform: Other

    Description

      The following snippet does not work because the parameters are not created
      correctly.

      To be precise:
      1. Define imageParameters with "JPEG" set as encoding
      2. TiffImageWriter#createTIFFEncodeParams(lines 60++) will NOT call
      setJPEGEncodeParam
      3. Eventually TiffImageEncoder gets called and in line 467ff a call to
      TIFFEncodeParam#getJPEGEncodeParam() is done, which returns null => NPE in line
      472 int maxSubH = jep.getHorizontalSubsampling(0);

      The whole class TiffImageWriter seems untested because if i look at the source i
      see in line 46 the method public void writeImage(RenderedImage image,
      OutputStream out) which passes null to as ImageWriterParams to 54:public void
      writeImage(RenderedImage image, OutputStream out,ImageWriterParams params)
      throws IOException , which in turn passed null to 61: private
      TIFFEncodeParam createTIFFEncodeParams(ImageWriterParams params).

      First statement in that method is if (params.getCompressionMethod() == null) ,
      so you will get NPE here too...

      org.apache.xmlgraphics.image.writer.ImageWriter imageWriter = new
      TIFFImageWriter();
      MultiImageWriter writer = null;
      try
      {
      writer = imageWriter.createMultiImageWriter(stream);
      // retrieve writer
      if (imageWriter != null)
      {
      log.info("get image writers parameters");

      ImageWriterParams iwp = new ImageWriterParams();
      iwp.setCompressionMethod("JPEG");
      iwp.setJPEGQuality(compressionQuality, true);
      iwp.setResolution(param.getDpi());

      log.info("render pages");
      for (int pageNumber = fromPageNumber; pageNumber <= toPageNumber; pageNumber++)

      { BufferedImage image; <snip> // do stuff to create image </snip> log.info("write image"); writer.writeImage(image, iwp); }

      }
      catch...
      finally
      writer.close()

      Attachments

        Activity

          People

            general@xmlgraphics.apache.org XML Graphics Project Mailing List
            mark.vollmann@opentext.com Mark Vollmann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: