| 7 | #include <fstream> |
| 8 | |
| 9 | int main(int argc, char** argv) { |
| 10 | if (argc < 3) { |
| 11 | fprintf(stderr, "Usage: %s <image.jpg> <pil_decoded.bin>\n", argv[0]); |
| 12 | return 1; |
| 13 | } |
| 14 | auto img = sam3_load_image(argv[1]); |
| 15 | if (img.data.empty()) { fprintf(stderr, "Failed to load image\n"); return 1; } |
| 16 | fprintf(stderr, "stb_image decoded: %dx%d, %d bytes\n", |
| 17 | img.width, img.height, (int)img.data.size()); |
| 18 | |
| 19 | // Load PIL reference |
| 20 | std::ifstream f(argv[2], std::ios::binary); |
| 21 | if (!f) { fprintf(stderr, "Failed to load PIL ref\n"); return 1; } |
| 22 | std::vector<uint8_t> pil_data(img.data.size()); |
| 23 | f.read(reinterpret_cast<char*>(pil_data.data()), pil_data.size()); |
| 24 | fprintf(stderr, "PIL decoded: %d bytes\n", (int)pil_data.size()); |
| 25 | |
| 26 | // Compare |
| 27 | int n_diff = 0, max_diff = 0; |
| 28 | for (size_t i = 0; i < img.data.size(); ++i) { |
| 29 | int d = abs((int)img.data[i] - (int)pil_data[i]); |
| 30 | if (d > 0) n_diff++; |
| 31 | if (d > max_diff) max_diff = d; |
| 32 | } |
| 33 | fprintf(stderr, "\n═══ JPEG Decoder Comparison ═══\n"); |
| 34 | fprintf(stderr, " max pixel diff: %d\n", max_diff); |
| 35 | fprintf(stderr, " pixels differing: %d / %d (%.2f%%)\n", |
| 36 | n_diff, (int)img.data.size(), 100.0 * n_diff / img.data.size()); |
| 37 | |
| 38 | // Check specific pixels |
| 39 | int y=16, x=517, c=2; |
| 40 | int idx = (y * img.width + x) * 3 + c; |
| 41 | fprintf(stderr, "\n stb pixel at (%d,%d,%d): %d\n", y, x, c, img.data[idx]); |
| 42 | fprintf(stderr, " PIL pixel at (%d,%d,%d): %d\n", y, x, c, pil_data[idx]); |
| 43 | |
| 44 | return max_diff > 0 ? 1 : 0; |
| 45 | } |
nothing calls this directly
no test coverage detected