MCPcopy Create free account
hub / github.com/VirtualGL/virtualgl / ppm_save

Function ppm_save

util/bmp.c:271–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269
270
271static 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
298int bmp_save(char *filename, unsigned char *buf, int width, int pitch,

Callers 1

bmp_saveFunction · 0.85

Calls 2

pixelConvertFunction · 0.85
pf_getFunction · 0.85

Tested by

no test coverage detected