comparison libmpcodecs/vf_spp.c @ 11993:4e2d99dbef78

spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
author michael
date Tue, 24 Feb 2004 11:23:27 +0000
parents cf76671b3d77
children a7751694c177
comparison
equal deleted inserted replaced
11992:d8890a065727 11993:4e2d99dbef78
93 }; 93 };
94 94
95 struct vf_priv_s { 95 struct vf_priv_s {
96 int log2_count; 96 int log2_count;
97 int qp; 97 int qp;
98 int mode;
98 int mpeg2; 99 int mpeg2;
99 unsigned int outfmt; 100 unsigned int outfmt;
100 int temp_stride; 101 int temp_stride;
101 uint8_t *src; 102 uint8_t *src;
102 int16_t *temp; 103 int16_t *temp;
104 DSPContext dsp; 105 DSPContext dsp;
105 }; 106 };
106 107
107 #define SHIFT 22 108 #define SHIFT 22
108 109
109 static void requantize_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ 110 static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
110 int i; 111 int i;
111 int bias= 0; //FIXME 112 int bias= 0; //FIXME
112 unsigned int threshold1, threshold2; 113 unsigned int threshold1, threshold2;
113 114
114 threshold1= qp*((1<<4) - bias) - 1; 115 threshold1= qp*((1<<4) - bias) - 1;
124 dst[j]= (level + 4)>>3; 125 dst[j]= (level + 4)>>3;
125 } 126 }
126 } 127 }
127 } 128 }
128 129
130 static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
131 int i;
132 int bias= 0; //FIXME
133 unsigned int threshold1, threshold2;
134
135 threshold1= qp*((1<<4) - bias) - 1;
136 threshold2= (threshold1<<1);
137
138 memset(dst, 0, 64*sizeof(DCTELEM));
139 dst[0]= (src[0] + 4)>>3;
140
141 for(i=1; i<64; i++){
142 int level= src[i];
143 if(((unsigned)(level+threshold1))>threshold2){
144 const int j= permutation[i];
145 if(level>0)
146 dst[j]= (level - threshold1 + 4)>>3;
147 else
148 dst[j]= (level + threshold1 + 4)>>3;
149 }
150 }
151 }
152
129 #ifdef HAVE_MMX 153 #ifdef HAVE_MMX
130 static void requantize_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ 154 static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
131 int bias= 0; //FIXME 155 int bias= 0; //FIXME
132 unsigned int threshold1; 156 unsigned int threshold1;
133 157
134 threshold1= qp*((1<<4) - bias) - 1; 158 threshold1= qp*((1<<4) - bias) - 1;
135 159
272 } 296 }
273 #endif 297 #endif
274 298
275 static void (*store_slice)(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)= store_slice_c; 299 static void (*store_slice)(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)= store_slice_c;
276 300
277 static void (*requantize)(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation)= requantize_c; 301 static void (*requantize)(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation)= hardthresh_c;
278 302
279 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){ 303 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){
280 int x, y, i; 304 int x, y, i;
281 const int count= 1<<p->log2_count; 305 const int count= 1<<p->log2_count;
282 const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15)); 306 const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15));
476 500
477 avcodec_init(); 501 avcodec_init();
478 502
479 vf->priv->avctx= avcodec_alloc_context(); 503 vf->priv->avctx= avcodec_alloc_context();
480 dsputil_init(&vf->priv->dsp, vf->priv->avctx); 504 dsputil_init(&vf->priv->dsp, vf->priv->avctx);
505
506 vf->priv->log2_count= 3;
507
508 if (args) sscanf(args, "%d:%d:%d", &vf->priv->log2_count, &vf->priv->qp, &vf->priv->mode);
509 switch(vf->priv->mode){
510 case 0: requantize= hardthresh_c; break;
511 case 1: requantize= softthresh_c; break;
512 }
513
481 #ifdef HAVE_MMX 514 #ifdef HAVE_MMX
482 if(gCpuCaps.hasMMX){ 515 if(gCpuCaps.hasMMX){
483 store_slice= store_slice_mmx; 516 store_slice= store_slice_mmx;
484 requantize= requantize_mmx; 517 switch(vf->priv->mode){
518 case 0: requantize= hardthresh_mmx; break;
519 //case 1: requantize= softthresh_mmx; break;
520 }
485 } 521 }
486 #endif 522 #endif
487 523
488 vf->priv->log2_count= 3;
489
490 if (args) sscanf(args, "%d:%d", &vf->priv->log2_count, &vf->priv->qp);
491
492 // check csp: 524 // check csp:
493 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); 525 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
494 if(!vf->priv->outfmt) 526 if(!vf->priv->outfmt)
495 { 527 {
496 uninit(vf); 528 uninit(vf);