aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generate_splash.py35
-rw-r--r--src/image.c74
-rw-r--r--src/image.h5
3 files changed, 103 insertions, 11 deletions
diff --git a/generate_splash.py b/generate_splash.py
new file mode 100644
index 0000000..12e89ab
--- /dev/null
+++ b/generate_splash.py
@@ -0,0 +1,35 @@
+"""
+generate a splash.bin to test again
+"""
+import sys
+
+COLORS = [
+ [b"\x00", b"\x00", b"\x00"],
+ [b"\xFF", b"\x00", b"\x00"],
+ [b"\xFF", b"\xFF", b"\x00"],
+ [b"\x00", b"\xFF", b"\x00"],
+ [b"\x00", b"\xFF", b"\xFF"],
+ [b"\x00", b"\x00", b"\xFF"],
+ [b"\xFF", b"\x00", b"\xFF"],
+]
+
+def main():
+ if len(sys.argv) < 2:
+ print("{} [output]".format(sys.argv[0]))
+ return
+
+ output = sys.argv[1]
+
+ height = 400
+ width = 240
+ with open(output, "wb") as fd:
+ for h in range(height):
+ for w in range(width):
+ i = w % len(COLORS)
+
+ for x in COLORS[i]:
+ fd.write(x)
+
+
+if __name__ == "__main__":
+ main() \ No newline at end of file
diff --git a/src/image.c b/src/image.c
index 618a854..71fb52b 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1,8 +1,61 @@
#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
#include <png.h>
#include "image.h"
+void rotate_rgba_counterclockwise(uint8_t** bufp, size_t size, size_t width)
+{
+ uint32_t* buf = (uint32_t*)*bufp;
+ uint32_t* out = malloc(size);
+
+ size_t pixel_count = (size/4);
+ size_t height = pixel_count/width;
+
+ for (uint32_t h = 0; h < height; ++h)
+ {
+ for (uint32_t w = 0; w < width; ++w)
+ {
+ size_t buf_index = (w + (h * width));
+ size_t out_index = (height * (width-1)) - (height * w) + h;
+
+ assert(pixel_count > buf_index && pixel_count > out_index);
+
+ out[out_index] = buf[buf_index];
+ }
+ }
+
+ free(*bufp);
+ *bufp = (uint8_t*)out;
+}
+
+
+void rotate_rgba_clockwise(uint8_t** bufp, size_t size, size_t width)
+{
+ uint32_t* buf = (uint32_t*)*bufp;
+ uint32_t* out = malloc(size);
+
+ size_t pixel_count = (size/4);
+ size_t height = pixel_count/width;
+
+ for (uint32_t h = 0; h < height; ++h)
+ {
+ for (uint32_t w = 0; w < width; ++w)
+ {
+ size_t buf_index = (w + (h * width));
+ size_t out_index = ((height * (w + 1)) - 1) - h;
+
+ assert(pixel_count > buf_index && pixel_count > out_index);
+
+ out[out_index] = buf[buf_index];
+ }
+ }
+
+ free(*bufp);
+ *bufp = (uint8_t*)out;
+}
+
size_t bin_to_rgba(uint8_t** bufp, size_t size)
{
size_t out_size = (size / 3) * 4;
@@ -17,6 +70,9 @@ size_t bin_to_rgba(uint8_t** bufp, size_t size)
}
free(*bufp);
*bufp = buf;
+
+ rotate_rgba_counterclockwise(bufp, out_size, BIN_DEFAULT_WIDTH);
+
return out_size;
}
@@ -26,6 +82,9 @@ size_t rgba_to_bin(uint8_t** bufp, size_t size)
size_t out_size = (size / 4) * 3;
uint8_t* buf = malloc(out_size);
+ size_t height = (out_size/3)/BIN_DEFAULT_WIDTH;
+ rotate_rgba_clockwise(bufp, size, height);
+
for (size_t i = 0, j = 0; i < size; i+=4, j+=3)
{
(buf+j)[0] = (*bufp+i)[2];
@@ -34,6 +93,7 @@ size_t rgba_to_bin(uint8_t** bufp, size_t size)
}
free(*bufp);
*bufp = buf;
+
return out_size;
}
@@ -56,8 +116,6 @@ size_t png_to_rgba(uint8_t** bufp, size_t size)
uint32_t w = png_get_image_width(png, info);
uint32_t h = png_get_image_height(png, info);
- printf("%i, %i\n", w, h);
-
png_byte color_type = png_get_color_type(png, info);
if(color_type == PNG_COLOR_TYPE_PALETTE)
@@ -87,8 +145,6 @@ size_t png_to_rgba(uint8_t** bufp, size_t size)
return out_size;
}
-#define DEFAULT_WIDTH 240
-
size_t rgba_to_png(uint8_t** bufp, size_t size)
{
uint32_t* buf = (uint32_t*)*bufp;
@@ -100,12 +156,8 @@ size_t rgba_to_png(uint8_t** bufp, size_t size)
FILE* fp = fmemopen(out, size, "wb");
png_bytep* row_pointers = NULL;
- uint32_t w = 240;
- uint32_t h = (uint32_t)((size/4)/w);
-
- printf("%i, %i\n", w, h);
-
- printf("%li\n", size);
+ uint32_t h = BIN_DEFAULT_WIDTH;
+ uint32_t w = (uint32_t)((size/4)/h);
/* initialize stuff */
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
@@ -135,7 +187,7 @@ size_t rgba_to_png(uint8_t** bufp, size_t size)
while (!out[out_size/4]) --out_size;
free(buf);
- *bufp = out;
+ *bufp = (uint8_t*)out;
return out_size;
} \ No newline at end of file
diff --git a/src/image.h b/src/image.h
index 5c14fdf..3c5397d 100644
--- a/src/image.h
+++ b/src/image.h
@@ -4,6 +4,11 @@
#include <stddef.h>
#include <stdint.h>
+#define BIN_DEFAULT_WIDTH 240
+
+void rotate_rgba_clockwise(uint8_t**, size_t, size_t);
+void rotate_rgba_counterclockwise(uint8_t**, size_t, size_t);
+
size_t bin_to_rgba(uint8_t**, size_t);
size_t rgba_to_bin(uint8_t**, size_t);