⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mga_bmp.c

📁 linux下显示各种格式图片
💻 C
字号:
/* 	(c) HelDoRe	Bitmap unit ... v0.0.9			Supported formats :			4bpp			8bpp , 8bpp + RLE			24bpp			32bpp			or ImageMagick*/			#define VERBMP " unit v0.0.9"#include <stdio.h>#include "../mga_view.h"void help_bmp(){#ifdef USE_MAG_BMP  printf("BMP%s\n   + uses ImageMagick\n",VERBMP);#else  printf("BMP%s\n   +  4 bpp\n   +  8 bpp\n   +  8 bpp rle\n   + 24 bpp\n   + 32 bpp\n",VERBMP);#endif  }typedef struct bmp_head {	short int BMPsyg;	short int nic[8];	short int ix;	short int nic2;	short int iy;	short int nic3[2];	short int depth;	short int rle;	short int nic4[11];	} bmp_head;		int detect_bmp(){    bmp_head bmp;        int rle,pocz;#ifndef USE_MAG_BMP    int omin;    unsigned char rozp;#endif        fread(&bmp,1,sizeof(bmp_head),plik);    if (bmp.BMPsyg != 19778)     {	return 1;     }    pocz=bmp.nic[4];    image_x=bmp.ix;    image_y=bmp.iy;    depth=bmp.depth;    if (check_image(image_x,image_y,depth)==3) return 3;    printf("Bitmap%s",VERBMP);#ifdef USE_MAG_BMP    printf(" (IM)");#endif        printf("\nBitmap detected : ");    printf("%ix%ix%i",image_x,image_y,depth);    rle=bmp.rle;    if (rle!=0) printf(" compressed");    printf("\n");#ifdef USE_MAG_BMP    detect_mag(0);#else    if ((depth != 32) && (depth != 24) && (depth != 8) && (depth !=4))	    {	    printf("Depth %i not supported ! \n",depth);	    return 2;	    }    rozp=ftell(plik);    fseek(plik,0,SEEK_END);    omin=ftell(plik);    omin=omin-pocz;    omin=omin-((image_x*image_y)*(depth/8));    omin=omin/(image_y);    fseek(plik,pocz,SEEK_SET);    if (depth==32) /* depth=32 */    {     for (y=0;y<image_y;y++)      {      for (x=0;x<image_x;x++)       {       tabb[x+(image_y-y-1)*image_x]=fgetc(plik);       tabg[x+(image_y-y-1)*image_x]=fgetc(plik);       tabr[x+(image_y-y-1)*image_x]=fgetc(plik);       tempi=fgetc(plik);       }      if (omin>0) 	for (tempi=0;tempi<omin;tempi++) fgetc(plik);	      }    }  /* end depth=32 */    if (depth==24) /* depth=24 */    {     for (y=0;y<image_y;y++)      {      for (x=0;x<image_x;x++)       {       tabb[x+(image_y-y-1)*image_x]=fgetc(plik);       tabg[x+(image_y-y-1)*image_x]=fgetc(plik);       tabr[x+(image_y-y-1)*image_x]=fgetc(plik);       }      if (omin>0) 	for (tempi=0;tempi<omin;tempi++) fgetc(plik);	      }    }  /* end depth=24 */    if (depth==8) /* depth=8 */    {	fseek(plik,-256*4,SEEK_CUR);     for (tempi=0;tempi<256;tempi++)      {	tab2b[tempi]=fgetc(plik);		tab2g[tempi]=fgetc(plik);		tab2r[tempi]=fgetc(plik);		x=fgetc(plik);      }    if (rle==0) {   /* nonRLE */	     for (y=0;y<image_y;y++)      {      for (x=0;x<image_x;x++)       {      if ((tempi=fgetc(plik))==-1) return 0;       tabr[x+(image_y-y-1)*image_x]=tab2r[tempi];       tabg[x+(image_y-y-1)*image_x]=tab2g[tempi];       tabb[x+(image_y-y-1)*image_x]=tab2b[tempi];      }      if (omin>0)  		       for (tempi=0;tempi<omin;tempi++) fgetc(plik);      }      }   /* end nonRLE */	else { /* RLE */     for (y=0;y<image_y;y++)      {      for (x=0;x<image_x;x++)       {        if ((depth=fgetc(plik))==-1) return 0;	tempi=fgetc(plik);	if (depth==0) {	for (rle=0;rle<tempi;rle++){	depth=fgetc(plik);       tabr[(x+rle)+(image_y-y-1)*image_x]=tab2r[depth];       tabg[(x+rle)+(image_y-y-1)*image_x]=tab2g[depth];       tabb[(x+rle)+(image_y-y-1)*image_x]=tab2b[depth];	}	if (tempi!=((tempi/2)*2)) tempi=fgetc(plik);	} else {	for (rle=0;rle<depth;rle++){       tabr[(x+rle)+(image_y-y-1)*image_x]=tab2r[tempi];       tabg[(x+rle)+(image_y-y-1)*image_x]=tab2g[tempi];       tabb[(x+rle)+(image_y-y-1)*image_x]=tab2b[tempi];	}		}	x+=rle-1;	}		}        } /* end RLE  */	depth=8;        } /* end depth=8 */    if (depth==4) /* depth=4 */    {	fseek(plik,-16*4,SEEK_CUR);     for (tempi=0;tempi<16;tempi++)      {	tab2b[tempi]=fgetc(plik);		tab2g[tempi]=fgetc(plik);		tab2r[tempi]=fgetc(plik);		x=fgetc(plik);      }    if (rle==0) {  /* nonRLE */	     for (y=0;y<image_y;y++)      {      for (x=0;x<image_x;x++)       {      tempi=fgetc(plik);      rozp=tempi;      rozp=(rozp & 0xf0)>>4;       tabr[x+(image_y-y-1)*image_x]=tab2r[rozp];       tabg[x+(image_y-y-1)*image_x]=tab2g[rozp];       tabb[x+(image_y-y-1)*image_x]=tab2b[rozp];	x++;      rozp=tempi;      rozp=(rozp & 0x0f);       tabr[x+(image_y-y-1)*image_x]=tab2r[rozp];       tabg[x+(image_y-y-1)*image_x]=tab2g[rozp];       tabb[x+(image_y-y-1)*image_x]=tab2b[rozp];      }      }      }    /* end nonRLE */      else { /* RLE */	         } /* end RLE */      depth=4;     }    /* end depth=4*/#endif    return 0;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -