Examples of PngWriter


Examples of ar.com.hjg.pngj.PngWriter

    private ImageInfo imgInfo;
    private PngWriter writer;
   
    public PNGWriter(File outputFile, int cols, int rows) {
      imgInfo = new ImageInfo(cols, rows, 8, false);
      writer = new PngWriter(outputFile, imgInfo, true);
     
      PngMetadata metaData = writer.getMetadata();
      metaData.setTimeNow();
      metaData.setText(PngChunkTextVar.KEY_Software, "OSM2World");
    }
View Full Code Here

Examples of ar.com.hjg.pngj.PngWriter

         * prevent having to allocate a bit pixel array in the first place, but we would need a
         * line-by-line iterator on the sample grid, which is currently not the case.
         */
        int[][] rgba = new int[rows][cols * channels];
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PngWriter pw = new PngWriter(baos, imgInfo);

        pw.getMetadata().setText(PngChunkTextVar.KEY_Software, "OTPA");
        pw.getMetadata().setText(PngChunkTextVar.KEY_Creation_Time, new Date().toString());
        pw.getMetadata().setText(PngChunkTextVar.KEY_Description, "Sample grid bitmap");

        String gridCornerStr = String.format(Locale.US, "%.8f,%.8f", sampleGrid.getCenter().y
                + sampleGrid.getYMin() * sampleGrid.getCellSize().y, sampleGrid.getCenter().x
                + sampleGrid.getXMin() * sampleGrid.getCellSize().x);
        String gridCellSzStr = String.format(Locale.US, "%.12f,%.12f", sampleGrid.getCellSize().y,
                sampleGrid.getCellSize().x);
        String offRoadDistStr = String.format(Locale.US, "%f",
                sampleGridRenderer.getOffRoadDistanceMeters(precisionMeters));

        PngChunkTEXT gridCornerChunk = new PngChunkTEXT(imgInfo);
        gridCornerChunk.setKeyVal(OTPA_GRID_CORNER, gridCornerStr);
        pw.getChunksList().queue(gridCornerChunk);
        PngChunkTEXT gridCellSzChunk = new PngChunkTEXT(imgInfo);
        gridCellSzChunk.setKeyVal(OTPA_GRID_CELL_SIZE, gridCellSzStr);
        pw.getChunksList().queue(gridCellSzChunk);
        PngChunkTEXT offRoadDistChunk = new PngChunkTEXT(imgInfo);
        offRoadDistChunk.setKeyVal(OTPA_OFFROAD_DIST, offRoadDistStr);
        pw.getChunksList().queue(offRoadDistChunk);

        double unit;
        switch (zDataType) {
        case TIME:
            unit = 1.0; // 1:1sec, max 18h
            break;
        case BOARDINGS:
            unit = 1000.0; // 1:0.001 boarding, max 65.5
            break;
        case WALK_DISTANCE:
            unit = 10.0; // 1:0.1m, max 6.55km
            break;
        default:
            throw new IllegalArgumentException("Unsupported Z DataType.");
        }

        for (ZSamplePoint<WTWD> p : sampleGrid) {
            WTWD z = p.getZ();
            int row = p.getY() - sampleGrid.getYMin();
            int col = p.getX() - sampleGrid.getXMin();
            double zz;
            switch (zDataType) {
            case TIME:
                zz = z.wTime / z.w;
                break;
            case BOARDINGS:
                zz = z.wBoardings / z.w;
                break;
            case WALK_DISTANCE:
                zz = z.wWalkDist / z.w;
                break;
            default:
                throw new IllegalArgumentException("Unsupported Z DataType.");
            }
            int iz;
            if (Double.isInfinite(zz)) {
                iz = 65535;
            } else {
                iz = ImageLineHelper.clampTo_0_65535((int) Math.round(zz * unit));
                if (iz == 65535)
                    iz = 65534; // Clamp
            }
            // d is expressed as a percentage of grid size, max 255%.
            // Sometimes d will be bigger than 2.55 x grid size,
            // but this should not be too much important as we are off-bounds.
            int id = ImageLineHelper.clampTo_0_255((int) Math.round(z.d / precisionMeters * 100));
            int offset = col * channels;
            rgba[row][offset + 0] = (iz & 0xFF); // z low 8 bits
            rgba[row][offset + 1] = (iz >> 8); // z high 8 bits
            rgba[row][offset + 2] = id; // d
            /*
             * Keep the alpha channel at 255, otherwise the RGB channel will be downsampled on some
             * rendering clients (namely, JS canvas).
             */
            rgba[row][offset + 3] = 255;
        }
        for (int row = 0; row < rgba.length; row++) {
            ImageLineInt iline = new ImageLineInt(imgInfo, rgba[row]);
            pw.writeRow(iline, row);
        }
        pw.end();

        // Disallow caching on client side
        CacheControl cc = new CacheControl();
        cc.setNoCache(true);
        // Also put the meta-data in the HTML header (easier to read from JS)
