|
JIU 0.14.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.jiu.ops.Operation
net.sourceforge.jiu.codecs.ImageCodec
net.sourceforge.jiu.codecs.PNGCodec
public class PNGCodec
A codec for the Portable Network Graphics (PNG) format. Supports both loading and saving of images.
ImageLoader
or ToolkitLoader
which require only a single line of code and can load all formats
supported by JIU, including PNG.
PNGCodec codec = new PNGCodec(); codec.setFile("image.png", CodecMode.LOAD); codec.process(); PixelImage image = codec.getImage();
PNGCodec codec = new PNGCodec(); codec.setFile("out.png", CodecMode.SAVE); codec.setImage(image); codec.setCompressionLevel(Deflater.BEST_COMPRESSION); codec.appendComment("Copyright (c) 1992 John Doe"); // sets last modification time to current time codec.setModification(new GregorianCalendar( new SimpleTimeZone(0, "UTC"))); codec.process();
BilevelImage
objects,
2, 4 and 8 bit streams as Gray8Image
and 16 bit as
Gray16Image
objects.Paletted8Image
.RGB24Image
,
48 bit streams as RGB48Image
objects.BilevelImage
objects are stored as grayscale 1 bit PNG streams.Paletted8Image
objects are stored as indexed 8 bit PNG streams.
Images will always be stored as 8 bit files, even if the palette has only 16, 4 or 2 entries.
Gray8Image
objects are stored as 8 bit grayscale PNG streams.Gray16Image
objects are stored as 16 bit grayscale PNG streams.RGB24Image
objects are stored as 24 bit RGB truecolor PNG streams.RGB48Image
objects are stored as 48 bit RGB truecolor PNG streams.ImageCodec.setBounds(int, int, int, int)
, the codec will only load or save
part of an image.
pHYs
chunks.
Use ImageCodec.getDpiX()
and ImageCodec.getDpiY()
to retrieve that information.
after the call to process()
.tEXt
chunks and can be retrieved
with ImageCodec.getComment(int)
after the call to process()
.ImageCodec.setDpi(int, int)
)
is stored in a pHYs
chunk.ImageCodec.appendComment(java.lang.String)
) are stored as tEXt
chunks.
The keyword used is Comment
.
Each of the ImageCodec.getNumComments()
is stored in a chunk of its own.tIME
chunk.
Use setModification(Calendar)
to give a point in time to this codec.
Constructor Summary | |
---|---|
PNGCodec()
|
Method Summary | |
---|---|
String |
getFormatName()
Returns the name of the file format supported by this codec. |
String[] |
getMimeTypes()
Return the MIME (Multipurpose Internet Mail Extensions) type strings for this format, or null
if none are available. |
boolean |
isLoadingSupported()
Returns if this codec is able to load images in the file format supported by this codec. |
boolean |
isSavingSupported()
Returns if this codec is able to save images in the file format supported by this codec. |
static void |
main(String[] args)
|
void |
process()
This method does the actual work of the operation. |
void |
setCompressionLevel(int newLevel)
Sets the compression level to be used with the underlying Deflater object which does the compression. |
void |
setCompressionStrategy(int newStrategy)
Sets the compression strategy to be used with the underlying Deflater object which does the compression. |
void |
setEncodingIdatSize(int newSize)
Sets the size of IDAT chunks generated when encoding. |
void |
setFile(String fileName,
CodecMode codecMode)
Gives a file name and codec mode to the codec which will then try to create the corresponding I/O object. |
void |
setModification(Calendar time)
Sets date and time of last modification of the image to be stored in a PNG stream when saving. |
String |
suggestFileExtension(PixelImage image)
Attempts to suggest a filename extension. |
Methods inherited from class net.sourceforge.jiu.codecs.ImageCodec |
---|
appendComment, checkBounds, checkImageResolution, close, getBoundsHeight, getBoundsWidth, getBoundsX1, getBoundsX2, getBoundsY1, getBoundsY2, getComment, getDataInput, getDataOutput, getDpiX, getDpiY, getFileExtensions, getImage, getImageIndex, getInputAsDataInput, getInputStream, getMode, getNumComments, getOutputAsDataOutput, getOutputStream, getRandomAccessFile, hasBounds, initModeFromIOObjects, isRowRequired, isTileRequired, removeAllComments, removeBounds, setBounds, setBoundsIfNecessary, setDataInput, setDataOutput, setDpi, setFile, setImage, setImageIndex, setInputStream, setOutputStream, setRandomAccessFile |
Methods inherited from class net.sourceforge.jiu.ops.Operation |
---|
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PNGCodec()
Method Detail |
---|
public String getFormatName()
ImageCodec
ImageCodec
must override this method.
When overriding, leave out any words in a particular language so
that this format name can be understood by everyone.
Usually it is enough to return the format creator plus a typical
abbreviation, e.g. Microsoft BMP
or Portable Anymap (PNM)
.
getFormatName
in class ImageCodec
public String[] getMimeTypes()
ImageCodec
null
if none are available.
getMimeTypes
in class ImageCodec
public boolean isLoadingSupported()
ImageCodec
true
is returned this does not necessarily mean that all files in this
format can be read, but at least some.
isLoadingSupported
in class ImageCodec
public boolean isSavingSupported()
ImageCodec
true
is returned this does not necessarily mean that all types files in this
format can be written, but at least some.
isSavingSupported
in class ImageCodec
public static void main(String[] args) throws Exception
Exception
public void process() throws InvalidFileStructureException, MissingParameterException, OperationFailedException, UnsupportedTypeException, WrongFileFormatException
Operation
process
in class Operation
MissingParameterException
- if any mandatory parameter was not given to the operation
WrongParameterException
- if at least one of the input parameters was
not initialized appropriately (values out of the valid interval, etc.)
OperationFailedException
InvalidFileStructureException
UnsupportedTypeException
WrongFileFormatException
public void setCompressionLevel(int newLevel)
Deflater
object which does the compression.
If no value is specified, Deflater.DEFAULT_COMPRESSION
is used.
newLevel
- compression level, from 0 to 9, 0 being fastest
and compressing worst and 9 offering highest compression and taking
the most timepublic void setCompressionStrategy(int newStrategy)
Deflater
object which does the compression.
If no value is specified, Deflater.DEFAULT_STRATEGY
is used.
newStrategy
- one of Deflater's strategy values:
Deflater.DEFAULT_STRATEGY
,
Deflater.FILTERED
,
Deflater.HUFFMAN_ONLY
public void setEncodingIdatSize(int newSize)
Compressed image data is spread over several IDAT chunks by this codec.
The length of the compressed data of a complete image is known only after the complete image
has been encoded.
With PNG, that length value has to be stored before the compressed data as a chunk size value.
This codec is supposed to work with OutputStream
objects,
so seeking back to adjust the chunk size value of an IDAT chunk is not
possible.
That's why all data of a chunk is compressed into a memory buffer.
Whenever the buffer gets full, it is written to output as an IDAT chunk.
Note that the last IDAT chunk may be smaller than the size defined here.
newSize
- size of encoding compressed data bufferpublic void setFile(String fileName, CodecMode codecMode) throws IOException, UnsupportedCodecModeException
ImageCodec
setFile
in class ImageCodec
fileName
- name of the file to be used for loading or savingcodecMode
- defines whether file is to be used for loading or saving
IOException
UnsupportedCodecModeException
public void setModification(Calendar time)
new GregorianCalendar(new SimpleTimeZone(0, "UTC"))
as parameter for this method.
time
- time of last modification of the imagepublic String suggestFileExtension(PixelImage image)
ImageCodec
PNMCodec
).
This default implementation always returns null
.
suggestFileExtension
in class ImageCodec
image
- the image that is to be written to a file
null
if no file extension can be recommended
|
JIU 0.14.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |