📄 mga_pxm.c
字号:
/* (c) HelDoRe Ppm pbm pgm unit ... v0.0.4 P1 P2 P3 P5 P6 P7 (xv ?)*/ #define VERPXM " unit v0.0.4"#include <stdio.h>#include "../mga_view.h"void help_pxm(){#ifdef USE_MAG_PXMprintf("PXM%s\n + use ImageMagick\n",VERPXM);#elseprintf("PXM%s\n + pbm P1\n + pgm P2 P5\n + ppm P3 P6\n",VERPXM);#endif}int detect_pxm(){ int wer,mnoz,temm;#ifndef USE_MAG_PXM int depth2;#endif char buff[10]; if (fgetc(plik) != 80) return 1 ; wer=fgetc(plik)-48; if (wer>7) return 1; if (wer==7) { tempi=fgetc32(plik); } tempi=fgetc(plik); tempi=fgetc(plik); while (tempi==35) { if (tempi==35) { do { tempi=fgetc(plik); } while (tempi != 10); } tempi=fgetc(plik); } if ((tempi != 10) && (tempi !=35)) fseek(plik,-1,SEEK_CUR); tempi=0; do { tempi++; buff[tempi]=zmien(fgetc(plik)); } while (buff[tempi] != -1); tempi--; mnoz=1;image_x=0; for (temm=tempi;temm>0;temm--) { image_x=image_x+buff[temm]*mnoz; mnoz=mnoz*10; } tempi=0; do { tempi++; buff[tempi]=zmien(fgetc(plik)); } while (buff[tempi] != -1); tempi--; mnoz=1;image_y=0; for (temm=tempi;temm>0;temm--) { image_y=image_y+buff[temm]*mnoz; mnoz=mnoz*10; } if ((wer != 1) && (wer != 4)) { tempi=0; do { tempi++; buff[tempi]=zmien(fgetc(plik)); } while (buff[tempi] != -1); tempi--; mnoz=1;depth=0; for (temm=tempi;temm>0;temm--) { depth=depth+buff[temm]*mnoz; mnoz=mnoz*10; }} else depth=1; if (check_image(image_x,image_y,8)==3) return 3; printf("pXm%s",VERPXM);#ifdef USE_MAG_PXM printf(" (IM)");#endif printf("\npXm v%i detected : %ix%i %i colors\n",wer,image_x,image_y,depth);#ifdef USE_MAG_PXM detect_mag(0);#else if (wer==4) { printf("v4 not supported yet !\n"); return 2; } if (wer==6) { for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { tabr[x+y*image_x]=fgetc(plik); tabg[x+y*image_x]=fgetc(plik); tabb[x+y*image_x]=fgetc(plik); } } } if (wer==7) { zoom=0; for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { tempi=fgetc(plik); tabr[x+y*image_x]=(((tempi >> 5) & 0x07) *255) / 7; tabg[x+y*image_x]=(((tempi >> 2) & 0x07) *255) / 7; tabb[x+y*image_x]=(((tempi >> 0) & 0x03) *255) / 3; } }} if (wer==5) { for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { tempi=fgetc(plik); tabr[x+y*image_x]=tempi; tabg[x+y*image_x]=tempi; tabb[x+y*image_x]=tempi; } } } if (wer==3) { for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { do { tempi=fgetc(plik); } while (tempi == 32); fseek(plik,-1,SEEK_CUR); tempi=0; do { tempi++; buff[tempi]=zmien(fgetc(plik)); } while (buff[tempi] != -1); tempi--; mnoz=1;depth2=0; for (temm=tempi;temm>0;temm--) { depth2=depth2+buff[temm]*mnoz; mnoz=mnoz*10; } tabr[x+y*image_x]=(256/depth)*depth2; do { tempi=fgetc(plik); } while (tempi == 32); fseek(plik,-1,SEEK_CUR); tempi=0; do { tempi++; buff[tempi]=zmien(fgetc(plik)); } while (buff[tempi] != -1); tempi--; mnoz=1;depth2=0; for (temm=tempi;temm>0;temm--) { depth2=depth2+buff[temm]*mnoz; mnoz=mnoz*10; } tabg[x+y*image_x]=(256/depth)*depth2; do { tempi=fgetc(plik); } while (tempi == 32); fseek(plik,-1,SEEK_CUR); tempi=0; do { tempi++; buff[tempi]=zmien(fgetc(plik)); } while (buff[tempi] != -1); tempi--; mnoz=1;depth2=0; for (temm=tempi;temm>0;temm--) { depth2=depth2+buff[temm]*mnoz; mnoz=mnoz*10; } tabb[x+y*image_x]=(256/depth)*depth2; } } } if (wer==2) { for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { do { tempi=fgetc(plik); } while (tempi == 32); fseek(plik,-1,SEEK_CUR); tempi=0; do { tempi++; buff[tempi]=zmien(fgetc(plik)); } while (buff[tempi] != -1); tempi--; mnoz=1;depth2=0; for (temm=tempi;temm>0;temm--) { depth2=depth2+buff[temm]*mnoz; mnoz=mnoz*10; } tabr[x+y*image_x]=(256/depth)*depth2; tabg[x+y*image_x]=(256/depth)*depth2; tabb[x+y*image_x]=(256/depth)*depth2; } } } if (wer==1) { for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { fgetc(plik); tempi=zmien(fgetc(plik)); tabr[x+y*image_x]=tempi*255; tabg[x+y*image_x]=tempi*255; tabb[x+y*image_x]=tempi*255; } } } #endif return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -