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