[FFmpeg-devel,5/7] avcodec/dpx: improve decoding of 10 bit gray images

Submitted by Paul B Mahol on Dec. 6, 2018, 7:34 p.m.

Details

Message ID 20181206193424.21383-5-onemda@gmail.com
State Accepted
Commit 788e116c2f10bbe99c334e94087560cf0ebb5f7a
Headers show

Commit Message

Paul B Mahol Dec. 6, 2018, 7:34 p.m.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/dpx.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Comments

Carl Eugen Hoyos Dec. 7, 2018, 12:48 p.m.
2018-12-06 20:34 GMT+01:00, Paul B Mahol <onemda@gmail.com>:

> +    temp = *lbuf >> shift & 0x3FF;
> +    *lbuf = *lbuf >> 10;
> +
> +    return temp;
> +}
> +
>  static uint16_t read10in32(const uint8_t **ptr, uint32_t * lbuf,
>                                    int * n_datum, int is_big, int shift)
>  {
> @@ -385,13 +403,17 @@ static int decode_frame(AVCodecContext *avctx,
>                                  (uint16_t*)ptr[1],
>                                  (uint16_t*)ptr[2],
>                                  (uint16_t*)ptr[3]};
> -            int shift = packing == 1 ? 22 : 20;
> +            int shift = elements > 1 ? packing == 1 ? 22 : 20 : packing ==
> 1 ? 2 : 0;

I still find this hard to read but if you cannot simplify please commit.

Thank you, Carl Eugen

Patch hide | download patch | download mbox

diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index cfe60aaaa1..ed17bf3858 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -51,6 +51,24 @@  static unsigned int read32(const uint8_t **ptr, int is_big)
     return temp;
 }
 
+static uint16_t read10in32_gray(const uint8_t **ptr, uint32_t *lbuf,
+                                int *n_datum, int is_big, int shift)
+{
+    uint16_t temp;
+
+    if (*n_datum)
+        (*n_datum)--;
+    else {
+        *lbuf = read32(ptr, is_big);
+        *n_datum = 2;
+    }
+
+    temp = *lbuf >> shift & 0x3FF;
+    *lbuf = *lbuf >> 10;
+
+    return temp;
+}
+
 static uint16_t read10in32(const uint8_t **ptr, uint32_t * lbuf,
                                   int * n_datum, int is_big, int shift)
 {
@@ -385,13 +403,17 @@  static int decode_frame(AVCodecContext *avctx,
                                 (uint16_t*)ptr[1],
                                 (uint16_t*)ptr[2],
                                 (uint16_t*)ptr[3]};
-            int shift = packing == 1 ? 22 : 20;
+            int shift = elements > 1 ? packing == 1 ? 22 : 20 : packing == 1 ? 2 : 0;
             for (y = 0; y < avctx->width; y++) {
                 if (elements >= 3)
                     *dst[2]++ = read10in32(&buf, &rgbBuffer,
                                            &n_datum, endian, shift);
-                *dst[0]++ = read10in32(&buf, &rgbBuffer,
-                                       &n_datum, endian, shift);
+                if (elements == 1)
+                    *dst[0]++ = read10in32_gray(&buf, &rgbBuffer,
+                                                &n_datum, endian, shift);
+                else
+                    *dst[0]++ = read10in32(&buf, &rgbBuffer,
+                                           &n_datum, endian, shift);
                 if (elements >= 2)
                     *dst[1]++ = read10in32(&buf, &rgbBuffer,
                                            &n_datum, endian, shift);