/* ico.c -- reads .ICO file * * Copyright (C) 2008 Erica Asai * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #define NDATA 10 struct { char reserved[2]; char type[2]; char count[2]; }header; struct { char width; char height; char colorCount; char reserved; char planes[2]; char bitCount[2]; char sizeInBytes[4]; char fileOffset[4]; }entry; struct { char size[4]; char width[4]; char height[4]; char planes[2]; char bitCount[2]; char compression[4]; char imageSize[4]; char xPixelsPerM[4]; char yPixelsPerM[4]; char colorUsed[4]; char colorsImportant[4]; }infoHeader; struct { char red; char green; char blue; char reserved; }colors; int btoi(char* buf,int len) { int x=0; if(len<=0) return x; int i=0; x=buf[len-1]&0xff; for(i=len-2;0<=i;i--) { x=x*0x100+(buf[i]&0xff); } return x; } int main(int argc, char *argv[]) { FILE *fp; if(0\n",i); if((nBytes=fread(&entry,sizeof(entry),1,fp))!=1) { printf("fread error, read %d data\n",nBytes); return 1; } if(entry.colorCount==0) nColors[i]=256; else nColors[i]=entry.colorCount; printf("Width %d\n",entry.width); printf("Height %d\n",entry.height); printf("ColorCount %d\n",entry.colorCount); printf("Reserved %d\n",entry.reserved); printf("Planes %d\n",btoi(entry.planes,2)); printf("BitCount %d\n",btoi(entry.bitCount,2)); printf("SizeInBytes %d\n",btoi(entry.sizeInBytes,4)); printf("FileOffset %d\n",btoi(entry.fileOffset,4)); sizeInBytes[i]=btoi(entry.sizeInBytes,4); } int sizeTotal=0; i=0; for(i=0;i\n"); } return 0; }