Package org.apache.commons.imaging

Examples of org.apache.commons.imaging.ImageWriteException


            params.remove(PARAM_KEY_FORMAT);
        }

        if (!params.isEmpty()) {
            final Object firstKey = params.keySet().iterator().next();
            throw new ImageWriteException("Unknown parameter: " + firstKey);
        }

        IcnsType imageType;
        if (src.getWidth() == 16 && src.getHeight() == 16) {
            imageType = IcnsType.ICNS_16x16_32BIT_IMAGE;
        } else if (src.getWidth() == 32 && src.getHeight() == 32) {
            imageType = IcnsType.ICNS_32x32_32BIT_IMAGE;
        } else if (src.getWidth() == 48 && src.getHeight() == 48) {
            imageType = IcnsType.ICNS_48x48_32BIT_IMAGE;
        } else if (src.getWidth() == 128 && src.getHeight() == 128) {
            imageType = IcnsType.ICNS_128x128_32BIT_IMAGE;
        } else {
            throw new ImageWriteException("Invalid/unsupported source width "
                    + src.getWidth() + " and height " + src.getHeight());
        }

        final BinaryOutputStream bos = new BinaryOutputStream(os,
                ByteOrder.BIG_ENDIAN);
View Full Code Here


            }
        }

        final List<JFIFPiece> result = new ArrayList<JFIFPiece>(segments);
        if (firstAppIndex == -1) {
            throw new ImageWriteException("JPEG file has no APP segments.");
        }
        result.addAll(firstAppIndex, newSegments);
        return result;
    }
View Full Code Here

        }

        final List<JFIFPiece> result = new ArrayList<JFIFPiece>(segments);
        if (lastAppIndex == -1) {
            if (segments.size() < 1) {
                throw new ImageWriteException("JPEG file has no APP segments.");
            }
            result.addAll(1, newSegments);
        } else {
            result.addAll(lastAppIndex + 1, newSegments);
        }
View Full Code Here

        final List<IptcBlock> blocks = data.getRawBlocks();
        for (IptcBlock block : blocks) {
            bos.write4Bytes(JpegConstants.CONST_8BIM);

            if (block.blockType < 0 || block.blockType > 0xffff) {
                throw new ImageWriteException("Invalid IPTC block type.");
            }
            bos.write2Bytes(block.blockType);

            if (block.blockNameBytes.length > 255) {
                throw new ImageWriteException("IPTC block name is too long: "
                        + block.blockNameBytes.length);
            }
            bos.write(block.blockNameBytes.length);
            bos.write(block.blockNameBytes);
            if (block.blockNameBytes.length % 2 == 0) {
                bos.write(0); // pad to even size, including length byte.
            }

            if (block.blockData.length > IptcConstants.IPTC_NON_EXTENDED_RECORD_MAXIMUM_SIZE) {
                throw new ImageWriteException("IPTC block data is too long: "
                        + block.blockData.length);
            }
            bos.write4Bytes(block.blockData.length);
            bos.write(block.blockData);
            if (block.blockData.length % 2 == 1) {
View Full Code Here

                bos.write(IptcConstants.IPTC_RECORD_TAG_MARKER);
                bos.write(IptcConstants.IPTC_APPLICATION_2_RECORD_NUMBER);
                if (element.iptcType.getType() < 0
                        || element.iptcType.getType() > 0xff) {
                    throw new ImageWriteException("Invalid record type: "
                            + element.iptcType.getType());
                }
                bos.write(element.iptcType.getType());

                final byte[] recordData = element.value.getBytes("ISO-8859-1");
                if (!new String(recordData, "ISO-8859-1").equals(element.value)) {
                    throw new ImageWriteException(
                            "Invalid record value, not ISO-8859-1");
                }

                bos.write2Bytes(recordData.length);
                bos.write(recordData);
View Full Code Here

            palette[i] = colorGroup.getMedianValue();

            colorGroup.paletteIndex = i;

            if (colorGroup.colorCounts.size() < 1) {
                throw new ImageWriteException("empty color_group: "
                        + colorGroup);
            }
        }

        if (paletteSize > discreteColors) {
            throw new ImageWriteException("palette_size > discrete_colors");
        }

        return new MedianCutPalette(root, palette);
    }
View Full Code Here

    public ColorGroup(final List<ColorCount> colorCounts, final boolean ignoreAlpha) throws ImageWriteException {
        this.colorCounts = colorCounts;
        this.ignoreAlpha = ignoreAlpha;

        if (colorCounts.size() < 1) {
            throw new ImageWriteException("empty color_group");
        }

        int total = 0;
        for (ColorCount color : colorCounts) {
            total += color.count;
View Full Code Here

            params.remove(PARAM_KEY_FORMAT);
        }

        if (!params.isEmpty()) {
            final Object firstKey = params.keySet().iterator().next();
            throw new ImageWriteException("Unknown parameter: " + firstKey);
        }

        writeMultiByteInteger(os, 0); // typeField
        os.write(0); // fixHeaderField
        writeMultiByteInteger(os, src.getWidth());
View Full Code Here

            pixelDensity = (PixelDensity) params
                    .remove(PARAM_KEY_PIXEL_DENSITY);
        }
        if (!params.isEmpty()) {
            final Object firstKey = params.keySet().iterator().next();
            throw new ImageWriteException("Unknown parameter: " + firstKey);
        }

        final SimplePalette palette = new PaletteFactory().makeExactRgbPaletteSimple(
                src, 256);
View Full Code Here

                final double number = numbers[i];
                rationalNumbers[i] = RationalNumber.valueOf(number);
            }
            return ByteConversions.toBytes(rationalNumbers, byteOrder);
        } else {
            throw new ImageWriteException("Invalid data", o);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.imaging.ImageWriteException

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.