Package org.apache.sanselan

Examples of org.apache.sanselan.ImageWriteException


    protected void setByteOrder(int a, int b) throws ImageWriteException,
            IOException
    {
        if (a != b)
            throw new ImageWriteException("Byte Order bytes don't match (" + a
                    + ", " + b + ").");

        if (a == BYTE_ORDER_MOTOROLA)
            byteOrder = a;
        else if (a == BYTE_ORDER_INTEL)
            byteOrder = a;
        else
            throw new ImageWriteException("Unknown Byte Order hint: " + a);
    }
View Full Code Here


    private void writeChunkiTXt(OutputStream os, PngText.iTXt text)
            throws IOException, ImageWriteException
    {
        if (!UnicodeUtils.isValidISO_8859_1(text.keyword))
            throw new ImageWriteException(
                    "Png tEXt chunk keyword is not ISO-8859-1: " + text.keyword);
        if (!UnicodeUtils.isValidISO_8859_1(text.languageTag))
            throw new ImageWriteException(
                    "Png tEXt chunk language tag is not ISO-8859-1: "
                            + text.languageTag);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

    private void writeChunkzTXt(OutputStream os, PngText.zTXt text)
            throws IOException, ImageWriteException
    {
        if (!UnicodeUtils.isValidISO_8859_1(text.keyword))
            throw new ImageWriteException(
                    "Png zTXt chunk keyword is not ISO-8859-1: " + text.keyword);
        if (!UnicodeUtils.isValidISO_8859_1(text.text))
            throw new ImageWriteException(
                    "Png zTXt chunk text is not ISO-8859-1: " + text.text);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        // keyword
View Full Code Here

    private void writeChunktEXt(OutputStream os, PngText.tEXt text)
            throws IOException, ImageWriteException
    {
        if (!UnicodeUtils.isValidISO_8859_1(text.keyword))
            throw new ImageWriteException(
                    "Png tEXt chunk keyword is not ISO-8859-1: " + text.keyword);
        if (!UnicodeUtils.isValidISO_8859_1(text.text))
            throw new ImageWriteException(
                    "Png tEXt chunk text is not ISO-8859-1: " + text.text);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        // keyword
View Full Code Here

        if (params.containsKey(PARAM_KEY_PNG_TEXT_CHUNKS))
            params.remove(PARAM_KEY_PNG_TEXT_CHUNKS);
        if (params.size() > 0)
        {
            Object firstKey = params.keySet().iterator().next();
            throw new ImageWriteException("Unknown parameter: " + firstKey);
        }
        params = rawParams;

        int width = src.getWidth();
        int height = src.getHeight();

        boolean hasAlpha = new PaletteFactory().hasTransparency(src);
        if (verbose)
            Debug.debug("hasAlpha", hasAlpha);
        // int transparency = new PaletteFactory().getTransparency(src);

        boolean isGrayscale = new PaletteFactory().isGrayscale(src);
        if (verbose)
            Debug.debug("isGrayscale", isGrayscale);

        byte colorType;
        {
            boolean forceIndexedColor = ParamMap.getParamBoolean(params,
                    PARAM_KEY_PNG_FORCE_INDEXED_COLOR, false);
            boolean forceTrueColor = ParamMap.getParamBoolean(params,
                    PARAM_KEY_PNG_FORCE_TRUE_COLOR, false);

            if (forceIndexedColor && forceTrueColor)
                throw new ImageWriteException(
                        "Params: Cannot force both indexed and true color modes");
            else if (forceIndexedColor)
            {
                colorType = COLOR_TYPE_INDEXED_COLOR;
            } else if (forceTrueColor)
            {
                colorType = (byte) (hasAlpha ? COLOR_TYPE_TRUE_COLOR_WITH_ALPHA
                        : COLOR_TYPE_TRUE_COLOR);
                isGrayscale = false;
            } else
                colorType = getColourType(hasAlpha, isGrayscale);
            if (verbose)
                Debug.debug("colorType", colorType);
        }

        byte bitDepth = getBitDepth(colorType, params);
        if (verbose)
            Debug.debug("bit_depth", bitDepth);

        int sampleDepth;
        if (colorType == COLOR_TYPE_INDEXED_COLOR)
            sampleDepth = 8;
        else
            sampleDepth = bitDepth;
        if (verbose)
            Debug.debug("sample_depth", sampleDepth);

        {
            os.write(PNG_Signature);
        }
        {
            // IHDR must be first

            byte compressionMethod = COMPRESSION_TYPE_INFLATE_DEFLATE;
            byte filterMethod = FILTER_METHOD_ADAPTIVE;
            byte interlaceMethod = INTERLACE_METHOD_NONE;

            ImageHeader imageHeader = new ImageHeader(width, height, bitDepth,
                    colorType, compressionMethod, filterMethod, interlaceMethod);

            writeChunkIHDR(os, imageHeader);
        }

        {
            // sRGB No Before PLTE and IDAT. If the sRGB chunk is present, the
            // iCCP chunk should not be present.

            // charles
        }

        Palette palette = null;
        if (colorType == COLOR_TYPE_INDEXED_COLOR)
        {
            // PLTE No Before first IDAT

            int max_colors = hasAlpha ? 255 : 256;

            palette = new MedianCutQuantizer(true).process(src, max_colors,
                    verbose);
            // Palette palette2 = new PaletteFactory().makePaletteSimple(src,
            // max_colors);

            // palette.dump();

            writeChunkPLTE(os, palette);
        }

        if (params.containsKey(PARAM_KEY_XMP_XML))
        {
            String xmpXml = (String) params.get(PARAM_KEY_XMP_XML);
            writeChunkXmpiTXt(os, xmpXml);
        }

        if (params.containsKey(PARAM_KEY_PNG_TEXT_CHUNKS))
        {
            List outputTexts = (List) params.get(PARAM_KEY_PNG_TEXT_CHUNKS);
            for (int i = 0; i < outputTexts.size(); i++)
            {
                PngText text = (PngText) outputTexts.get(i);
                if (text instanceof PngText.tEXt)
                    writeChunktEXt(os, (PngText.tEXt) text);
                else if (text instanceof PngText.zTXt)
                    writeChunkzTXt(os, (PngText.zTXt) text);
                else if (text instanceof PngText.iTXt)
                    writeChunkiTXt(os, (PngText.iTXt) text);
                else
                    throw new ImageWriteException(
                            "Unknown text to embed in PNG: " + text);
            }
        }

        {
View Full Code Here

                palette[i] = color_group.getMedianValue();

                color_group.palette_index = i;

                if (color_group.color_counts.size() < 1)
                    throw new ImageWriteException("empty color_group: "
                            + color_group);

                //                if(color_group.)
                //                Debug.debug("color_group", color_group);
                //                Debug.debug("palette[" + i + "]", palette[i] + " ("
                //                        + Integer.toHexString(palette[i]) + ")");
            }

            if (palette_size > discrete_colors)
                throw new ImageWriteException("palette_size>discrete_colors");

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

                throws ImageWriteException
        {
            this.color_counts = color_counts;

            if (color_counts.size() < 1)
                throw new ImageWriteException("empty color_group");

            for (int i = 0; i < color_counts.size(); i++)
            {
                ColorCount color = (ColorCount) color_counts.get(i);
View Full Code Here

    public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
            Number number) throws ImageWriteException
    {
        if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
            throw new ImageWriteException("Tag has no default data type.");
        FieldType fieldType = tagInfo.dataTypes[0];

        if (tagInfo.length != 1)
            throw new ImageWriteException("Tag does not expect a single value.");

        byte bytes[] = fieldType.writeData(number, byteOrder);

        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
    }
View Full Code Here

    public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
            Number value[]) throws ImageWriteException
    {
        if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
            throw new ImageWriteException("Tag has no default data type.");
        FieldType fieldType = tagInfo.dataTypes[0];

        if (tagInfo.length != value.length)
            throw new ImageWriteException("Tag does not expect a single value.");

        byte bytes[] = fieldType.writeData(value, byteOrder);

        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType,
                value.length, bytes);
View Full Code Here

        if (tagInfo.dataTypes == null)
            fieldType = FIELD_TYPE_ASCII;
        else if (tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII)
            fieldType = FIELD_TYPE_ASCII;
        else
            throw new ImageWriteException("Tag has unexpected data type.");

        byte bytes[] = fieldType.writeData(value, byteOrder);

        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
    }
View Full Code Here

TOP

Related Classes of org.apache.sanselan.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.