📄 mga_pcx.c
字号:
/* (c) HelDoRe PCX unit ... v0.0.5 Supported formats : 8bpp + RLE 24bpp + RLE or ImageMagick*/ #define VERPCX " unit v0.0.5"#include <stdio.h>#include "../mga_view.h"void help_pcx(){#ifdef USE_MAG_PCXprintf("PCX%s\n + uses ImageMagick\n",VERPCX);#elseprintf("PCX%s\n + 8 bpp rle\n + 24 bpp rle\n",VERPCX);#endif}int detect_pcx(){ int depth,tempi,compr,xmin,ymin,xmax,ymax,nplanes,bpline; int PCXsyg; PCXsyg=fgetc(plik); if (PCXsyg != 10) return 1; tempi=fgetc(plik); compr=fgetc(plik); depth=fgetc(plik); xmin=fgetc16b(plik); ymin=fgetc16b(plik); xmax=fgetc16b(plik); ymax=fgetc16b(plik); image_x=xmax+1; image_y=ymax+1; if (check_image(image_x,image_y,depth)==3) return 3; printf("PCX%s",VERPCX);#ifdef USE_MAG_PCX printf(" (IM)");#endif printf("\nPCX version "); switch (tempi) { case 0 :printf("2.5");break; case 2 :printf("2.8");break; case 3 :printf("2.8");break; case 4 :printf("???");break; case 5 :printf("3.0");break; }#ifndef USE_MAG_PCX if (tempi !=5) { printf("\nOnly PCX v3.0 supported\n"); return 2; }#endif fseek(plik,53,SEEK_CUR); nplanes=fgetc(plik); bpline=fgetc16b(plik); fseek(plik,60,SEEK_CUR); printf(" : %ix%ix%i",image_x,image_y,depth*nplanes); if (compr==1) printf(" compressed"); if (tempi==2) printf(" with palette"); if (tempi==3) printf(" without palette"); printf("\n");#ifdef USE_MAG_PCX detect_mag(0);#else if (tempi !=5) { printf("Only PCX v3.0 supported "); return 2; } fseek(plik,-768,SEEK_END); for (tempi=0;tempi<256;tempi++) { tab2r[tempi]=fgetc(plik); tab2g[tempi]=fgetc(plik); tab2b[tempi]=fgetc(plik); } fseek(plik,128,SEEK_SET); if ((depth==8) && (nplanes==1)) { /* depth=8 */ for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { if ((tempi=fgetc(plik))==-1) return 0; if ((tempi>192)) { xmin=fgetc(plik); for (compr=0;compr<(tempi-192);compr++) { tabr[x+compr+y*image_x]=tab2r[xmin]; tabg[x+compr+y*image_x]=tab2g[xmin]; tabb[x+compr+y*image_x]=tab2b[xmin]; } x+=compr-1; } else { tabr[x+y*image_x]=tab2r[tempi]; tabg[x+y*image_x]=tab2g[tempi]; tabb[x+y*image_x]=tab2b[tempi]; } } } } /* end depth=8 */ if (depth==1) { /* depth=1 */ } /* end depth=1 */ if ((depth==8) && (nplanes==3)) { /* depth=24 */ for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { if ((tempi=fgetc(plik))==-1) return 0; if ((tempi>192)) { xmin=fgetc(plik); for (compr=0;compr<(tempi-192);compr++) { tabr[x+compr+y*image_x]=xmin; } x+=compr-1; } else { tabr[x+y*image_x]=tempi; } } for (x=0;x<image_x;x++) { if ((tempi=fgetc(plik))==-1) return 0; if ((tempi>192)) { xmin=fgetc(plik); for (compr=0;compr<(tempi-192);compr++) { tabg[x+compr+y*image_x]=xmin; } x+=compr-1; } else { tabg[x+y*image_x]=tempi; } } for (x=0;x<image_x;x++) { if ((tempi=fgetc(plik))==-1) return 0; if ((tempi>192)) { xmin=fgetc(plik); for (compr=0;compr<(tempi-192);compr++) { tabb[x+compr+y*image_x]=xmin; } x+=compr-1; } else { tabb[x+y*image_x]=tempi; } } } } /* end depth=24 */#endif return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -