only allocate alpha_plane_ up to crop_bottom row
-> reduces memory consumption in case of cropping
work for bug #288
Change-Id: Icab6eb8e67e3c5c184a9363fffcd9f6acd0b311c
diff --git a/src/dec/alpha.c b/src/dec/alpha.c
index bce0105..d6c8ac2 100644
--- a/src/dec/alpha.c
+++ b/src/dec/alpha.c
@@ -113,7 +113,7 @@
static int ALPHDecode(VP8Decoder* const dec, int row, int num_rows) {
ALPHDecoder* const alph_dec = dec->alph_dec_;
const int width = alph_dec->width_;
- const int height = alph_dec->height_;
+ const int height = alph_dec->io_.crop_bottom;
uint8_t* const output = dec->alpha_plane_;
if (alph_dec->method_ == ALPHA_NO_COMPRESSION) {
const size_t offset = row * width;
@@ -131,7 +131,7 @@
}
}
- if (row + num_rows >= alph_dec->io_.crop_bottom) {
+ if (row + num_rows >= height) {
dec->is_alpha_decoded_ = 1;
}
return 1;
@@ -139,12 +139,14 @@
static int AllocateAlphaPlane(VP8Decoder* const dec, const VP8Io* const io) {
const int stride = io->width;
- const int height = io->height;
+ const int height = io->crop_bottom;
const uint64_t alpha_size = (uint64_t)stride * height;
assert(dec->alpha_plane_mem_ == NULL);
dec->alpha_plane_mem_ =
(uint8_t*)WebPSafeMalloc(alpha_size, sizeof(*dec->alpha_plane_));
- if (dec->alpha_plane_mem_ == NULL) return 0;
+ if (dec->alpha_plane_mem_ == NULL) {
+ return 0;
+ }
dec->alpha_plane_ = dec->alpha_plane_mem_;
return 1;
}