Make --output-bit-depth option working with variable resolution.

Buffer for bit-depth conversion was allocated only on the first frame.
The next frame with resolution different from the first one led to
decoding error. With this changes decoder performs buffer reallocation
in such case.

Change-Id: I3a701ca8df53a60246354876856624e70efe81aa
This commit is contained in:
Alexander Voronov
2014-09-10 14:55:19 +04:00
parent f9b4008020
commit 7dc3cdba0c

View File

@@ -692,6 +692,14 @@ static void img_downshift(vpx_image_t *dst, vpx_image_t *src,
low_img_downshift(dst, src, down_shift);
}
}
static int img_shifted_realloc_required(const vpx_image_t *img,
const vpx_image_t *shifted,
vpx_img_fmt_t required_fmt) {
return img->d_w != shifted->d_w ||
img->d_h != shifted->d_h ||
required_fmt != shifted->fmt;
}
#endif
int main_loop(int argc, const char **argv_) {
@@ -1127,14 +1135,17 @@ int main_loop(int argc, const char **argv_) {
out_bit_depth = img->bit_depth;
// Shift up or down if necessary
if (out_bit_depth != img->bit_depth) {
vpx_img_fmt_t shifted_fmt = out_bit_depth == 8
? img->fmt ^ (img->fmt & VPX_IMG_FMT_HIGH)
: img->fmt | VPX_IMG_FMT_HIGH;
if (img_shifted &&
img_shifted_realloc_required(img, img_shifted, shifted_fmt)) {
vpx_img_free(img_shifted);
img_shifted = NULL;
}
if (!img_shifted) {
if (out_bit_depth == 8) {
img_shifted = vpx_img_alloc(NULL, img->fmt - VPX_IMG_FMT_HIGH,
img->d_w, img->d_h, 16);
} else {
img_shifted = vpx_img_alloc(NULL, img->fmt | VPX_IMG_FMT_HIGH,
img->d_w, img->d_h, 16);
}
img_shifted = vpx_img_alloc(NULL, shifted_fmt,
img->d_w, img->d_h, 16);
img_shifted->bit_depth = out_bit_depth;
}
if (out_bit_depth > img->bit_depth) {