本文整理汇总了Java中ar.com.hjg.pngj.ImageLineHelper类的典型用法代码示例。如果您正苦于以下问题:Java ImageLineHelper类的具体用法?Java ImageLineHelper怎么用?Java ImageLineHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageLineHelper类属于ar.com.hjg.pngj包,在下文中一共展示了ImageLineHelper类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: writePngImage
import ar.com.hjg.pngj.ImageLineHelper; //导入依赖的package包/类
/**
* Writes a {@link BufferedImage} to the specified {@link OutputStream} using the PNGJ library
* which is much faster than Java's ImageIO library.
*
* This implementation was copied from
* <a href="https://github.com/leonbloy/pngj/wiki/Snippets">
* https://github.com/leonbloy/pngj/wiki/Snippets
* </a>.
*
* @param bufferedImage image to write.
* @param compressionLevel 0 (no compression) - 9 (max compression)
* @param filterType internal prediction filter type.
* @param outputStream target stream.
*
* @throws IOException
* if the image is not ARGB or it's data buffer contains the wrong number of banks.
*/
public static void writePngImage(final BufferedImage bufferedImage,
final int compressionLevel,
final FilterType filterType,
final OutputStream outputStream)
throws IOException {
if (bufferedImage.getType() != BufferedImage.TYPE_INT_ARGB) {
throw new IOException("invalid image type (" + bufferedImage.getType() +
"), must be BufferedImage.TYPE_INT_ARGB");
}
final ImageInfo imageInfo = new ImageInfo(bufferedImage.getWidth(), bufferedImage.getHeight(), 8, true);
final PngWriter pngWriter = new PngWriter(outputStream, imageInfo);
pngWriter.setCompLevel(compressionLevel);
pngWriter.setFilterType(filterType);
final DataBufferInt dataBuffer =((DataBufferInt) bufferedImage.getRaster().getDataBuffer());
if (dataBuffer.getNumBanks() != 1) {
throw new IOException("invalid number of banks (" + dataBuffer.getNumBanks() + "), must be 1");
}
final SinglePixelPackedSampleModel sampleModel = (SinglePixelPackedSampleModel) bufferedImage.getSampleModel();
final ImageLineInt line = new ImageLineInt(imageInfo);
final int[] data = dataBuffer.getData();
for (int row = 0; row < imageInfo.rows; row++) {
int elem = sampleModel.getOffset(0, row);
for (int col = 0; col < imageInfo.cols; col++) {
final int sample = data[elem++];
ImageLineHelper.setPixelRGBA8(line, col, sample);
}
pngWriter.writeRow(line, row);
}
pngWriter.end();
// // This looked like a nicer option, but only works for DataBufferByte (not DataBufferInt)
// final ImageLineSetARGBbi lines = new ImageLineSetARGBbi(bufferedImage, imageInfo);
// pngWriter.writeRows(lines);
// pngWriter.end();
}
开发者ID:saalfeldlab,项目名称:render,代码行数:58,代码来源:BufferedImageStreamingOutput.java
示例2: convertToPNG
import ar.com.hjg.pngj.ImageLineHelper; //导入依赖的package包/类
public void convertToPNG(Dds dds, OutputStream outputStream, String swizzle) throws IOException {
DdsHeader header = dds.getHeader();
FormatDecoder decoder = Decoders.getDecoder(dds);
ImageInfo imageInfo = new ImageInfo(header.getDwWidth(), header.getDwHeight(), 8, true);
PngWriter pngWriter = new PngWriter(outputStream, imageInfo);
ImageLineInt imageLine = new ImageLineInt(imageInfo);
for (int[] ints : decoder) {
swizzle(ints, swizzle);
ImageLineHelper.setPixelsRGBA8(imageLine, ints);
pngWriter.writeRow(imageLine);
}
pngWriter.end();
}
开发者ID:vincentzhang96,项目名称:DDS4J,代码行数:15,代码来源:DdsImageDecoder.java
示例3: pregenTexture
import ar.com.hjg.pngj.ImageLineHelper; //导入依赖的package包/类
private void pregenTexture(boolean[][] chars) throws IOException {
final int totalChars = this.intervalsTotalSize;
int w = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charW)));
int h = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charH)));
int maxIndexW = (int) Math.floor(((double) w) / ((double) charW)) - 1;
int maxIndexH = (int) Math.floor(((double) h) / ((double) charH)) - 1;
if (w > h) {
System.out.println("w > h");
h = powerOf2((int) (Math.ceil((((double)totalChars)/((double)(maxIndexW))) * charH)));
maxIndexH = (int) Math.floor(((double) h) / ((double) charH)) - 1;
} else {
System.out.println("w <= h");
w = powerOf2((int) (Math.ceil((((double)totalChars)/((double)(maxIndexH))) * charW)));
maxIndexW = (int) Math.floor(((double) w) / ((double) charW)) - 1;
}
// final int h = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charH)));
System.out.println(((int)Math.ceil(Math.sqrt(totalChars) * charW)) + " * " + ((int)Math.ceil(Math.sqrt(totalChars) * charH)) + " --> " + w + " * " + h);
File f = Files.createTempFile("texture-font-", ".png").toFile();
final FileOutputStream outputStream = new FileOutputStream(f);
final ImageInfo imi = new ImageInfo(w, h, 8, true); // 8 bits per channel, alpha
// open image for writing to a output stream
final PngWriter png = new PngWriter(outputStream, imi);
for (int y = 0; y < png.imgInfo.rows; y++) {
ImageLineInt iline = new ImageLineInt(imi);
int[] xValues = new int[imi.cols];
for (int indexX = 0; indexX <= maxIndexW; indexX++) {// this line will be written to all rows
final int charY = (y % charH);
final int indexY = (y - charY)/charH;
final int i = indexY * (maxIndexW+1) + indexX - this.minCharIndex;
boolean[] currentChar;
if (i < totalChars && (currentChar=chars[i]) != null) {
for (int charX = 0; charX < charW; charX++) {
if (i >= 0 & i < totalChars && currentChar != null && currentChar[charX + charY * charW]) {
xValues[indexX * charW + charX] = 0xFFFFFFFF;
}
// ImageLineHelper.setPixelRGBA8(iline, x, color, color, color, color);
}
}
}
ImageLineHelper.setPixelsRGBA8(iline, xValues);
if (y % 10 == 0) {
System.out.println(y + "/" + png.imgInfo.rows);
}
png.writeRow(iline);
}
chars = null;
png.end();
Utils.gc();
try {
memoryWidth = w;
memoryHeight = h;
memoryWidthOfEachColumn = maxIndexW + 1;
textureW = w;
textureH = h;
outputStream.flush();
outputStream.close();
Utils.gc();
this.tmpFont = f;
} catch (GLException | IOException e) {
e.printStackTrace();
}
}
开发者ID:XDrake99,项目名称:WarpPI,代码行数:66,代码来源:GPUFont.java
注:本文中的ar.com.hjg.pngj.ImageLineHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论