yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
bpp_format_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_GFX_BPP_FORMAT_MANAGER_H
2#define YAZE_APP_GFX_BPP_FORMAT_MANAGER_H
3
5
6#include <memory>
7#include <string>
8#include <unordered_map>
9#include <vector>
10
11#include "app/gfx/core/bitmap.h"
14
15namespace yaze {
16namespace gfx {
17
21enum class BppFormat {
22 kBpp2 = 2,
23 kBpp3 = 3,
24 kBpp4 = 4,
25 kBpp8 = 8
26};
27
33 std::string name;
39 std::string description;
40
41 BppFormatInfo() = default;
42
43 BppFormatInfo(BppFormat fmt, const std::string& n, int bpp, int max_col,
44 int bytes_tile, int bytes_sheet, bool compressed,
45 const std::string& desc)
46 : format(fmt),
47 name(n),
48 bits_per_pixel(bpp),
49 max_colors(max_col),
50 bytes_per_tile(bytes_tile),
51 bytes_per_sheet(bytes_sheet),
52 is_compressed(compressed),
53 description(desc) {}
54};
55
81
110 public:
111 static BppFormatManager& Get();
112
116 void Initialize();
117
123 const BppFormatInfo& GetFormatInfo(BppFormat format) const;
124
129 std::vector<BppFormat> GetAvailableFormats() const;
130
140 std::vector<uint8_t> ConvertFormat(const std::vector<uint8_t>& data,
141 BppFormat from_format, BppFormat to_format,
142 int width, int height);
143
152 const std::vector<uint8_t>& sheet_data, int sheet_id,
153 const SnesPalette& palette);
154
162 BppFormat DetectFormat(const std::vector<uint8_t>& data, int width,
163 int height);
164
173 BppFormat target_format,
174 const std::vector<int>& used_colors);
175
180 std::unordered_map<std::string, int> GetConversionStats() const;
181
185 void ClearCache();
186
191 std::pair<size_t, size_t> GetMemoryStats() const;
192
193 private:
194 BppFormatManager() = default;
195 ~BppFormatManager() = default;
196
197 // Format information storage
198 std::unordered_map<BppFormat, BppFormatInfo> format_info_;
199
200 // Conversion cache for performance
201 std::unordered_map<std::string, std::vector<uint8_t>> conversion_cache_;
202
203 // Analysis cache
204 std::unordered_map<int, GraphicsSheetAnalysis> analysis_cache_;
205
206 // Statistics tracking
207 std::unordered_map<std::string, int> conversion_stats_;
208
209 // Memory usage tracking
212
213 // Helper methods
215 std::string GenerateCacheKey(const std::vector<uint8_t>& data,
216 BppFormat from_format, BppFormat to_format,
217 int width, int height);
218 BppFormat AnalyzeColorDepth(const std::vector<uint8_t>& data, int width,
219 int height);
220 std::vector<uint8_t> Convert2BppTo8Bpp(const std::vector<uint8_t>& data,
221 int width, int height);
222 std::vector<uint8_t> Convert3BppTo8Bpp(const std::vector<uint8_t>& data,
223 int width, int height);
224 std::vector<uint8_t> Convert4BppTo8Bpp(const std::vector<uint8_t>& data,
225 int width, int height);
226 std::vector<uint8_t> Convert8BppTo2Bpp(const std::vector<uint8_t>& data,
227 int width, int height);
228 std::vector<uint8_t> Convert8BppTo3Bpp(const std::vector<uint8_t>& data,
229 int width, int height);
230 std::vector<uint8_t> Convert8BppTo4Bpp(const std::vector<uint8_t>& data,
231 int width, int height);
232
233 // Analysis helpers
234 int CountUsedColors(const std::vector<uint8_t>& data, int max_colors);
235 float CalculateCompressionRatio(const std::vector<uint8_t>& original,
236 const std::vector<uint8_t>& compressed);
237 std::vector<int> AnalyzeTileUsagePattern(const std::vector<uint8_t>& data,
238 int width, int height,
239 int tile_size);
240};
241
246 public:
247 BppConversionScope(BppFormat from_format, BppFormat to_format, int width,
248 int height);
250
251 std::vector<uint8_t> Convert(const std::vector<uint8_t>& data);
252
253 private:
258 std::string operation_name_;
260};
261
262} // namespace gfx
263} // namespace yaze
264
265#endif // YAZE_APP_GFX_BPP_FORMAT_MANAGER_H
RAII wrapper for BPP format conversion operations.
BppConversionScope(BppFormat from_format, BppFormat to_format, int width, int height)
std::vector< uint8_t > Convert(const std::vector< uint8_t > &data)
Comprehensive BPP format management system for SNES ROM hacking.
std::vector< uint8_t > Convert8BppTo3Bpp(const std::vector< uint8_t > &data, int width, int height)
SnesPalette OptimizePaletteForFormat(const SnesPalette &palette, BppFormat target_format, const std::vector< int > &used_colors)
Optimize palette for specific BPP format.
std::unordered_map< std::string, int > GetConversionStats() const
Get conversion statistics.
std::unordered_map< BppFormat, BppFormatInfo > format_info_
std::vector< uint8_t > Convert8BppTo2Bpp(const std::vector< uint8_t > &data, int width, int height)
std::pair< size_t, size_t > GetMemoryStats() const
Get memory usage statistics.
std::vector< int > AnalyzeTileUsagePattern(const std::vector< uint8_t > &data, int width, int height, int tile_size)
std::string GenerateCacheKey(const std::vector< uint8_t > &data, BppFormat from_format, BppFormat to_format, int width, int height)
BppFormat DetectFormat(const std::vector< uint8_t > &data, int width, int height)
Detect BPP format from bitmap data.
std::unordered_map< int, GraphicsSheetAnalysis > analysis_cache_
std::vector< BppFormat > GetAvailableFormats() const
Get all available BPP formats.
GraphicsSheetAnalysis AnalyzeGraphicsSheet(const std::vector< uint8_t > &sheet_data, int sheet_id, const SnesPalette &palette)
Analyze graphics sheet to determine original and current BPP formats.
std::vector< uint8_t > Convert3BppTo8Bpp(const std::vector< uint8_t > &data, int width, int height)
std::vector< uint8_t > ConvertFormat(const std::vector< uint8_t > &data, BppFormat from_format, BppFormat to_format, int width, int height)
Convert bitmap data between BPP formats.
int CountUsedColors(const std::vector< uint8_t > &data, int max_colors)
void Initialize()
Initialize the BPP format manager.
std::vector< uint8_t > Convert2BppTo8Bpp(const std::vector< uint8_t > &data, int width, int height)
std::unordered_map< std::string, std::vector< uint8_t > > conversion_cache_
float CalculateCompressionRatio(const std::vector< uint8_t > &original, const std::vector< uint8_t > &compressed)
static BppFormatManager & Get()
BppFormat AnalyzeColorDepth(const std::vector< uint8_t > &data, int width, int height)
std::vector< uint8_t > Convert8BppTo4Bpp(const std::vector< uint8_t > &data, int width, int height)
void ClearCache()
Clear conversion cache.
std::vector< uint8_t > Convert4BppTo8Bpp(const std::vector< uint8_t > &data, int width, int height)
const BppFormatInfo & GetFormatInfo(BppFormat format) const
Get BPP format information.
std::unordered_map< std::string, int > conversion_stats_
RAII timer for automatic timing management.
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
BppFormat
BPP format enumeration for SNES graphics.
@ kBpp4
4 bits per pixel (16 colors)
@ kBpp3
3 bits per pixel (8 colors)
@ kBpp2
2 bits per pixel (4 colors)
@ kBpp8
8 bits per pixel (256 colors)
SDL2/SDL3 compatibility layer.
BPP format metadata and conversion information.
BppFormatInfo(BppFormat fmt, const std::string &n, int bpp, int max_col, int bytes_tile, int bytes_sheet, bool compressed, const std::string &desc)
Graphics sheet analysis result.