]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/imgresample.c
ac3: detect dba errors and prevent writing past end of array
[ffmpeg] / libavcodec / imgresample.c
index d2c5364b45ca50db052bbad46e53cb6030104361..3c70c2a1cb91fba75d4b2fa17e7a2ddabb5c435e 100644 (file)
@@ -53,7 +53,7 @@ struct SwsContext {
     enum PixelFormat src_pix_fmt, dst_pix_fmt;
 };
 
-struct ImgReSampleContext {
+typedef struct ImgReSampleContext {
     int iwidth, iheight, owidth, oheight;
     int topBand, bottomBand, leftBand, rightBand;
     int padtop, padbottom, padleft, padright;
@@ -62,7 +62,7 @@ struct ImgReSampleContext {
     DECLARE_ALIGNED_8(int16_t, h_filters[NB_PHASES][NB_TAPS]); /* horizontal filters */
     DECLARE_ALIGNED_8(int16_t, v_filters[NB_PHASES][NB_TAPS]); /* vertical filters */
     uint8_t *line_buf;
-};
+} ImgReSampleContext;
 
 void av_build_filter(int16_t *filter, double factor, int tap_count, int phase_count, int scale, int type);
 
@@ -343,7 +343,7 @@ static void h_resample(uint8_t *dst, int dst_width, const uint8_t *src,
         n = dst_width;
     }
 #ifdef HAVE_MMX
-    if ((mm_flags & MM_MMX) && NB_TAPS == 4)
+    if ((mm_flags & FF_MM_MMX) && NB_TAPS == 4)
         h_resample_fast4_mmx(dst, n,
                              src, src_width, src_start, src_incr, filters);
     else
@@ -401,17 +401,17 @@ static void component_resample(ImgReSampleContext *s,
         phase_y = get_phase(src_y);
 #ifdef HAVE_MMX
         /* desactivated MMX because loss of precision */
-        if ((mm_flags & MM_MMX) && NB_TAPS == 4 && 0)
+        if ((mm_flags & FF_MM_MMX) && NB_TAPS == 4 && 0)
             v_resample4_mmx(output, owidth,
                             s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
                             &s->v_filters[phase_y][0]);
         else
 #endif
 #ifdef HAVE_ALTIVEC
-            if ((mm_flags & MM_ALTIVEC) && NB_TAPS == 4 && FILTER_BITS <= 6)
-                v_resample16_altivec(output, owidth,
-                                s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
-                                &s->v_filters[phase_y][0]);
+        if ((mm_flags & FF_MM_ALTIVEC) && NB_TAPS == 4 && FILTER_BITS <= 6)
+            v_resample16_altivec(output, owidth,
+                                 s->line_buf + (ring_y - NB_TAPS + 1) * owidth,
+                                 owidth, &s->v_filters[phase_y][0]);
         else
 #endif
             v_resample(output, owidth,
@@ -424,13 +424,6 @@ static void component_resample(ImgReSampleContext *s,
     }
 }
 
-ImgReSampleContext *img_resample_init(int owidth, int oheight,
-                                      int iwidth, int iheight)
-{
-    return img_resample_full_init(owidth, oheight, iwidth, iheight,
-            0, 0, 0, 0, 0, 0, 0, 0);
-}
-
 ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
                                       int iwidth, int iheight,
                                       int topBand, int bottomBand,
@@ -484,6 +477,13 @@ fail:
     return NULL;
 }
 
+ImgReSampleContext *img_resample_init(int owidth, int oheight,
+                                      int iwidth, int iheight)
+{
+    return img_resample_full_init(owidth, oheight, iwidth, iheight,
+            0, 0, 0, 0, 0, 0, 0, 0);
+}
+
 void img_resample(ImgReSampleContext *s,
                   AVPicture *output, const AVPicture *input)
 {
@@ -512,7 +512,12 @@ void img_resample_close(ImgReSampleContext *s)
     av_free(s);
 }
 
-static const AVClass context_class = { "imgresample", NULL, NULL };
+static const char *context_to_name(void* ptr)
+{
+    return "imgconvert";
+}
+
+static const AVClass context_class = { "imgresample", context_to_name, NULL };
 
 struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat,
                                   int dstW, int dstH, int dstFormat,
@@ -785,7 +790,7 @@ int main(int argc, char **argv)
         }
     }
     save_pgm("/tmp/in.pgm", img, XSIZE, YSIZE);
-    for(i=0;i<sizeof(factors)/sizeof(float);i++) {
+    for(i=0;i<FF_ARRAY_ELEMS(factors);i++) {
         fact = factors[i];
         xsize = (int)(XSIZE * fact);
         ysize = (int)((YSIZE - 100) * fact);
@@ -806,7 +811,7 @@ int main(int argc, char **argv)
     fact = 0.72;
     xsize = (int)(XSIZE * fact);
     ysize = (int)(YSIZE * fact);
-    mm_flags = MM_MMX;
+    mm_flags = FF_MM_MMX;
     s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
     component_resample(s, img1, xsize, xsize, ysize,
                        img, XSIZE, XSIZE, YSIZE);