Browse code

remove mpegvideo.c img resample dependancy

Originally committed as revision 5258 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2006/04/01 05:43:37
Showing 4 changed files
... ...
@@ -4056,6 +4056,11 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
4056 4056
     c->inner_add_yblock = ff_snow_inner_add_yblock;
4057 4057
 #endif
4058 4058
 
4059
+    c->shrink[0]= ff_img_copy_plane;
4060
+    c->shrink[1]= ff_shrink22;
4061
+    c->shrink[2]= ff_shrink44;
4062
+    c->shrink[3]= ff_shrink88;
4063
+
4059 4064
     c->prefetch= just_return;
4060 4065
 
4061 4066
 #ifdef HAVE_MMX
... ...
@@ -76,6 +76,12 @@ void ff_vp3_idct_c(DCTELEM *block/* align 16*/);
76 76
 void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
77 77
 void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
78 78
 
79
+/* 1/2^n downscaling functions from imgconvert.c */
80
+void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
81
+void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
82
+void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
83
+void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
84
+
79 85
 /* minimum alignment rules ;)
80 86
 if u notice errors in the align stuff, need more alignment for some asm code for some cpu
81 87
 or need to use a function with less aligned data then send a mail to the ffmpeg-dev list, ...
... ...
@@ -345,6 +351,8 @@ typedef struct DSPContext {
345 345
     void (*inner_add_yblock)(uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8);
346 346
 
347 347
     void (*prefetch)(void *mem, int stride, int h);
348
+
349
+    void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height);
348 350
 } DSPContext;
349 351
 
350 352
 void dsputil_static_init(void);
... ...
@@ -572,7 +572,7 @@ int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
572 572
     return dst_pix_fmt;
573 573
 }
574 574
 
575
-static void img_copy_plane(uint8_t *dst, int dst_wrap,
575
+void ff_img_copy_plane(uint8_t *dst, int dst_wrap,
576 576
                            const uint8_t *src, int src_wrap,
577 577
                            int width, int height)
578 578
 {
... ...
@@ -612,7 +612,7 @@ void img_copy(AVPicture *dst, const AVPicture *src,
612 612
             break;
613 613
         }
614 614
         bwidth = (width * bits + 7) >> 3;
615
-        img_copy_plane(dst->data[0], dst->linesize[0],
615
+        ff_img_copy_plane(dst->data[0], dst->linesize[0],
616 616
                        src->data[0], src->linesize[0],
617 617
                        bwidth, height);
618 618
         break;
... ...
@@ -626,17 +626,17 @@ void img_copy(AVPicture *dst, const AVPicture *src,
626 626
                 h >>= pf->y_chroma_shift;
627 627
             }
628 628
             bwidth = (w * pf->depth + 7) >> 3;
629
-            img_copy_plane(dst->data[i], dst->linesize[i],
629
+            ff_img_copy_plane(dst->data[i], dst->linesize[i],
630 630
                            src->data[i], src->linesize[i],
631 631
                            bwidth, h);
632 632
         }
633 633
         break;
634 634
     case FF_PIXEL_PALETTE:
635
-        img_copy_plane(dst->data[0], dst->linesize[0],
635
+        ff_img_copy_plane(dst->data[0], dst->linesize[0],
636 636
                        src->data[0], src->linesize[0],
637 637
                        width, height);
638 638
         /* copy the palette */
639
-        img_copy_plane(dst->data[1], dst->linesize[1],
639
+        ff_img_copy_plane(dst->data[1], dst->linesize[1],
640 640
                        src->data[1], src->linesize[1],
641 641
                        4, 256);
642 642
         break;
... ...
@@ -1210,7 +1210,7 @@ static void shrink12(uint8_t *dst, int dst_wrap,
1210 1210
 }
1211 1211
 
1212 1212
 /* 2x2 -> 1x1 */
1213
-static void shrink22(uint8_t *dst, int dst_wrap,
1213
+void ff_shrink22(uint8_t *dst, int dst_wrap,
1214 1214
                      const uint8_t *src, int src_wrap,
1215 1215
                      int width, int height)
1216 1216
 {
... ...
@@ -1243,7 +1243,7 @@ static void shrink22(uint8_t *dst, int dst_wrap,
1243 1243
 }
1244 1244
 
1245 1245
 /* 4x4 -> 1x1 */
1246
-static void shrink44(uint8_t *dst, int dst_wrap,
1246
+void ff_shrink44(uint8_t *dst, int dst_wrap,
1247 1247
                      const uint8_t *src, int src_wrap,
1248 1248
                      int width, int height)
1249 1249
 {
... ...
@@ -1273,6 +1273,28 @@ static void shrink44(uint8_t *dst, int dst_wrap,
1273 1273
     }
1274 1274
 }
1275 1275
 
1276
+/* 8x8 -> 1x1 */
1277
+void ff_shrink88(uint8_t *dst, int dst_wrap,
1278
+                     const uint8_t *src, int src_wrap,
1279
+                     int width, int height)
1280
+{
1281
+    int w, i;
1282
+
1283
+    for(;height > 0; height--) {
1284
+        for(w = width;w > 0; w--) {
1285
+            int tmp=0;
1286
+            for(i=0; i<8; i++){
1287
+                tmp += src[0] + src[1] + src[2] + src[3] + src[4] + src[5] + src[6] + src[7];
1288
+                src += src_wrap;
1289
+            }
1290
+            *(dst++) = (tmp + 32)>>6;
1291
+            src += 8 - 8*src_wrap;
1292
+        }
1293
+        src += 8*src_wrap - 8*width;
1294
+        dst += dst_wrap - width;
1295
+    }
1296
+}
1297
+
1276 1298
 static void grow21_line(uint8_t *dst, const uint8_t *src,
1277 1299
                         int width)
1278 1300
 {
... ...
@@ -2023,7 +2045,7 @@ int img_convert(AVPicture *dst, int dst_pix_fmt,
2023 2023
         uint8_t *d;
2024 2024
 
2025 2025
         if (dst_pix->color_type == FF_COLOR_YUV_JPEG) {
2026
-            img_copy_plane(dst->data[0], dst->linesize[0],
2026
+            ff_img_copy_plane(dst->data[0], dst->linesize[0],
2027 2027
                      src->data[0], src->linesize[0],
2028 2028
                      dst_width, dst_height);
2029 2029
         } else {
... ...
@@ -2051,7 +2073,7 @@ int img_convert(AVPicture *dst, int dst_pix_fmt,
2051 2051
     if (is_yuv_planar(src_pix) &&
2052 2052
         dst_pix_fmt == PIX_FMT_GRAY8) {
2053 2053
         if (src_pix->color_type == FF_COLOR_YUV_JPEG) {
2054
-            img_copy_plane(dst->data[0], dst->linesize[0],
2054
+            ff_img_copy_plane(dst->data[0], dst->linesize[0],
2055 2055
                      src->data[0], src->linesize[0],
2056 2056
                      dst_width, dst_height);
2057 2057
         } else {
... ...
@@ -2089,7 +2111,7 @@ int img_convert(AVPicture *dst, int dst_pix_fmt,
2089 2089
            YUV444 format */
2090 2090
         switch(xy_shift) {
2091 2091
         case 0x00:
2092
-            resize_func = img_copy_plane;
2092
+            resize_func = ff_img_copy_plane;
2093 2093
             break;
2094 2094
         case 0x10:
2095 2095
             resize_func = shrink21;
... ...
@@ -2101,10 +2123,10 @@ int img_convert(AVPicture *dst, int dst_pix_fmt,
2101 2101
             resize_func = shrink12;
2102 2102
             break;
2103 2103
         case 0x11:
2104
-            resize_func = shrink22;
2104
+            resize_func = ff_shrink22;
2105 2105
             break;
2106 2106
         case 0x22:
2107
-            resize_func = shrink44;
2107
+            resize_func = ff_shrink44;
2108 2108
             break;
2109 2109
         case 0xf0:
2110 2110
             resize_func = grow21;
... ...
@@ -2126,7 +2148,7 @@ int img_convert(AVPicture *dst, int dst_pix_fmt,
2126 2126
             goto no_chroma_filter;
2127 2127
         }
2128 2128
 
2129
-        img_copy_plane(dst->data[0], dst->linesize[0],
2129
+        ff_img_copy_plane(dst->data[0], dst->linesize[0],
2130 2130
                        src->data[0], src->linesize[0],
2131 2131
                        dst_width, dst_height);
2132 2132
 
... ...
@@ -2180,10 +2180,11 @@ static int estimate_best_b_count(MpegEncContext *s){
2180 2180
     int i, j, out_size, p_lambda, b_lambda, lambda2;
2181 2181
     int outbuf_size= s->width * s->height; //FIXME
2182 2182
     uint8_t *outbuf= av_malloc(outbuf_size);
2183
-    ImgReSampleContext *resample;
2184 2183
     int64_t best_rd= INT64_MAX;
2185 2184
     int best_b_count= -1;
2186 2185
 
2186
+    assert(scale>=0 && scale <=3);
2187
+
2187 2188
 //    emms_c();
2188 2189
     p_lambda= s->last_lambda_for[P_TYPE]; //s->next_picture_ptr->quality;
2189 2190
     b_lambda= s->last_lambda_for[B_TYPE]; //p_lambda *ABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
... ...
@@ -2205,8 +2206,6 @@ static int estimate_best_b_count(MpegEncContext *s){
2205 2205
     if (avcodec_open(c, codec) < 0)
2206 2206
         return -1;
2207 2207
 
2208
-    resample= img_resample_init(c->width, c->height, s->width, s->height); //FIXME use sws
2209
-
2210 2208
     for(i=0; i<s->max_b_frames+2; i++){
2211 2209
         int ysize= c->width*c->height;
2212 2210
         int csize= (c->width/2)*(c->height/2);
... ...
@@ -2229,9 +2228,11 @@ static int estimate_best_b_count(MpegEncContext *s){
2229 2229
         input[i].linesize[1]=
2230 2230
         input[i].linesize[2]= c->width/2;
2231 2231
 
2232
-        if(!i || s->input_picture[i-1])
2233
-            img_resample(resample, (AVPicture*)&input[i],
2234
-                         (AVPicture*)&pre_input);
2232
+        if(!i || s->input_picture[i-1]){
2233
+            s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height);
2234
+            s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1);
2235
+            s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1);
2236
+        }
2235 2237
     }
2236 2238
 
2237 2239
     for(j=0; j<s->max_b_frames+1; j++){
... ...
@@ -2273,7 +2274,6 @@ static int estimate_best_b_count(MpegEncContext *s){
2273 2273
     av_freep(&outbuf);
2274 2274
     avcodec_close(c);
2275 2275
     av_freep(&c);
2276
-    img_resample_close(resample);
2277 2276
 
2278 2277
     for(i=0; i<s->max_b_frames+2; i++){
2279 2278
         av_freep(&input[i].data[0]);