diff --git a/src/dec/vp8l_dec.c b/src/dec/vp8l_dec.c index 11c00ea9..ebb0e7b6 100644 --- a/src/dec/vp8l_dec.c +++ b/src/dec/vp8l_dec.c @@ -20,10 +20,9 @@ #include "src/dsp/dsp.h" #include "src/dsp/lossless.h" #include "src/dsp/lossless_common.h" -#include "src/dsp/yuv.h" -#include "src/utils/endian_inl_utils.h" #include "src/utils/huffman_utils.h" #include "src/utils/utils.h" +#include "src/webp/format_constants.h" #define NUM_ARGB_CACHE_ROWS 16 @@ -381,7 +380,8 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize, if (allow_recursion && VP8LReadBits(br, 1)) { // use meta Huffman codes. - const int huffman_precision = VP8LReadBits(br, 3) + 2; + const int huffman_precision = + MIN_HUFFMAN_BITS + VP8LReadBits(br, NUM_HUFFMAN_BITS); const int huffman_xsize = VP8LSubSampleSize(xsize, huffman_precision); const int huffman_ysize = VP8LSubSampleSize(ysize, huffman_precision); const int huffman_pixs = huffman_xsize * huffman_ysize; @@ -1351,7 +1351,8 @@ static int ReadTransform(int* const xsize, int const* ysize, switch (type) { case PREDICTOR_TRANSFORM: case CROSS_COLOR_TRANSFORM: - transform->bits_ = VP8LReadBits(br, 3) + 2; + transform->bits_ = + MIN_TRANSFORM_BITS + VP8LReadBits(br, NUM_TRANSFORM_BITS); ok = DecodeImageStream(VP8LSubSampleSize(transform->xsize_, transform->bits_), VP8LSubSampleSize(transform->ysize_, diff --git a/src/enc/vp8l_enc.c b/src/enc/vp8l_enc.c index d1e4b2ae..44cb0b6e 100644 --- a/src/enc/vp8l_enc.c +++ b/src/enc/vp8l_enc.c @@ -30,6 +30,7 @@ // Maximum number of histogram images (sub-blocks). #define MAX_HUFF_IMAGE_SIZE 2600 +#define MAX_HUFFMAN_BITS (MIN_HUFFMAN_BITS + (1 << NUM_HUFFMAN_BITS) - 1) // ----------------------------------------------------------------------------- // Palette @@ -1083,8 +1084,8 @@ static int ApplyPredictFilter(VP8LEncoder* const enc, int width, int height, } VP8LPutBits(bw, TRANSFORM_PRESENT, 1); VP8LPutBits(bw, PREDICTOR_TRANSFORM, 2); - assert(pred_bits >= 2); - VP8LPutBits(bw, pred_bits - 2, 3); + assert(pred_bits >= MIN_TRANSFORM_BITS); + VP8LPutBits(bw, pred_bits - MIN_TRANSFORM_BITS, NUM_TRANSFORM_BITS); return EncodeImageNoHuffman( bw, enc->transform_data_, (VP8LHashChain*)&enc->hash_chain_, (VP8LBackwardRefs*)&enc->refs_[0], transform_width, transform_height, @@ -1107,8 +1108,9 @@ static int ApplyCrossColorFilter(const VP8LEncoder* const enc, int width, } VP8LPutBits(bw, TRANSFORM_PRESENT, 1); VP8LPutBits(bw, CROSS_COLOR_TRANSFORM, 2); - assert(ccolor_transform_bits >= 2); - VP8LPutBits(bw, ccolor_transform_bits - 2, 3); + assert(ccolor_transform_bits >= MIN_TRANSFORM_BITS); + VP8LPutBits(bw, ccolor_transform_bits - MIN_TRANSFORM_BITS, + NUM_TRANSFORM_BITS); return EncodeImageNoHuffman( bw, enc->transform_data_, (VP8LHashChain*)&enc->hash_chain_, (VP8LBackwardRefs*)&enc->refs_[0], transform_width, transform_height, diff --git a/src/webp/format_constants.h b/src/webp/format_constants.h index 999035c5..9b007c8a 100644 --- a/src/webp/format_constants.h +++ b/src/webp/format_constants.h @@ -46,7 +46,12 @@ #define CODE_LENGTH_CODES 19 #define MIN_HUFFMAN_BITS 2 // min number of Huffman bits -#define MAX_HUFFMAN_BITS 9 // max number of Huffman bits +#define NUM_HUFFMAN_BITS 3 + +// the maximum number of bits defining a transform is +// MIN_TRANSFORM_BITS + (1 << NUM_TRANSFORM_BITS) - 1 +#define MIN_TRANSFORM_BITS 2 +#define NUM_TRANSFORM_BITS 3 #define TRANSFORM_PRESENT 1 // The bit to be written when next data // to be read is a transform.