| 171 | } |
| 172 | |
| 173 | void write_ppm(unsigned width, unsigned height, unsigned short *bitmap, |
| 174 | const char *fname) |
| 175 | { |
| 176 | if (!bitmap) |
| 177 | return; |
| 178 | |
| 179 | FILE *f = fopen(fname, "wb"); |
| 180 | if (!f) |
| 181 | return; |
| 182 | int bits = 16; |
| 183 | fprintf(f, "P5\n%d %d\n%d\n", width, height, (1 << bits) - 1); |
| 184 | unsigned char *data = (unsigned char *)bitmap; |
| 185 | unsigned data_size = width * height * 2; |
| 186 | #define SWAP(a, b) \ |
| 187 | { \ |
| 188 | a ^= b; \ |
| 189 | a ^= (b ^= a); \ |
| 190 | } |
| 191 | for (unsigned i = 0; i < data_size; i += 2) |
| 192 | SWAP(data[i], data[i + 1]); |
| 193 | #undef SWAP |
| 194 | fwrite(data, data_size, 1, f); |
| 195 | fclose(f); |
| 196 | } |
| 197 | |
| 198 | /* == gamma curve and tiff writer - simplified cut'n'paste from dcraw.c */ |
| 199 | |