IMG_gif.c
branchSDL-1.2
changeset 607 1a1189c2978f
parent 288 cbf4a9d168ff
child 678 776aa1fbe453
equal deleted inserted replaced
606:4872fdc71670 607:1a1189c2978f
   318     case 0xff:			/* Application Extension */
   318     case 0xff:			/* Application Extension */
   319 	str = "Application Extension";
   319 	str = "Application Extension";
   320 	break;
   320 	break;
   321     case 0xfe:			/* Comment Extension */
   321     case 0xfe:			/* Comment Extension */
   322 	str = "Comment Extension";
   322 	str = "Comment Extension";
   323 	while (GetDataBlock(src, (unsigned char *) buf) != 0)
   323 	while (GetDataBlock(src, (unsigned char *) buf) > 0)
   324 	    ;
   324 	    ;
   325 	return FALSE;
   325 	return FALSE;
   326     case 0xf9:			/* Graphic Control Extension */
   326     case 0xf9:			/* Graphic Control Extension */
   327 	str = "Graphic Control Extension";
   327 	str = "Graphic Control Extension";
   328 	(void) GetDataBlock(src, (unsigned char *) buf);
   328 	(void) GetDataBlock(src, (unsigned char *) buf);
   330 	Gif89.inputFlag = (buf[0] >> 1) & 0x1;
   330 	Gif89.inputFlag = (buf[0] >> 1) & 0x1;
   331 	Gif89.delayTime = LM_to_uint(buf[1], buf[2]);
   331 	Gif89.delayTime = LM_to_uint(buf[1], buf[2]);
   332 	if ((buf[0] & 0x1) != 0)
   332 	if ((buf[0] & 0x1) != 0)
   333 	    Gif89.transparent = buf[3];
   333 	    Gif89.transparent = buf[3];
   334 
   334 
   335 	while (GetDataBlock(src, (unsigned char *) buf) != 0)
   335 	while (GetDataBlock(src, (unsigned char *) buf) > 0)
   336 	    ;
   336 	    ;
   337 	return FALSE;
   337 	return FALSE;
   338     default:
   338     default:
   339 	str = (char *)buf;
   339 	str = (char *)buf;
   340 	sprintf(str, "UNKNOWN (0x%02x)", label);
   340 	sprintf(str, "UNKNOWN (0x%02x)", label);
   341 	break;
   341 	break;
   342     }
   342     }
   343 
   343 
   344     while (GetDataBlock(src, (unsigned char *) buf) != 0)
   344     while (GetDataBlock(src, (unsigned char *) buf) > 0)
   345 	;
   345 	;
   346 
   346 
   347     return FALSE;
   347     return FALSE;
   348 }
   348 }
   349 
   349 
   388 	    return -1;
   388 	    return -1;
   389 	}
   389 	}
   390 	buf[0] = buf[last_byte - 2];
   390 	buf[0] = buf[last_byte - 2];
   391 	buf[1] = buf[last_byte - 1];
   391 	buf[1] = buf[last_byte - 1];
   392 
   392 
   393 	if ((count = GetDataBlock(src, &buf[2])) == 0)
   393 	if ((count = GetDataBlock(src, &buf[2])) <= 0)
   394 	    done = TRUE;
   394 	    done = TRUE;
   395 
   395 
   396 	last_byte = 2 + count;
   396 	last_byte = 2 + count;
   397 	curbit = (curbit - lastbit) + 16;
   397 	curbit = (curbit - lastbit) + 16;
   398 	lastbit = (2 + count) * 8;
   398 	lastbit = (2 + count) * 8;
   437 
   437 
   438 	for (i = 0; i < clear_code; ++i) {
   438 	for (i = 0; i < clear_code; ++i) {
   439 	    table[0][i] = 0;
   439 	    table[0][i] = 0;
   440 	    table[1][i] = i;
   440 	    table[1][i] = i;
   441 	}
   441 	}
       
   442 	table[1][0] = 0;
   442 	for (; i < (1 << MAX_LWZ_BITS); ++i)
   443 	for (; i < (1 << MAX_LWZ_BITS); ++i)
   443 	    table[0][i] = table[1][0] = 0;
   444 	    table[0][i] = 0;
   444 
   445 
   445 	sp = stack;
   446 	sp = stack;
   446 
   447 
   447 	return 0;
   448 	return 0;
   448     } else if (fresh) {
   449     } else if (fresh) {
   491 	if (code >= max_code) {
   492 	if (code >= max_code) {
   492 	    *sp++ = firstcode;
   493 	    *sp++ = firstcode;
   493 	    code = oldcode;
   494 	    code = oldcode;
   494 	}
   495 	}
   495 	while (code >= clear_code) {
   496 	while (code >= clear_code) {
       
   497 	    /* Guard against buffer overruns */
       
   498 	    if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
       
   499 		RWSetMsg("invalid LWZ data");
       
   500 		return -3;
       
   501 	    }
   496 	    *sp++ = table[1][code];
   502 	    *sp++ = table[1][code];
   497 	    if (code == table[0][code])
   503 	    if (code == table[0][code]) {
   498 		RWSetMsg("circular table entry BIG ERROR");
   504 		RWSetMsg("circular table entry BIG ERROR");
       
   505 		return -3;
       
   506 	    }
   499 	    code = table[0][code];
   507 	    code = table[0][code];
   500 	}
   508 	}
   501 
   509 
       
   510 	/* Guard against buffer overruns */
       
   511 	if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
       
   512 	    RWSetMsg("invalid LWZ data");
       
   513 	    return -4;
       
   514 	}
   502 	*sp++ = firstcode = table[1][code];
   515 	*sp++ = firstcode = table[1][code];
   503 
   516 
   504 	if ((code = max_code) < (1 << MAX_LWZ_BITS)) {
   517 	if ((code = max_code) < (1 << MAX_LWZ_BITS)) {
   505 	    table[0][code] = oldcode;
   518 	    table[0][code] = oldcode;
   506 	    table[1][code] = firstcode;
   519 	    table[1][code] = firstcode;