mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-09-22 11:04:57 -04:00
Merge pull request #69 from alex-chew/patch-1
fix: correct write count in savePPM
This commit is contained in:
commit
0477b60c10
5
util.c
5
util.c
@ -470,9 +470,10 @@ int savePPM(const char *path, const unsigned char *pixels, const unsigned int sx
|
||||
if (!fp)
|
||||
return -1;
|
||||
fprintf(fp, "P6\n%d %d\n255\n", sx, sy);
|
||||
int written = fwrite(pixels, sx*sy, 3, fp);
|
||||
size_t pixelsLen = 3 * sx * sy;
|
||||
size_t written = fwrite(pixels, sizeof pixels[0], pixelsLen, fp);
|
||||
fclose(fp);
|
||||
return (unsigned int)written != 3*sx*sy;
|
||||
return written != pixelsLen;
|
||||
}
|
||||
|
||||
|
||||
|
3
util.h
3
util.h
@ -29,6 +29,9 @@ int biomesToImage(unsigned char *pixels,
|
||||
const unsigned int sx, const unsigned int sy,
|
||||
const unsigned int pixscale, const int flip);
|
||||
|
||||
/// Save the pixel buffer (e.g. from biomesToImage) to the given path in PPM format.
|
||||
/// Returns 0 if successful, or -1 if the file could not be opened,
|
||||
/// or 1 if not all the pixel data could be written to the file.
|
||||
int savePPM(const char* path, const unsigned char *pixels,
|
||||
const unsigned int sx, const unsigned int sy);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user