aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-05-27 23:33:49 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-05-27 23:33:49 -0700
commitf1c95bdd11811020d27b7bf569a2ecae15dca49e (patch)
tree6ed84ebfdb7cda735f6ba0a340abbc03464e6a62
parent0c3da11e39673f0a809426bb6cb745c75582ef6a (diff)
downloadmirror-meh-f1c95bdd11811020d27b7bf569a2ecae15dca49e.tar.gz
mirror-meh-f1c95bdd11811020d27b7bf569a2ecae15dca49e.tar.bz2
mirror-meh-f1c95bdd11811020d27b7bf569a2ecae15dca49e.zip
work towards GIF support
-rw-r--r--src/gif.c75
1 files changed, 73 insertions, 2 deletions
diff --git a/src/gif.c b/src/gif.c
index 018b1db..bc3df8c 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -11,7 +11,7 @@ unsigned char *loadgif(FILE *infile, int *bufwidth, int *bufheight){
int version;
unsigned char *palette;
int pallen;
- unsigned char *buf;
+ unsigned char *buf = NULL;
unsigned int bpp;
{
@@ -88,14 +88,85 @@ unsigned char *loadgif(FILE *infile, int *bufwidth, int *bufheight){
return NULL;
}
+ buf = malloc((*bufwidth) * (*bufheight) * 3);
+
{
- int initcodesize, curcodesize;
+ unsigned int initcodesize, curcodesize;
+ unsigned int clearcode, endcode, newcode;
+ int bytesleft = 0;
+ int i;
+
+ /* Get code size */
initcodesize = fgetc(infile);
if(initcodesize < 1 || initcodesize > 9){
printf("bad code size %i\n", initcodesize);
return NULL;
}
curcodesize = initcodesize + 1;
+ clearcode = 1 << initcodesize;
+ endcode = clearcode + 1;
+ newcode = endcode + 1;
+
+ int count = 0;
+ for(;;){
+ int byte0 = -1, byte1 = -1, byteshift = 0;
+ if(1){
+ bytesleft = fgetc(infile);
+ printf("%i\n", bytesleft);
+ if(bytesleft < 0){
+ printf("unexpected EOF (0)\n");
+ return NULL;
+ }else if(bytesleft == 0)
+ break;
+ }
+ printf("start %i, %i\n", count++, bytesleft);
+ for(;;){
+ int code;
+ /* get code */
+
+ while(byte1 == -1){
+ if((byte1 = fgetc(infile)) == EOF){
+ printf("unexpected EOF (1)\n");
+ return NULL;
+ }
+ if(byte0 == -1){
+ byte0 = byte1;
+ }
+ bytesleft--;
+ }
+ if(bytesleft < 0){
+ break;
+ }
+ code = (byte0 | byte1 << 8) >> byteshift & ((1 << curcodesize) - 1);
+ byteshift += curcodesize;
+ while(byteshift >= 8){
+ byte0 = byte1;
+ byte1 = -1;
+ byteshift -= 8;
+ }
+
+ if(code == clearcode){
+ printf("clearcode\n");
+ curcodesize = initcodesize + 1;
+ newcode = endcode + 1;
+ }else if(code == endcode){
+ printf("endcode with %i bytes left\n", bytesleft);
+ break;
+ }else{
+ newcode++;
+ }
+
+ /* process code */
+ if(newcode == 1 << curcodesize){
+ curcodesize++;
+ }
+ }
+ }
+
+ /*for(i = 0; i < (*bufwidth) * (*bufheight); i++){
+ }*/
+ printf("good end\n");
+ return buf;
}
break;