mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
webp-lossless-bitstream-spec: fix ColorTransform impl
and the corresponding InverseTransform(); the operations were swapped. The forward transform subtracts the deltas, the inverse adds them. Bug: webp:551 Change-Id: Ieb90a24f843cee7cdfe46cbb15ec7d716ca9d269
This commit is contained in:
parent
7a7e33e977
commit
44dd765def
@ -395,8 +395,8 @@ typedef struct {
|
|||||||
The actual color transformation is done by defining a color transform
|
The actual color transformation is done by defining a color transform
|
||||||
delta. The color transform delta depends on the `ColorTransformElement`,
|
delta. The color transform delta depends on the `ColorTransformElement`,
|
||||||
which is the same for all the pixels in a particular block. The delta is
|
which is the same for all the pixels in a particular block. The delta is
|
||||||
added during color transform. The inverse color transform then is just
|
subtracted during color transform. The inverse color transform then is just
|
||||||
subtracting those deltas.
|
adding those deltas.
|
||||||
|
|
||||||
The color transform function is defined as follows:
|
The color transform function is defined as follows:
|
||||||
|
|
||||||
@ -405,13 +405,13 @@ void ColorTransform(uint8 red, uint8 blue, uint8 green,
|
|||||||
ColorTransformElement *trans,
|
ColorTransformElement *trans,
|
||||||
uint8 *new_red, uint8 *new_blue) {
|
uint8 *new_red, uint8 *new_blue) {
|
||||||
// Transformed values of red and blue components
|
// Transformed values of red and blue components
|
||||||
uint32 tmp_red = red;
|
int tmp_red = red;
|
||||||
uint32 tmp_blue = blue;
|
int tmp_blue = blue;
|
||||||
|
|
||||||
// Applying transform is just adding the transform deltas
|
// Applying the transform is just subtracting the transform deltas
|
||||||
tmp_red += ColorTransformDelta(trans->green_to_red, green);
|
tmp_red -= ColorTransformDelta(p->green_to_red_, green);
|
||||||
tmp_blue += ColorTransformDelta(trans->green_to_blue, green);
|
tmp_blue -= ColorTransformDelta(p->green_to_blue_, green);
|
||||||
tmp_blue += ColorTransformDelta(trans->red_to_blue, red);
|
tmp_blue -= ColorTransformDelta(p->red_to_blue_, red);
|
||||||
|
|
||||||
*new_red = tmp_red & 0xff;
|
*new_red = tmp_red & 0xff;
|
||||||
*new_blue = tmp_blue & 0xff;
|
*new_blue = tmp_blue & 0xff;
|
||||||
@ -429,7 +429,7 @@ int8 ColorTransformDelta(int8 t, int8 c) {
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
A conversion from the 8-bit unsigned representation (uint8) to the 8-bit
|
A conversion from the 8-bit unsigned representation (uint8) to the 8-bit
|
||||||
signed one (int8) is required before calling ColorTransformDelta().
|
signed one (int8) is required before calling `ColorTransformDelta()`.
|
||||||
It should be performed using 8-bit two's complement (that is: uint8 range
|
It should be performed using 8-bit two's complement (that is: uint8 range
|
||||||
\[128-255\] is mapped to the \[-128, -1\] range of its converted int8 value).
|
\[128-255\] is mapped to the \[-128, -1\] range of its converted int8 value).
|
||||||
|
|
||||||
@ -467,14 +467,18 @@ channels.
|
|||||||
void InverseTransform(uint8 red, uint8 green, uint8 blue,
|
void InverseTransform(uint8 red, uint8 green, uint8 blue,
|
||||||
ColorTransformElement *p,
|
ColorTransformElement *p,
|
||||||
uint8 *new_red, uint8 *new_blue) {
|
uint8 *new_red, uint8 *new_blue) {
|
||||||
// Applying inverse transform is just subtracting the
|
// Transformed values of red and blue components
|
||||||
// color transform deltas
|
int tmp_red = red;
|
||||||
red -= ColorTransformDelta(p->green_to_red_, green);
|
int tmp_blue = blue;
|
||||||
blue -= ColorTransformDelta(p->green_to_blue_, green);
|
|
||||||
blue -= ColorTransformDelta(p->red_to_blue_, red & 0xff);
|
|
||||||
|
|
||||||
*new_red = red & 0xff;
|
// Applying inverse transform is just adding the
|
||||||
*new_blue = blue & 0xff;
|
// color transform deltas
|
||||||
|
tmp_red += ColorTransformDelta(trans->green_to_red, green);
|
||||||
|
tmp_blue += ColorTransformDelta(trans->green_to_blue, green);
|
||||||
|
tmp_blue += ColorTransformDelta(trans->red_to_blue, tmp_red & 0xff);
|
||||||
|
|
||||||
|
*new_red = tmp_red & 0xff;
|
||||||
|
*new_blue = tmp_blue & 0xff;
|
||||||
}
|
}
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user