summaryrefslogtreecommitdiff
path: root/src/tiledio.c
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2023-12-27 02:39:15 +0000
committerdavidovski <david@davidovski.xyz>2023-12-27 02:39:15 +0000
commit00bade5c186bc0c1d703bb8d52afdabb1ff0ab92 (patch)
tree22fd992cf5f61d97af0677e97d10c164a59e0437 /src/tiledio.c
parent5651b14b3084d18061516c65fa58b47134b926fe (diff)
remove whitespace
Diffstat (limited to 'src/tiledio.c')
-rw-r--r--src/tiledio.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/tiledio.c b/src/tiledio.c
new file mode 100644
index 0000000..2d06ba7
--- /dev/null
+++ b/src/tiledio.c
@@ -0,0 +1,51 @@
+#include "tiledio.h"
+
+const int endian = 1;
+#define is_bigendian() ( (*(char*)&endian) == 0 )
+
+
+void textureFromPixels(Texture2D *texOut, Color *pixels, int width, int height) {
+ Image checkedIm = {
+ .data = pixels,
+ .width = width,
+ .height = height,
+ .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
+ .mipmaps = 1
+ };
+
+ *texOut = LoadTextureFromImage(checkedIm);
+}
+
+
+int readb(char * out, size_t noBytes, FILE * file) {
+ if (!fread(out, (size_t)1, (size_t) noBytes, file))
+ return 1;
+
+ if (is_bigendian())
+ return 0;
+
+ int tmp;
+ // reverse byte order
+ for(int i = 0; i < noBytes/2; i++) {
+ tmp = out[i];
+ out[i] = out[noBytes-i-1];
+ out[noBytes-i-1] = tmp;
+ }
+
+ return 0;
+}
+
+int writeb(char * in, size_t noBytes, FILE * file) {
+ if (!is_bigendian()) {
+ int tmp;
+ // reverse byte order
+ for(int i = 0; i < noBytes/2; i++) {
+ tmp = in[i];
+ in[i] = in[noBytes-i-1];
+ in[noBytes-i-1] = tmp;
+ }
+ }
+
+ return fwrite(in, (size_t)1, (size_t) noBytes, file);
+}
+