View Full Code Here

Examples of com.itextpdf.text.pdf.codec.PngWriter

            wr.writeFile(ms);
            streamContentType = ImageBytesType.CCITT;
            imageBytes = ms.toByteArray();
            return;
        } else {
            PngWriter png = new PngWriter(ms);
            if (decode != null){
                if (pngBitDepth == 1){
                    // if the decode array is 1,0, then we need to invert the image
                    if(decode.getAsNumber(0).intValue() == 1 && decode.getAsNumber(1).intValue() == 0){
                        int len = imageBytes.length;
                        for (int t = 0; t < len; ++t) {
                            imageBytes[t] ^= 0xff;
                        }
                    } else {
                        // if the decode array is 0,1, do nothing.  It's possible that the array could be 0,0 or 1,1 - but that would be silly, so we'll just ignore that case
                    }
                } else {
                    // todo: add decode transformation for other depths
                }
            }
            png.writeHeader(width, height, pngBitDepth, pngColorType);
            if (icc != null)
                png.writeIccProfile(icc);
            if (palette != null)
                png.writePalette(palette);
            png.writeData(imageBytes, stride);
            png.writeEnd();
            streamContentType = ImageBytesType.PNG;
            imageBytes = ms.toByteArray();
        }
    }
View Full Code Here

Examples of com.itextpdf.text.pdf.codec.PngWriter

                wr.addField(new TiffWriter.FieldUndefined(TIFFConstants.TIFFTAG_ICCPROFILE, icc));
            wr.writeFile(ms);
            fileType = TYPE_TIF;
            return ms.toByteArray();
        }
        PngWriter png = new PngWriter(ms);
        png.writeHeader(width, height, pngBitDepth, pngColorType);
        if (icc != null)
            png.writeIccProfile(icc);
        if (palette != null)
            png.writePalette(palette);
        png.writeData(streamBytes, stride);
        png.writeEnd();
        fileType = TYPE_PNG;
        return ms.toByteArray();
    }
View Full Code Here

Examples of com.itextpdf.text.pdf.codec.PngWriter

            wr.writeFile(ms);
            streamContentType = ImageBytesType.CCITT;
            imageBytes = ms.toByteArray();
            return;
        } else {
            PngWriter png = new PngWriter(ms);
            if (decode != null){
                if (pngBitDepth == 1){
                    // if the decode array is 1,0, then we need to invert the image
                    if(decode.getAsNumber(0).intValue() == 1 && decode.getAsNumber(1).intValue() == 0){
                        int len = imageBytes.length;
                        for (int t = 0; t < len; ++t) {
                            imageBytes[t] ^= 0xff;
                        }
                    } else {
                        // if the decode array is 0,1, do nothing.  It's possible that the array could be 0,0 or 1,1 - but that would be silly, so we'll just ignore that case
                    }
                } else {
                    // todo: add decode transformation for other depths
                }
            }
            png.writeHeader(width, height, pngBitDepth, pngColorType);
            if (icc != null)
                png.writeIccProfile(icc);
            if (palette != null)
                png.writePalette(palette);
            png.writeData(imageBytes, stride);
            png.writeEnd();
            streamContentType = ImageBytesType.PNG;
            imageBytes = ms.toByteArray();
        }
    }
View Full Code Here

Examples of com.itextpdf.text.pdf.codec.PngWriter

            wr.writeFile(ms);
            streamContentType = ImageBytesType.CCITT;
            imageBytes = ms.toByteArray();
            return;
        } else {
            PngWriter png = new PngWriter(ms);
            if (decode != null){
                if (pngBitDepth == 1){
                    // if the decode array is 1,0, then we need to invert the image
                    if(decode.getAsNumber(0).intValue() == 1 && decode.getAsNumber(1).intValue() == 0){
                        int len = imageBytes.length;
                        for (int t = 0; t < len; ++t) {
                            imageBytes[t] ^= 0xff;
                        }
                    } else {
                        // if the decode array is 0,1, do nothing.  It's possible that the array could be 0,0 or 1,1 - but that would be silly, so we'll just ignore that case
                    }
                } else {
                    // todo: add decode transformation for other depths
                }
            }
            png.writeHeader(width, height, pngBitDepth, pngColorType);
            if (icc != null)
                png.writeIccProfile(icc);
            if (palette != null)
                png.writePalette(palette);
            png.writeData(imageBytes, stride);
            png.writeEnd();
            streamContentType = ImageBytesType.PNG;
            imageBytes = ms.toByteArray();
        }
    }
View Full Code Here

Examples of it.geosolutions.imageio.plugins.png.PNGWriter

                .produceLegendGraphic(legendGraphicRequest);
        if (legendGraphic instanceof BufferedImageLegendGraphic) {
            BufferedImage image = ((BufferedImageLegendGraphic) legendGraphic)
                    .getLegend();

            PNGWriter writer = new PNGWriter();
            FileOutputStream outStream = null;
            try {
                File sampleFile = new File(sampleLegendFolder.getAbsolutePath() + File.separator +
                        getSampleFileName(style));
                if(!sampleFile.getParentFile().exists()) {
                    sampleFile.getParentFile().mkdirs();
                }
                outStream = new FileOutputStream(sampleFile);
                writer.writePNG(image, outStream, 0.0f, FilterType.FILTER_NONE);
                removeStyleSampleInvalidation(style);
                return new Dimension(image.getWidth(), image.getHeight());
            } finally {
                if(outStream != null) {
                    outStream.close();
View Full Code Here

Examples of it.geosolutions.imageio.plugins.png.PNGWriter

    public RenderedImage writePNG(RenderedImage image, OutputStream outStream, float quality,
            WMSMapContent mapContent) {
        // what kind of scaline filtering are we going to use?
        FilterType filterType = getFilterType(mapContent);
        // Creation of a new PNGWriter object
        PNGWriter writer = new PNGWriter();
        // Check if a Scanline is supported by the writer
        boolean isScanlineSupported = writer.isScanlineSupported(image);
        // If it is not supported, then the image is rescaled to bytes
        if(!isScanlineSupported){
            image = new ImageWorker(image).rescaleToBytes().forceComponentColorModel().getRenderedImage();          
        }
       
        RenderedImage output = null;
        // Image writing
        try {
            output =  writer.writePNG(image, outStream, quality, filterType);
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Failed to encode the PNG", e);
            throw new ServiceException(e);
        }
       
View Full Code Here

Examples of it.geosolutions.imageio.plugins.png.PNGWriter

        // If the new PNGWriter must be disabled then the other writers are used
        if (disablePNG) {
            super.encode(image, destination, aggressiveOutputStreamOptimization, type, map);
        } else {
            // Creation of the associated Writer
            PNGWriter writer = new PNGWriter();
            OutputStream stream = null;
            try {
                // writer = new PNGJWriter();
                // Check if the input object is an OutputStream
                if (destination instanceof OutputStream) {
                    boolean isScanlinePresent = writer.isScanlineSupported(image);
                    if (!isScanlinePresent) {
                        image = new ImageWorker(image).rescaleToBytes().forceComponentColorModel()
                                .getRenderedImage();
                    }
                    Object filterObj = null;
                    if (map != null) {
                        filterObj = map.get(FILTER_TYPE);
                    }
                    FilterType filter = null;
                    if (filterObj == null || !(filterObj instanceof FilterType)) {
                        filter = FilterType.FILTER_NONE;
                    } else {
                        filter = (FilterType) filterObj;
                    }
                    stream = (OutputStream) destination;
                   
                    //Image preparation if an image helper is present
                    WriteHelper helper = getHelper();
                    RenderedImage finalImage = image;
                    if(helper!=null){
                        finalImage = helper.prepareImage(image, type);
                    }                  
                    // Image writing
                    writer.writePNG(finalImage, stream, quality, filter);
                } else {
                    throw new IllegalArgumentException(
                            "Only an OutputStream can be provided to the PNGEncoder");
                }
            } catch (Exception e) {
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.