client/tests/png_filter.c (3205B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_250CBDE0(void); 5 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 6 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 7 recomp_func_t recomp_lookup(uint32_t address) { abort(); } 8 9 static unsigned yields; 10 static void observe_row_yield(void) 11 { 12 ++yields; 13 assert(g_esp == 0x5002fff4 && g_ebp == 0x50030004); 14 assert(g_eax == 0x50010001 && g_esi == 0x50020001); 15 assert(g_ebx == 11 && g_ecx == 48 && g_edx == 70 && g_edi == 33); 16 assert(MEM32(g_ebp + 0x18) == 0x5000fffe); 17 assert(MEM32(g_ebp - 4) == 70 && MEM32(g_ebp + 8) == 0x5001fffe); 18 assert(MEM32(g_ebp + 0xc) == 48 && MEM32(g_ebp + 0x14) == 8); 19 assert(MEM32(g_ebp + 0x10) == 0x50010001); 20 assert(MEM8(0x5000fffd) == 33 && MEM8(0x5000fffe) == 208); 21 assert(MEM8(0x5000ffff) == 194 && MEM8(0x50010000) == 75); 22 assert(MEM8(0x50010001) == 99); 23 } 24 25 int main(void) 26 { 27 assert(guest_map("PNG row filter", 0x50000000, 0x40000)); 28 assert(guest_map("PNG filter dispatch", 0x250c0000, 0x10000)); 29 MEM32(0x250cbf98) = 0x250cbeaf; 30 const struct { 31 unsigned depth, count; 32 unsigned char row[12], previous[12], expected[12]; 33 } cases[] = { 34 {24, 12, {11,200,250,5,99,17,255,0,76,55,77,88}, 35 {22,8,200,70,5,250,15,90,90,255,9,10}, 36 {33,208,194,75,51,11,14,90,87,54,86,98}}, 37 {32, 8, {255,255,5,0,100,88,77,15}, 38 {255,128,64,10,50,70,30,200}, {254,127,69,10,150,158,107,215}}, 39 /* Upper-left prediction, then the two observable distance ties. */ 40 {8, 2, {246,20}, {100,110}, {90,120}}, 41 {8, 2, {246,1}, {10,30}, {0,31}}, 42 {8, 2, {20,1}, {10,0}, {30,31}}, 43 /* Packed pixels still use a full byte as the left neighbor. */ 44 {1, 2, {20,1}, {10,0}, {30,31}}, 45 {48, 6, {1,2,3,4,5,6}, {10,20,30,40,50,60}, {11,22,33,44,55,66}} 46 }; 47 for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) { 48 memset((void *)ADDR(0x50000000), 0xa5, 0x40000); 49 memcpy((void *)ADDR(0x5000fffd), cases[i].row, cases[i].count); 50 memcpy((void *)ADDR(0x5001fffd), cases[i].previous, cases[i].count); 51 MEM32(0x50001004) = cases[i].count; 52 MEM8(0x5000100b) = cases[i].depth; 53 g_esp = 0x50030008; 54 g_ebp = 123; g_ebx = 234; g_esi = 345; g_edi = 456; 55 MEM32(g_esp + 4) = 0x50002000; 56 MEM32(g_esp + 8) = 0x50001000; 57 MEM32(g_esp + 12) = 0x5000fffd; 58 MEM32(g_esp + 16) = 0x5001fffd; 59 MEM32(g_esp + 20) = 4; 60 /* Yield on the first Paeth byte after the initial RGB pixel. */ 61 recomp_yield_hook = i == 0 ? observe_row_yield : NULL; 62 g_backedges = RECOMP_YIELD_EVERY - 4; 63 yields = 0; 64 65 sub_250CBDE0(); 66 67 assert(!memcmp((void *)ADDR(0x5000fffd), cases[i].expected, cases[i].count)); 68 assert(!memcmp((void *)ADDR(0x5001fffd), cases[i].previous, cases[i].count)); 69 assert(MEM8(0x5000fffc) == 0xa5 && MEM8(0x5000fffd + cases[i].count) == 0xa5); 70 assert(yields == (i == 0 ? 1 : 0)); 71 assert(g_esp == 0x5003000c && g_ebp == 123); 72 assert(g_ebx == 234 && g_esi == 345 && g_edi == 456); 73 } 74 }