int64_t lzbench_lzrw_decompress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t level, size_t, char* workmem) { if (!workmem) return 0; uint32_t decomplen = 0; switch (level) { default: case 1: lzrw1_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen); break; case 2: lzrw1a_compress(COMPRESS_ACTION_DECOMPRESS, (uint8_t*)workmem, (uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen); break; case 3: lzrw2_compress(COMPRESS_ACTION_DECOMPRESS, (uint8_t*)workmem, (uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen); break; case 4: lzrw3_compress(COMPRESS_ACTION_DECOMPRESS, (uint8_t*)workmem, (uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen); break; case 5: lzrw3a_compress(COMPRESS_ACTION_DECOMPRESS, (uint8_t*)workmem, (uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen); break; } return decomplen; }
void compare (UBYTE* source, UBYTE* destination, ULONG bytes) { ULONG compressedSize; ULONG decompressedSize; /* Make a copy of the source page so that we have a version of the source that is guaranteed to be unmolested. */ UBYTE* copy = (UBYTE*)malloc(sizeof(UBYTE) * bytes); memcpy ((void*)copy, (void*)source, sizeof (UBYTE) * bytes); /* Compress and then decompress the data. */ lzrw1_compress(copy, bytes, destination, &compressedSize); lzrw1_decompress(destination, compressedSize, copy, &decompressedSize); /* Compare the decompressed data to the original. */ if (bytes != decompressedSize) { printf("Differed in size!\n"); } if (memcmp ((void*)source, (void*)copy, sizeof (UBYTE) * bytes) == 0) { printf ("Matched\n"); } else { unsigned int byte; printf ("Differed...sadness...\n"); printf ("\tsource\t\tcopy\n"); for (byte = 0; byte < bytes; byte++) { printf("\t%8lx\t%8lx\n", source[byte], copy[byte]); } } printf("\n"); }