public class PngWriter extends Object
| Modifier and Type | Field and Description |
|---|---|
protected int |
currentChunkGroup
Current chunk grounp, (0-6) already read or reading
|
protected boolean |
filterPreserve
If the ImageLine has a valid filterType (and origin image is not
interlaced) that file type will be used.
|
protected IFilterWriteStrategy |
filterStrat
PNG filter strategy
|
ImageInfo |
imgInfo |
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. |
void |
end()
Finalizes all the steps and closes the stream.
|
ChunksListForWrite |
getChunksList()
returns the chunks list (queued and writen chunks)
|
PngMetadata |
getMetadata()
Retruns a high level wrapper over for metadata handling
|
boolean |
isFilterPreserve() |
void |
queueChunk(PngChunk chunk) |
void |
setCompLevel(int compLevel)
Sets compression level of ZIP algorithm.
|
void |
setDeflaterStrategy(int deflaterStrategy)
Deflater strategy: one of Deflater.FILTERED Deflater.HUFFMAN_ONLY
Deflater.DEFAULT_STRATEGY
|
void |
setFilterPreserve(boolean filterPreserve) |
void |
setFilterStrategy(IFilterWriteStrategy filterS)
Set an alternative strategy for selecting the prediction filter
|
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 IFilterWriteStrategy filterStrat
protected boolean filterPreserve
Default: false
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)
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 ChunkCopyBehaviourcopyChunksFrom(ChunksList, ChunkPredicate)public void copyChunksFrom(ChunksList chunks)
copyChunksFrom(ChunksList, int)
for more infopublic void copyChunksFrom(ChunksList chunks, ChunkPredicate predicate)
ChunkPredicatechunks - predicate - The chunks (ancillary or PLTE) will be copied if and only if
predicate matchesfor more infopublic 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 setCompLevel(int compLevel)
This must be called just after constructor, before starting writing.
See also setFilterType()
compLevel - between 0 and 9 (default:6 , recommended: 6 or more)public void setFilterType(FilterType filterType)
This must be called just after constructor, before starting writing.
See also setFilterStrategy setCompLevel()
filterType - One of the five prediction types or strategy to choose it (see
PngFilterType) Recommended values: DEFAULT
(default) or AGGRESIVEpublic void setFilterStrategy(IFilterWriteStrategy filterS)
filterS - public boolean isFilterPreserve()
filterPreservepublic void setFilterPreserve(boolean filterPreserve)
filterPreservepublic void setIdatMaxSize(int idatMaxSize)
idatMaxSize - default=0 : use defaultSize (64K)public void setShouldCloseStream(boolean shouldCloseStream)
default=true
public void setDeflaterStrategy(int deflaterStrategy)
Default: Deflater.FILTERED (for filter NONE usually DEFAULT_STRATEGY is a little better
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)
Copyright © 2013. All rights reserved.