libnedit
Lightweight C++ library for Nintendo DS(i) formats
Loading...
Searching...
No Matches
gfx_BannerIcon.hpp
1
2#pragma once
3#include <ntr/gfx/gfx_Conversion.hpp>
4
5namespace ntr::gfx {
6
7 constexpr size_t IconWidth = 32;
8 constexpr size_t IconHeight = 32;
9
10 constexpr size_t IconCharSize = 0x200;
11 constexpr size_t IconPaletteSize = 0x20;
12 constexpr size_t IconPaletteColorCount = IconPaletteSize / sizeof(xbgr1555::Color);
13
14 constexpr PixelFormat IconPixelFormat = PixelFormat::Palette16;
15 constexpr CharacterFormat IconCharacterFormat = CharacterFormat::Char;
16
17 inline Result ConvertBannerIconToRgba(const u8 *icon_char, const u8 *icon_plt, abgr8888::Color *&out_rgba) {
18 GraphicsToRgbaContext ctx = {
19 .gfx_data = icon_char,
20 .gfx_data_size = IconCharSize,
21 .plt_data = icon_plt,
22 .plt_data_size = IconPaletteSize,
23 .plt_idx = 0,
24 .def_width = IconWidth,
25 .def_height = IconHeight,
26 .pix_fmt = IconPixelFormat,
27 .char_fmt = IconCharacterFormat,
28 .first_color_transparent = true
29 };
30 NTR_R_TRY(ConvertGraphicsToRgba(ctx));
31
32 if((ctx.out_width != IconWidth) || (ctx.out_height != IconHeight)) {
33 NTR_R_FAIL(ResultUnexpectedBannerIconDimensions);
34 }
35
36 out_rgba = ctx.out_rgba;
37 NTR_R_SUCCEED();
38 }
39
40 inline Result ConvertBannerIconFromRgba(const abgr8888::Color *icon, u8 *&out_icon_char, u8 *&out_icon_plt) {
41 RgbaToGraphicsContext ctx = {
42 .rgba_data = icon,
43 .width = IconWidth,
44 .height = IconHeight,
45 .pix_fmt = IconPixelFormat,
46 .char_fmt = IconCharacterFormat,
47 .gen_scr_data = false
48 };
49 NTR_R_TRY(ConvertRgbaToGraphics(ctx));
50
51 if((ctx.out_gfx_data_size != IconCharSize) || (ctx.out_plt_data_size != IconPaletteSize)) {
52 NTR_R_FAIL(ResultUnexpectedBannerIconDimensions);
53 }
54
55 out_icon_char = ctx.out_gfx_data;
56 out_icon_plt = ctx.out_plt_data;
57 NTR_R_SUCCEED();
58 }
59
60}