--- plugin_ssim.c 2006/10/13 06:32:02 1.2 +++ plugin_ssim.c 2006/10/30 11:21:42 1.5 @@ -26,7 +26,7 @@ #include #include #include -#include +#include "../portab.h" #include "../xvid.h" #include "plugin_ssim.h" #include "../utils/emms.h" @@ -62,6 +62,8 @@ uint8_t* errmap; */ + int grid; + /*for average SSIM*/ float ssim_sum; int frame_cnt; @@ -107,12 +109,12 @@ /*writeout the collected stats*/ void framestat_write(ssim_data_t* ssim, char* path){ + framestat_t* tmp = ssim->head; FILE* out = fopen(path,"w"); if(out==NULL) printf("Cannot open %s in plugin_ssim\n",path); - framestat_t* tmp = ssim->head; fprintf(out,"SSIM Error Metric\n"); - fprintf(out,"quant avg min max"); + fprintf(out,"quant avg min max\n"); while(tmp->next->next != NULL){ fprintf(out,"%3d %1.4f %1.4f %1.4f\n",tmp->quant,tmp->ssim_avg,tmp->ssim_min,tmp->ssim_max); tmp = tmp->next; @@ -122,10 +124,9 @@ /*writeout the collected stats in octave readable format*/ void framestat_write_oct(ssim_data_t* ssim, char* path){ - + framestat_t* tmp; FILE* out = fopen(path,"w"); if(out==NULL) printf("Cannot open %s in plugin_ssim\n",path); - framestat_t* tmp; fprintf(out,"quant = ["); tmp = ssim->head; @@ -233,25 +234,26 @@ } /*calculate contrast and correlation of the two blocks*/ -void iconsim_c(uint8_t* ptro, uint8_t* ptrc, int stride, int lumo, int lumc, int* pdevo, int* pdevc, int* pcorr){ - int valo, valc, devo =0, devc=0, corr=0; - int i,j; +void consim_c(uint8_t* ptro, uint8_t* ptrc, int stride, int lumo, int lumc, int* pdevo, int* pdevc, int* pcorr){ + unsigned int valo, valc, devo=0, devc=0, corr=0,i,j,str; + str = stride - 8; for(i=0;i< 8;i++){ for(j=0;j< 8;j++){ - valo = *ptro - lumo; - valc = *ptrc - lumc; + valo = *ptro; + valc = *ptrc; devo += valo*valo; - ptro++; devc += valc*valc; - ptrc++; corr += valo*valc; + ptro++; + ptrc++; } - ptro += stride -8; - ptrc += stride -8; + ptro += str; + ptrc += str; } - *pdevo = devo; - *pdevc = devc; - *pcorr = corr; + + *pdevo = devo - ((lumo*lumo + 32) >> 6); + *pdevc = devc - ((lumc*lumc + 32) >> 6); + *pcorr = corr - ((lumo*lumc + 32) >> 6); }; /*calculate the final ssim value*/ @@ -264,7 +266,7 @@ fdevo = (float) devo; fdevc = (float) devc; fcorr = (float) corr; -// printf("meano: %f meanc: %f devo: %f devc: %f corr: %f\n",fmeano,fmeanc,fdevo,fdevc,fcorr); + /* printf("meano: %f meanc: %f devo: %f devc: %f corr: %f\n",fmeano,fmeanc,fdevo,fdevc,fcorr); */ return ((2.0*fmeano*fmeanc + c1)*(fcorr/32.0 + c2))/((fmeano*fmeano + fmeanc*fmeanc + c1)*(fdevc/64.0 + fdevo/64.0 + c2)); } @@ -276,13 +278,11 @@ int meanc, meano; int devc, devo, corr; - #define GRID 1 - width = data->width - 8; height = data->height - 8; str = data->original.stride[0]; if(str != data->current.stride[0]) printf("WARNING: Different strides in plugin_ssim original: %d current: %d\n",str,data->current.stride[0]); - ovr = str - width + (width % GRID); + ovr = str - width + (width % ssim->grid); ptr1 = (unsigned char*) data->original.plane[0]; ptr2 = (unsigned char*) data->current.plane[0]; @@ -290,12 +290,12 @@ /*TODO: Thread*/ - for(i=0;igrid){ /*begin of each row*/ meano = meanc = devc = devo = corr = 0; meano = ssim->func8x8(ptr1,str); meanc = ssim->func8x8(ptr2,str); - ssim->consim(ptr1,ptr2,str,meano>>6,meanc>>6,&devo,&devc,&corr); + ssim->consim(ptr1,ptr2,str,meano,meanc,&devo,&devc,&corr); emms(); val = calc_ssim(meano,meanc,devo,devc,corr); @@ -306,19 +306,21 @@ ssim->errmap[i*width] = (uint8_t) 127*val; */ + if(val < min) min = val; if(val > max) max = val; - ptr1+=GRID; - ptr2+=GRID; + ptr1+=ssim->grid; + ptr2+=ssim->grid; /*rest of each row*/ - for(j=1;jgrid;jgrid){ + if(ssim->grid == 1){ meano += ssim->func2x8(ptr1,str); meanc += ssim->func2x8(ptr2,str); - */ + } else { meano = ssim->func8x8(ptr1,str); meanc = ssim->func8x8(ptr2,str); - ssim->consim(ptr1,ptr2,str,meano>>6,meanc>>6,&devo,&devc,&corr); + } + ssim->consim(ptr1,ptr2,str,meano,meanc,&devo,&devc,&corr); emms(); val = calc_ssim(meano,meanc,devo,devc,corr); @@ -330,8 +332,8 @@ */ if(val < min) min = val; if(val > max) max = val; - ptr1+=GRID; - ptr2+=GRID; + ptr1+=ssim->grid; + ptr2+=ssim->grid; } ptr1 +=ovr; ptr2 +=ovr; @@ -352,7 +354,7 @@ } */ if(ssim->param->b_printstat){ - printf("SSIM: avg: %f min: %f max: %f\n",isum,min,max); + printf(" SSIM: avg: %f min: %f max: %f\n",isum,min,max); } } @@ -369,16 +371,24 @@ ssim->func8x8 = lum_8x8_c; ssim->func2x8 = lum_2x8_c; - ssim->consim = iconsim_c; + ssim->consim = consim_c; ssim->param = param; + ssim->grid = param->acc; + + /*gaussian weigthing not implemented*/ + if(ssim->grid == 0) ssim->grid = 1; + if(ssim->grid > 4) ssim->grid = 4; + + printf("Grid: %d\n",ssim->grid); + #if defined(ARCH_IS_IA32) - if(cpu_flags & XVID_CPU_MMX){ + if((cpu_flags & XVID_CPU_MMX) && (param->acc > 0)){ ssim->func8x8 = lum_8x8_mmx; ssim->consim = consim_mmx; } - if(cpu_flags & XVID_CPU_SSE2){ + if((cpu_flags & XVID_CPU_SSE2) && (param->acc > 0)){ ssim->consim = consim_sse2; } #endif @@ -425,7 +435,7 @@ if(ssim->param->stat_path != NULL) framestat_write(ssim,ssim->param->stat_path); framestat_free(ssim->head); - //free(ssim->errmap); + /*free(ssim->errmap);*/ free(ssim->param); free(ssim); break;