本文整理汇总了Java中ar.com.hjg.pngj.chunks.PngChunkPLTE类的典型用法代码示例。如果您正苦于以下问题:Java PngChunkPLTE类的具体用法?Java PngChunkPLTE怎么用?Java PngChunkPLTE使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PngChunkPLTE类属于ar.com.hjg.pngj.chunks包,在下文中一共展示了PngChunkPLTE类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: palette2rgb
import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入依赖的package包/类
private static int[] palette2rgb(IImageLine line, PngChunkPLTE pal, PngChunkTRNS trns, int[] buf,
boolean alphaForced) {
boolean isalpha = trns != null;
int channels = isalpha ? 4 : 3;
ImageLineInt linei = (ImageLineInt) (line instanceof ImageLineInt ? line : null);
ImageLineByte lineb = (ImageLineByte) (line instanceof ImageLineByte ? line : null);
boolean isbyte = lineb != null;
int cols = linei != null ? linei.imgInfo.cols : lineb.imgInfo.cols;
int nsamples = cols * channels;
if (buf == null || buf.length < nsamples)
buf = new int[nsamples];
int nindexesWithAlpha = trns != null ? trns.getPalletteAlpha().length : 0;
for (int c = 0; c < cols; c++) {
int index = isbyte ? (lineb.scanline[c] & 0xFF) : linei.scanline[c];
pal.getEntryRgb(index, buf, c * channels);
if (isalpha) {
int alpha = index < nindexesWithAlpha ? trns.getPalletteAlpha()[index] : 255;
buf[c * channels + 3] = alpha;
}
}
return buf;
}
开发者ID:4142,项目名称:audio2png,代码行数:23,代码来源:ImageLineHelper.java
示例2: lineToARGB32
import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入依赖的package包/类
/**
* Warning: the line should be upscaled, see {@link #scaleUp(IImageLineArray)}
*/
static int[] lineToARGB32(ImageLineByte line, PngChunkPLTE pal, PngChunkTRNS trns, int[] buf) {
boolean alphachannel = line.imgInfo.alpha;
int cols = line.getImageInfo().cols;
if (buf == null || buf.length < cols)
buf = new int[cols];
int index, rgb, alpha, ga, g;
if (line.getImageInfo().indexed) {// palette
int nindexesWithAlpha = trns != null ? trns.getPalletteAlpha().length : 0;
for (int c = 0; c < cols; c++) {
index = line.scanline[c] & 0xFF;
rgb = pal.getEntry(index);
alpha = index < nindexesWithAlpha ? trns.getPalletteAlpha()[index] : 255;
buf[c] = (alpha << 24) | rgb;
}
} else if (line.imgInfo.greyscale) { // gray
ga = trns != null ? trns.getGray() : -1;
for (int c = 0, c2 = 0; c < cols; c++) {
g = (line.scanline[c2++] & 0xFF);
alpha = alphachannel ? line.scanline[c2++] & 0xFF : (g != ga ? 255 : 0);
buf[c] = (alpha << 24) | g | (g << 8) | (g << 16);
}
} else { // true color
ga = trns != null ? trns.getRGB888() : -1;
for (int c = 0, c2 = 0; c < cols; c++) {
rgb =
((line.scanline[c2++] & 0xFF) << 16) | ((line.scanline[c2++] & 0xFF) << 8)
| (line.scanline[c2++] & 0xFF);
alpha = alphachannel ? line.scanline[c2++] & 0xFF : (rgb != ga ? 255 : 0);
buf[c] = (alpha << 24) | rgb;
}
}
return buf;
}
开发者ID:4142,项目名称:audio2png,代码行数:37,代码来源:ImageLineHelper.java
示例3: lineToRGB888
import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入依赖的package包/类
static byte[] lineToRGB888(ImageLineByte line, PngChunkPLTE pal, byte[] buf) {
boolean alphachannel = line.imgInfo.alpha;
int cols = line.imgInfo.cols;
int bytes = cols * 3;
if (buf == null || buf.length < bytes)
buf = new byte[bytes];
byte val;
int[] rgb = new int[3];
if (line.imgInfo.indexed) {// palette
for (int c = 0, b = 0; c < cols; c++) {
pal.getEntryRgb(line.scanline[c] & 0xFF, rgb);
buf[b++] = (byte) rgb[0];
buf[b++] = (byte) rgb[1];
buf[b++] = (byte) rgb[2];
}
} else if (line.imgInfo.greyscale) { //
for (int c = 0, b = 0; b < bytes; ) {
val = line.scanline[c++];
buf[b++] = val;
buf[b++] = val;
buf[b++] = val;
if (alphachannel)
c++; // skip alpha
}
} else { // true color
if (!alphachannel) // same format!
System.arraycopy(line.scanline, 0, buf, 0, bytes);
else {
for (int c = 0, b = 0; b < bytes; ) {
buf[b++] = line.scanline[c++];
buf[b++] = line.scanline[c++];
buf[b++] = line.scanline[c++];
c++;// skip alpha
}
}
}
return buf;
}
开发者ID:4142,项目名称:audio2png,代码行数:39,代码来源:ImageLineHelper.java
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: lineToRGBA8888
import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入依赖的package包/类
/**
* Warning: the line should be upscaled, see {@link #scaleUp(IImageLineArray)}
*/
static byte[] lineToRGBA8888(ImageLineByte line, PngChunkPLTE pal, PngChunkTRNS trns, byte[] buf) {
boolean alphachannel = line.imgInfo.alpha;
int cols = line.imgInfo.cols;
int bytes = cols * 4;
if (buf == null || buf.length < bytes)
buf = new byte[bytes];
int index, rgb, ga;
byte val;
if (line.imgInfo.indexed) {// palette
int nindexesWithAlpha = trns != null ? trns.getPalletteAlpha().length : 0;
for (int c = 0, b = 0; c < cols; c++) {
index = line.scanline[c] & 0xFF;
rgb = pal.getEntry(index);
buf[b++] = (byte) ((rgb >> 16) & 0xFF);
buf[b++] = (byte) ((rgb >> 8) & 0xFF);
buf[b++] = (byte) (rgb & 0xFF);
buf[b++] = (byte) (index < nindexesWithAlpha ? trns.getPalletteAlpha()[index] : 255);
}
} else if (line.imgInfo.greyscale) { //
ga = trns != null ? trns.getGray() : -1;
for (int c = 0, b = 0; b < bytes; ) {
val = line.scanline[c++];
buf[b++] = val;
buf[b++] = val;
buf[b++] = val;
buf[b++] =
alphachannel ? line.scanline[c++] : ((int) (val & 0xFF) == ga) ? (byte) 0 : (byte) 255;
}
} else { // true color
if (alphachannel) // same format!
System.arraycopy(line.scanline, 0, buf, 0, bytes);
else {
for (int c = 0, b = 0; b < bytes; ) {
buf[b++] = line.scanline[c++];
buf[b++] = line.scanline[c++];
buf[b++] = line.scanline[c++];
buf[b++] = (byte) (255); // tentative (probable)
if (trns != null && buf[b - 3] == (byte) trns.getRGB()[0]
&& buf[b - 2] == (byte) trns.getRGB()[1] && buf[b - 1] == (byte) trns.getRGB()[2]) // not
// very
// efficient,
// but
// not
// frecuent
buf[b - 1] = 0;
}
}
}
return buf;
}
开发者ID:4142,项目名称:audio2png,代码行数:54,代码来源:ImageLineHelper.java
示例9: convert2rgba
import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入依赖的package包/类
/**
* this is not very efficient, only for tests and troubleshooting
*/
public static int[] convert2rgba(IImageLineArray line, PngChunkPLTE pal, PngChunkTRNS trns,
int[] buf) {
ImageInfo imi = line.getImageInfo();
int nsamples = imi.cols * 4;
if (buf == null || buf.length < nsamples)
buf = new int[nsamples];
int maxval = imi.bitDepth == 16 ? (1 << 16) - 1 : 255;
Arrays.fill(buf, maxval);
if (imi.indexed) {
int tlen = trns != null ? trns.getPalletteAlpha().length : 0;
for (int s = 0; s < imi.cols; s++) {
int index = line.getElem(s);
pal.getEntryRgb(index, buf, s * 4);
if (index < tlen) {
buf[s * 4 + 3] = trns.getPalletteAlpha()[index];
}
}
} else if (imi.greyscale) {
int[] unpack = null;
if (imi.bitDepth < 8)
unpack = ImageLineHelper.DEPTH_UNPACK[imi.bitDepth];
for (int s = 0, i = 0, p = 0; p < imi.cols; p++) {
buf[s++] = unpack != null ? unpack[line.getElem(i++)] : line.getElem(i++);
buf[s] = buf[s - 1];
s++;
buf[s] = buf[s - 1];
s++;
if (imi.channels == 2)
buf[s++] = unpack != null ? unpack[line.getElem(i++)] : line.getElem(i++);
else
buf[s++] = maxval;
}
} else {
for (int s = 0, i = 0, p = 0; p < imi.cols; p++) {
buf[s++] = line.getElem(i++);
buf[s++] = line.getElem(i++);
buf[s++] = line.getElem(i++);
buf[s++] = imi.alpha ? line.getElem(i++) : maxval;
}
}
return buf;
}
开发者ID:4142,项目名称:audio2png,代码行数:47,代码来源:ImageLineHelper.java
示例10: 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
示例11: 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
示例12: palette2rgba
import ar.com.hjg.pngj.chunks.PngChunkPLTE; //导入依赖的package包/类
/**
* Same as palette2rgbx , but returns rgba always, even if trns is null
*
* @param line ImageLine as returned from PngReader
* @param pal Palette chunk
* @param trns Transparency chunk, can be null (absent)
* @param buf Preallocated array, optional
* @return R G B (A), one sample 0-255 per array element. Ready for pngw.writeRowInt()
*/
public static int[] palette2rgba(ImageLineInt line, PngChunkPLTE pal, PngChunkTRNS trns, int[] buf) {
return palette2rgb(line, pal, trns, buf, true);
}
开发者ID:4142,项目名称:audio2png,代码行数:13,代码来源:ImageLineHelper.java
注:本文中的ar.com.hjg.pngj.chunks.PngChunkPLTE类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论