add tomato image generator helper functions (untested)
Some checks are pending
ContinuousDelivery / linux-ubuntu (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / linux (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run

This commit is contained in:
Green Sky
2025-01-08 01:39:39 +01:00
parent 3647ff3d54
commit d9a6eed921
5 changed files with 923 additions and 0 deletions

View File

@ -13,6 +13,9 @@ target_sources(tomato PUBLIC
./main.cpp
./icon.rc
./icon_generator.hpp
./icon_generator.cpp
./sys_check.hpp
./sys_check.cpp

62
src/icon_generator.cpp Normal file
View File

@ -0,0 +1,62 @@
#include "./icon_generator.hpp"
#include <qoi/qoi.h>
#include <cstdlib>
namespace {
#include "../res/icon/tomato_v1_256.qoi.h"
}
namespace IconGenerator {
SDL_Surface* base(void) {
//ImageLoaderQOI{}.loadFromMemoryRGBA(tomato_v1_256_qoi, tomato_v1_256_qoi_len);
qoi_desc desc;
uint8_t* img_data = static_cast<uint8_t*>(
qoi_decode(tomato_v1_256_qoi, tomato_v1_256_qoi_len, &desc, 4)
);
if (img_data == nullptr) {
// not readable
return {};
}
auto* surf = SDL_CreateSurfaceFrom(desc.width, desc.height, SDL_PIXELFORMAT_RGBA32, img_data, 0);
if (surf == nullptr) {
return {}; // ??
}
auto* surf_dup = SDL_DuplicateSurface(surf);
SDL_DestroySurface(surf);
free(img_data);
return surf_dup;
}
SDL_Surface* colorIndicator(float r, float g, float b, float a) {
auto* surf = base();
if (surf == nullptr) {
return nullptr;
}
const SDL_Rect rect {
// TODO: gaps and smaller
// lower right quarter
surf->w/2,
surf->h/2,
surf->w/2,
surf->h/2,
};
const auto color = SDL_MapSurfaceRGBA(surf, r*255, g*255, b*255, a*255);
SDL_FillSurfaceRect(surf, &rect, color);
return surf;
}
} // IconGenerator

18
src/icon_generator.hpp Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <SDL3/SDL.h>
#include <memory>
namespace IconGenerator {
// remember to SDL_DestroySurface()
// tomato icon
SDL_Surface* base(void);
// tomato icon with colored indicator
SDL_Surface* colorIndicator(float r, float g, float b, float a);
} // IconGenerator