aboutsummaryrefslogtreecommitdiff
path: root/tools/Vulkan-Tools/cube/cube.c
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2026-03-31 01:51:18 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2026-03-31 01:51:42 +0200
commit7716eebaaeaccc4f145a0670280dd8fcdf096e6b (patch)
tree224e6ee2fe034f6415926e7652e545f15089ef73 /tools/Vulkan-Tools/cube/cube.c
parent2a39842cbf77b7d98f66d8ce50ea868d3d2417a6 (diff)
downloadusermoji-7716eebaaeaccc4f145a0670280dd8fcdf096e6b.tar.xz
vkcube: load image file at runtime
Diffstat (limited to 'tools/Vulkan-Tools/cube/cube.c')
-rw-r--r--tools/Vulkan-Tools/cube/cube.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/tools/Vulkan-Tools/cube/cube.c b/tools/Vulkan-Tools/cube/cube.c
index c08d41fd..29946c90 100644
--- a/tools/Vulkan-Tools/cube/cube.c
+++ b/tools/Vulkan-Tools/cube/cube.c
@@ -1698,13 +1698,27 @@ static void demo_prepare_depth(struct demo *demo) {
demo_name_object(demo, VK_OBJECT_TYPE_IMAGE_VIEW, (uint64_t)demo->depth.view, "DepthView");
}
-/* Convert ppm image data from header file into RGBA texture image */
-#include "lunarg.ppm.h"
+/* Convert ppm image data from file into RGBA texture image */
bool loadTexture(const char *filename, uint8_t *rgba_data, VkSubresourceLayout *layout, int32_t *width, int32_t *height) {
- (void)filename;
+ FILE *file = fopen(filename, "rb");
+ if (!file)
+ return false;
+ if (fseek(file, 0, SEEK_END) == -1)
+ return false;
+ long size = ftell(file);
+ if (size == -1)
+ return false;
+ if (fseek(file, 0, SEEK_SET) == -1)
+ return false;
+ char *buffer = malloc(size);
+ if (!buffer)
+ return false;
+ if (fread(buffer, 1, size, file) != (size_t) size)
+ return false;
+ fclose(file);
char *cPtr;
- cPtr = (char *)lunarg_ppm;
- if ((unsigned char *)cPtr >= (lunarg_ppm + lunarg_ppm_len) || strncmp(cPtr, "P6\n", 3)) {
+ cPtr = buffer;
+ if (cPtr >= (buffer + size) || strncmp(cPtr, "P6\n", 3)) {
return false;
}
while (strncmp(cPtr++, "\n", 1));
@@ -1713,7 +1727,7 @@ bool loadTexture(const char *filename, uint8_t *rgba_data, VkSubresourceLayout *
return true;
}
while (strncmp(cPtr++, "\n", 1));
- if ((unsigned char *)cPtr >= (lunarg_ppm + lunarg_ppm_len) || strncmp(cPtr, "255\n", 4)) {
+ if (cPtr >= (buffer + size) || strncmp(cPtr, "255\n", 4)) {
return false;
}
while (strncmp(cPtr++, "\n", 1));
@@ -1727,6 +1741,7 @@ bool loadTexture(const char *filename, uint8_t *rgba_data, VkSubresourceLayout *
}
rgba_data += layout->rowPitch;
}
+ free(buffer);
return true;
}