mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
use a bit-set transforms_seen_ instead of looping
may be useful later for instance to bypass some code if we know we don't use the Bundle+ColorMap transform. Change-Id: I9dc70d18165b2363ad9ede763684ef3d8eba5903
This commit is contained in:
parent
18da1f53fc
commit
7f2dfc92dc
@ -714,7 +714,6 @@ static int ExpandColorMap(int num_colors, VP8LTransform* const transform) {
|
|||||||
|
|
||||||
static int ReadTransform(int* const xsize, int const* ysize,
|
static int ReadTransform(int* const xsize, int const* ysize,
|
||||||
VP8LDecoder* const dec) {
|
VP8LDecoder* const dec) {
|
||||||
int i;
|
|
||||||
int ok = 1;
|
int ok = 1;
|
||||||
VP8LBitReader* const br = &dec->br_;
|
VP8LBitReader* const br = &dec->br_;
|
||||||
VP8LTransform* transform = &dec->transforms_[dec->next_transform_];
|
VP8LTransform* transform = &dec->transforms_[dec->next_transform_];
|
||||||
@ -722,19 +721,17 @@ static int ReadTransform(int* const xsize, int const* ysize,
|
|||||||
(VP8LImageTransformType)VP8LReadBits(br, 2);
|
(VP8LImageTransformType)VP8LReadBits(br, 2);
|
||||||
|
|
||||||
// Each transform type can only be present once in the stream.
|
// Each transform type can only be present once in the stream.
|
||||||
// TODO(later): use a bit set to mark already-used transforms.
|
if (dec->transforms_seen_ & (1U << type)) {
|
||||||
for (i = 0; i < dec->next_transform_; ++i) {
|
|
||||||
if (dec->transforms_[i].type_ == type) {
|
|
||||||
return 0; // Already there, let's not accept the second same transform.
|
return 0; // Already there, let's not accept the second same transform.
|
||||||
}
|
}
|
||||||
}
|
dec->transforms_seen_ |= (1U << type);
|
||||||
assert(dec->next_transform_ < NUM_TRANSFORMS);
|
|
||||||
|
|
||||||
transform->type_ = type;
|
transform->type_ = type;
|
||||||
transform->xsize_ = *xsize;
|
transform->xsize_ = *xsize;
|
||||||
transform->ysize_ = *ysize;
|
transform->ysize_ = *ysize;
|
||||||
transform->data_ = NULL;
|
transform->data_ = NULL;
|
||||||
++dec->next_transform_;
|
++dec->next_transform_;
|
||||||
|
assert(dec->next_transform_ <= NUM_TRANSFORMS);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PREDICTOR_TRANSFORM:
|
case PREDICTOR_TRANSFORM:
|
||||||
@ -808,6 +805,7 @@ void VP8LClear(VP8LDecoder* const dec) {
|
|||||||
ClearTransform(&dec->transforms_[i]);
|
ClearTransform(&dec->transforms_[i]);
|
||||||
}
|
}
|
||||||
dec->next_transform_ = 0;
|
dec->next_transform_ = 0;
|
||||||
|
dec->transforms_seen_ = 0;
|
||||||
|
|
||||||
free(dec->rescaler_memory);
|
free(dec->rescaler_memory);
|
||||||
dec->rescaler_memory = NULL;
|
dec->rescaler_memory = NULL;
|
||||||
|
@ -89,6 +89,8 @@ typedef struct {
|
|||||||
|
|
||||||
int next_transform_;
|
int next_transform_;
|
||||||
VP8LTransform transforms_[NUM_TRANSFORMS];
|
VP8LTransform transforms_[NUM_TRANSFORMS];
|
||||||
|
// or'd bitset storing the transforms types.
|
||||||
|
uint32_t transforms_seen_;
|
||||||
|
|
||||||
uint8_t *rescaler_memory; // Working memory for rescaling work.
|
uint8_t *rescaler_memory; // Working memory for rescaling work.
|
||||||
WebPRescaler *rescaler; // Common rescaler for all channels.
|
WebPRescaler *rescaler; // Common rescaler for all channels.
|
||||||
|
Loading…
Reference in New Issue
Block a user