PTdecode/src/main.cpp

changeset 13
a933b13e087f
parent 5
1204ebf9340d
child 23
f2c7acb4a258
     1.1 --- a/PTdecode/src/main.cpp	Wed Aug 05 15:00:54 2009 +0100
     1.2 +++ b/PTdecode/src/main.cpp	Wed Aug 05 15:02:31 2009 +0100
     1.3 @@ -95,31 +95,39 @@
     1.4  				ch = getNext();
     1.5  				len = (((int)getNext()) << 8) + ch;
     1.6  
     1.7 -				// Dump the gfx data
     1.8 -				rowpos = 0;
     1.9 -				while (len > 0) {
    1.10 -					// get the prefix byte
    1.11 -					ch = getNext(); len--;
    1.12 -
    1.13 -					// Is this a "run" (a single byte replicated) or a "copy"?
    1.14 -					int runlen;
    1.15 -					if (ch & 0x80) {
    1.16 -						// MSB set, it's a run
    1.17 -						runlen = 257 - ((int)ch);
    1.18 +				// Is gfx payload compressed or uncompressed?
    1.19 +				if (cm == 1) {
    1.20 +					// Uncompressed. Read straight into the row buffer.
    1.21 +					while (len > 0) {
    1.22 +						row[rowpos++] = getNext(); len--;
    1.23 +					}
    1.24 +				} else {
    1.25 +					// Decompress the gfx data
    1.26 +					rowpos = 0;
    1.27 +					while (len > 0) {
    1.28 +						// get the prefix byte
    1.29 +						ch = getNext(); len--;
    1.30  
    1.31 -						// Get the byte to replicate, and replicate it into the o/p buffer
    1.32 -						ch = getNext(); len--;
    1.33 -						while (runlen-- > 0) {
    1.34 -							row[rowpos++] = ch;
    1.35 -						}
    1.36 -					} else {
    1.37 -						// MSB clear, it's a copy
    1.38 -						runlen = ((int)ch) + 1;
    1.39 +						// Is this a "run" (a single byte replicated) or a "copy"?
    1.40 +						int runlen;
    1.41 +						if (ch & 0x80) {
    1.42 +							// MSB set, it's a run
    1.43 +							runlen = 257 - ((int)ch);
    1.44  
    1.45 -						// Copy N bytes from the input stream to the output
    1.46 -						while (runlen-- > 0) {
    1.47 -							row[rowpos++] = getNext();
    1.48 -							len--;
    1.49 +							// Get the byte to replicate, and replicate it into the o/p buffer
    1.50 +							ch = getNext(); len--;
    1.51 +							while (runlen-- > 0) {
    1.52 +								row[rowpos++] = ch;
    1.53 +							}
    1.54 +						} else {
    1.55 +							// MSB clear, it's a copy
    1.56 +							runlen = ((int)ch) + 1;
    1.57 +
    1.58 +							// Copy N bytes from the input stream to the output
    1.59 +							while (runlen-- > 0) {
    1.60 +								row[rowpos++] = getNext();
    1.61 +								len--;
    1.62 +							}
    1.63  						}
    1.64  					}
    1.65  				}