| 33 | #define MODE_DECODE 1 |
| 34 | |
| 35 | int main(int argc, char **argv) |
| 36 | { |
| 37 | // Parse command line |
| 38 | if (argc != 6) |
| 39 | { |
| 40 | printf("Usage: astc_rgbm_codec [-ch|-dh] <M> <low_clamp> <source> <dest>\n"); |
| 41 | exit(1); |
| 42 | } |
| 43 | |
| 44 | int opmode; |
| 45 | if (strcmp(argv[1], "-ch") == 0) |
| 46 | { |
| 47 | opmode = MODE_ENCODE; |
| 48 | } |
| 49 | else if (strcmp(argv[1], "-dh") == 0) |
| 50 | { |
| 51 | opmode = MODE_DECODE; |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | printf("ERROR: Bad operation mode\n"); |
| 56 | exit(1); |
| 57 | } |
| 58 | |
| 59 | float rgbm_multiplier = atof(argv[2]); |
| 60 | float low_clamp = atof(argv[3]); |
| 61 | |
| 62 | const char* src_file = argv[4]; |
| 63 | const char* dst_file = argv[5]; |
| 64 | |
| 65 | // Convert an HDR input file into an RGBM encoded LDR file |
| 66 | if (opmode == MODE_ENCODE) |
| 67 | { |
| 68 | // Load the input image |
| 69 | int dim_x; |
| 70 | int dim_y; |
| 71 | const float* data_in = stbi_loadf(src_file, &dim_x, &dim_y, nullptr, 4); |
| 72 | if (!data_in) |
| 73 | { |
| 74 | printf("ERROR: Failed to load input image.\n"); |
| 75 | exit(1); |
| 76 | } |
| 77 | |
| 78 | // Allocate the output image |
| 79 | uint8_t* data_out = (uint8_t*)malloc(4 * dim_y * dim_x); |
| 80 | if (!data_out) |
| 81 | { |
| 82 | printf("ERROR: Failed to allow output image.\n"); |
| 83 | exit(1); |
| 84 | } |
| 85 | |
| 86 | // For each pixel apply RGBM encoding |
| 87 | for (int y = 0; y < dim_y; y++) |
| 88 | { |
| 89 | const float* row_in = data_in + (4 * dim_x * y); |
| 90 | uint8_t* row_out = data_out + (4 * dim_x * y); |
| 91 | |
| 92 | for (int x = 0; x < dim_x; x++) |
nothing calls this directly
no test coverage detected