first commit

This commit is contained in:
sillysagiri 2024-09-18 17:01:45 +07:00
commit aae0e4c97d
4 changed files with 136 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.cache
build

33
CMakeLists.txt Normal file
View File

@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.27)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(PROJECT_NAME sillyimage CACHE BOOL "")
set(PROJECT_VERSION 1.0)
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION})
message(STATUS "find Magick++ library")
add_definitions(-DMAGICKCORE_QUANTUM_DEPTH=8)
add_definitions(-DMAGICKCORE_HDRI_ENABLE=0)
find_package(ImageMagick COMPONENTS Magick++)
# yes... im using glob... dont judge me....
file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS
"src/*.cpp" "src/*.c")
set(PROJECT_INCLUDE
"src"
${ImageMagick_INCLUDE_DIRS})
set(PROJECT_LIBRARY
${ImageMagick_LIBRARIES})
set(PROJECT_DEFINITION
VERSION="${PROJECT_VERSION}")
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE})
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_LIBRARY})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PROJECT_DEFINITION})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist")

10
readme.txt Normal file
View File

@ -0,0 +1,10 @@
i make this tool for my ds framebuffer rendering...
since ptexconv (https://github.com/Garhoogin/ptexconv) automatically convert the image dimension into power of two...
i decided to make my own...
not sure if grit did the same, i hate grit lol...
Usage: sillyimage <input image> <output image>
first and second 4 byte is image width and height.
the rest is raw argb15, no fancy compression or anything, just a simple raw data...

91
src/main.cpp Normal file
View File

@ -0,0 +1,91 @@
#include <Magick++/Image.h>
#include <filesystem>
#include <fstream>
// Macro to convert 8-bit RGB components into a single 15 bit RGB triplet.
#define RGBtoRGB15(r,g,b,a) (((a) ? 0x8000 : 0) | ((r >> 3) & 0x1F) | (((g >> 3) & 0x1F) << 5) | (((b >> 3) & 0x1F) << 10))
namespace fs = std::filesystem;
void Print_Help();
int main(int argc, char* argv[])
{
if (argc <= 1 || argc > 3) {
Print_Help();
return 1;
}
fs::path str_input = argv[1];
fs::path str_output = "";
std::ifstream file_in;
std::ofstream file_out;
Magick::Image magick_img;
uint32_t size_width;
uint32_t size_height;
uint32_t *buffer_rgba;
uint16_t *buffer_argb15;
if (argc == 3) str_output = argv[2];
else
{
printf("\nNo explicit output path. Borrowing from input path\n");
str_output = str_input.parent_path() / str_input.stem();
str_output += ".bin";
}
file_in.open(str_input, std::ios::binary);
if (!file_in.good())
{
printf("\nInput file doesnt exists!\n");
return 1;
}
file_in.close();
magick_img.read(str_input);
size_width = magick_img.columns();
size_height = magick_img.rows();
buffer_rgba = new uint32_t[size_width * size_height];
buffer_argb15 = new uint16_t[size_width * size_height];
printf("\n");
printf("input: %s\n", str_input.c_str());
printf("output: %s\n", str_output.c_str());
printf("dimension: %ux%u\n", size_width, size_height);
printf("\n");
magick_img.write(0, 0, size_width, size_height, "RGBA", Magick::CharPixel, buffer_rgba);
for (int i=0, n=size_width*size_height; i<n; i++)
{
uint32_t rgba = buffer_rgba[i];
uint8_t a = (rgba >> 24) & 0xFF;
uint8_t b = (rgba >> 16) & 0xFF;
uint8_t g = (rgba >> 8) & 0xFF;
uint8_t r = rgba & 0xFF;
buffer_argb15[i] = RGBtoRGB15(r, g, b, a);
}
file_out.open(str_output, std::ios::binary);
file_out.write(reinterpret_cast<char*>(&size_width), sizeof(uint32_t));
file_out.write(reinterpret_cast<char*>(&size_height), sizeof(uint32_t));
file_out.write(reinterpret_cast<char*>(buffer_argb15), size_width*size_height*sizeof(uint16_t));
file_out.close();
printf("\ndone...\n");
// clean up
delete[] buffer_rgba;
delete[] buffer_argb15;
return 0;
}
void Print_Help()
{
printf("\n");
printf("Simple image converter into raw argb15 color for DS %s\n\n", VERSION);
printf("Usage: sillyimage <input image> <output image>\n");
printf("\n");
}