diff options
| author | Ray <raysan5@gmail.com> | 2014-12-31 19:28:38 +0100 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2014-12-31 19:28:38 +0100 |
| commit | 3c4a91658e8586ecb5504d3167796d043e79d065 (patch) | |
| tree | 89aeddb683c133c6d94f1a03f9d1a1399d2a6bf4 /src/utils.c | |
| parent | 0c606092689d7a1823f7acd5e8b849052e297b7a (diff) | |
| parent | fad81f36e4cfd37901caad8555c49c41ac65aaee (diff) | |
| download | raylib-3c4a91658e8586ecb5504d3167796d043e79d065.tar.gz raylib-3c4a91658e8586ecb5504d3167796d043e79d065.zip | |
Merge pull request #12 from raysan5/develop
Integration from develop branch
Diffstat (limited to 'src/utils.c')
| -rw-r--r-- | src/utils.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/utils.c b/src/utils.c index b5112111..c3c20b47 100644 --- a/src/utils.c +++ b/src/utils.c @@ -133,18 +133,25 @@ void WriteBitmap(const char *fileName, unsigned char *imgData, int width, int he FILE *bmpFile = fopen(fileName, "wb"); // Define a pointer to bitmap file and open it in write-binary mode - // NOTE: fwrite parameters are: data pointer, size in bytes of each element to be written, number of elements, file-to-write pointer - fwrite(bmpFileHeader, sizeof(unsigned char), 14, bmpFile); // Write BMP file header data - fwrite(bmpInfoHeader, sizeof(unsigned char), 40, bmpFile); // Write BMP info header data - - // Write pixel data to file - for (int y = 0; y < height ; y++) + if (bmpFile == NULL) + { + TraceLog(WARNING, "[%s] BMP file could not be created", fileName); + } + else { - for (int x = 0; x < width; x++) + // NOTE: fwrite parameters are: data pointer, size in bytes of each element to be written, number of elements, file-to-write pointer + fwrite(bmpFileHeader, sizeof(unsigned char), 14, bmpFile); // Write BMP file header data + fwrite(bmpInfoHeader, sizeof(unsigned char), 40, bmpFile); // Write BMP info header data + + // Write pixel data to file + for (int y = 0; y < height ; y++) { - fputc(imgData[(x*4)+2 + (y*width*4)], bmpFile); - fputc(imgData[(x*4)+1 + (y*width*4)], bmpFile); - fputc(imgData[(x*4) + (y*width*4)], bmpFile); + for (int x = 0; x < width; x++) + { + fputc(imgData[(x*4)+2 + (y*width*4)], bmpFile); + fputc(imgData[(x*4)+1 + (y*width*4)], bmpFile); + fputc(imgData[(x*4) + (y*width*4)], bmpFile); + } } } @@ -157,7 +164,9 @@ void WritePNG(const char *fileName, unsigned char *imgData, int width, int heigh { stbi_write_png(fileName, width, height, 4, imgData, width*4); // It WORKS!!! } +#endif +#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) // Outputs a trace log message (INFO, ERROR, WARNING) // NOTE: If a file has been init, output log is written there void TraceLog(int msgType, const char *text, ...) @@ -262,6 +271,23 @@ const char *GetExtension(const char *fileName) return (dot + 1); } +// Calculate next power-of-two value for a given num +int GetNextPOT(int num) +{ + if (num != 0) + { + num--; + num |= (num >> 1); // Or first 2 bits + num |= (num >> 2); // Or next 2 bits + num |= (num >> 4); // Or next 4 bits + num |= (num >> 8); // Or next 8 bits + num |= (num >> 16); // Or next 16 bits + num++; + } + + return num; +} + //---------------------------------------------------------------------------------- // Module specific Functions Definition //---------------------------------------------------------------------------------- |
