Log In  


I tried to decompress the source code of my dithering-demo:
https://www.lexaloffle.com/bbs/?tid=49309
and my code failed.

First i thought my code is wrong, I translated from this source:
https://github.com/dansanderson/lexaloffle/blob/main/pxa_compress_snippets.c
the decompress-code to lua, so it is possible that I made a mistake.

I can't find a erro, so I looked at the rom-data:

4300  00 70 78 61 03 BC 02 39 02 40 C1 AC CE 6D 8C 2E  .pxa.¼.9.@Á¬ÎmŒ.

the first 8 bytes (00 70 78 61 03 BC 02 39) are the header, so the first databyte is 02
or binary: 00000010

When I look in decompress code:

while (src_pos < comp_len && dest_pos < raw_len && dest_pos < max_len)
	{
		int block_type = getbit();

		// printf("%d %d\n", src_pos, block_type); fflush(stdout);

		if (block_type == 0)
		{
			// block

			int block_offset = getnum() + 1;
			int block_len = getchain(BLOCK_LEN_CHAIN_BITS, 100000) + PXA_MIN_BLOCK_LEN;

			// copy // don't just memcpy because might be copying self for repeating pattern
			while (block_len > 0){
				out_p[dest_pos] = out_p[dest_pos - block_offset];
				dest_pos++;
				block_len--;
			}

it read the first bit (a zero) from 0x02 and go through the block_type==0 code.
At this moment the out_p is complete empty and dest_pos is 0, so when the code comes to "out_p[dest_pos] = out_p[dest_pos - block_offset];" it copied data BELOW the output-buffer.



Check https://pico-8.fandom.com/wiki/P8PNGFileFormat for the format description - especially the "As a special exception" bit - it's a relatively-newly-introduced literal block.


thanks - i was able to update my code. It works now.



[Please log in to post a comment]