级别: 工作组
- 注册时间:
- 2003-08-26
- 在线时间:
- 13小时
- 发帖:
- 6600
|
- #include
- #include
- #include
- struct solution
- {
- int hcrop, vcrop;
- double ae, absae;
- };
- solution * sol[625];
- int recount = 0;
- void usort()
- {
- int i, j;
- solution * temp1;
- for(i = 0; i < recount - 1; i++)
- for(j = 0; j < recount - i - 1; j++)
- if(sol[j]->absae > sol[j+1]->absae)
- {
- temp1 = sol[j];
- sol[j] = sol[j+1];
- sol[j+1] = temp1;
- }
- }
- void freeall()
- {
- int i;
- for(i = 0; i < recount; i++)
- free(sol[recount]);
- recount = 0;
- }
- int main()
- {
- int mode, ar, hrev, vrev, hcrop, vcrop, srange, output, c=720, d, k, l, i;
- double maxae, factor2, aa, bb, cc, dd; //Ahhh~, i hate these variable names!!!
- char filename[200];
- FILE * fp;
- puts(" Crop & Resize Calculator @ C++");
- puts(" by MR, v 0.1\n");
- printf("制式\t\t1 - NTSC\t2 - PAL:");
- scanf("%d", &mode);
- printf("屏幕比例\t1 - 16:9\t2 - 4:3:");
- scanf("%d", &ar);
- printf("Target 横向分辨率:");
- scanf("%d", &hrev);
- printf("Target 纵向分辨率:");
- scanf("%d", &vrev);
- printf("横向最小切边(默认0):");
- scanf("%d", &hcrop);
- printf("纵向最小切边(默认0):");
- scanf("%d", &vcrop);
- printf("切边搜寻范围(建议20以内):");
- scanf("%d", &srange);
- printf("最大可接受AE(0 - 默认1.0):");
- scanf("%lf", &maxae);
- printf("输出过滤\t1 - All\t2 - Even number crop only:");
- scanf("%d", &output);
- getchar();
- if(maxae < 1e-6)
- maxae = 1.0;
- if(srange < 0)
- srange = 10;
- if(mode == 1)
- d = 480;
- else
- d = 576;
- if(ar == 1)
- factor2 = 0.75;
- else
- factor2 = 1.0;
- bb = (double)hrev / (double)vrev;
- for(k = hcrop; k < hcrop + srange; k++)
- {
- for(l = vcrop; l < vcrop + srange; l++)
- {
- // NTSC计算公式
- if (mode == 1)
- aa = ((c - k) * 72. / 79) / ((d - l) * factor2);
- // PAL计算公式
- else
- aa = ((c - k) * 128. / 117) / ((d - l) * factor2);
- cc = aa / bb - 1;
- dd = fabs(cc);
- if(dd < maxae && (output == 1 || output == 2 && k % 2 == 0 && l % 2 == 0))
- {
- sol[recount] = (solution*)malloc(sizeof(solution));
- sol[recount] -> hcrop = k;
- sol[recount] -> vcrop = l;
- sol[recount] -> ae = cc;
- sol[recount] -> absae = dd;
- recount++;
- }
- }
- }
- usort();
- printf("Write to file(ENTER to print on screen):");
- gets(filename);
- if(filename[0] != 0)
- {
- // to file
- fp = fopen(filename, "w");
- fputs("H-Crop,V-Crop,AspectError,Abs AspectError\n", fp);
- for(i = 0; i < recount; i++)
- fprintf(fp, "%d,%d,%.8lf,%.8lf\n", sol[i]->hcrop, sol[i]->vcrop, sol[i]->ae, sol[i]->absae);
- fclose(fp);
- puts("Written to file.");
- }
- else
- {
- puts("H-Crop\tV-Crop\t Aspect Error\tAbs AspectError");
- for(i = 0; i < recount; i++)
- printf("%3d\t%3d\t%12.8lf\t%13.8lf\n", sol[i]->hcrop, sol[i]->vcrop, sol[i]->ae, sol[i]->absae);
- }
- freeall();
- printf("Press enter key to exit...");
- getchar();
- }
C++的版本,可以用Dev-CPP附带的gcc编译器编译。
|