vs solution, animations, some warnings fixed

This commit is contained in:
maksw committed 2025-11-12 08:56:21 +01:00
commit 1b31faa7ee
115 files changed
+81650

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
#pragma warning(push, 0)
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include <stb_image_resize2.h>
#pragma warning(pop)
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <image.h>
extern "C" {
uint32_t* image_load(const char* filename, int* width, int* height) {
int n;
unsigned char* data = stbi_load(filename, width, height, &n, 4); // force 4 channels (RGBA)
if (!data) return nullptr;
// Convert RGBA to ARGB
uint32_t* out = (uint32_t*)malloc(*width * *height * sizeof(uint32_t));
if (!out) {
fprintf(stderr, "image.cpp 19: malloc failed!");
return nullptr;
}
for (int i = 0; i < *width * *height; ++i) {
uint8_t r = data[4*i + 0];
uint8_t g = data[4*i + 1];
uint8_t b = data[4*i + 2];
uint8_t a = data[4*i + 3];
out[i] = (a << 24) | (r << 16) | (g << 8) | b;
}
stbi_image_free(data);
return out;
}
uint32_t* image_load_resized(const char* filename, int desired_width, int desired_height) {
int original_width, original_height, n;
unsigned char* data = stbi_load(filename, &original_width, &original_height, &n, 4);
if (!data) return nullptr;
// Allocate buffer for resized image
unsigned char* resized = (unsigned char*)malloc(desired_width * desired_height * 4);
if (!resized) {
fprintf(stderr, "image.cpp 41: malloc failed!");
return nullptr;
}
// Resize the image
stbir_resize_uint8_linear(data, original_width, original_height, 0,
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) {
fprintf(stderr, "image.cpp 55: malloc failed!");
free(resized);
return nullptr;
}
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;
}
free(resized);
return out;
}
void image_free(uint32_t* data) {
free(data);
}
}