📄 ijg_timing.c
字号:
if(EOF == write_dword(biCompression,fo)) { printf("can't write to file\n"); res = -1; goto Exit; } if(EOF == write_dword(biSizeImage,fo)) { printf("can't write to file\n"); res = -1; goto Exit; } if(EOF == write_dword(biXPelsPerMeter,fo)) { printf("can't write to file\n"); res = -1; goto Exit; } if(EOF == write_dword(biYPelsPerMeter,fo)) { printf("can't write to file\n"); res = -1; goto Exit; } if(EOF == write_dword(biClrUsed,fo)) { printf("can't write to file\n"); res = -1; goto Exit; } if(EOF == write_dword(biClrImportant,fo)) { printf("can't write to file\n"); res = -1; goto Exit; } if(nchannels == 1) { for(i = 0; i < 256; i += 4) { palette[i+0] = (Ipp8u)i; /* rgbBlue */ palette[i+1] = (Ipp8u)i; /* rgbGreen */ palette[i+2] = (Ipp8u)i; /* rgbRed */ palette[i+3] = (Ipp8u)0; /* rgbReserved */ } cnt = fwrite(&palette,sizeof(Ipp8u),sizeof(palette),fo); if(cnt != sizeof(palette)) { printf("can't write to file\n"); res = -1; goto Exit; } } for(row = 0; row < height; row++) { outptr = buffer + row * bmp_width; cnt = fwrite(outptr,sizeof(Ipp8u),bmp_width,fo); if(cnt != (size_t)bmp_width) { printf("can't write to file\n"); res = -1; goto Exit; } } res = 0;Exit: if(NULL != fo) { fclose(fo); } return res;} /* write_bmp() */int get_differences( const Ipp8u* src, const Ipp8u* dst, int width, int height, int nchannels, Ipp8u** dif){ int i; int j; int c; int res = 0; int step; int size; int diff; int C[4]; double RL1[4]; double RL2[4]; double rl1[4]; double rl2[4]; Ipp8u* ptr1; Ipp8u* ptr2; Ipp8u* ptr3; Ipp8u* tmp = NULL; step = nchannels * width; while(step & 3) { step++; } size = step * height; tmp = (Ipp8u*)malloc(size); if(NULL == tmp) { res = -1; goto Exit; } memset(tmp,0,size); C[0] = 0; C[1] = 0; C[2] = 0; C[3] = 0; RL1[0] = 0.0; RL1[1] = 0.0; RL1[2] = 0.0; RL1[3] = 0.0; RL2[0] = 0.0; RL2[1] = 0.0; RL2[2] = 0.0; RL2[3] = 0.0; rl1[0] = 0.0; rl1[1] = 0.0; rl1[2] = 0.0; rl1[3] = 0.0; rl2[0] = 0.0; rl2[1] = 0.0; rl2[2] = 0.0; rl2[3] = 0.0; for(i = 0; i < height; i++) { ptr1 = (Ipp8u*)src + i*step; ptr2 = (Ipp8u*)dst + i*step; ptr3 = tmp + i*step; for(j = 0; j < width; j++) { for(c = 0; c < nchannels; c++) { diff = ptr1[c] - ptr2[c]; if(abs(diff) > C[c]) { C[c] = abs(diff); } RL1[c] += (double)abs(diff); rl1[c] += (double)ptr2[c]; RL2[c] += (double)(diff*diff); rl2[c] += (double)(ptr2[c]*ptr2[c]); ptr3[c] = (Ipp8u)abs(diff); } ptr1 += nchannels; ptr2 += nchannels; ptr3 += nchannels; } } for(c = 0; c < nchannels; c++) { printf("channels %d C[%d] L1[%8d] RL1[%2.6f] L2[%8d] RL2[%2.6f]\n", c,C[c],(int)RL1[c],RL1[c]/rl1[c],(int)RL2[c],sqrt(RL2[c])/sqrt(rl2[c])); } *dif = tmp;Exit: return res;} /* get_differences() */typedef struct _TEST_PARAM{ int ch; JSS ss; char* jpg; char* bmp;} TP;static int do_auto_test(void){ int i; unsigned int clk; int res = 0; Ipp8u* src = NULL; Ipp8u* dst = NULL; int width = 1024; int height = 768; int quality = 75; TP tp[] = { { 1, SS_444, "ae_1_444.jpg", "ad_1_444.bmp" }, { 3, SS_444, "ae_3_444.jpg", "ad_3_444.bmp" }, { 3, SS_422, "ae_3_422.jpg", "ad_3_422.bmp" }, { 3, SS_411, "ae_3_411.jpg", "ad_3_411.bmp" }, { 4, SS_444, "ae_4_444.jpg", "ad_4_444.bmp" }, { 4, SS_422, "ae_4_422.jpg", "ad_4_422.bmp" }, { 4, SS_411, "ae_4_411.jpg", "ad_4_411.bmp" } }; src = (Ipp8u*)malloc(width*height*4); if(NULL == src) { printf("can't allocate %d bytes\n",width*height*4); res = -1; goto Exit; } srand(0); for(i = 0; i < width*height*4; i++) { src[i] = (Ipp8u)rand(); } for(i = 0; i < 7; i++) { ijg_encode(src,width,height,tp[i].ch,tp[i].ss,quality,tp[i].jpg,&clk); printf("encode %d X %d X %d - %d - %d - cpe %f\n", width,height,tp[i].ch,tp[i].ss,quality,(float)clk/(width*height)); } for(i = 0; i < 7; i++) { ijg_decode(tp[i].jpg,&dst,&width,&height,&tp[i].ch,&tp[i].ss,&clk); printf("decode %d X %d X %d - %d - %d - cpe %f\n", width,height,tp[i].ch,tp[i].ss,quality,(float)clk/(width*height)); write_bmp(dst,width,height,tp[i].ch,tp[i].bmp); if(NULL != dst) { free(dst); dst = NULL; } }Exit: if(NULL != src) { free(src); } return res;} /* do_auto_test() */static int do_through_test( char* bmp_name, int quality, JSS sampling){ int width; int height; int nchannels; unsigned int clk; int res = 0; Ipp8u* src = NULL; Ipp8u* dst = NULL; Ipp8u* dif = NULL; char* diff_name = NULL; char path_buffer[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath(bmp_name,drive,dir,fname,ext); sprintf(&path_buffer[0],"%s_%d_%d_diff.bmp",fname,quality,sampling); diff_name = &path_buffer[0]; res = load_bmp(bmp_name,&src,&width,&height,&nchannels); if(0 != res) { goto Exit; } res = ijg_encode(src,width,height,nchannels,sampling,quality,"through_test.jpg",&clk); if(0 != res) { goto Exit; } printf("encode %d X %d X %d - %d - %d - cpe %f\n", width,height,nchannels,sampling,quality,(float)clk/(width*height)); res = ijg_decode("through_test.jpg",&dst,&width,&height,&nchannels,&sampling,&clk); if(0 != res) { goto Exit; } printf("decode %d X %d X %d - %d - %d - cpe %f\n", width,height,nchannels,sampling,quality,(float)clk/(width*height)); res = get_differences(src,dst,width,height,nchannels,&dif); if(0 != res) { goto Exit; } res = write_bmp(dif,width,height,nchannels,diff_name); if(0 != res) { goto Exit; }Exit: if(NULL != src) { free(src); } if(NULL != dst) { free(dst); } if(NULL != dif) { free(dif); } return res;} /* do_through_test() */static int do_encode( char* bmp_name, int jpeg_quality, JSS jpeg_sampling){ int res; int width; int height; int nchannels; unsigned int clk; char* jpeg_name; Ipp8u* bmp_buff = NULL; char path_buffer[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT];#ifdef _DEBUG printf("File name: %s\n",bmp_name); printf("Quality: %d\n",jpeg_quality); printf("Sampling: %d\n",jpeg_sampling);#endif res = load_bmp(bmp_name,&bmp_buff,&width,&height,&nchannels); if(0 != res) { goto Exit; } _splitpath(bmp_name,drive,dir,fname,ext); _makepath(path_buffer,drive,dir,fname,"jpg"); jpeg_name = &path_buffer[0]; res = ijg_encode(bmp_buff,width,height,nchannels,jpeg_sampling,jpeg_quality,jpeg_name,&clk); printf("encode %d X %d X %d - %d - %d - cpe %f\n", width,height,nchannels,jpeg_sampling,jpeg_quality,(float)clk / (width*height));Exit: if(NULL != bmp_buff) { free(bmp_buff); } return res;} /* do_encode() */static int do_decode( char* jpg_name){ int res = 0; int width; int height; int nchannels; JSS ss; unsigned int clocks; float cpe; char* bmp_name = NULL; Ipp8u* bmp_buff = NULL; char path_buffer[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath(jpg_name,drive,dir,fname,ext); _makepath(path_buffer,drive,dir,fname,"bmp"); bmp_name = &path_buffer[0]; res = ijg_decode(jpg_name,&bmp_buff,&width,&height,&nchannels,&ss,&clocks); if(0 != res) { printf("ijg_decode() failed!\n"); goto Exit; } write_bmp(bmp_buff,width,height,nchannels,bmp_name); cpe = (float)clocks / (width*height); printf("image: %s %dx%dx%d - %d - clocks %u\tcpe %6.2f\n", jpg_name, width, height, nchannels, ss, clocks, cpe);Exit: if(NULL != bmp_buff) { free(bmp_buff); } return res;} /* do_decode() */int main(int ArgC, char** ArgV){ int i; char c; int quality = 75; JSS sampling = SS_444; int show_version = 0; int decode_file = 0; int encode_file = 0; int auto_test = 0; int through_test = 0; char* p = NULL; char* name = NULL; if(ippStsNoErr > ippStaticInit()) { fprintf(stderr,"Can't initialize Intel(R) IPP library\n"); exit(EXIT_FAILURE); } if(ArgC < 2) { copyright(); usage(); return 0; } i = 0; do { p = ArgV[++i]; if(NULL == p) { break; } c = p[0]; if(c != '-' && c != '/') { printf("ERROR: Invalid parameter %d - [%s]\n\n",i,p); usage(); return 1; } c = p[1]; switch(c) { case '?': case 'h': copyright(); usage(); break; case 'v': show_version = 1; break; case 'a': auto_test = 1; break; case 't': through_test = 1; name = &p[2]; break; case 'e': encode_file = 1; if(decode_file) { printf("WARN: only one decode or encode is possible for time.\n"); printf(" Last options will be ignored\n\n"); encode_file = 0; } name = &p[2]; break; case 'd': decode_file = 1; if(encode_file) { printf("WARN: only one decode or encode is possible for time.\n"); printf(" Last options will be ignored\n\n"); decode_file = 0; } name = &p[2]; break; case 'q': quality = atoi(&p[2]); break; case 's': sampling = (JSS)atoi(&p[2]); break; default: printf("ERROR: Invalid parameter %d - [%s]\n\n",i,p); usage(); return 1; } } while(c != 0); if(auto_test && (encode_file || decode_file || through_test)) { printf("WARN: auto test must be standalone. Other options will be ignored\n"); encode_file = 0; decode_file = 0; through_test = 0; } if(show_version) { copyright(); ipp_version(); } if(auto_test) { do_auto_test(); } if(through_test) { do_through_test(name,quality,sampling); } if(encode_file) { do_encode(name,quality,sampling); } if(decode_file) { do_decode(name); } return 0;} /* main() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -