aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c46
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
//----------------------------------------------------------------------------------