shithub: qk1

Download patch

ref: 6847239cc62b476b397eae0bcc672def968b0fa4
parent: 85eb6d45853f5eee23c79717a6a878469a08de92
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Dec 18 01:27:36 EST 2023

separate image resize into its own file

--- a/Makefile
+++ b/Makefile
@@ -39,6 +39,7 @@
 	host.o\
 	host_cmd.o\
 	i_external.o\
+	i_resize.o\
 	i_tga.o\
 	i_wad.o\
 	keys.o\
@@ -158,7 +159,7 @@
 
 ${OBJS}: ${HDRS}
 
-i_external.o: stb_image_resize2.h
+i_resize.o: stb_image_resize2.h
 
 clean:
 	rm -f ${TARG} ${OBJS}
--- a/i_external.c
+++ b/i_external.c
@@ -1,11 +1,4 @@
 #include "quakedef.h"
-#define STB_IMAGE_RESIZE_IMPLEMENTATION
-#define STBIR_ASSERT(x) assert(x)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-function"
-#pragma GCC diagnostic ignored "-Warray-bounds"
-#include "stb_image_resize2.h"
-#pragma GCC diagnostic pop
 
 texture_t *
 Load_ExternalTexture(char *map, char *name)
@@ -53,10 +46,12 @@
 		w /= 2;
 		h /= 2;
 		n = w*h;
-		stbir_resize_uint8_srgb(
-			(byte*)(tx->pixels+tx->offsets[0]), tx->width, tx->height, tx->width*sizeof(pixel_t),
-			(byte*)(tx->pixels+tx->offsets[i]), w, h, w*sizeof(pixel_t),
-			premult ? STBIR_RGBA_PM : STBIR_RGBA
+		pixels_resize(
+			tx->pixels+tx->offsets[0],
+			tx->pixels+tx->offsets[i],
+			tx->width, tx->height,
+			w, h,
+			premult
 		);
 	}
 
--- /dev/null
+++ b/i_resize.c
@@ -1,0 +1,18 @@
+#include "quakedef.h"
+#define STB_IMAGE_RESIZE_IMPLEMENTATION
+#define STBIR_ASSERT(x) assert(x)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+#pragma GCC diagnostic ignored "-Warray-bounds"
+#include "stb_image_resize2.h"
+#pragma GCC diagnostic pop
+
+void
+pixels_resize(pixel_t *in, pixel_t *out, int iw, int ih, int ow, int oh, bool premulalpha)
+{
+	stbir_resize_uint8_srgb(
+		(byte*)in, iw, ih, iw*sizeof(pixel_t),
+		(byte*)out, ow, oh, ow*sizeof(pixel_t),
+		premulalpha ? STBIR_RGBA_PM : STBIR_RGBA
+	);
+}
--- a/mkfile
+++ b/mkfile
@@ -34,6 +34,7 @@
 	host.$O\
 	host_cmd.$O\
 	i_external.$O\
+	i_resize.$O\
 	i_tga.$O\
 	i_wad.$O\
 	in.$O\
@@ -131,7 +132,7 @@
 
 </sys/src/cmd/mkone
 
-i_external.$O: stb_image_resize2.h
+i_resize.$O: stb_image_resize2.h
 
-i_external.$O: i_external.c
-	$CC $CFLAGS -p i_external.c
+i_resize.$O: i_resize.c
+	$CC $CFLAGS -p i_resize.c
--- a/quakedef.h
+++ b/quakedef.h
@@ -136,6 +136,8 @@
 	pixel_t pixels[];
 }qpic_t;
 
+void pixels_resize(pixel_t *in, pixel_t *out, int iw, int ih, int ow, int oh, bool premulalpha);
+
 #include "i_tga.h"
 #include "i_wad.h"
 #include "draw.h"