Commit a75a9e8f authored by Nick Renieris's avatar Nick Renieris Committed by Paul B Mahol

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: 's avatarNick Renieris <velocityra@gmail.com>
parent c510ed2e
...@@ -412,14 +412,18 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) ...@@ -412,14 +412,18 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
/* Lossless JPEGs encoded in DNGs are commonly bayer-encoded. They contain 2 if (s->bayer) {
interleaved components and the width stored in their SOF3 markers is the if (nb_components == 2) {
width of each one. We only output a single component, therefore we need /* Bayer images embedded in DNGs can contain 2 interleaved components and the
to adjust the output image width. */ width stored in their SOF3 markers is the width of each one. We only output
if (s->lossless == 1 && nb_components == 2) { a single component, therefore we need to adjust the output image width. We
s->bayer = 1; handle the deinterleaving (but not the debayering) in this file. */
width *= 2; 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 */ /* if different size, realloc/alloc picture */
if (width != s->width || height != s->height || bits != s->bits || if (width != s->width || height != s->height || bits != s->bits ||
...@@ -1184,11 +1188,17 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int p ...@@ -1184,11 +1188,17 @@ 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 + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1];
ptr[3*mb_x + 2] = buffer[mb_x][2] + 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) { } 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++) { 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 + 0] = buffer[mb_x][0];
((uint16_t*)ptr)[2*mb_x + 1] = buffer[mb_x][1]; ((uint16_t*)ptr)[2*mb_x + 1] = buffer[mb_x][1];
} }
}
} else { } else {
for(i=0; i<nb_components; i++) { for(i=0; i<nb_components; i++) {
int c= s->comp_index[i]; int c= s->comp_index[i];
......
...@@ -839,6 +839,13 @@ static int dng_decode_jpeg_tile(AVCodecContext *avctx, AVFrame *frame, ...@@ -839,6 +839,13 @@ static int dng_decode_jpeg_tile(AVCodecContext *avctx, AVFrame *frame,
jpkt.data = (uint8_t*)s->gb.buffer; jpkt.data = (uint8_t*)s->gb.buffer;
jpkt.size = tile_byte_count; jpkt.size = tile_byte_count;
if (s->is_bayer) {
MJpegDecodeContext *mjpegdecctx = s->avctx_mjpeg->priv_data;
/* We have to set this information here, there is no way to know if a given JPEG is a DNG-embedded
image or not from its own data (and we need that information when decoding it). */
mjpegdecctx->bayer = 1;
}
ret = avcodec_send_packet(s->avctx_mjpeg, &jpkt); ret = avcodec_send_packet(s->avctx_mjpeg, &jpkt);
if (ret < 0) { if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n"); av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment