Package org.apache.commons.imaging.common

Examples of org.apache.commons.imaging.common.ImageBuilder


        final int nColumnsOfTiles = (width + tileWidth - 1) / tileWidth;

        final int x0 = col0 * tileWidth;
        final int y0 = row0 * tileLength;
       
        final ImageBuilder workingBuilder =
                new ImageBuilder(workingWidth, workingHeight, false);
       
        for (int iRow = row0; iRow <= row1; iRow++) {
            for (int iCol = col0; iCol <= col1; iCol++) {
                final int tile = iRow * nColumnsOfTiles + iCol;
                final byte[] compressed = imageData.tiles[tile].getData();
                final byte[] decompressed = decompress(compressed, compression,
                        bytesPerTile, tileWidth, tileLength);
                x = iCol * tileWidth - x0;
                y = iRow * tileLength - y0;
                interpretTile(workingBuilder, decompressed, x, y, workingWidth, workingHeight);
            }
        }
  
        if (subImage.x == x0
                && subImage.y == y0
                && subImage.width == workingWidth
                && subImage.height == workingHeight) {
            return workingBuilder.getBufferedImage();
        }
        return workingBuilder.getSubimage(
            subImage.x - x0,
            subImage.y - y0,
            subImage.width,
            subImage.height);
    }
View Full Code Here


                }
            } else {
                imageData = imageElement.data;
            }

            final ImageBuilder imageBuilder = new ImageBuilder(imageType.getWidth(),
                    imageType.getHeight(), true);
            switch (imageType.getBitsPerPixel()) {
            case 1:
                decode1BPPImage(imageType, imageData, imageBuilder);
                break;
            case 4:
                decode4BPPImage(imageType, imageData, imageBuilder);
                break;
            case 8:
                decode8BPPImage(imageType, imageData, imageBuilder);
                break;
            case 32:
                decode32BPPImage(imageType, imageData, imageBuilder);
                break;
            default:
                throw new ImageReadException("Unsupported bit depth " + imageType.getBitsPerPixel());
            }

            if (maskElement != null) {
                if (maskType.getBitsPerPixel() == 1) {
                    apply1BPPMask(maskElement.data, imageBuilder);
                } else if (maskType.getBitsPerPixel() == 8) {
                    apply8BPPMask(maskElement.data, imageBuilder);
                } else {
                    throw new ImageReadException("Unsupport mask bit depth " + maskType.getBitsPerPixel());
                }
            }

            result.add(imageBuilder.getBufferedImage());
        }
        return result;
    }
View Full Code Here

        BufferedImage result = null;
        if (subImage != null) {
            result = dataReader.readImageData(subImage);
        } else {
            final boolean hasAlpha = false;
            final ImageBuilder imageBuilder = new ImageBuilder(width, height, hasAlpha);

            dataReader.readImageData(imageBuilder);
            result =  imageBuilder.getBufferedImage();
        }
        return result;    
    }
View Full Code Here

            final int width = info.width;
            final int height = info.height;

            final boolean hasAlpha = info.hasAlpha();
            final ImageBuilder imageBuilder = new ImageBuilder(width, height,
                    hasAlpha);
            info.readImage(imageBuilder, is);

            final BufferedImage ret = imageBuilder.getBufferedImage();
            canThrow = true;
            return ret;
        } finally {
            IoUtils.closeQuietly(canThrow, is);
        }
View Full Code Here

        final int yLimit = subImage.y - y0 + subImage.height;


        // TO DO: we can probably save some processing by using yLimit instead
        //        or working
        final ImageBuilder workingBuilder =
                new ImageBuilder(width, workingHeight, false);

        for (int strip = strip0; strip <= strip1; strip++) {
            final long rowsPerStripLong = 0xFFFFffffL & rowsPerStrip;
            final long rowsRemaining = height - (strip * rowsPerStripLong);
            final long rowsInThisStrip = Math.min(rowsRemaining, rowsPerStripLong);
            final long bytesPerRow = (bitsPerPixel * width + 7) / 8;
            final long bytesPerStrip = rowsInThisStrip * bytesPerRow;
            final long pixelsPerStrip = rowsInThisStrip * width;

            final byte[] compressed = imageData.strips[strip].getData();

            final byte[] decompressed = decompress(compressed, compression,
                    (int) bytesPerStrip, width, (int) rowsInThisStrip);

            interpretStrip(
                    workingBuilder,
                    decompressed,
                    (int) pixelsPerStrip,
                    yLimit);
        }

        if (subImage.x == 0
                && subImage.y == y0
                && subImage.width == width
                && subImage.height == workingHeight) {
            // the subimage exactly matches the ImageBuilder bounds
            return workingBuilder.getBufferedImage();
        }
        return workingBuilder.getSubimage(
                subImage.x,
                subImage.y - y0,
                subImage.width,
                subImage.height);     
    }
View Full Code Here

            System.out.println("width*height: " + width * height);
            System.out.println("width*height*4: " + width * height * 4);
        }

        final PixelParser pixelParser = ic.pixelParser;
        final ImageBuilder imageBuilder = new ImageBuilder(width, height, true);
        pixelParser.processImage(imageBuilder);

        return imageBuilder.getBufferedImage();

    }
View Full Code Here

        boolean hasAlpha = false;
        if (gce != null && gce.transparency) {
            hasAlpha = true;
        }

        final ImageBuilder imageBuilder = new ImageBuilder(width, height, hasAlpha);

        int[] colorTable;
        if (id.localColorTable != null) {
            colorTable = getColorTable(id.localColorTable);
        } else if (imageContents.globalColorTable != null) {
            colorTable = getColorTable(imageContents.globalColorTable);
        } else {
            throw new ImageReadException("Gif: No Color Table");
        }

        int transparentIndex = -1;
        if (hasAlpha) {
            transparentIndex = gce.transparentColorIndex;
        }

        int counter = 0;

        final int rowsInPass1 = (height + 7) / 8;
        final int rowsInPass2 = (height + 3) / 8;
        final int rowsInPass3 = (height + 1) / 4;
        final int rowsInPass4 = (height) / 2;

        for (int row = 0; row < height; row++) {
            int y;
            if (id.interlaceFlag) {
                int theRow = row;
                if (theRow < rowsInPass1) {
                    y = theRow * 8;
                } else {
                    theRow -= rowsInPass1;
                    if (theRow < (rowsInPass2)) {
                        y = 4 + (theRow * 8);
                    } else {
                        theRow -= rowsInPass2;
                        if (theRow < (rowsInPass3)) {
                            y = 2 + (theRow * 4);
                        } else {
                            theRow -= rowsInPass3;
                            if (theRow < (rowsInPass4)) {
                                y = 1 + (theRow * 2);
                            } else {
                                throw new ImageReadException("Gif: Strange Row");
                            }
                        }
                    }
                }
            } else {
                y = row;
            }

            for (int x = 0; x < width; x++) {
                final int index = 0xff & id.imageData[counter++];
                int rgb = colorTable[index];

                if (transparentIndex == index) {
                    rgb = 0x00;
                }

                imageBuilder.setRGB(x, y, rgb);
            }

        }

        return imageBuilder.getBufferedImage();

    }
View Full Code Here

TOP

Related Classes of org.apache.commons.imaging.common.ImageBuilder

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.