mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 14:34:33 +02:00
EXPERIMENTAL: add support for alpha channel
This is a (minor) bitstream change: if the 'color_space' bit is set to '1' (which is normally an undefined/invalid behaviour), we add extra data at the end of partition #0 (so-called 'extensions') Namely, we add the size of the extension data as 3 bytes (little-endian), followed by a set of bits telling which extensions we're incorporating. The data then _preceeds_ this trailing tags. This is all experimental, and you'll need to have '#define WEBP_EXPERIMENTAL_FEATURES' in webp/types.h to enable this code (at your own risk! :)) Still, this hack produces almost-valid WebP file for decoders that don't check this color_space bit. In particular, previous 'dwebp' (and for instance Chrome) will recognize this files and decode them, but without the alpha of course. Other decoder will just see random extra stuff at the end of partition #0. To experiment with the alpha-channel, you need to compile on Unix platform and use PNGs for input/output. If 'alpha.png' is a source with alpha channel, then you can try (on Unix): cwebp alpha.png -o alpha.webp dwebp alpha.webp -o test.png cwebp now has a '-noalpha' flag to ignore any alpha information from the source, if present. More hacking and experimenting welcome! Change-Id: I3c7b1fd8411c9e7a9f77690e898479ad85c52f3e
This commit is contained in:
@ -326,6 +326,10 @@ struct VP8Encoder {
|
||||
VP8BitWriter bw_; // part0
|
||||
VP8BitWriter parts_[MAX_NUM_PARTITIONS]; // token partitions
|
||||
|
||||
// transparency blob
|
||||
uint8_t* alpha_data_;
|
||||
size_t alpha_data_size_;
|
||||
|
||||
// quantization info (one set of DC/AC dequant factor per segment)
|
||||
VP8SegmentInfo dqm_[NUM_MB_SEGMENTS];
|
||||
int base_quant_; // nominal quantizer value. Only used
|
||||
@ -414,6 +418,11 @@ void VP8SetSegmentParams(VP8Encoder* const enc, float quality);
|
||||
// Pick best modes and fills the levels. Returns true if skipped.
|
||||
int VP8Decimate(VP8EncIterator* const it, VP8ModeScore* const rd, int rd_opt);
|
||||
|
||||
// in alpha.c
|
||||
// Compress transparency information into enc->alpha_data_. Return true if ok.
|
||||
int VP8EncProcessAlpha(VP8Encoder* enc);
|
||||
void VP8EncDeleteAlpha(VP8Encoder* enc); // delete compressed data
|
||||
|
||||
// in dsp.c
|
||||
// Transforms
|
||||
// VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
|
||||
|
Reference in New Issue
Block a user