lodepng.Encode
License:
Copyright (c) 2005-2007 Lode Vandevenne
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Lode Vandevenne nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors:
Lode Vandevenne (original version in C++), Lutger Blijdestijn (D version) : lutger dot blijdestijn at gmail dot com,
Stewart Gordon (bug fixes)
Date:
Januari 16, 2008
About:
The lodepng encoder can encode images of any of the supported png color formats to 24-bit RGB or
32-bit RGBA png images. Conversion, if needed, is done automatically. It is compatible with the
Phobos and Tango libraries.
This module publicly imports lodepng.Common, where you'll find the data types used by both the encoder
and decoder, as well as some utility and image format conversion routines.
Features:
The following features are understood by the encoder:
- conformant encoding of 24-bit RGB and 32-bit RGBA PNG images
- automatic conversion of other color formats
- setting the compression and filter methods
- textual key-value metadata: normal and compressed latin1, unicode (utf-8)
- transparency / colorkey
- encoding raw chunks
- the following chunks are written by the encoder
- IHDR (image information)
- IDAT (pixel data)
- IEND (the final chunk)
- tRNS (colorkey)
- bKGD (suggested background color)
- tEXt (uncompressed latin-1 key-value strings)
- zTXt (compressed latin-1 key-value strings)
- iTXt (utf8 key-value strings)
Limitations:
The following features are not supported.
- Ouput in any color formats other than 24-bit RGB or 32-bit RGBA
- Interlacing
- The encoder does not understand the following chunk types:
- PLTE (color palette)
- cHRM (device independent color info)
- gAMA (device independent color info)
- iCCP (device independent color info)
- sBIT (original number of significant bits)
- sRGB (device independent color info)
- pHYs (physical pixel dimensions)
- sPLT (suggested reduced palette)
- tIME (last image modification time)
References:
Original lodepng
PNG Specification
PNG Suite: set of test images
OptiPNG: tool to experimentally optimize png images
- ubyte[]
encode
(ubyte[] source, PngInfo info);
- Encode pixels as a png file
This function will attempt to convert to 24-bit RGB if it is a lossless operation, otherwise
the resulting image will be in the 32-bit RGBA format. The array returned can be written to disk
as a png file.
Params:
ubyte[] source |
the pixels to be encoded |
PngInfo info |
description of the source pixels |
Throws:
PngException
Returns:
png file of the raw pixels provided by source and described by settings.info
- ubyte[]
encode
(ubyte[] source, PngInfo info, ref Chunk [] chunkList);
- Encode pixels and / or raw chunks as a png file
If chunkList contains IDAT chunks, they must be in order and no source pixels should be provided
Params:
ubyte[] source |
the pixels to be encoded, can be null |
PngInfo info |
description of the source pixels |
Chunk [] chunkList |
array of chunks to be written |
Throws:
PngException
Returns:
png file of the raw pixels provided by source and described by info
- ubyte[]
encode
(ubyte[] source, Settings options);
- Encode pixels as a png file
See Also:
Settings
Params:
ubyte[] source |
the pixels to be encoded |
Settings options |
description and options needed to
encode
the png file |
Throws:
PngException
Returns:
png file of the raw pixels provided by source and described by options.info
- ubyte[]
encode
(ubyte[] source, Settings options, ref Chunk [] chunkList);
- Encode pixels as a png file
See Also:
Settings
Params:
ubyte[] source |
the pixels to be encoded |
Settings options |
description and options needed to
encode
the png file |
Chunk [] chunkList |
array of chunks to be written |
Throws:
PngException
Returns:
png file of the raw pixels provided by source and described by options.info
- enum
FilterStrategy
;
- Filter method
The png specification defines five types of filters. In addition each scanline can have a
different filtering method applied (Dynamic). The latter method usually gives the best compression,
when a fixed method is preferred paeth gives the best result most of the times.
-
None
-
Up
-
Sub
-
Average
-
Paeth
-
Dynamic
- enum
CompressionStrategy
;
- Zlib compression method
Which compression scheme works best depends on the type of image. Tools such as optipng can
figure this out experimentally. However, RLE seems to give the best results in compression and
performance.
-
Default
-
Filtered
-
RLE
-
None
- struct
Settings
;
- Controls all information needed to encode a png file
- static Settings
opCall
();
static Settings
opCall
(PngInfo info, bool autoRemoveAlpha = false);
static Settings
opCall
(PngImage image, bool autoRemoveAlpha = false);
- constructor
- PngInfo
info
;
- png image information
- ColorType
targetColorType
;
- The colortype of the target image
lodepng can only encode in RGB(A) format (yet?)
. If the format is set ColorType.Any, RGB or
RGBA is chosen depending on whether the source image has an alpha channel.
- bool
autoRemoveAlpha
;
- Remove alpha channel
If set to true and the source image has an alpha channel, this will be removed if (and
only if) the image is fully opaque or a colorkey can be written. This is considered a
lossless operation.
- bool
compressText
;
- if zlib compression is to be used on text
- ubyte
compressionLevel
;
- zlib compression level, affects memory use. Must be in range 0-9
- FilterStrategy
filterStrategy
;
- see FilterStrategy
- CompressionStrategy
compressionStrategy
;
- see CompressionStrategy
)
|