当前位置: 首页>>代码示例>>Java>>正文


Java PngChunkPLTE.setEntry方法代码示例

本文整理汇总了Java中ar.com.hjg.pngj.chunks.PngChunkPLTE.setEntry方法的典型用法代码示例。如果您正苦于以下问题:Java PngChunkPLTE.setEntry方法的具体用法?Java PngChunkPLTE.setEntry怎么用?Java PngChunkPLTE.setEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ar.com.hjg.pngj.chunks.PngChunkPLTE的用法示例。


在下文中一共展示了PngChunkPLTE.setEntry方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: timePNGJEncode

import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入方法依赖的package包/类
@Test
public void timePNGJEncode() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ColorModel colorModel = image.getColorModel();
    boolean indexed = colorModel instanceof IndexColorModel;
    boolean hasAlpha = colorModel.hasAlpha();
    boolean grayscale = !indexed && colorModel.getNumColorComponents() == 1;
    ImageInfo ii = new ImageInfo(image.getWidth(), image.getHeight(), 8, hasAlpha, grayscale,
            indexed);
    PngWriter pw = new PngWriter(bos, ii);
    pw.setCompLevel(4);
    // pw.setDeflaterStrategy(Deflater.NO_COMPRESSION);
    pw.setFilterType(ar.com.hjg.pngj.FilterType.getByVal(filterType.getType()));

    if (indexed) {
        IndexColorModel icm = (IndexColorModel) colorModel;
        PngChunkPLTE palette = pw.getMetadata().createPLTEChunk();
        int ncolors = icm.getNumComponents();
        palette.setNentries(ncolors);
        for (int i = 0; i < ncolors; i++) {
            palette.setEntry(i, icm.getRed(i), icm.getGreen(i), icm.getBlue(i));
        }
        if (icm.hasAlpha()) {
            PngChunkTRNS transparent = new PngChunkTRNS(ii);
            int[] alpha = new int[ncolors];
            for (int i = 0; i < ncolors; i++) {
                alpha[i] = icm.getAlpha(i);
            }
            transparent.setPalletteAlpha(alpha);
            pw.getChunksList().queue(transparent);

        }
    }

    ScanlineProvider scanlines = ScanlineProviderFactory.getProvider(image);
    for (int row = 0; row < image.getHeight(); row++) {
        pw.writeRow(scanlines);

    }
    pw.end();
    byte[] png = bos.toByteArray();
    collectPng("pngj", png);
}
 
开发者ID:aaime,项目名称:png-experiments,代码行数:44,代码来源:BufferedImageEncodingBenchmark.java

示例2: timePNGJEncode

import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入方法依赖的package包/类
public void timePNGJEncode(ar.com.hjg.pngj.FilterType filterType, String name) throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ColorModel colorModel = image.getColorModel();
    boolean indexed = colorModel instanceof IndexColorModel;
    boolean hasAlpha = colorModel.hasAlpha();
    boolean grayscale = !indexed && colorModel.getNumColorComponents() == 1;
    ImageInfo ii = new ImageInfo(image.getWidth(), image.getHeight(), 8, hasAlpha, grayscale,
            indexed);
    PngWriter pw = new PngWriter(bos, ii);
    pw.setCompLevel(compression);
    pw.setFilterType(filterType);

    if (indexed) {
        IndexColorModel icm = (IndexColorModel) colorModel;
        PngChunkPLTE palette = pw.getMetadata().createPLTEChunk();
        int ncolors = icm.getNumComponents();
        palette.setNentries(ncolors);
        for (int i = 0; i < ncolors; i++) {
            palette.setEntry(i, icm.getRed(i), icm.getGreen(i), icm.getBlue(i));
        }
        if (icm.hasAlpha()) {
            PngChunkTRNS transparent = new PngChunkTRNS(ii);
            int[] alpha = new int[ncolors];
            for (int i = 0; i < ncolors; i++) {
                alpha[i] = icm.getAlpha(i);
            }
            transparent.setPalletteAlpha(alpha);
            pw.getChunksList().queue(transparent);

        }
    }

    ScanlineProvider scanlines = ScanlineProviderFactory.getProvider(image);
    for (int row = 0; row < image.getHeight(); row++) {
        pw.writeRow(scanlines);
    }
    pw.end();
    byte[] png = bos.toByteArray();
    collectPng(name, png);
}
 
开发者ID:aaime,项目名称:png-experiments,代码行数:41,代码来源:SamplesEncodingBenchmark.java

示例3: encodeIndexedPNG

