mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
fix TIFF encoder regarding rgbA/RGBA
Encoder: We were always using ExtraSamples=1, which means associated-alpha. But we don't need the (lossy) excursion to rgbA format. We can save the samples as RGBA directly, by changing ExtraSamples to '2'. The TIFF encoder now checks the colorspace properly, to handle premultiplied format as well as non-premultiplied. Decoder: The result of TIFFReadRGBAImageOriented() is always pre-multiply. So, in case an alpha channel is present, we need to unmultiply it before calling WebPPictureImportRGBA(). See: https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf (page 31) and also http://www.asmail.be/msg0055469184.html Change-Id: I3258bfdb0eb2e1a53d6c04414f55edb2926c938c
This commit is contained in:
@ -361,6 +361,7 @@ int WebPWriteTIFF(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const uint8_t* rgba = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const uint8_t bytes_per_px = has_alpha ? 4 : 3;
|
||||
const int assoc_alpha = WebPIsPremultipliedMode(buffer->colorspace) ? 1 : 2;
|
||||
// For non-alpha case, we omit tag 0x152 (ExtraSamples).
|
||||
const uint8_t num_ifd_entries = has_alpha ? NUM_IFD_ENTRIES
|
||||
: NUM_IFD_ENTRIES - 1;
|
||||
@ -388,7 +389,8 @@ int WebPWriteTIFF(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
EXTRA_DATA_OFFSET + 8, 0, 0, 0,
|
||||
0x1c, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 154: PlanarConfiguration
|
||||
0x28, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 166: ResolutionUnit (inch)
|
||||
0x52, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 178: ExtraSamples: rgbA
|
||||
0x52, 0x01, 3, 0, 1, 0, 0, 0,
|
||||
assoc_alpha, 0, 0, 0, // 178: ExtraSamples: rgbA/RGBA
|
||||
0, 0, 0, 0, // 190: IFD terminator
|
||||
// EXTRA_DATA_OFFSET:
|
||||
8, 0, 8, 0, 8, 0, 8, 0, // BitsPerSample
|
||||
|
Reference in New Issue
Block a user