| 269 | |
| 270 | |
| 271 | static int ppm_save(char *filename, unsigned char *buf, int width, int pitch, |
| 272 | int height, PF *pf, enum BMPORN orientation) |
| 273 | { |
| 274 | FILE *file = NULL; int ret = 0; |
| 275 | unsigned char *tempbuf = NULL; |
| 276 | |
| 277 | if((file = fopen(filename, "wb")) == NULL) THROW(strerror(errno)); |
| 278 | if(fprintf(file, "P6\n") < 1) THROW("Write error"); |
| 279 | if(fprintf(file, "%d %d\n", width, height) < 1) THROW("Write error"); |
| 280 | if(fprintf(file, "255\n") < 1) THROW("Write error"); |
| 281 | |
| 282 | if((tempbuf = (unsigned char *)malloc(width * height * 3)) == NULL) |
| 283 | THROW("Memory allocation error"); |
| 284 | |
| 285 | pixelConvert(buf, width, pitch, height, pf, tempbuf, width * 3, |
| 286 | pf_get(PF_RGB), orientation == BMPORN_BOTTOMUP); |
| 287 | |
| 288 | if((fwrite(tempbuf, width * height * 3, 1, file)) != 1) |
| 289 | THROW("Write error"); |
| 290 | |
| 291 | finally: |
| 292 | free(tempbuf); |
| 293 | if(file) fclose(file); |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | int bmp_save(char *filename, unsigned char *buf, int width, int pitch, |
no test coverage detected