Package org.apache.xmlgraphics.image.codec.tiff

Examples of org.apache.xmlgraphics.image.codec.tiff.TIFFEncodeParam


    }

    /** {@inheritDoc} */
    public void writeImage(RenderedImage image, OutputStream out,
            ImageWriterParams params) throws IOException {
        TIFFEncodeParam encodeParams = createTIFFEncodeParams(params);
        TIFFImageEncoder encoder = new TIFFImageEncoder(out, encodeParams);
        encoder.encode(image);
    }
View Full Code Here


        TIFFImageEncoder encoder = new TIFFImageEncoder(out, encodeParams);
        encoder.encode(image);
    }

    private TIFFEncodeParam createTIFFEncodeParams(ImageWriterParams params) {
        TIFFEncodeParam encodeParams = new TIFFEncodeParam();
        if (params == null) {
            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
        } else {
            if (params.getCompressionMethod() == null) {
                //PackBits as default
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
            } else if ("PackBits".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
            } else if ("NONE".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
            } else if ("Deflate".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
            } else {
                throw new UnsupportedOperationException("Compression method not supported: "
                        + params.getCompressionMethod());
            }

            if (params.getResolution() != null) {
                // Set target resolution
                float pixSzMM = 25.4f / params.getResolution().floatValue();
                // num Pixs in 100 Meters
                int numPix = (int)(((1000 * 100) / pixSzMM) + 0.5);
                int denom = 100 * 100// Centimeters per 100 Meters;
                long [] rational = {numPix, denom};
                TIFFField [] fields = {
                    new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT,
                                  TIFFField.TIFF_SHORT, 1,
                                  new char[] {(char)3}),
                    new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION,
                                  TIFFField.TIFF_RATIONAL, 1,
                                  new long[][] {rational}),
                    new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION,
                                  TIFFField.TIFF_RATIONAL, 1,
                                  new long[][] {rational})
                        };
                encodeParams.setExtraFields(fields);
            }
        }
        return encodeParams;
    }
View Full Code Here

    /**
     * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream, ImageWriterParams)
     */
    public void writeImage(RenderedImage image, OutputStream out,
            ImageWriterParams params) throws IOException {
        TIFFEncodeParam encodeParams = createTIFFEncodeParams(params);
        TIFFImageEncoder encoder = new TIFFImageEncoder(out, encodeParams);
        encoder.encode(image);
    }
View Full Code Here

        TIFFImageEncoder encoder = new TIFFImageEncoder(out, encodeParams);
        encoder.encode(image);
    }

    private TIFFEncodeParam createTIFFEncodeParams(ImageWriterParams params) {
        TIFFEncodeParam encodeParams = new TIFFEncodeParam();
        if (params.getCompressionMethod() == null) {
            //PackBits as default
            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
        } else if ("PackBits".equalsIgnoreCase(params.getCompressionMethod())) {
            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
        } else if ("NONE".equalsIgnoreCase(params.getCompressionMethod())) {
            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
        } else if ("JPEG".equalsIgnoreCase(params.getCompressionMethod())) {
            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_JPEG_TTN2);
        } else if ("Deflate".equalsIgnoreCase(params.getCompressionMethod())) {
            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
        } else {
            throw new UnsupportedOperationException("Compression method not supported: "
                    + params.getCompressionMethod());
        }
       
        if (params.getResolution() != null) {
            // Set target resolution
            float pixSzMM = 25.4f / params.getResolution().floatValue();
            // num Pixs in 100 Meters
            int numPix = (int)(((1000 * 100) / pixSzMM) + 0.5);
            int denom = 100 * 100// Centimeters per 100 Meters;
            long [] rational = {numPix, denom};
            TIFFField [] fields = {
                new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT,
                              TIFFField.TIFF_SHORT, 1,
                              new char[] {(char)3}),
                new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION,
                              TIFFField.TIFF_RATIONAL, 1,
                              new long[][] {rational}),
                new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION,
                              TIFFField.TIFF_RATIONAL, 1,
                              new long[][] {rational})
                    };
            encodeParams.setExtraFields(fields);
        }
        return encodeParams;
    }
View Full Code Here

    /**
     * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream, ImageWriterParams)
     */
    public void writeImage(RenderedImage image, OutputStream out,
            ImageWriterParams params) throws IOException {
        TIFFEncodeParam encodeParams = createTIFFEncodeParams(params);
        updateParams(encodeParams, params, image);
        TIFFImageEncoder encoder = new TIFFImageEncoder(out, encodeParams);
        encoder.encode(image);
    }
View Full Code Here

            encodeParams.setJPEGEncodeParam(jpegParam);
        }
    }

    private TIFFEncodeParam createTIFFEncodeParams(ImageWriterParams params) {
        TIFFEncodeParam encodeParams = new TIFFEncodeParam();
        if (params == null) {
            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
        } else {
            if (params.getCompressionMethod() == null) {
                //PackBits as default
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
            } else if ("PackBits".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
            } else if ("NONE".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
            } else if ("JPEG".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_JPEG_TTN2);
            } else if ("Deflate".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
            } else {
                throw new UnsupportedOperationException("Compression method not supported: "
                        + params.getCompressionMethod());
            }
           
            if (params.getResolution() != null) {
                // Set target resolution
                float pixSzMM = 25.4f / params.getResolution().floatValue();
                // num Pixs in 100 Meters
                int numPix = (int)(((1000 * 100) / pixSzMM) + 0.5);
                int denom = 100 * 100// Centimeters per 100 Meters;
                long [] rational = {numPix, denom};
                TIFFField [] fields = {
                    new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT,
                                  TIFFField.TIFF_SHORT, 1,
                                  new char[] {(char)3}),
                    new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION,
                                  TIFFField.TIFF_RATIONAL, 1,
                                  new long[][] {rational}),
                    new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION,
                                  TIFFField.TIFF_RATIONAL, 1,
                                  new long[][] {rational})
                        };
                encodeParams.setExtraFields(fields);
            }
        }
        return encodeParams;
    }
View Full Code Here

        File outfile = new File(filename);
        OutputStream fos = createFile(outfile);
        if (fos == null) {
            return;
        }
        TIFFEncodeParam param = new TIFFEncodeParam();
        TIFFImageEncoder encoder = new TIFFImageEncoder(fos, param);
        try {
            encoder.encode(image);
        } catch (IOException e) {
            JMeterUtils.reportErrorToUser("TIFFImageEncoder reported: "+e.getMessage(), "Problem creating image file");
View Full Code Here

    /**
     * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream, ImageWriterParams)
     */
    public void writeImage(RenderedImage image, OutputStream out,
            ImageWriterParams params) throws IOException {
        TIFFEncodeParam encodeParams = createTIFFEncodeParams(params);
        updateParams(encodeParams, params, image);
        TIFFImageEncoder encoder = new TIFFImageEncoder(out, encodeParams);
        encoder.encode(image);
    }
View Full Code Here

            encodeParams.setJPEGEncodeParam(jpegParam);
        }
    }

    private TIFFEncodeParam createTIFFEncodeParams(ImageWriterParams params) {
        TIFFEncodeParam encodeParams = new TIFFEncodeParam();
        if (params == null) {
            encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
        } else {
            if (params.getCompressionMethod() == null) {
                //PackBits as default
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
            } else if ("PackBits".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
            } else if ("NONE".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
            } else if ("JPEG".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_JPEG_TTN2);
            } else if ("Deflate".equalsIgnoreCase(params.getCompressionMethod())) {
                encodeParams.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
            } else {
                throw new UnsupportedOperationException("Compression method not supported: "
                        + params.getCompressionMethod());
            }

            if (params.getResolution() != null) {
                // Set target resolution
                float pixSzMM = 25.4f / params.getResolution().floatValue();
                // num Pixs in 100 Meters
                int numPix = (int)(((1000 * 100) / pixSzMM) + 0.5);
                int denom = 100 * 100// Centimeters per 100 Meters;
                long [] rational = {numPix, denom};
                TIFFField [] fields = {
                    new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT,
                                  TIFFField.TIFF_SHORT, 1,
                                  new char[] {(char)3}),
                    new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION,
                                  TIFFField.TIFF_RATIONAL, 1,
                                  new long[][] {rational}),
                    new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION,
                                  TIFFField.TIFF_RATIONAL, 1,
                                  new long[][] {rational})
                        };
                encodeParams.setExtraFields(fields);
            }
        }
        return encodeParams;
    }
View Full Code Here

        return MIME_TYPE;
    }

    /** Creates TIFF renderer. */
    public TIFFRenderer() {
        renderParams = new TIFFEncodeParam();
        //Default to packbits compression which is widely supported
        renderParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
    }
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.image.codec.tiff.TIFFEncodeParam

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.