image.cpp: remove unused macros, in-place conversion from rgba to argb.

main.cpp: change move assignment in generic raii wrapper, change the Interpreter from struct to class to better reflect what it actually is.
window.cpp: implement a workaround for the window to not freeze during dragging. fuck you ms.
This commit is contained in:
maksw committed 2026-04-15 18:23:28 +02:00
1 parent 469f0db39c
commit a2671bed5d
4 files changed
+164 -93

No files matched your search

+14 -18
View File
@@ -9,9 +9,6 @@
#include <cstdint>
#include <image.h>
#define STR2(x) #x
#define STR(x) STR2(x)
extern "C" {
uint32_t* image_load(const char* filename, int* width, int* height) {
int n;
@@ -41,7 +38,7 @@ uint32_t* image_load_resized(const char* filename, int desired_width, int desire
if (!data) return nullptr;
// Allocate buffer for resized image
unsigned char* resized = (unsigned char*)malloc(desired_width * desired_height * 4);
uint32_t* resized = (uint32_t*)malloc(desired_width * desired_height * 4);
if (!resized) {
stbi_image_free(data);
return nullptr;
@@ -49,26 +46,25 @@ uint32_t* image_load_resized(const char* filename, int desired_width, int desire
// Resize the image
stbir_resize_uint8_linear(data, original_width, original_height, 0,
resized, desired_width, desired_height, 0,
(unsigned char* )resized, desired_width, desired_height, 0,
STBIR_RGBA);
stbi_image_free(data);
// Convert RGBA to ARGB
uint32_t* out = (uint32_t*)malloc(desired_width * desired_height * sizeof(uint32_t));
if (!out) {
free(resized);
return nullptr;
}
// In-place conversion from RGBA to ARGB
// We iterate backwards to ensure we don't overwrite bytes before reading them,
// though since we are working within the same 4-byte boundaries, forward works too!
for (int i = 0; i < desired_width * desired_height; ++i) {
uint8_t r = resized[4*i + 0];
uint8_t g = resized[4*i + 1];
uint8_t b = resized[4*i + 2];
uint8_t a = resized[4*i + 3];
out[i] = (a << 24) | (r << 16) | (g << 8) | b;
uint8_t* pixel = (uint8_t*)&resized[i];
uint8_t r = pixel[0];
uint8_t g = pixel[1];
uint8_t b = pixel[2];
uint8_t a = pixel[3];
resized[i] = ((uint32_t)a << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
}
free(resized);
return out;
return resized;
}
void image_free(uint32_t* data) {