mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 22:28:22 +01:00
Merge "WebPDequantizeLevels(): use stride in CountLevels()"
This commit is contained in:
commit
6d8c07d375
@ -122,12 +122,12 @@ static int ALPHDecode(VP8Decoder* const dec, int row, int num_rows) {
|
|||||||
const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
|
const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
|
||||||
const VP8Io* const io,
|
const VP8Io* const io,
|
||||||
int row, int num_rows) {
|
int row, int num_rows) {
|
||||||
const int width = dec->pic_hdr_.width_;
|
const int width = io->width;
|
||||||
const int height = dec->pic_hdr_.height_;
|
const int height = io->crop_bottom;
|
||||||
|
|
||||||
assert(dec != NULL && io != NULL);
|
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.
|
return NULL; // sanity check.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
|
|||||||
dec->alph_dec_ = ALPHNew();
|
dec->alph_dec_ = ALPHNew();
|
||||||
if (dec->alph_dec_ == NULL) return NULL;
|
if (dec->alph_dec_ == NULL) return NULL;
|
||||||
if (!ALPHInit(dec->alph_dec_, dec->alpha_data_, dec->alpha_data_size_,
|
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_);
|
ALPHDelete(dec->alph_dec_);
|
||||||
dec->alph_dec_ = NULL;
|
dec->alph_dec_ = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -149,23 +149,21 @@ const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (io->use_cropping) {
|
if (row + num_rows > height) {
|
||||||
if (row + num_rows > io->crop_bottom) {
|
num_rows = height - row;
|
||||||
num_rows = io->crop_bottom - row;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dec->is_alpha_decoded_) {
|
if (!dec->is_alpha_decoded_) {
|
||||||
int ok = ALPHDecode(dec, row, num_rows);
|
int ok = ALPHDecode(dec, row, num_rows);
|
||||||
assert(dec->alph_dec_ != NULL);
|
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_) {
|
if (!ok || dec->is_alpha_decoded_) {
|
||||||
ALPHDelete(dec->alph_dec_);
|
ALPHDelete(dec->alph_dec_);
|
||||||
dec->alph_dec_ = NULL;
|
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.
|
if (!ok) return NULL; // Error.
|
||||||
}
|
}
|
||||||
// Return a pointer to the current decoded row.
|
// Return a pointer to the current decoded row.
|
||||||
|
@ -179,18 +179,21 @@ static void InitCorrectionLUT(int16_t* const lut, int min_dist) {
|
|||||||
lut[0] = 0;
|
lut[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CountLevels(const uint8_t* const data, int size,
|
static void CountLevels(SmoothParams* const p) {
|
||||||
SmoothParams* const p) {
|
int i, j, last_level;
|
||||||
int i, last_level;
|
|
||||||
uint8_t used_levels[256] = { 0 };
|
uint8_t used_levels[256] = { 0 };
|
||||||
|
const uint8_t* data = p->src_;
|
||||||
p->min_ = 255;
|
p->min_ = 255;
|
||||||
p->max_ = 0;
|
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];
|
const int v = data[i];
|
||||||
if (v < p->min_) p->min_ = v;
|
if (v < p->min_) p->min_ = v;
|
||||||
if (v > p->max_) p->max_ = v;
|
if (v > p->max_) p->max_ = v;
|
||||||
used_levels[v] = 1;
|
used_levels[v] = 1;
|
||||||
}
|
}
|
||||||
|
data += p->stride_;
|
||||||
|
}
|
||||||
// Compute the mininum distance between two non-zero levels.
|
// Compute the mininum distance between two non-zero levels.
|
||||||
p->min_level_dist_ = p->max_ - p->min_;
|
p->min_level_dist_ = p->max_ - p->min_;
|
||||||
last_level = -1;
|
last_level = -1;
|
||||||
@ -242,7 +245,7 @@ static int InitParams(uint8_t* const data, int width, int height, int stride,
|
|||||||
p->row_ = -radius;
|
p->row_ = -radius;
|
||||||
|
|
||||||
// analyze the input distribution so we can best-fit the threshold
|
// analyze the input distribution so we can best-fit the threshold
|
||||||
CountLevels(data, width * height, p);
|
CountLevels(p);
|
||||||
|
|
||||||
// correction table
|
// correction table
|
||||||
p->correction_ = ((int16_t*)mem) + LUT_SIZE;
|
p->correction_ = ((int16_t*)mem) + LUT_SIZE;
|
||||||
|
Loading…
Reference in New Issue
Block a user