diff mbox

[FFmpeg-devel] lavc/dpx: Support 12-bit packing method b (msbpad)

Message ID CAB0OVGrPz=tN5Wim3VErDje=m3ANA1YoYy+deqqsNTd-rVT0xQ@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos June 16, 2018, 8:54 p.m. UTC
2018-06-16 17:18 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:

> Attached patch allows to decode files that can be created with
> GraphicsMagick:
> $ gm convert input -depth 12 -define dpx:packing-method=b out.dpx

Updated patch attached, hoping I understood Jerome's comment correctly.

Please comment, Carl Eugen

Comments

Carl Eugen Hoyos June 21, 2018, 5:43 p.m. UTC | #1
2018-06-16 22:54 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
> 2018-06-16 17:18 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
>
>> Attached patch allows to decode files that can be created with
>> GraphicsMagick:
>> $ gm convert input -depth 12 -define dpx:packing-method=b out.dpx
>
> Updated patch attached, hoping I understood Jerome's comment correctly.

Patch applied.

Carl Eugen
diff mbox

Patch

From 93c9de7a1ca638dfe7bb2a4108974e55ab13c9b8 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Sat, 16 Jun 2018 17:11:58 +0200
Subject: [PATCH] lavc/dpx: Support 12-bit packing method b (msbpad).

---
 libavcodec/dpx.c |   22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 582a861..69d594b 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -170,10 +170,6 @@  static int decode_frame(AVCodecContext *avctx,
     packing = read16(&buf, endian);
     encoding = read16(&buf, endian);
 
-    if (packing > 1) {
-        avpriv_report_missing_feature(avctx, "Packing %d", packing);
-        return AVERROR_PATCHWELCOME;
-    }
     if (encoding) {
         avpriv_report_missing_feature(avctx, "Encoding %d", encoding);
         return AVERROR_PATCHWELCOME;
@@ -225,7 +221,7 @@  static int decode_frame(AVCodecContext *avctx,
         stride = avctx->width * elements;
         break;
     case 10:
-        if (!packing) {
+        if (!packing || packing > 1) {
             av_log(avctx, AV_LOG_ERROR, "Packing to 32bit required\n");
             return -1;
         }
@@ -387,16 +383,16 @@  static int decode_frame(AVCodecContext *avctx,
                                 (uint16_t*)ptr[1],
                                 (uint16_t*)ptr[2],
                                 (uint16_t*)ptr[3]};
+            int shift = packing == 1 ? 4 : 0;
             for (y = 0; y < avctx->width; y++) {
                 if (packing) {
-                if (elements >= 3)
-                    *dst[2]++ = read16(&buf, endian) >> 4;
-                *dst[0] = read16(&buf, endian) >> 4;
-                dst[0]++;
-                if (elements >= 2)
-                    *dst[1]++ = read16(&buf, endian) >> 4;
-                if (elements == 4)
-                    *dst[3]++ = read16(&buf, endian) >> 4;
+                    if (elements >= 3)
+                        *dst[2]++ = read16(&buf, endian) >> shift & 0xFFF;
+                    *dst[0]++ = read16(&buf, endian) >> shift & 0xFFF;
+                    if (elements >= 2)
+                        *dst[1]++ = read16(&buf, endian) >> shift & 0xFFF;
+                    if (elements == 4)
+                        *dst[3]++ = read16(&buf, endian) >> shift & 0xFFF;
                 } else {
                     *dst[2]++ = read12in32(&buf, &rgbBuffer,
                                            &n_datum, endian);
-- 
1.7.10.4