12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

§105 ANNOYANCE-FILTER FLASH STREAM DECODER 85<br />

105. Flash files are a little schizophrenic when it comes to the definition of strings. Sometimes they’re<br />

stored with a leading count byte followed by the given number of bytes of text, while in other places<br />

they’re stored C style, with a zero terminator byte marking the end of the string. <strong>The</strong> getString method<br />

handles both kinds. If called with no length argument, it reads a zero terminated string, otherwise it<br />

reads a string of n characters. It’s up to the caller to first read the length and pass it as the n argument,<br />

〈 Class implementations 11 〉 +≡<br />

void flashStream ::getString (string &s, int n)<br />

{<br />

s = "";<br />

}<br />

char ch ;<br />

if (n ≡ −1) {<br />

while ((ch = get8 ( )) ≠ 0) {<br />

s += ch ;<br />

}<br />

}<br />

else {<br />

while (n > 0) {<br />

ch = get8 ( );<br />

s += ch ;<br />

n−−;<br />

}<br />

}<br />

106. A rectangle is stored as a 5 bit field which specifies the number of bits in the extent fields which<br />

follow, which are sign extended when extracted.<br />

〈 Class implementations 11 〉 +≡<br />

void flashStream ::getRect (rect ∗ r)<br />

{<br />

initBits ( );<br />

}<br />

int nBits = static cast〈int〉(getBits (5));<br />

r ⃗ xMin = getSignedBits (nBits );<br />

r ⃗ xMax = getSignedBits (nBits );<br />

r ⃗ yMin = getSignedBits (nBits );<br />

r ⃗ yMax = getSignedBits (nBits );

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!