import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入方法依赖的package包/类
public byte [] encodeIndexedPNG (int [] pixels, int width, int height, boolean color, int bits) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    int [] palette = getPalette();

    boolean alpha = Color.alpha(palette[0]) == 0;
    boolean grayscale = !color;
    //Log.d(TAG, "encodeIndexedPNG: color = "+color +", alpha ="+alpha+", grayscale = "+grayscale);

    //ImageInfo imageInfo = new ImageInfo(width, height, bits, alpha, grayscale, color);
    ImageInfo imageInfo = new ImageInfo(width, height, bits, false, grayscale, color);
    PngWriter writer = new PngWriter(bos, imageInfo);
    writer.getPixelsWriter().setDeflaterCompLevel(9);

    if (color) {
        PngChunkPLTE paletteChunk = writer.getMetadata().createPLTEChunk();
        paletteChunk.setNentries(palette.length);

        for (int i = 0; i < palette.length; i++) {
            int c = palette[i];
            paletteChunk.setEntry(i, Color.red(c), Color.green(c), Color.blue(c));
        }
    }

    if (alpha) {
        PngChunkTRNS trnsChunk = writer.getMetadata().createTRNSChunk();
        if (color) {
            trnsChunk.setIndexEntryAsTransparent(0);
        } else {
            trnsChunk.setGray(1);
        }
    }
    else {
        quantize(pixels, imageInfo.cols);
    }
    ImageLineInt line = new ImageLineInt(imageInfo);
    for (int y = 0; y < imageInfo.rows; y++) {
        int [] lineData = line.getScanline();
        for (int x = 0; x < imageInfo.cols; x++) {
            int pixel = pixels[y * imageInfo.cols + x];
            //lineData[x] = getNearestColorIndex(pixel) ^ (x % 2) ^ (y % 2);
            lineData[x] = getNearestColorIndex(pixel);
        }
        writer.writeRow(line);
    }

    writer.end();
    return bos.toByteArray();
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:50,代码来源:SimpleImageEncoder.java

示例4: encodeIndexedPNG

import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入方法依赖的package包/类
public byte [] encodeIndexedPNG (int [] pixels, int width, int height, boolean color, int bits) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    int [] palette = getPalette();

    boolean alpha = Color.alpha(palette[0]) == 0;
    boolean grayscale = !color;
    //Log.d(TAG, "encodeIndexedPNG: color = "+color +", alpha ="+alpha+", grayscale = "+grayscale);

    //ImageInfo imageInfo = new ImageInfo(width, height, bits, alpha, grayscale, color);
    ImageInfo imageInfo = new ImageInfo(width, height, bits, false, grayscale, color);
    PngWriter writer = new PngWriter(bos, imageInfo);
    writer.getPixelsWriter().setDeflaterCompLevel(9);

    if (color) {
        PngChunkPLTE paletteChunk = writer.getMetadata().createPLTEChunk();
        paletteChunk.setNentries(palette.length);

        for (int i = 0; i < palette.length; i++) {
            int c = palette[i];
            paletteChunk.setEntry(i, Color.red(c), Color.green(c), Color.blue(c));
        }
    }

    if (alpha) {
        PngChunkTRNS trnsChunk = writer.getMetadata().createTRNSChunk();
        if (color) {
            trnsChunk.setIndexEntryAsTransparent(0);
        } else {
            trnsChunk.setGray(1);
        }
    }
    else {
        quantize(pixels, imageInfo.cols);
    }
    ImageLineInt line = new ImageLineInt(imageInfo);
    for (int y = 0; y < imageInfo.rows; y++) {
        int [] lineData = line.getScanline();
        for (int x = 0; x < imageInfo.cols; x++) {
            int pixel = pixels[y * imageInfo.cols + x];

            lineData[x] = getNearestColorIndex(pixel);
        }
        writer.writeRow(line);
    }

    writer.end();
    return bos.toByteArray();
}
 
开发者ID:StephenBlackWasAlreadyTaken,项目名称:xDrip-Experimental,代码行数:50,代码来源:SimpleImageEncoder.java

示例5: roundTripPNGJ

