]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/g2meet.c
avcodec: loongson optimized mpegvideo dct unquantize with mmi
[ffmpeg] / libavcodec / g2meet.c
index 2a7124a378625160731e71af72ba6b72a645593b..22efd7583aac9c28b4d47bfe2c9dea448ad40cbd 100644 (file)
@@ -387,20 +387,10 @@ static int jpg_decode_data(JPGContext *c, int width, int height,
 #define G_shift  8
 #define B_shift  0
 
-static inline int log2_ceil(uint32_t x)
-{
-    int c = 0;
-
-    for (--x; x > 0; x >>= 1)
-        c++;
-
-    return c;
-}
-
 /* improved djb2 hash from http://www.cse.yorku.ca/~oz/hash.html */
 static int djb2_hash(uint32_t key)
 {
-    int h = 5381;
+    uint32_t h = 5381;
 
     h = (h * 33) ^ ((key >> 24) & 0xFF); // xxx: probably not needed at all
     h = (h * 33) ^ ((key >> 16) & 0xFF);
@@ -565,6 +555,11 @@ static uint32_t epic_decode_pixel_pred(ePICContext *dc, int x, int y,
         B     = ((pred >> B_shift) & 0xFF) - TOSIGNED(delta);
     }
 
+    if (R<0 || G<0 || B<0) {
+        av_log(NULL, AV_LOG_ERROR, "RGB %d %d %d is out of range\n", R, G, B);
+        return 0;
+    }
+
     return (R << R_shift) | (G << G_shift) | (B << B_shift);
 }
 
@@ -702,7 +697,7 @@ static int epic_decode_run_length(ePICContext *dc, int x, int y, int tile_width,
                 if (!(above_row[pos] == pix))
                     break;
             run = pos - start_pos - 1;
-            idx = log2_ceil(run);
+            idx = av_ceil_log2(run);
             if (ff_els_decode_bit(&dc->els_ctx, &dc->prev_row_rung[idx]))
                 *pRun += run;
             else {
@@ -1181,11 +1176,12 @@ static int g2m_init_buffers(G2MContext *c)
         c->tile_stride     = FFALIGN(c->tile_width, 16) * 3;
         c->epic_buf_stride = FFALIGN(c->tile_width * 4, 16);
         aligned_height     = FFALIGN(c->tile_height,    16);
-        av_free(c->synth_tile);
-        av_free(c->jpeg_tile);
-        av_free(c->kempf_buf);
-        av_free(c->kempf_flags);
-        av_free(c->epic_buf_base);
+        av_freep(&c->synth_tile);
+        av_freep(&c->jpeg_tile);
+        av_freep(&c->kempf_buf);
+        av_freep(&c->kempf_flags);
+        av_freep(&c->epic_buf_base);
+        c->epic_buf    = NULL;
         c->synth_tile  = av_mallocz(c->tile_stride      * aligned_height);
         c->jpeg_tile   = av_mallocz(c->tile_stride      * aligned_height);
         c->kempf_buf   = av_mallocz((c->tile_width + 1) * aligned_height +
@@ -1614,6 +1610,7 @@ static av_cold int g2m_decode_end(AVCodecContext *avctx)
     jpg_free_context(&c->jc);
 
     av_freep(&c->epic_buf_base);
+    c->epic_buf = NULL;
     av_freep(&c->kempf_buf);
     av_freep(&c->kempf_flags);
     av_freep(&c->synth_tile);