Skip to content

Commit

Permalink
Use (MIN/NUM)_(TRANSFORM/HUFFMAN)_BITS where appropriate
Browse files Browse the repository at this point in the history
Change-Id: I849ff8864f7abcc723dfe2b7ee0f290c8ee89c3f
  • Loading branch information
vrabaud committed May 6, 2024
1 parent a90160e commit 64d1ec2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/dec/vp8l_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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_,
Expand Down
10 changes: 6 additions & 4 deletions src/enc/vp8l_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/webp/format_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 64d1ec2

Please sign in to comment.