converted gifanalyzer.c to UNIX file endings

This commit is contained in:
Thomas Bernard 2018-01-08 17:26:48 +01:00
parent 1c6a9e5830
commit 26ab4c6844

View File

@ -1,97 +1,97 @@
/* vim:expandtab:ts=2 sw=2: /* vim:expandtab:ts=2 sw=2:
*/ */
/* Grafx2 - The Ultimate 256-color bitmap paint program /* Grafx2 - The Ultimate 256-color bitmap paint program
* Gif Analyzer tool * Gif Analyzer tool
Copyright 2010 Adrien Destugues Copyright 2010 Adrien Destugues
Grafx2 is free software; you can redistribute it and/or Grafx2 is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 as published by the Free Software Foundation; version 2
of the License. of the License.
Grafx2 is distributed in the hope that it will be useful, Grafx2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/> along with Grafx2; if not, see <http://www.gnu.org/licenses/>
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <math.h> #include <math.h>
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
FILE* theFile; FILE* theFile;
if(argc != 2) if(argc != 2)
{ {
printf("%s file.gif\n",argv[0]); printf("%s file.gif\n",argv[0]);
exit(-1); exit(-1);
} }
theFile = fopen(argv[1], "r"); theFile = fopen(argv[1], "r");
uint8_t buffer[256]; uint8_t buffer[256];
fread(buffer, 1, 6, theFile); fread(buffer, 1, 6, theFile);
buffer[6] = 0; buffer[6] = 0;
printf("Signature: %6s\n", buffer); printf("Signature: %6s\n", buffer);
uint16_t w,h; uint16_t w,h;
fread(&w,2,1,theFile); fread(&w,2,1,theFile);
fread(&h,2,1,theFile); fread(&h,2,1,theFile);
printf("Resolution: %dx%d\n",w,h); printf("Resolution: %dx%d\n",w,h);
fread(buffer,1,3,theFile); fread(buffer,1,3,theFile);
int colors = ((buffer[0]&0b01110000)>>4)+1; int colors = ((buffer[0]&0b01110000)>>4)+1;
colors = pow(2,colors); colors = pow(2,colors);
int bpp = (buffer[0]&0xF) +1; int bpp = (buffer[0]&0xF) +1;
printf("Color palette: %#02.2x\n",buffer[0]&0xFF); printf("Color palette: %#02.2x\n",buffer[0]&0xFF);
if (buffer[0] & 0b10000000) if (buffer[0] & 0b10000000)
printf("\tGlobal palette\n"); printf("\tGlobal palette\n");
printf("\tColor count: %d\n", colors); printf("\tColor count: %d\n", colors);
printf("\tBits per pixel: %d\n",bpp); printf("\tBits per pixel: %d\n",bpp);
printf("Index of background color: %d\n",buffer[1]); printf("Index of background color: %d\n",buffer[1]);
printf("(reserved byte: %d)\n",buffer[2]); printf("(reserved byte: %d)\n",buffer[2]);
printf("Color palette:\n"); printf("Color palette:\n");
for (int i = 0; i < pow(2,bpp); i++) for (int i = 0; i < pow(2,bpp); i++)
{ {
fread(buffer,1,3,theFile); fread(buffer,1,3,theFile);
printf("\t%d: %u %u %u\t",i,buffer[0], buffer[1], buffer[2]); printf("\t%d: %u %u %u\t",i,buffer[0], buffer[1], buffer[2]);
if ((i+1)%4 ==0)puts(""); if ((i+1)%4 ==0)puts("");
} }
int i = 0; int i = 0;
do { do {
fread(buffer,1,1,theFile); fread(buffer,1,1,theFile);
i++; i++;
} while (i != ','); } while (i != ',');
if (i > 1); if (i > 1);
printf("Skipped %d meaningless bytes before image descriptor\n",i); printf("Skipped %d meaningless bytes before image descriptor\n",i);
uint16_t x,y; uint16_t x,y;
fread(&x,2,1,theFile); fread(&x,2,1,theFile);
fread(&y,2,1,theFile); fread(&y,2,1,theFile);
fread(&w,2,1,theFile); fread(&w,2,1,theFile);
fread(&h,2,1,theFile); fread(&h,2,1,theFile);
printf("Image descriptor\n"); printf("Image descriptor\n");
printf("\tx=%d y=%d w=%d h=%d\n",x,y,w,h); printf("\tx=%d y=%d w=%d h=%d\n",x,y,w,h);
fclose(theFile); fclose(theFile);
} }