Package org.apache.sanselan

Examples of org.apache.sanselan.ImageWriteException


            params.remove(PARAM_KEY_FORMAT);

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

        final PaletteFactory paletteFactory = new PaletteFactory();
        final SimplePalette palette = paletteFactory.makePaletteSimple(src, 256);
        final int bitCount;
View Full Code Here


      params.remove(PARAM_KEY_FORMAT);

    if (params.size() > 0)
    {
      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());

    BinaryOutputStream bos = new BinaryOutputStream(os, BYTE_ORDER_BIG_ENDIAN);
    bos.write4Bytes(ICNS_MAGIC);
    bos.write4Bytes(4 + 4 + 4 + 4 + 4*imageType.getWidth()*imageType.getHeight() +
View Full Code Here

                return dstDir;
            }
            catch (ImageReadException e)
            {
                throw new ImageWriteException(e.getMessage(), e);
            }
        }
View Full Code Here

            params.remove(PARAM_KEY_FORMAT);

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

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

            params.remove(PARAM_KEY_FORMAT);

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

        String name = randomName();

        os.write(("#define " + name + "_width " + src.getWidth() + "\n").getBytes("US-ASCII"));
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

        }

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

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

        boolean hasAlpha = new PaletteFactory().hasTransparency(src);

        int max_colors = hasAlpha ? 255 : 256;

        Palette palette2 = new PaletteFactory().makePaletteSimple(src,
                max_colors);
        // int palette[] = new PaletteFactory().makePaletteSimple(src, 256);
        // Map palette_map = paletteToMap(palette);

        if (palette2 == null)
        {
            palette2 = new PaletteFactory().makePaletteQuantized(src,
                    max_colors);
            if (verbose)
                System.out.println("quantizing");
        } else if (verbose)
            System.out.println("exact palette");

        if (palette2 == null)
            throw new ImageWriteException(
                    "Gif: can't write images with more than 256 colors");
        int palette_size = palette2.length() + (hasAlpha ? 1 : 0);

        BinaryOutputStream bos = new BinaryOutputStream(os, BYTE_ORDER_LSB);
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.