From d96fe5e079999587be7f0c73a528c69245adbee0 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Wed, 30 Mar 2016 23:18:54 -0700 Subject: [PATCH] WebPDequantizeLevels(): use stride in CountLevels() follow-up for patch #333712 Change-Id: I3f85e3fce9e1c9d1a862a14ba56134882807718f --- src/dec/alpha.c | 22 ++++++++++------------ src/utils/quant_levels_dec.c | 21 ++++++++++++--------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/dec/alpha.c b/src/dec/alpha.c index 6d54b92a..7f90ddca 100644 --- a/src/dec/alpha.c +++ b/src/dec/alpha.c @@ -122,12 +122,12 @@ static int ALPHDecode(VP8Decoder* const dec, int row, int num_rows) { const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, const VP8Io* const io, int row, int num_rows) { - const int width = dec->pic_hdr_.width_; - const int height = dec->pic_hdr_.height_; + const int width = io->width; + const int height = io->crop_bottom; assert(dec != NULL && io != NULL); - if (row < 0 || num_rows <= 0 || row + num_rows > height) { + if (row < 0 || num_rows <= 0 || row + num_rows > io->height) { return NULL; // sanity check. } @@ -136,7 +136,7 @@ const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, dec->alph_dec_ = ALPHNew(); if (dec->alph_dec_ == NULL) return NULL; if (!ALPHInit(dec->alph_dec_, dec->alpha_data_, dec->alpha_data_size_, - width, height, dec->alpha_plane_)) { + io->width, io->height, dec->alpha_plane_)) { ALPHDelete(dec->alph_dec_); dec->alph_dec_ = NULL; return NULL; @@ -149,23 +149,21 @@ const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec, } } - if (io->use_cropping) { - if (row + num_rows > io->crop_bottom) { - num_rows = io->crop_bottom - row; - } + if (row + num_rows > height) { + num_rows = height - row; } if (!dec->is_alpha_decoded_) { int ok = ALPHDecode(dec, row, num_rows); assert(dec->alph_dec_ != NULL); - if (ok && dec->alpha_dithering_ > 0) { - ok = WebPDequantizeLevels(dec->alpha_plane_, width, height, width, - dec->alpha_dithering_); - } if (!ok || dec->is_alpha_decoded_) { ALPHDelete(dec->alph_dec_); dec->alph_dec_ = NULL; } + if (ok && dec->is_alpha_decoded_ && dec->alpha_dithering_ > 0) { + ok = WebPDequantizeLevels(dec->alpha_plane_, width, height, width, + dec->alpha_dithering_); + } if (!ok) return NULL; // Error. } // Return a pointer to the current decoded row. diff --git a/src/utils/quant_levels_dec.c b/src/utils/quant_levels_dec.c index 05b42616..ee0a3fe1 100644 --- a/src/utils/quant_levels_dec.c +++ b/src/utils/quant_levels_dec.c @@ -179,17 +179,20 @@ static void InitCorrectionLUT(int16_t* const lut, int min_dist) { lut[0] = 0; } -static void CountLevels(const uint8_t* const data, int size, - SmoothParams* const p) { - int i, last_level; +static void CountLevels(SmoothParams* const p) { + int i, j, last_level; uint8_t used_levels[256] = { 0 }; + const uint8_t* data = p->src_; p->min_ = 255; p->max_ = 0; - for (i = 0; i < size; ++i) { - const int v = data[i]; - if (v < p->min_) p->min_ = v; - if (v > p->max_) p->max_ = v; - used_levels[v] = 1; + for (j = 0; j < p->height_; ++j) { + for (i = 0; i < p->width_; ++i) { + const int v = data[i]; + if (v < p->min_) p->min_ = v; + if (v > p->max_) p->max_ = v; + used_levels[v] = 1; + } + data += p->stride_; } // Compute the mininum distance between two non-zero levels. p->min_level_dist_ = p->max_ - p->min_; @@ -242,7 +245,7 @@ static int InitParams(uint8_t* const data, int width, int height, int stride, p->row_ = -radius; // analyze the input distribution so we can best-fit the threshold - CountLevels(data, width * height, p); + CountLevels(p); // correction table p->correction_ = ((int16_t*)mem) + LUT_SIZE;