aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-05-22 01:41:47 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-05-22 01:41:47 -0700
commit3551b64bd20efb9c7378ef4fd606df35941d4ee9 (patch)
tree6aa4bdef5a8cc9e7e16de080f70554a8f5c05db4 /src
parentc10594536108203e215e50bf3cf61c7e8aeb733f (diff)
downloadmirror-meh-3551b64bd20efb9c7378ef4fd606df35941d4ee9.tar.gz
mirror-meh-3551b64bd20efb9c7378ef4fd606df35941d4ee9.tar.bz2
mirror-meh-3551b64bd20efb9c7378ef4fd606df35941d4ee9.zip
work towards gif support
Diffstat (limited to 'src')
-rw-r--r--src/gif.c103
-rw-r--r--src/main.c2
2 files changed, 104 insertions, 1 deletions
diff --git a/src/gif.c b/src/gif.c
index 0c1ebb3..6928dd2 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -1,9 +1,112 @@
#include <stdio.h>
+#include <string.h>
#include "gif.h"
+#define GIF87a 0
+#define GIF89a 1
+
unsigned char *loadgif(FILE *infile, int *bufwidth, int *bufheight){
+ int version;
+ unsigned char *palette;
+ int pallen;
+ unsigned char *buf;
+ unsigned int bpp;
+
+ {
+ /* Read header*/
+ unsigned char packed;
+ unsigned char header[13];
+
+ if(fread(header, 1, 13, infile) != 13)
+ return NULL;
+ if(!memcmp("GIF89a", header, 6))
+ version = GIF89a;
+ else if(!memcmp("GIF87a", header, 6))
+ version = GIF87a;
+ else
+ return NULL;
+
+ *bufwidth = header[6] | header[7] << 8;
+ *bufheight = header[8] | header[9] << 8;
+ packed = header[10];
+ bpp = (packed & 7) + 1;
+
+ /* Read colormap */
+ if(packed & 0x80){
+ printf("Reading palette\n");
+ pallen = 1 << bpp;
+ printf("pallen: %i\n", pallen);
+ palette = malloc(3 * pallen);
+ fread(palette, 1, 3 * pallen, infile);
+ }
+ }
+
+ {
+ int blocktype;
+ while((blocktype = fgetc(infile)) != EOF){
+ if(blocktype == ';'){
+ printf("end of file\n");
+ break;
+ }else if(blocktype == '!'){
+ int bytecount, fncode;
+ if((fncode = fgetc(infile)) == EOF)
+ return NULL;
+ while(1){
+ bytecount = fgetc(infile);
+ printf("Skipping extblock 0x%x\n", fncode);
+ if(bytecount == EOF)
+ return NULL;
+ else if(bytecount > 0)
+ fseek(infile, bytecount, SEEK_CUR);
+ else
+ break;
+ }
+ }else if(blocktype == ','){
+ int imagex, imagey, imagew, imageh;
+ unsigned char imagedesc[9];
+ if(fread(imagedesc, 1, 9, infile) != 9)
+ return NULL;
+ if(imagedesc[8] & 0x80){
+ printf("ERROR: local palettes not supported\n");
+ return NULL;
+ }
+ if(imagedesc[8] & 0x40){
+ printf("ERROR: interlaced images\n");
+ return NULL;
+ }
+
+ imagex = imagedesc[0] | imagedesc[1] << 8;
+ imagey = imagedesc[2] | imagedesc[3] << 8;
+ imagew = imagedesc[4] | imagedesc[5] << 8;
+ imageh = imagedesc[6] | imagedesc[7] << 8;
+
+ if(imagex != 0 || imagey != 0 || imagew != *bufwidth || imageh != *bufheight){
+ printf("%ix%i %ix%i\n", imagex, imagey, imagew, imageh);
+ printf("TODO: allow this sort of thing\n");
+ return NULL;
+ }
+
+ {
+ int initcodesize, curcodesize;
+ initcodesize = fgetc(infile);
+ if(initcodesize < 1 || initcodesize > 9){
+ printf("bad code size %i\n", initcodesize);
+ return NULL;
+ }
+ curcodesize = initcodesize + 1;
+ }
+
+ break;
+ }else{
+ printf("Unknown block type %i\n", blocktype);
+ return NULL;
+ }
+ }
+ }
+
+ printf("end\n");
return NULL;
}
diff --git a/src/main.c b/src/main.c
index e9c0517..8553495 100644
--- a/src/main.c
+++ b/src/main.c
@@ -18,7 +18,7 @@ Window window;
GC gc;
void usage(){
- printf("USAGE: meh [FILE1 [FILE2 [...]]]");
+ printf("USAGE: meh [FILE1 [FILE2 [...]]]\n");
exit(1);
}