import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入方法依赖的package包/类
private void roundTripPNGJ(BufferedImage original, RenderedImage source) throws IOException {
    ColorModel colorModel = source.getColorModel();
    boolean indexed = colorModel instanceof IndexColorModel;
    boolean hasAlpha = colorModel.hasAlpha();
    ScanlineProvider scanlines = ScanlineProviderFactory.getProvider(source);
    int numColorComponents = colorModel.getNumColorComponents();
    boolean grayscale = !indexed && numColorComponents < 3;
    byte bitDepth = scanlines.getBitDepth();
    ImageInfo ii = new ImageInfo(source.getWidth(), source.getHeight(), bitDepth, hasAlpha, grayscale,
            indexed);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PngWriter pw = new PngWriter(bos, ii);
    pw.setCompLevel(4);
    pw.setFilterType(ar.com.hjg.pngj.FilterType.FILTER_NONE);

    if (indexed) {
        IndexColorModel icm = (IndexColorModel) colorModel;
        PngChunkPLTE palette = pw.getMetadata().createPLTEChunk();
        int ncolors = icm.getMapSize();
        palette.setNentries(ncolors);
        for (int i = 0; i < ncolors; i++) {
            final int red = icm.getRed(i);
            final int green = icm.getGreen(i);
            final int blue = icm.getBlue(i);
            palette.setEntry(i, red, green, blue);
        }
        if (icm.hasAlpha()) {
            PngChunkTRNS transparent = new PngChunkTRNS(ii);
            int[] alpha = new int[ncolors];
            for (int i = 0; i < ncolors; i++) {
                final int a = icm.getAlpha(i);
                alpha[i] = a;
            }
            transparent.setPalletteAlpha(alpha);
            pw.getChunksList().queue(transparent);

        }
    }

    for (int row = 0; row < source.getHeight(); row++) {
        pw.writeRow(scanlines);
    }
    pw.end();

    byte[] bytes = bos.toByteArray();
    writeToFile(new File("./target/roundTripNone", sourceFile.getName()), bytes);

    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    BufferedImage image = ImageIO.read(bis);

    assertEquals(original.getWidth(), image.getWidth());
    assertEquals(original.getHeight(), image.getHeight());
    // we cannot match in output the image types generated by the CLIB reader, they are not
    // really matching the PNG data model
    if(!clibAvailable) {
        assertEquals(original.getSampleModel(), image.getSampleModel());
        assertEquals(original.getColorModel(), image.getColorModel());
    }

    for (int x = 0; x < original.getWidth(); x++) {
        for (int y = 0; y < original.getHeight(); y++) {
            int rgbOriginal = original.getRGB(x, y);
            int rgbActual = image.getRGB(x, y);
            assertEquals("Comparison failed at " + x + "," + y, rgbOriginal, rgbActual);
        }
    }
}
 
开发者ID:aaime,项目名称:png-experiments,代码行数:68,代码来源:PngSuiteImagesTest.java

示例6: timePNGJEncode

import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入方法依赖的package包/类
@Test
    public void timePNGJEncode() throws Exception {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ColorModel colorModel = image.getColorModel();
        boolean indexed = colorModel instanceof IndexColorModel;
        boolean hasAlpha = colorModel.hasAlpha();
        boolean grayscale = !indexed && colorModel.getNumColorComponents() == 1;
        ImageInfo ii = new ImageInfo(image.getWidth(), image.getHeight(), 8, hasAlpha, grayscale,
                indexed);
        PngWriter pw = new PngWriter(bos, ii);
        pw.setCompLevel(compression);
//       pw.setDeflaterStrategy(Deflater.NO_COMPRESSION);
        pw.setFilterType(filterType);

        if (indexed) {
            IndexColorModel icm = (IndexColorModel) colorModel;
            PngChunkPLTE palette = pw.getMetadata().createPLTEChunk();
            int ncolors = icm.getNumComponents();
            palette.setNentries(ncolors);
            for (int i = 0; i < ncolors; i++) {
                palette.setEntry(i, icm.getRed(i), icm.getGreen(i), icm.getBlue(i));
            }
            if (icm.hasAlpha()) {
                PngChunkTRNS transparent = new PngChunkTRNS(ii);
                int[] alpha = new int[ncolors];
                for (int i = 0; i < ncolors; i++) {
                    alpha[i] = icm.getAlpha(i);
                }
                transparent.setPalletteAlpha(alpha);
                pw.getChunksList().queue(transparent);

            }
        }

        ScanlineProvider scanlines = ScanlineProviderFactory.getProvider(image);
        for (int row = 0; row < image.getHeight(); row++) {
            pw.writeRow(scanlines);

        }
        pw.end();
        byte[] png = bos.toByteArray();
        collectPng("pngj", png);
    }
 
开发者ID:aaime,项目名称:png-experiments,代码行数:44,代码来源:PNJEncodingBenchmark.java


注:本文中的ar.com.hjg.pngj.chunks.PngChunkPLTE.setEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。