Merge commit '3360ad995530ea6967b1e83981b4aa8240fbb0ed'
[ffmpeg.git] / libavcodec / ljpegenc.c
index 76c3cb9..c467d63 100644 (file)
@@ -57,10 +57,14 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
                         * s->mjpeg_hsample[0] * s->mjpeg_vsample[0];
     }
 
-    if (!s->edge_emu_buffer &&
-        (ret = ff_mpv_frame_size_alloc(s, pict->linesize[0])) < 0) {
-        av_log(avctx, AV_LOG_ERROR, "failed to allocate context scratch buffers.\n");
-        return ret;
+    if (!s->rd_scratchpad) {
+        int alloc_size = FFALIGN(FFABS(pict->linesize[0]) + 64, 32);
+        s->me.scratchpad =
+        s->rd_scratchpad = av_mallocz(alloc_size * 4 * 16 * 2);
+        if (!s->rd_scratchpad) {
+            av_log(avctx, AV_LOG_ERROR, "failed to allocate context scratch buffers.\n");
+            return ret;
+        }
     }
 
     if ((ret = ff_alloc_packet2(avctx, pkt, max_pkt_size)) < 0)
@@ -75,7 +79,8 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
     p->pict_type= AV_PICTURE_TYPE_I;
     p->key_frame= 1;
 
-    ff_mjpeg_encode_picture_header(s);
+    ff_mjpeg_encode_picture_header(avctx, &s->pb, &s->intra_scantable,
+                                   s->intra_matrix);
 
     s->header_bits= put_bits_count(&s->pb);
 
@@ -205,8 +210,9 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
 
     emms_c();
     av_assert0(s->esc_pos == s->header_bits >> 3);
+
     ff_mjpeg_encode_stuffing(s);
-    ff_mjpeg_encode_picture_trailer(s);
+    ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits);
     s->picture_number++;
 
     flush_put_bits(&s->pb);
@@ -221,6 +227,7 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
 
 AVCodec ff_ljpeg_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them
     .name           = "ljpeg",
+    .long_name      = NULL_IF_CONFIG_SMALL("Lossless JPEG"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_LJPEG,
     .priv_data_size = sizeof(MpegEncContext),
@@ -232,5 +239,4 @@ AVCodec ff_ljpeg_encoder = { //FIXME avoid MPV_* lossless JPEG should not need t
         AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P,
         AV_PIX_FMT_NONE},
-    .long_name      = NULL_IF_CONFIG_SMALL("Lossless JPEG"),
 };