Examples of TIFFField


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

            if (dir.isTagPresent(TIFFImageDecoder.TIFF_RESOLUTION_UNIT)) {
                unit = (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_RESOLUTION_UNIT);
            }
            if (unit == 2 || unit == 3) {
                float xRes, yRes;
                TIFFField fldx = dir.getField(TIFFImageDecoder.TIFF_X_RESOLUTION);
                TIFFField fldy = dir.getField(TIFFImageDecoder.TIFF_Y_RESOLUTION);
                if (fldx == null || fldy == null) {
                    unit = 2;
                    xRes = context.getSourceResolution();
                    yRes = xRes;
                } else {
                    xRes = fldx.getAsFloat(0);
                    yRes = fldy.getAsFloat(0);
                }
                if (unit == 2) {
                    size.setResolution(xRes, yRes); //Inch
                } else {
                    size.setResolution(
                            UnitConv.in2mm(xRes) / 10,
                            UnitConv.in2mm(yRes) / 10); //Centimeters
                }
            } else {
                size.setResolution(context.getSourceResolution());
            }
            size.calcSizeFromPixels();
            if (log.isTraceEnabled()) {
                log.trace("TIFF image detected: " + size);
            }

            info = new ImageInfo(uri, MimeConstants.MIME_TIFF);
            info.setSize(size);

            TIFFField fld;

            fld = dir.getField(TIFFImageDecoder.TIFF_COMPRESSION);
            if (fld != null) {
                int compression = fld.getAsInt(0);
                if (log.isTraceEnabled()) {
                    log.trace("TIFF compression: " + compression);
                }
                info.getCustomObjects().put("TIFF_COMPRESSION", new Integer(compression));
            }

            fld = dir.getField(TIFFImageDecoder.TIFF_TILE_WIDTH);
            if (fld != null) {
                if (log.isTraceEnabled()) {
                    log.trace("TIFF is tiled");
                }
                info.getCustomObjects().put("TIFF_TILED", Boolean.TRUE);
            }

            int stripCount;
            fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
            if (fld == null) {
                stripCount = 1;
            } else {
                stripCount = (int)Math.ceil(size.getHeightPx() / (double)fld.getAsLong(0));
            }
            if (log.isTraceEnabled()) {
                log.trace("TIFF has " + stripCount + " strips.");
            }
            info.getCustomObjects().put("TIFF_STRIP_COUNT", new Integer(stripCount));
View Full Code Here

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

        ImageInputStream in = ImageUtil.needImageInputStream(src);
        in.mark();
        try {
            SeekableStream seekable = new SeekableStreamAdapter(in);
            dir = new TIFFDirectory(seekable, 0);
            TIFFField fld;

            fld = dir.getField(TIFFImageDecoder.TIFF_COMPRESSION);
            if (fld != null) {
                compression = fld.getAsInt(0);
                switch (compression) {
                case TIFFImage.COMP_FAX_G3_1D:
                case TIFFImage.COMP_FAX_G3_2D:
                case TIFFImage.COMP_FAX_G4_2D:
                    break;
                default:
                    log.debug("Unsupported compression " + compression);
                    throw new ImageException(
                            "ImageLoader doesn't support TIFF compression: " + compression);
                }
            }
            //Read information used for raw embedding
            fld = dir.getField(TIFFImageDecoder.TIFF_FILL_ORDER);
            if (fld != null) {
                fillOrder = fld.getAsInt(0);
            }

            int stripCount;
            fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
            if (fld == null) {
                stripCount = 1;
            } else {
                stripCount = (int)(info.getSize().getHeightPx() / fld.getAsLong(0));
            }
            if (stripCount > 1) {
                log.debug("More than one strip found in TIFF image.");
                throw new ImageException(
                        "ImageLoader doesn't support multiple strips");
View Full Code Here

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

    protected CachableRed decodeImage(SeekableStream stream) throws IOException {
        org.apache.xmlgraphics.image.codec.tiff.TIFFImage img
            = new org.apache.xmlgraphics.image.codec.tiff.TIFFImage
                (stream, null, 0);
        TIFFDirectory dir = (TIFFDirectory)img.getProperty("tiff_directory");
        TIFFField fld = dir.getField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT);
        int resUnit = fld.getAsInt(0);
        fld = dir.getField(TIFFImageDecoder.TIFF_X_RESOLUTION);
        double xRes = fld.getAsDouble(0);
        fld = dir.getField(TIFFImageDecoder.TIFF_Y_RESOLUTION);
        double yRes = fld.getAsDouble(0);
        switch (resUnit) {
        case 2: //inch
            this.dpiHorizontal = xRes;
            this.dpiVertical = yRes;
            break;
        case 3: //cm
            this.dpiHorizontal = xRes * 2.54f;
            this.dpiVertical = yRes * 2.54f;
            break;
        default:
            //ignored
            log.warn("Cannot determine bitmap resolution."
                    + " Unimplemented resolution unit: " + resUnit);
        }
        fld = dir.getField(TIFFImageDecoder.TIFF_COMPRESSION);
        if (fld != null) {
            compression = fld.getAsInt(0);
        }
        fld = dir.getField(TIFFImageDecoder.TIFF_BITS_PER_SAMPLE);
        if (fld != null) {
            bitsPerPixel = fld.getAsInt(0);
        }
        fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
        if (fld == null) {
            stripCount = 1;
        } else {
            stripCount = (int)(dir.getFieldAsLong(TIFFImageDecoder.TIFF_IMAGE_LENGTH)
                                / fld.getAsLong(0));
        }

        fld = dir.getField(TIFFImageDecoder.TIFF_FILL_ORDER);
        if (fld != null) {
            fillOrder = fld.getAsInt(0);
        }

        stripOffset = dir.getField(TIFFImageDecoder.TIFF_STRIP_OFFSETS).getAsLong(0);
        stripLength = dir.getField(TIFFImageDecoder.TIFF_STRIP_BYTE_COUNTS).getAsLong(0);
       
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.