mirror of
https://github.com/webmproject/libwebp.git
synced 2025-04-11 11:26:47 +02:00
Merge "fix alignment of allocated memory in AllocateTransformBuffer"
This commit is contained in:
commit
927ccdc43b
@ -1122,28 +1122,30 @@ static WebPEncodingError AllocateTransformBuffer(VP8LEncoder* const enc,
|
|||||||
int width, int height) {
|
int width, int height) {
|
||||||
WebPEncodingError err = VP8_ENC_OK;
|
WebPEncodingError err = VP8_ENC_OK;
|
||||||
if (enc->argb_ == NULL) {
|
if (enc->argb_ == NULL) {
|
||||||
const int tile_size = 1 << enc->transform_bits_;
|
const int tile_size = 1 << enc->transform_bits_;
|
||||||
const uint64_t image_size = width * height;
|
const uint64_t image_size = width * height;
|
||||||
const uint64_t argb_scratch_size =
|
const uint64_t argb_scratch_size =
|
||||||
enc->use_predict_ ? tile_size * width + width : 0;
|
enc->use_predict_ ? tile_size * width + width : 0;
|
||||||
const int transform_data_size =
|
const int transform_data_size =
|
||||||
(enc->use_predict_ || enc->use_cross_color_) ?
|
(enc->use_predict_ || enc->use_cross_color_)
|
||||||
VP8LSubSampleSize(width, enc->transform_bits_) *
|
? VP8LSubSampleSize(width, enc->transform_bits_) *
|
||||||
VP8LSubSampleSize(height, enc->transform_bits_) : 0;
|
VP8LSubSampleSize(height, enc->transform_bits_)
|
||||||
const uint64_t total_size =
|
: 0;
|
||||||
image_size + argb_scratch_size + (uint64_t)transform_data_size;
|
const uint64_t total_size =
|
||||||
uint32_t* mem = (uint32_t*)WebPSafeMalloc(total_size, sizeof(*mem));
|
image_size + WEBP_ALIGN_CST +
|
||||||
if (mem == NULL) {
|
argb_scratch_size + WEBP_ALIGN_CST +
|
||||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
(uint64_t)transform_data_size;
|
||||||
goto Error;
|
uint32_t* mem = (uint32_t*)WebPSafeMalloc(total_size, sizeof(*mem));
|
||||||
}
|
if (mem == NULL) {
|
||||||
// TODO(skal): align
|
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||||
enc->argb_ = mem;
|
goto Error;
|
||||||
mem += image_size;
|
}
|
||||||
enc->argb_scratch_ = mem;
|
enc->argb_ = mem;
|
||||||
mem += argb_scratch_size;
|
mem = (uint32_t*)WEBP_ALIGN(mem + image_size);
|
||||||
enc->transform_data_ = mem;
|
enc->argb_scratch_ = mem;
|
||||||
enc->current_width_ = width;
|
mem = (uint32_t*)WEBP_ALIGN(mem + argb_scratch_size);
|
||||||
|
enc->transform_data_ = mem;
|
||||||
|
enc->current_width_ = width;
|
||||||
}
|
}
|
||||||
Error:
|
Error:
|
||||||
return err;
|
return err;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user