Ticket #2171: 2171-filters-v2.patch
File 2171-filters-v2.patch, 13.6 KB (added by , 18 years ago) |
---|
-
filters/adjust/filter_adjust.c
34 34 { 35 35 VideoFilter vf; 36 36 37 int yend;38 int cend;39 40 int width;41 int height;42 43 37 #ifdef MMX 44 38 int yfilt; 45 39 int cfilt; … … 141 135 } 142 136 #endif /* MMX */ 143 137 144 static void SetupSize(ThisFilter *filter, VideoFrameType inpixfmt,145 int *width, int *height)146 {147 filter->width = *width;148 filter->height = *height;149 150 filter->yend = *width * *height;151 152 switch (inpixfmt)153 {154 case FMT_YV12:155 filter->cend = filter->yend + *width * *height / 2;156 break;157 case FMT_YUV422P:158 filter->cend = filter->yend + *width * *height;159 break;160 default:161 break;162 }163 }164 165 138 int adjustFilter (VideoFilter *vf, VideoFrame *frame) 166 139 { 167 140 ThisFilter *filter = (ThisFilter *) vf; 168 141 TF_VARS; 169 142 170 if (frame->width != filter->width || frame->height != filter->height)171 SetupSize(filter, frame->codec, &frame->width, &frame->height);172 173 143 TF_START; 144 { 145 unsigned char *ybeg = frame->buf + frame->offsets[0]; 146 unsigned char *yend = ybeg + (frame->pitches[0] * frame->height); 147 int cheight = (frame->codec == FMT_YV12) ? 148 (frame->height >> 1) : frame->height; 149 unsigned char *ubeg = frame->buf + frame->offsets[1]; 150 unsigned char *uend = ubeg + (frame->pitches[1] * cheight); 151 unsigned char *vbeg = frame->buf + frame->offsets[2]; 152 unsigned char *vend = ubeg + (frame->pitches[2] * cheight); 174 153 175 154 #ifdef MMX 176 if (filter->yfilt)177 adjustRegionMMX(frame->buf, frame->buf + filter->yend, filter->ytable,178 &(filter->yshift), &(filter->yscale), &(filter->ymin),179 mm_cpool + 1, mm_cpool + 2);180 else181 adjustRegion(frame->buf, frame->buf + filter->yend, filter->ytable);155 if (filter->yfilt) 156 adjustRegionMMX(ybeg, yend, filter->ytable, 157 &(filter->yshift), &(filter->yscale), 158 &(filter->ymin), mm_cpool + 1, mm_cpool + 2); 159 else 160 adjustRegion(ybeg, yend, filter->ytable); 182 161 183 if (filter->cfilt) 184 adjustRegionMMX(frame->buf + filter->yend, frame->buf + filter->cend, 185 filter->ctable, &(filter->cshift), &(filter->cscale), 186 &(filter->cmin), mm_cpool + 3, mm_cpool + 4); 187 else 188 adjustRegion(frame->buf + filter->yend, frame->buf + filter->cend, 189 filter->ctable); 162 if (filter->cfilt) 163 { 164 adjustRegionMMX(ubeg, uend, filter->ctable, 165 &(filter->cshift), &(filter->cscale), 166 &(filter->cmin), mm_cpool + 3, mm_cpool + 4); 167 adjustRegionMMX(vbeg, vend, filter->ctable, 168 &(filter->cshift), &(filter->cscale), 169 &(filter->cmin), mm_cpool + 3, mm_cpool + 4); 170 } 171 else 172 { 173 adjustRegion(ubeg, uend, filter->ctable); 174 adjustRegion(vbeg, vend, filter->ctable); 175 } 190 176 191 if (filter->yfilt || filter->cfilt)192 emms();177 if (filter->yfilt || filter->cfilt) 178 emms(); 193 179 194 180 #else /* MMX */ 195 adjustRegion(frame->buf, frame->buf + filter->yend, filter->ytable);196 adjustRegion(frame->buf + filter->yend, frame->buf + filter->cend,197 181 adjustRegion(ybeg, yend, filter->ytable); 182 adjustRegion(ubeg, uend, filter->ctable); 183 adjustRegion(vbeg, vend, filter->ctable); 198 184 #endif /* MMX */ 199 185 } 200 186 TF_END(filter, "Adjust: "); 201 187 return 0; 202 188 } … … 249 235 250 236 VideoFilter * 251 237 newAdjustFilter (VideoFrameType inpixfmt, VideoFrameType outpixfmt, 252 238 int *width, int *height, char *options) 253 239 { 254 240 ThisFilter *filter; 255 241 int numopts, ymin, ymax, cmin, cmax; 256 242 float ygamma, cgamma; 243 (void) width; 244 (void) height; 257 245 258 246 if (inpixfmt != outpixfmt || 259 247 (inpixfmt != FMT_YV12 && inpixfmt != FMT_YUV422P)) … … 305 293 fillTable (filter->ctable, cmin, cmax, 16, 240, cgamma); 306 294 #endif 307 295 308 SetupSize(filter, inpixfmt, width, height);309 310 296 filter->vf.filter = &adjustFilter; 311 297 filter->vf.cleanup = NULL; 312 298 -
filters/kerneldeint/filter_kerneldeint.c
16 16 #include "config.h" 17 17 #include "dsputil.h" 18 18 19 #undef ABS 19 20 #define ABS(A) ( (A) > 0 ? (A) : -(A) ) 20 21 #define CLAMP(A,L,U) ((A)>(U)?(U):((A)<(L)?(L):(A))) 21 22 … … 35 36 { 36 37 VideoFilter vf; 37 38 38 int width;39 int height;40 int uoff;41 int voff;42 int cwidth;43 int cheight;44 39 int threshold; 45 40 int skipchroma; 46 41 int mm_flags; 47 int size;48 42 void (*filtfunc)(uint8_t*, uint8_t*, int, int, int); 49 43 mmx_t threshold_low; 50 44 mmx_t threshold_high; 51 45 uint8_t *line; 46 int linesize; 52 47 TF_STRUCT; 53 48 } ThisFilter; 54 49 … … 249 244 } 250 245 #endif 251 246 252 static void SetupSize(ThisFilter *filter, VideoFrameType inpixfmt,253 int *width, int *height)254 {255 filter->width = *width;256 filter->height = *height;257 filter->cwidth = *width / 2;258 filter->uoff = *width * *height;259 260 switch (inpixfmt)261 {262 case FMT_YUV422P:263 filter->voff = filter->uoff + *width * *height / 2;264 filter->size = *width * *height * 2;265 filter->cheight = *height;266 break;267 case FMT_YV12:268 filter->voff = filter->uoff + *width * *height / 4;269 filter->size = *width * *height * 3 / 2;270 filter->cheight = *height / 2;271 break;272 default:273 ;274 }275 276 if (filter->line)277 free(filter->line);278 279 filter->line = malloc(*width);280 }281 282 247 static int 283 248 KernelDeint (VideoFilter * f, VideoFrame * frame) 284 249 { 285 250 ThisFilter *filter = (ThisFilter *) f; 286 251 TF_VARS; 287 252 288 if (frame->width != filter->width || frame->height != filter->height) 289 SetupSize(filter, frame->codec, &frame->width, &frame->height); 253 if (frame->pitches[0] > filter->linesize) 254 { 255 if (filter->line) 256 free(filter->line); 257 filter->line = malloc(frame->pitches[0]); 258 filter->linesize = frame->pitches[0]; 259 } 290 260 291 261 if (!filter->line) 292 262 { … … 295 265 } 296 266 297 267 TF_START; 298 (filter->filtfunc)(frame->buf, filter->line, filter->width,299 filter->height, filter->threshold);300 if (!filter->skipchroma)301 268 { 302 (filter->filtfunc)(frame->buf + filter->uoff, filter->line, 303 filter->cwidth, filter->cheight, filter->threshold); 304 (filter->filtfunc)(frame->buf + filter->voff, filter->line, 305 filter->cwidth, filter->cheight, filter->threshold); 306 } 269 unsigned char *ybeg = frame->buf + frame->offsets[0]; 270 unsigned char *ubeg = frame->buf + frame->offsets[1]; 271 unsigned char *vbeg = frame->buf + frame->offsets[2]; 272 int cheight = (frame->codec == FMT_YV12) ? 273 (frame->height >> 1) : frame->height; 274 275 (filter->filtfunc)(ybeg, filter->line, frame->pitches[0], 276 frame->height, filter->threshold); 277 278 if (!filter->skipchroma) 279 { 280 (filter->filtfunc)(ubeg, filter->line, frame->pitches[1], 281 cheight, filter->threshold); 282 (filter->filtfunc)(vbeg, filter->line, frame->pitches[2], 283 cheight, filter->threshold); 284 } 307 285 #ifdef MMX 308 if (filter->mm_flags)309 emms();286 if (filter->mm_flags) 287 emms(); 310 288 #endif 289 } 311 290 TF_END(filter, "KernelDeint: "); 312 291 return 0; 313 292 } … … 315 294 void 316 295 CleanupKernelDeintFilter (VideoFilter * filter) 317 296 { 318 free (((ThisFilter *)filter)->line); 297 if (((ThisFilter *)filter)->line) 298 free (((ThisFilter *)filter)->line); 319 299 } 320 300 321 301 VideoFilter * … … 324 304 { 325 305 ThisFilter *filter; 326 306 int numopts; 307 (void) height; 327 308 328 309 if ( inpixfmt != outpixfmt || 329 310 (inpixfmt != FMT_YV12 && inpixfmt != FMT_YUV422P) ) … … 356 337 #endif 357 338 filter->filtfunc = &KDP; 358 339 359 filter->line = NULL;360 SetupSize(filter, inpixfmt, width, height);340 filter->line = malloc(*width); 341 filter->linesize = *width; 361 342 362 343 if (filter->line == NULL) 363 344 { -
filters/ivtc/filter_ivtc.c
22 22 VideoFilter vf; 23 23 24 24 struct pullup_context *context; 25 int uoff;26 int voff;27 25 int height; 28 26 int width; 29 27 int progressive_frame_seen; … … 31 29 int apply_filter; 32 30 } ThisFilter; 33 31 32 static void SetupFilter(ThisFilter *vf, int width, int height, int *pitches); 33 34 34 static inline void * memcpy_pic(void * dst, const void * src, int height, int dstStride, int srcStride) 35 35 { 36 36 void *retval=dst; … … 71 71 if (!filter->apply_filter) 72 72 return 1; 73 73 74 SetupFilter(filter, frame->width, frame->height, (int*)frame->pitches); 75 74 76 struct pullup_buffer *b; 75 77 struct pullup_frame *f; 76 int height = frame->height;77 int width = frame->width;78 int c width = width / 2;79 int cheight = height / 2;78 int ypitch = filter->context->stride[0]; 79 int height = filter->height; 80 int cpitch = filter->context->stride[1]; 81 int cheight = filter->height >> 1; 80 82 int p = frame->top_field_first ^ 1; 81 83 82 84 struct pullup_context *c = filter->context; 83 85 if (c->bpp[0] == 0) 84 86 c->bpp[0] = c->bpp[1] = c->bpp[2] = frame->bpp; 85 87 86 if ((frame->width != filter->width) ||87 (frame->height != filter->height))88 {89 return 0;90 }91 92 93 88 b = pullup_get_buffer(c,2); 94 89 if (!b) 95 90 { … … 98 93 return 0; 99 94 } 100 95 101 memcpy_pic(b->planes[0], frame->buf, height, width, width); 102 memcpy_pic(b->planes[1], frame->buf + filter->uoff, cheight, cwidth, cwidth); 103 memcpy_pic(b->planes[2], frame->buf + filter->voff, cheight, cwidth, cwidth); 96 memcpy_pic(b->planes[0], frame->buf + frame->offsets[0], 97 height, ypitch, ypitch); 98 memcpy_pic(b->planes[1], frame->buf + frame->offsets[1], 99 cheight, cpitch, cpitch); 100 memcpy_pic(b->planes[2], frame->buf + frame->offsets[2], 101 cheight, cpitch, cpitch); 104 102 105 103 pullup_submit_field(c, b, p); 106 104 pullup_submit_field(c, b, p^1); … … 142 140 pullup_pack_frame(c, f); 143 141 } 144 142 145 memcpy_pic(frame->buf, f->buffer->planes[0], height, width, width); 146 memcpy_pic(frame->buf + filter->uoff, f->buffer->planes[1], cheight, cwidth, cwidth); 147 memcpy_pic(frame->buf + filter->voff, f->buffer->planes[2], cheight, cwidth, cwidth); 143 memcpy_pic(frame->buf + frame->offsets[0], f->buffer->planes[0], 144 height, ypitch, ypitch); 145 memcpy_pic(frame->buf + frame->offsets[1], f->buffer->planes[1], 146 cheight, cpitch, cpitch); 147 memcpy_pic(frame->buf + frame->offsets[2], f->buffer->planes[2], 148 cheight, cpitch, cpitch); 148 149 149 150 pullup_release_frame(f); 151 150 152 return 1; 151 153 } 152 154 … … 156 158 pullup_free_context((((ThisFilter *)filter)->context)); 157 159 } 158 160 161 static void SetupFilter(ThisFilter *vf, int width, int height, int *pitches) 162 { 163 if (vf->width == width && 164 vf->height == height && 165 vf->context->stride[0] == pitches[0] && 166 vf->context->stride[1] == pitches[1] && 167 vf->context->stride[2] == pitches[2]) 168 { 169 return; 170 } 171 172 vf->width = width; 173 vf->height = height; 174 175 vf->context->w[0] = width; 176 vf->context->w[1] = width >> 1; 177 vf->context->w[2] = width >> 1; 178 vf->context->w[3] = 0; 179 vf->context->h[0] = height; 180 vf->context->h[1] = height >> 1; 181 vf->context->h[2] = height >> 1; 182 vf->context->h[3] = 0; 183 vf->context->stride[0] = pitches[0]; 184 vf->context->stride[1] = pitches[1]; 185 vf->context->stride[2] = pitches[2]; 186 vf->context->stride[3] = 0; 187 } 188 159 189 VideoFilter * 160 190 NewIvtcFilter (VideoFrameType inpixfmt, VideoFrameType outpixfmt, 161 191 int *width, int *height, char *options) … … 176 206 return NULL; 177 207 } 178 208 209 bzero (filter, sizeof (ThisFilter)); 179 210 filter->progressive_frame_seen = 0; 180 211 filter->interlaced_frame_seen = 0; 181 212 filter->apply_filter = 0; 182 filter->height = *height;183 filter->width = *width;184 filter->uoff = *width * *height;185 filter->voff = *width * *height * 5 / 4;186 213 filter->context = pullup_alloc_context(); 187 214 struct pullup_context *c = filter->context; 188 215 c->metric_plane = 0; … … 194 221 c->nplanes = 4; 195 222 pullup_preinit_context(c); 196 223 c->bpp[0] = c->bpp[1] = c->bpp[2] = 0; 197 c->w[0] = *width;198 c->h[0] = *height;199 c->w[1] = c->w[2] = (*width >> 1);200 c->h[1] = c->h[2] = (*height >> 1);201 c->w[3] = 0;202 c->h[3] = 0;203 c->stride[0] = *width;204 c->stride[1] = c->stride[2] = (*width >> 1);205 c->stride[3] = c->w[3];206 224 c->background[1] = c->background[2] = 128; 207 225 226 int pitches[3] = { *width, *width >> 1, *width >> 1 }; 227 SetupFilter(filter, *width, *height, pitches); 228 208 229 #ifdef HAVE_MMX 209 230 c->cpu |= PULLUP_CPU_MMX; 210 231 #endif