[FFmpeg-devel] [PATCH] avcodec/cfhd: Add support for 12-bit RGBA.

Kieran Kunhya kieran at kunhya.com
Mon Feb 8 22:42:53 CET 2016


Plays all known samples
---
 libavcodec/cfhd.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c
index 2436aae..0773ffa 100644
--- a/libavcodec/cfhd.c
+++ b/libavcodec/cfhd.c
@@ -152,14 +152,15 @@ static void free_buffers(AVCodecContext *avctx)
 static int alloc_buffers(AVCodecContext *avctx)
 {
     CFHDContext *s = avctx->priv_data;
-    int i, j, k, ret;
+    int i, j, k, ret, planes;
 
     if ((ret = ff_set_dimensions(avctx, s->coded_width, s->coded_height)) < 0)
         return ret;
 
     avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift);
+    planes = av_pix_fmt_count_planes(avctx->pix_fmt);
 
-    for (i = 0; i < 3; i++) {
+    for (i = 0; i < planes; i++) {
         int width = i ? avctx->width >> s->chroma_x_shift : avctx->width;
         int height = i ? avctx->height >> s->chroma_y_shift : avctx->height;
         int stride = FFALIGN(width / 8, 8) * 8;
@@ -224,7 +225,7 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
     GetByteContext gb;
     ThreadFrame frame = { .f = data };
     AVFrame *pic = data;
-    int ret = 0, i, j, plane, got_buffer = 0;
+    int ret = 0, i, j, planes, plane, got_buffer = 0;
     int16_t *coeff_data;
 
     avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
@@ -254,7 +255,7 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
         } else if (tag == 12) {
             av_log(avctx, AV_LOG_DEBUG, "Channel Count: %"PRIu16"\n", data);
             s->channel_cnt = data;
-            if (data != 3) {
+            if (data > 4) {
                 av_log(avctx, AV_LOG_ERROR, "Channel Count of %"PRIu16" is unsupported\n", data);
                 ret = AVERROR_PATCHWELCOME;
                 break;
@@ -269,7 +270,7 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
         } else if (tag == 62) {
             s->channel_num = data;
             av_log(avctx, AV_LOG_DEBUG, "Channel number %"PRIu16"\n", data);
-            if (s->channel_num > 2) {
+            if (s->channel_num > 3) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid channel number\n");
                 ret = AVERROR(EINVAL);
                 break;
@@ -403,6 +404,8 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
                 avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
             else if (data == 3)
                 avctx->pix_fmt = AV_PIX_FMT_GBRP12;
+            else if (data == 4)
+                avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
             else {
                 avpriv_report_missing_feature(avctx, "Sample format of %"PRIu16" is unsupported\n", data);
                 ret = AVERROR_PATCHWELCOME;
@@ -564,12 +567,13 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
         goto end;
     }
 
-    for (plane = 0; plane < 3 && !ret; plane++) {
+    planes = av_pix_fmt_count_planes(avctx->pix_fmt);
+    for (plane = 0; plane < planes && !ret; plane++) {
         /* level 1 */
         int lowpass_height  = s->plane[plane].band[0][0].height;
         int lowpass_width   = s->plane[plane].band[0][0].width;
         int highpass_stride = s->plane[plane].band[0][1].stride;
-        int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : 0;
+        int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
         int16_t *low, *high, *output, *dst;
 
         if (lowpass_height > s->plane[plane].band[0][0].a_height || lowpass_width > s->plane[plane].band[0][0].a_width ||
@@ -612,7 +616,7 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             high   += lowpass_width;
             output += lowpass_width * 2;
         }
-        if (avctx->pix_fmt == AV_PIX_FMT_GBRP12) {
+        if (s->bpc == 12) {
             output = s->plane[plane].subband[0];
             for (i = 0; i < lowpass_height * 2; i++) {
                 for (j = 0; j < lowpass_width * 2; j++)
-- 
1.9.1



More information about the ffmpeg-devel mailing list