Created
February 22, 2012 17:55
-
-
Save wjlafrance/1886309 to your computer and use it in GitHub Desktop.
Reading RECT from SWF file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* read signed bit */ | |
/* flush = YES to clear remaining bits */ | |
uint8 readSB(FILE *file, BOOL flush) | |
{ | |
static uint8 bits = 0; | |
static uint8 bitpos = 8; | |
if (bitpos > 7) { | |
bits = readUI8(file); | |
bitpos = 0; | |
} | |
if (flush) { | |
bitpos = 8; | |
return 0; | |
} | |
return (bits >> (7 - bitpos++)) & 0x01; | |
} | |
CGRect readRECT(FILE *file) | |
{ | |
int nbits = readSB(file, NO) << 4 | | |
readSB(file, NO) << 3 | | |
readSB(file, NO) << 2 | | |
readSB(file, NO) << 1 | | |
readSB(file, NO); | |
uint64 Xmin = 0, Xmax = 0, Ymin = 0, Ymax = 0; | |
for (int bit = nbits; bit > 0; ) { Xmin |= readSB(file, NO) << --bit; } | |
for (int bit = nbits; bit > 0; ) { Xmax |= readSB(file, NO) << --bit; } | |
for (int bit = nbits; bit > 0; ) { Ymin |= readSB(file, NO) << --bit; } | |
for (int bit = nbits; bit > 0; ) { Ymax |= readSB(file, NO) << --bit; } | |
readSB(NULL, YES); | |
return CGRectMake(Xmin, Ymin, Xmax, Ymax); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment