📄 mga_tif.c
字号:
/* (c) HelDoRe TIFF unit ... v0.0.6 Supported formats : 8bpp 24bpp or libtiff*/ #define VERTIF " unit v0.0.6"#include <stdio.h>#include "../mga_view.h"#ifdef USE_LIBTIFF#include <tiffio.h>#endifvoid help_tiff(){#ifdef USE_LIBTIFFprintf("TIF%s\n + uses libtiff\n",VERTIF);#elseprintf("TIF%s\n + 8 bpp\n + 24 bpp\n",VERTIF);#endif}#ifdef USE_LIBTIFFint detect_tiff(){TIFF* tif_plik; char *name,*descr; short int IIsyg; int compres=0; uint32 *scanline; fread(&IIsyg,sizeof(short int),1,plik); if ((IIsyg != 18761) && (IIsyg != 19789)) { return 1; } tif_plik=TIFFOpen(mee,"r"); if (!tif_plik) return 1; printf("TIFF%s\n",VERTIF); TIFFGetField(tif_plik,TIFFTAG_IMAGEWIDTH,&image_x); TIFFGetField(tif_plik,TIFFTAG_IMAGELENGTH,&image_y); TIFFGetField(tif_plik,TIFFTAG_BITSPERSAMPLE,&depth); TIFFGetField(tif_plik,TIFFTAG_COMPRESSION,&compres); depth=(depth & 0xff); check_image(image_x,image_y,depth); printf("TIFF detected : %ix%ix%i ",image_x,image_y,depth); switch (compres) { case 1:break; case 2:printf("RLE");break; case 3:printf("Group 3 FAX");break; case 4:printf("Group 4 FAX");break; case 5:printf("LZW");break; case 6:printf("JPEG");break; case 7:printf("JPEG DCT");break; case 8:printf("Adobe");break; case 32766:printf("NeXT 2-bit RLE");break; case 32773:printf("Macintosh RLE");break; case 34676:printf("SGI Luminance RLE");break; case 34677:printf("SGI 24 bpp packed");break; case 32946:printf("Deflate");break; case 32809:printf("ThunderScan RLE");break; default: break; } printf("\n"); if (TIFFGetField(tif_plik,TIFFTAG_DOCUMENTNAME,&name)) printf("Document name : %s\n",name); if (TIFFGetField(tif_plik,TIFFTAG_IMAGEDESCRIPTION,&descr)) printf("Description : %s\n",descr); scanline=(uint32*) malloc(image_x*image_y* sizeof (uint32)+1); TIFFReadRGBAImage(tif_plik,image_x,image_y,scanline,0); i=0; for (y=0;y<image_y;y++) for (x=0;x<image_x;x++) { tabb[x+(image_y-y)*image_x]=((scanline[i] & 0xff0000)>>16); tabg[x+(image_y-y)*image_x]=((scanline[i] & 0xff00)>>8); tabr[x+(image_y-y)*image_x]=((scanline[i] & 0xff)); i++; } free(scanline); if (tif_plik) TIFFClose(tif_plik);return 0;}#elsevoid get_palete(int wielkosc,int skok) { int petla,noop; fseek(plik,skok,SEEK_CUR); for (petla=0;petla<wielkosc/3;petla++) { tab2r[petla]=fgetc(plik); fseek(plik,(wielkosc/3)*2-1,SEEK_CUR); tab2g[petla]=fgetc(plik); fseek(plik,(wielkosc/3)*2-1,SEEK_CUR); tab2b[petla]=fgetc(plik); fseek(plik,-(wielkosc/3)*4,SEEK_CUR); noop=fgetc(plik); } fseek(plik,-skok-(wielkosc/3),SEEK_CUR); }void wypisz(int wielkosc,int skok) { char napis[wielkosc]; int petla; fseek(plik,skok,SEEK_CUR); for (petla=0;petla<wielkosc;petla++) { napis[petla]=(char)fgetc(plik); } printf(" %s\n",napis); fseek(plik,-skok-wielkosc,SEEK_CUR); }int detect_tiff(){ short int IIsyg; int header; int flip,dane,ile,compres=0; fread(&IIsyg,sizeof(short int),1,plik); if (IIsyg != 18761) { return 1; } printf("TIFF%s\n",VERTIF); if (fgetc(plik) != 42) return 1; fseek(plik,1,SEEK_CUR); header=fgetc(plik)+(256*fgetc(plik))+(256*256*fgetc(plik)); fseek(plik,header,SEEK_SET); flip=fgetc(plik); fseek(plik,1,SEEK_CUR); depth=0; for (x=0;x<flip;x++) { tempi=fgetc16b(plik); fseek(plik,6,SEEK_CUR); if (tempi==257) { image_y=fgetc32b(plik); fseek(plik,-4,SEEK_CUR); } if (tempi==256) { image_x=fgetc32b(plik); fseek(plik,-4,SEEK_CUR); } if (tempi==258) { fseek(plik,-4,SEEK_CUR); depth=fgetc(plik)*8; fseek(plik,3,SEEK_CUR); } if (tempi==259) { compres=fgetc(plik); fseek(plik,-1,SEEK_CUR); } if (tempi==269) { fseek(plik,-4,SEEK_CUR); ile=fgetc16b(plik); fseek(plik,2,SEEK_CUR); dane=fgetc32b(plik); printf("Document name :"); dane=dane-(header+(12*(x+1)))-2; wypisz(ile,dane); fseek(plik,-4,SEEK_CUR); } if (tempi==270) { fseek(plik,-4,SEEK_CUR); ile=fgetc16b(plik); fseek(plik,2,SEEK_CUR); dane=fgetc32b(plik); printf("Description :"); dane=dane-(header+(12*(x+1)))-2; wypisz(ile,dane); fseek(plik,-4,SEEK_CUR); } if (tempi==320) { fseek(plik,-4,SEEK_CUR); ile=fgetc16b(plik); fseek(plik,2,SEEK_CUR); dane=fgetc32b(plik); dane=dane-(header+(12*(x+1)))-2; get_palete(ile,dane); fseek(plik,-4,SEEK_CUR); } fseek(plik,4,SEEK_CUR); } printf("TIFF detected : %ix%ix%i\n",image_x,image_y,depth); if (compres !=1) { printf("Decompression not supported yet !\n"); return 2; } if ((depth !=24) && (depth !=8)) { printf("Only 24 and 8 bit TIFF supported\n"); return 2; } if (depth==24){ fseek(plik,8,SEEK_SET); 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 (depth==8){ fseek(plik,8,SEEK_SET); for (y=0;y<image_y;y++) { for (x=0;x<image_x;x++) { tempi=fgetc(plik); tabr[x+y*image_x]=tab2r[tempi]; tabg[x+y*image_x]=tab2g[tempi]; tabb[x+y*image_x]=tab2b[tempi]; } } } return 0; }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -