no error reporting, only params check
| 78 | |
| 79 | // no error reporting, only params check |
| 80 | void write_ppm(libraw_processed_image_t *img, const char *basename) |
| 81 | { |
| 82 | if (!img) |
| 83 | return; |
| 84 | // type SHOULD be LIBRAW_IMAGE_BITMAP, but we'll check |
| 85 | if (img->type != LIBRAW_IMAGE_BITMAP) |
| 86 | return; |
| 87 | if (img->colors != 3 && img->colors != 1) |
| 88 | { |
| 89 | printf("Only monochrome and 3-color images supported for PPM output\n"); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | char fn[1024]; |
| 94 | snprintf(fn, 1024, "%s.p%cm", basename, img->colors==1?'g':'p'); |
| 95 | FILE *f = fopen(fn, "wb"); |
| 96 | if (!f) |
| 97 | return; |
| 98 | fprintf(f, "P%d\n%d %d\n%d\n", img->colors/2 + 5, img->width, img->height, (1 << img->bits) - 1); |
| 99 | /* |
| 100 | NOTE: |
| 101 | data in img->data is not converted to network byte order. |
| 102 | So, we should swap values on some architectures for dcraw compatibility |
| 103 | (unfortunately, xv cannot display 16-bit PPMs with network byte order data |
| 104 | */ |
| 105 | #define SWAP(a, b) \ |
| 106 | { \ |
| 107 | a ^= b; \ |
| 108 | a ^= (b ^= a); \ |
| 109 | } |
| 110 | if (img->bits == 16 && htons(0x55aa) != 0x55aa) |
| 111 | for (unsigned i = 0; i < img->data_size-1; i += 2) |
| 112 | SWAP(img->data[i], img->data[i + 1]); |
| 113 | #undef SWAP |
| 114 | |
| 115 | fwrite(img->data, img->data_size, 1, f); |
| 116 | fclose(f); |
| 117 | } |
| 118 | |
| 119 | void write_thumb(libraw_processed_image_t *img, const char *basename) |
| 120 | { |
no outgoing calls
no test coverage detected