Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 9 Jan 2014 14:46:31 +0000 (15:46 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 9 Jan 2014 14:46:31 +0000 (15:46 +0100)
* qatar/master:
  mjpegdec: apply flipping after decoding, not before

Conflicts:
libavcodec/mjpegdec.c
libavcodec/mjpegdec.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/mjpegdec.c
libavcodec/mjpegdec.h

@@@ -479,9 -367,17 +479,15 @@@ unk_pixfmt
              s->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
      }
  
+     s->pix_desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
+     if (!s->pix_desc) {
+         av_log(s->avctx, AV_LOG_ERROR, "Could not get a pixel format descriptor.\n");
+         return AVERROR_BUG;
+     }
      av_frame_unref(s->picture_ptr);
 -    if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0) {
 -        av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 +    if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0)
          return -1;
 -    }
      s->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
      s->picture_ptr->key_frame = 1;
      s->got_picture            = 1;
@@@ -1106,11 -830,6 +1112,13 @@@ static int mjpeg_decode_scan(MJpegDecod
      if (mb_bitmask)
          init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height);
  
 +    if (s->flipped && s->avctx->lowres) {
 +        av_log(s->avctx, AV_LOG_ERROR, "Can not flip image with lowres\n");
 +        s->flipped = 0;
 +    }
++
 +    s->restart_count = 0;
++
      for (i = 0; i < nb_components; i++) {
          int c   = s->comp_index[i];
          data[c] = s->picture_ptr->data[c];
@@@ -1904,26 -1576,27 +1905,35 @@@ eoi_parser
                  s->bottom_field ^= 1;
                  /* if not bottom field, do not output image yet */
                  if (s->bottom_field == !s->interlace_polarity)
 -                    goto not_the_end;
 +                    break;
              }
-             if ((ret = av_frame_ref(data, s->picture_ptr)) < 0)
+             if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0)
                  return ret;
+             if (s->flipped) {
+                 int i;
+                 for (i = 0; frame->data[i]; i++) {
+                     int h = frame->height >> ((i == 1 || i == 2) ?
+                                               s->pix_desc->log2_chroma_h : 0);
+                     frame->data[i] += frame->linesize[i] * (h - 1);
+                     frame->linesize[i] *= -1;
+                 }
+             }
              *got_frame = 1;
 +            s->got_picture = 0;
 +
 +            if (!s->lossless) {
 +                int qp = FFMAX3(s->qscale[0],
 +                                s->qscale[1],
 +                                s->qscale[2]);
 +                int qpw = (s->width + 15) / 16;
 +                AVBufferRef *qp_table_buf = av_buffer_alloc(qpw);
 +                if (qp_table_buf) {
 +                    memset(qp_table_buf->data, qp, qpw);
 +                    av_frame_set_qp_table(data, qp_table_buf, 0, FF_QSCALE_TYPE_MPEG1);
 +                }
  
 -            if (!s->lossless &&
 -                avctx->debug & FF_DEBUG_QP) {
 -                av_log(avctx, AV_LOG_DEBUG,
 -                       "QP: %d\n", FFMAX3(s->qscale[0],
 -                                          s->qscale[1],
 -                                          s->qscale[2]));
 +                if(avctx->debug & FF_DEBUG_QP)
 +                    av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", qp);
              }
  
              goto the_end;
@@@ -119,7 -114,8 +120,9 @@@ typedef struct MJpegDecodeContext 
      unsigned int ljpeg_buffer_size;
  
      int extern_huff;
 +    AVDictionary *exif_metadata;
+     const AVPixFmtDescriptor *pix_desc;
  } MJpegDecodeContext;
  
  int ff_mjpeg_decode_init(AVCodecContext *avctx);