From 65d12313e6cba59fcab2dcac09bab11ff11f50af Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sun, 25 Jan 2015 10:32:01 -0800 Subject: [PATCH] Banners should use RGBA4444 color. --- source/3ds/cbmd.cpp | 2 +- source/3ds/cwav.cpp | 10 +++++----- source/3ds/util.cpp | 27 +++++++++++++++++---------- source/3ds/util.h | 9 +++++++-- source/main.cpp | 4 ++-- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/source/3ds/cbmd.cpp b/source/3ds/cbmd.cpp index 81a6cd1..778da86 100644 --- a/source/3ds/cbmd.cpp +++ b/source/3ds/cbmd.cpp @@ -31,7 +31,7 @@ u8* build_cbmd_data(CBMD cbmd, u32* size, bool bnr) { u32 pad = 0; if(bnr) { - pad = 16 - (offset % 16); + pad = 0x10 - (offset % 0x10); offset += pad; } diff --git a/source/3ds/cwav.cpp b/source/3ds/cwav.cpp index 3659a4f..e7288b2 100644 --- a/source/3ds/cwav.cpp +++ b/source/3ds/cwav.cpp @@ -30,11 +30,6 @@ typedef struct { u32 totalChannels; } InfoHeader; -typedef struct { - char magic[4] = {'D', 'A', 'T', 'A'}; - u32 length; -} DataHeader; - typedef struct { u32 flags = 0x7100; u32 offset; @@ -48,6 +43,11 @@ typedef struct { u32 padding = 0; } ChannelData; +typedef struct { + char magic[4] = {'D', 'A', 'T', 'A'}; + u32 length; +} DataHeader; + u8* build_cwav(WAV wav, u32* size) { Header header; u32 offset = sizeof(Header); diff --git a/source/3ds/util.cpp b/source/3ds/util.cpp index ebe4b53..cebd666 100644 --- a/source/3ds/util.cpp +++ b/source/3ds/util.cpp @@ -7,14 +7,23 @@ u8 TILE_ORDER[64] = { 0, 1, 8, 9, 2, 3, 10, 11, 16, 17, 24, 25, 18, 19, 26 32, 33, 40, 41, 34, 35, 42, 43, 48, 49, 56, 57, 50, 51, 58, 59, 36, 37, 44, 45, 38, 39, 46, 47, 52, 53, 60, 61, 54, 55, 62, 63 }; -u16 rgba_to_rgb565(u8 r, u8 g, u8 b, u8 a) { - r = (u8) (1.0f * r * a / 255.0f) >> 3; - g = (u8) (1.0f * g * a / 255.0f) >> 2; - b = (u8) (1.0f * b * a / 255.0f) >> 3; - return (r << 11) | (g << 5) | b; +u16 pack_color(u8 r, u8 g, u8 b, u8 a, PixelFormat format) { + if(format == RGB565) { + float alpha = a / 255.0f; + r = (u8) (r * alpha) >> 3; + g = (u8) (g * alpha) >> 2; + b = (u8) (b * alpha) >> 3; + return (r << 11) | (g << 5) | b; + } else if(format == RGBA4444) { + r >>= 4; + g >>= 4; + b >>= 4; + a >>= 4; + return r << 12 | g << 8 | b << 4 | a; + } } -u16* image_to_tiles(const char* image, u32 width, u32 height, u32* size) { +u16* image_to_tiles(const char* image, u32 width, u32 height, PixelFormat format, u32* size) { unsigned char* img; unsigned int imgWidth, imgHeight; if(lodepng_decode32_file(&img, &imgWidth, &imgHeight, image)) { @@ -44,7 +53,7 @@ u16* image_to_tiles(const char* image, u32 width, u32 height, u32* size) { u32 yy = (u32) (TILE_ORDER[k] >> 3); u8* pixel = img + (((y + yy) * width + (x + xx)) * 4); - converted[n++] = rgba_to_rgb565(pixel[0], pixel[1], pixel[2], pixel[3]); + converted[n++] = pack_color(pixel[0], pixel[1], pixel[2], pixel[3], format); } } } @@ -57,11 +66,9 @@ u16* image_to_tiles(const char* image, u32 width, u32 height, u32* size) { } void utf8_to_utf16(u16* dst, const char* src, size_t max_len) { - u8* u8dst = (u8*) dst; size_t n = 0; while(src[n]) { - u8dst[n * 2] = (u8) src[n]; - u8dst[n * 2 + 1] = 0; + dst[n] = (u16) src[n] << 8; if(n++ >= max_len) { return; } diff --git a/source/3ds/util.h b/source/3ds/util.h index 5bb5937..63b0556 100644 --- a/source/3ds/util.h +++ b/source/3ds/util.h @@ -3,8 +3,13 @@ #include "../types.h" -u16 rgba_to_rgb565(u8 r, u8 g, u8 b, u8 a); -u16* image_to_tiles(const char* image, u32 width, u32 height, u32* size); +typedef enum { + RGB565, + RGBA4444 +} PixelFormat; + +u16 pack_color(u8 r, u8 g, u8 b, u8 a, PixelFormat format); +u16* image_to_tiles(const char* image, u32 width, u32 height, PixelFormat format, u32* size); void utf8_to_utf16(u16* dst, const char* src, size_t max_len); #endif \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index c7948b0..da25379 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -11,7 +11,7 @@ u8* convert_to_cgfx(const char* image, u32 width, u32 height, u32* size) { u32 convertedSize = 0; - u16* converted = image_to_tiles(image, width, height, &convertedSize); + u16* converted = image_to_tiles(image, width, height, RGBA4444, &convertedSize); if(converted == NULL) { return NULL; } @@ -110,7 +110,7 @@ int make_banner(const char* image, const char* audio, char* cgfxFile, char* cwav } int make_smdh(char* shortDescription, char* longDescription, char* publisher, char* icon, char* output) { - u16* icon48 = image_to_tiles(icon, 48, 48, NULL); + u16* icon48 = image_to_tiles(icon, 48, 48, RGB565, NULL); if(icon48 == NULL) { return 1; }