libnedit
Lightweight C++ library for Nintendo DS(i) formats
Loading...
Searching...
No Matches
fmt_NCGR.hpp
1
2#pragma once
3#include <ntr/fmt/fmt_Common.hpp>
4#include <ntr/gfx/gfx_Base.hpp>
5
6namespace ntr::fmt {
7
8 struct NCGR : public fs::FileFormat {
9
10 struct Header : CommonHeader<0x4E434752 /* "RGCN" */ > {
11 };
12
13 struct CharacterDataBlock : CommonBlock<0x43484152 /* "RAHC" */ > {
14 u16 tile_height;
15 u16 tile_width;
16 gfx::PixelFormat pix_fmt;
17 gfx::MappingType map_type;
18 gfx::CharacterFormat char_fmt;
19 u32 data_size;
20 u32 unk;
21 };
22
23 struct CharacterPositionBlock : CommonBlock<0x43504F53 /* "SOPC" */ > {
24 u16 src_pos_x;
25 u16 src_pos_y;
26 u16 src_width;
27 u16 src_height;
28 };
29
30 Header header;
31 CharacterDataBlock char_data;
33 u8 *data;
34
35 NCGR() : data(nullptr) {}
36 NCGR(const NCGR&) = delete;
37
38 ~NCGR() {
39 if(this->data != nullptr) {
40 delete[] this->data;
41 this->data = nullptr;
42 }
43 }
44
45 inline constexpr void ComputeDimensions(u32 &out_width, u32 &out_height) {
46 switch(this->char_data.map_type) {
47 case gfx::MappingType::Mode1D32K: {
48 out_width = 32;
49 out_height = this->char_data.data_size * ((this->char_data.pix_fmt == gfx::PixelFormat::Palette16) ? 2 : 1) / 32;
50 break;
51 }
52 case gfx::MappingType::Mode1D64K: {
53 out_width = 64;
54 out_height = this->char_data.data_size * ((this->char_data.pix_fmt == gfx::PixelFormat::Palette16) ? 2 : 1) / 64;
55 break;
56 }
57 case gfx::MappingType::Mode1D128K: {
58 out_width = 128;
59 out_height = this->char_data.data_size * ((this->char_data.pix_fmt == gfx::PixelFormat::Palette16) ? 2 : 1) / 128;
60 break;
61 }
62 case gfx::MappingType::Mode1D256K: {
63 out_width = 256;
64 out_height = this->char_data.data_size * ((this->char_data.pix_fmt == gfx::PixelFormat::Palette16) ? 2 : 1) / 256;
65 break;
66 }
67 default: {
68 out_width = this->char_data.tile_width * gfx::TileSize;
69 out_height = this->char_data.tile_height * gfx::TileSize;
70 break;
71 }
72 }
73 }
74
75 Result ValidateImpl(const std::string &path, std::shared_ptr<fs::FileHandle> file_handle, const fs::FileCompression comp) override;
76 Result ReadImpl(const std::string &path, std::shared_ptr<fs::FileHandle> file_handle, const fs::FileCompression comp) override;
77 Result WriteImpl(const std::string &path, std::shared_ptr<fs::FileHandle> file_handle, const fs::FileCompression comp) override;
78 };
79
80}
Definition fmt_Common.hpp:53
Definition fmt_Common.hpp:35
Definition fmt_NCGR.hpp:13
Definition fmt_NCGR.hpp:23
Definition fmt_NCGR.hpp:10
Definition fmt_NCGR.hpp:8
Definition fs_Base.hpp:45