aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mjpegdec.c
diff options
context:
space:
mode:
authorNick Renieris <velocityra@gmail.com>2019-08-29 16:10:48 +0300
committerPaul B Mahol <onemda@gmail.com>2019-09-02 09:26:52 +0200
commita75a9e8f64ec9660b7c6e16653299f07bfe00f9d (patch)
tree101df2e6d34aeb26197538dbda0ebbd11b925423 /libavcodec/mjpegdec.c
parentc510ed2ee8b3d5ec373d9d8a7e5a25c132ca620e (diff)
downloadffmpeg-a75a9e8f64ec9660b7c6e16653299f07bfe00f9d.tar.gz
lavc/mjpegdec: Enable decoding of single-component bayer images
Also, ensure no false positives when determining DNG bayer images, by setting them in tiff.c instead of relying on a heuristic. There's no way to determine this just from the JPEG data, so we have to pass this information from outside the MJPEG decoder. Signed-off-by: Nick Renieris <velocityra@gmail.com>
Diffstat (limited to 'libavcodec/mjpegdec.c')
-rw-r--r--libavcodec/mjpegdec.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 6391107f78..0a920a7144 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -412,13 +412,17 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
return AVERROR_PATCHWELCOME;
}
- /* Lossless JPEGs encoded in DNGs are commonly bayer-encoded. They contain 2
- interleaved components and the width stored in their SOF3 markers is the
- width of each one. We only output a single component, therefore we need
- to adjust the output image width. */
- if (s->lossless == 1 && nb_components == 2) {
- s->bayer = 1;
- width *= 2;
+ if (s->bayer) {
+ if (nb_components == 2) {
+ /* Bayer images embedded in DNGs can contain 2 interleaved components and the
+ width stored in their SOF3 markers is the width of each one. We only output
+ a single component, therefore we need to adjust the output image width. We
+ handle the deinterleaving (but not the debayering) in this file. */
+ width *= 2;
+ }
+ /* They can also contain 1 component, which is double the width and half the height
+ of the final image (rows are interleaved). We don't handle the decoding in this
+ file, but leave that to the TIFF/DNG decoder. */
}
/* if different size, realloc/alloc picture */
@@ -1184,10 +1188,16 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int p
ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1];
}
- } else if (s->bayer && nb_components == 2) {
- for (mb_x = 0; mb_x < width; mb_x++) {
- ((uint16_t*)ptr)[2*mb_x + 0] = buffer[mb_x][0];
- ((uint16_t*)ptr)[2*mb_x + 1] = buffer[mb_x][1];
+ } else if (s->bayer) {
+ if (nb_components == 1) {
+ /* Leave decoding to the TIFF/DNG decoder (see comment in ff_mjpeg_decode_sof) */
+ for (mb_x = 0; mb_x < width; mb_x++)
+ ((uint16_t*)ptr)[mb_x] = buffer[mb_x][0];
+ } else if (nb_components == 2) {
+ for (mb_x = 0; mb_x < width; mb_x++) {
+ ((uint16_t*)ptr)[2*mb_x + 0] = buffer[mb_x][0];
+ ((uint16_t*)ptr)[2*mb_x + 1] = buffer[mb_x][1];
+ }
}
} else {
for(i=0; i<nb_components; i++) {