Merge "WebPDequantizeLevels(): use stride in CountLevels()"

This commit is contained in:
Pascal Massimino 2016-03-31 07:49:56 +00:00 committed by Gerrit Code Review
commit 6d8c07d375
2 changed files with 22 additions and 21 deletions

View File

@ -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.

View File

@ -179,18 +179,21 @@ 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) {
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_;
last_level = -1;
@ -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;