From 00bade5c186bc0c1d703bb8d52afdabb1ff0ab92 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 27 Dec 2023 02:39:15 +0000 Subject: remove whitespace --- src/tiledio.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/tiledio.c (limited to 'src/tiledio.c') 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); +} + -- cgit v1.2.1