[FFmpeg-devel] [PATCH 2/2] avcodec/dpx: improve decoding support for 10 bit depth
Paul B Mahol
onemda at gmail.com
Thu Dec 6 12:56:40 EET 2018
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavcodec/dpx.c | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 0297287938..84894abda5 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -50,6 +50,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)
{
@@ -107,6 +125,7 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *const p = data;
uint8_t *ptr[AV_NUM_DATA_POINTERS];
uint32_t header_version, version = 0;
+ const uint8_t *creator;
unsigned int offset;
int magic_num, endian;
@@ -151,6 +170,9 @@ static int decode_frame(AVCodecContext *avctx,
av_log(avctx, AV_LOG_WARNING, "Unknown header format version %s.\n",
av_fourcc2str(header_version));
+ buf = avpkt->data + 160;
+ creator = buf;
+
// Check encryption
buf = avpkt->data + 660;
ret = read32(&buf, endian);
@@ -320,6 +342,7 @@ static int decode_frame(AVCodecContext *avctx,
case 51121:
avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
break;
+ case 6100:
case 6101:
avctx->pix_fmt = AV_PIX_FMT_GRAY10;
break;
@@ -373,13 +396,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);
@@ -388,7 +415,8 @@ static int decode_frame(AVCodecContext *avctx,
read10in32(&buf, &rgbBuffer,
&n_datum, endian, shift);
}
- n_datum = 0;
+ if (version != 2 || !memcmp(creator, "GraphicsMagick", 14))
+ n_datum = 0;
for (i = 0; i < elements; i++)
ptr[i] += p->linesize[i];
}
--
2.17.1
More information about the ffmpeg-devel
mailing list