public class PngWriter extends Object
Modifier and Type | Field and Description |
---|---|
protected int |
currentChunkGroup
Current chunk grounp, (0-6) already written or currently writing (this is advanced when just starting to write the
new group, not when finalizing the previous)
|
protected StringBuilder |
debuginfo |
ImageInfo |
imgInfo |
protected PixelsWriter |
pixelsWriter |
protected int |
rowNum
last writen row number, starting from 0
|
Constructor and Description |
---|
PngWriter(File file,
ImageInfo imgInfo) |
PngWriter(File file,
ImageInfo imgInfo,
boolean allowoverwrite)
Opens a file for writing.
|
PngWriter(OutputStream outputStream,
ImageInfo imgInfo)
Constructs a new PngWriter from a output stream.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes and releases resources
|
double |
computeCompressionRatio()
Computes compressed size/raw size, approximate.
|
void |
copyChunksFrom(ChunksList chunks)
Copy all chunks from origin.
|
void |
copyChunksFrom(ChunksList chunks,
ChunkPredicate predicate)
Copy chunks from origin depending on some
ChunkPredicate |
void |
copyChunksFrom(ChunksList chunks,
int copyMask)
Sets an origin (typically from a
PngReader ) of Chunks to be copied. |
protected PixelsWriter |
createPixelsWriter(ImageInfo imginfo)
Factory method for pixels writer.
|
void |
end()
Finalizes all the steps and closes the stream.
|
ChunksListForWrite |
getChunksList()
returns the chunks list (queued and writen chunks)
|
String |
getDebuginfo() |
PngMetadata |
getMetadata()
Retruns a high level wrapper over for metadata handling
|
PixelsWriter |
getPixelsWriter() |
void |
queueChunk(PngChunk chunk)
Queues an ancillary chunk for writing.
|
void |
setCompLevel(int complevel)
This is kept for backwards compatibility, now the PixelsWriter object should be used for setting
compression/filtering options
|
void |
setFilterPreserve(boolean filterPreserve) |
void |
setFilterType(FilterType filterType)
Sets internal prediction filter type, or strategy to choose it.
|
void |
setIdatMaxSize(int idatMaxSize)
Sets maximum size of IDAT fragments.
|
void |
setShouldCloseStream(boolean shouldCloseStream)
If true, output stream will be closed after ending write
|
void |
writeRow(IImageLine imgline)
Writes next row, does not check row number.
|
void |
writeRow(IImageLine imgline,
int rownumber) |
void |
writeRowInt(int[] buf)
Utility method, uses internaly a ImageLineInt
|
void |
writeRows(IImageLineSet<? extends IImageLine> imglines)
Writes the full set of row.
|
public final ImageInfo imgInfo
protected int rowNum
protected int currentChunkGroup
see ChunksList
protected PixelsWriter pixelsWriter
protected StringBuilder debuginfo
public PngWriter(File file, ImageInfo imgInfo, boolean allowoverwrite)
Sets shouldCloseStream=true. For more info see PngWriter(OutputStream, ImageInfo)
file
- imgInfo
- allowoverwrite
- If false and file exists, an PngjOutputException
is thrownpublic PngWriter(File file, ImageInfo imgInfo)
(overwrite=true)
public PngWriter(OutputStream outputStream, ImageInfo imgInfo)
outputStream
- Open stream for binary writingimgInfo
- Basic image parameterspublic void queueChunk(PngChunk chunk)
If a "equivalent" chunk is already queued (see {@link ChunkHelper#equivalent(PngChunk, PngChunk)), this overwrites it.
The chunk will be written as late as possible, unless the priority is set.
chunk
- public void copyChunksFrom(ChunksList chunks, int copyMask)
PngReader
) of Chunks to be copied. This should be called only once, before
starting writing the rows. It doesn't matter the current state of the PngReader reading, this is a live object and
what matters is that when the writer writes the pixels (IDAT) the reader has already read them, and that when the
writer ends, the reader is already ended (all this is very natural).
Apart from the copyMask, there is some addional heuristics:
- The chunks will be queued, but will be written as late as possible (unless you explicitly set priority=true)
- The chunk will not be queued if an "equivalent" chunk was already queued explicitly. And it will be overwriten another is queued explicitly.
chunks
- copyMask
- Some bitmask from ChunkCopyBehaviour
copyChunksFrom(ChunksList, ChunkPredicate)
public void copyChunksFrom(ChunksList chunks)
copyChunksFrom(ChunksList, int)
for more infopublic void copyChunksFrom(ChunksList chunks, ChunkPredicate predicate)
ChunkPredicate
chunks
- predicate
- The chunks (ancillary or PLTE) will be copied if and only if predicate matchesfor more info
public double computeCompressionRatio()
Actually: compressed size = total size of IDAT data , raw size = uncompressed pixel bytes = rows * (bytesPerRow + 1). This must be called after pngw.end()
public void end()
public void close()
This is normally called internally from end()
, you should only call this for aborting the writing and
release resources (close the stream).
Idempotent and secure - never throws exceptions
public ChunksListForWrite getChunksList()
public PngMetadata getMetadata()
public void setFilterType(FilterType filterType)
This must be called just after constructor, before starting writing.
public void setCompLevel(int complevel)
compLevel
- between 0 (no compression, max speed) and 9 (max compression)PixelsWriter#setCompressionFactor(double)
public void setFilterPreserve(boolean filterPreserve)
public void setIdatMaxSize(int idatMaxSize)
idatMaxSize
- default=0 : use defaultSize (32K)public void setShouldCloseStream(boolean shouldCloseStream)
default=true
public void writeRow(IImageLine imgline)
imgline
- public void writeRows(IImageLineSet<? extends IImageLine> imglines)
public void writeRow(IImageLine imgline, int rownumber)
public void writeRowInt(int[] buf)
protected PixelsWriter createPixelsWriter(ImageInfo imginfo)
imginfo
- Might be different than that of this object (eg: APNG with subimages)os
- Output streampublic final PixelsWriter getPixelsWriter()
public String getDebuginfo()
Copyright © 2014. All rights reserved.