avcodec/ljpegenc: fix mem allocation failure return code encode_picture_lossless()
[ffmpeg.git] / libavcodec / ljpegenc.c
index 09ae790..7e536a8 100644 (file)
@@ -63,7 +63,7 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
         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;
+            return AVERROR(ENOMEM);
         }
     }
 
@@ -132,9 +132,9 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
                     diff= ((left[i] - pred + 0x100)&0x1FF) - 0x100;
 
                     if(i==0)
-                        ff_mjpeg_encode_dc(s, diff, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
+                        ff_mjpeg_encode_dc(&s->pb, diff, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
                     else
-                        ff_mjpeg_encode_dc(s, diff, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
+                        ff_mjpeg_encode_dc(&s->pb, diff, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
                 }
             }
         }
@@ -175,9 +175,9 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
                                 }
 
                                 if(i==0)
-                                    ff_mjpeg_encode_dc(s, *ptr - pred, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
+                                    ff_mjpeg_encode_dc(&s->pb, *ptr - pred, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
                                 else
-                                    ff_mjpeg_encode_dc(s, *ptr - pred, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
+                                    ff_mjpeg_encode_dc(&s->pb, *ptr - pred, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
                             }
                         }
                     }
@@ -187,19 +187,19 @@ static int encode_picture_lossless(AVCodecContext *avctx, AVPacket *pkt,
                         int x, y, h, v, linesize;
                         h = s->mjpeg_hsample[i];
                         v = s->mjpeg_vsample[i];
-                        linesize= p->linesize[i];
+                        linesize = pict->linesize[i];
 
                         for(y=0; y<v; y++){
                             for(x=0; x<h; x++){
                                 int pred;
 
-                                ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
+                                ptr = pict->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
                                 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
 
                                 if(i==0)
-                                    ff_mjpeg_encode_dc(s, *ptr - pred, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
+                                    ff_mjpeg_encode_dc(&s->pb, *ptr - pred, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
                                 else
-                                    ff_mjpeg_encode_dc(s, *ptr - pred, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
+                                    ff_mjpeg_encode_dc(&s->pb, *ptr - pred, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
                             }
                         }
                     }
@@ -210,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);