| 238 | } |
| 239 | |
| 240 | static int alloc_buffers(AVCodecContext *avctx) |
| 241 | { |
| 242 | CFHDContext *s = avctx->priv_data; |
| 243 | int ret, planes, bayer = 0; |
| 244 | int chroma_x_shift, chroma_y_shift; |
| 245 | |
| 246 | if ((ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height)) < 0) |
| 247 | return ret; |
| 248 | avctx->pix_fmt = s->coded_format; |
| 249 | |
| 250 | ff_cfhddsp_init(&s->dsp, s->bpc, avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16); |
| 251 | |
| 252 | if ((ret = av_pix_fmt_get_chroma_sub_sample(s->coded_format, |
| 253 | &chroma_x_shift, |
| 254 | &chroma_y_shift)) < 0) |
| 255 | return ret; |
| 256 | planes = av_pix_fmt_count_planes(s->coded_format); |
| 257 | if (s->coded_format == AV_PIX_FMT_BAYER_RGGB16) { |
| 258 | planes = 4; |
| 259 | chroma_x_shift = 1; |
| 260 | chroma_y_shift = 1; |
| 261 | bayer = 1; |
| 262 | } |
| 263 | |
| 264 | for (int i = 0; i < planes; i++) { |
| 265 | int w8, h8, w4, h4, w2, h2; |
| 266 | int width = (i || bayer) ? s->coded_width >> chroma_x_shift : s->coded_width; |
| 267 | int height = (i || bayer) ? s->coded_height >> chroma_y_shift : s->coded_height; |
| 268 | ptrdiff_t stride = (FFALIGN(width / 8, 8) + 64) * 8; |
| 269 | |
| 270 | if ((ret = av_image_check_size2(stride, height, avctx->max_pixels, s->coded_format, 0, avctx)) < 0) |
| 271 | return ret; |
| 272 | |
| 273 | if (chroma_y_shift && !bayer) |
| 274 | height = FFALIGN(height / 8, 2) * 8; |
| 275 | s->plane[i].width = width; |
| 276 | s->plane[i].height = height; |
| 277 | s->plane[i].stride = stride; |
| 278 | |
| 279 | w8 = FFALIGN(s->plane[i].width / 8, 8) + 64; |
| 280 | h8 = FFALIGN(height, 8) / 8; |
| 281 | w4 = w8 * 2; |
| 282 | h4 = h8 * 2; |
| 283 | w2 = w4 * 2; |
| 284 | h2 = h4 * 2; |
| 285 | |
| 286 | if (s->transform_type == 0) { |
| 287 | s->plane[i].idwt_size = FFALIGN(height, 8) * stride; |
| 288 | s->plane[i].idwt_buf = |
| 289 | av_calloc(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_buf)); |
| 290 | s->plane[i].idwt_tmp = |
| 291 | av_malloc_array(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_tmp)); |
| 292 | } else { |
| 293 | s->plane[i].idwt_size = FFALIGN(height, 8) * stride * 2; |
| 294 | s->plane[i].idwt_buf = |
| 295 | av_calloc(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_buf)); |
| 296 | s->plane[i].idwt_tmp = |
| 297 | av_malloc_array(s->plane[i].idwt_size, sizeof(*s->plane[i].idwt_tmp)); |
no test coverage detected