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
4#include <SDL.h>
5#include <vector>
6#include <unordered_map>
7#include <memory>
8#include <string>
9
10#include "app/gfx/bitmap.h"
13
14namespace yaze {
15namespace gfx {
16
20enum class BppFormat {
21 kBpp2 = 2,
22 kBpp3 = 3,
23 kBpp4 = 4,
24 kBpp8 = 8
25};
26
32 std::string name;
38 std::string description;
39
40 BppFormatInfo() = default;
41
42 BppFormatInfo(BppFormat fmt, const std::string& n, int bpp, int max_col,
43 int bytes_tile, int bytes_sheet, bool compressed, const std::string& desc)
44 : format(fmt), name(n), bits_per_pixel(bpp), max_colors(max_col),
45 bytes_per_tile(bytes_tile), bytes_per_sheet(bytes_sheet),
46 is_compressed(compressed), description(desc) {}
47};
48
69
98 public:
99 static BppFormatManager& Get();
100
104 void Initialize();
105
111 const BppFormatInfo& GetFormatInfo(BppFormat format) const;
112
117 std::vector<BppFormat> GetAvailableFormats() const;
118
128 std::vector<uint8_t> ConvertFormat(const std::vector<uint8_t>& data,
129 BppFormat from_format, BppFormat to_format,
130 int width, int height);
131
139 GraphicsSheetAnalysis AnalyzeGraphicsSheet(const std::vector<uint8_t>& sheet_data,
140 int sheet_id,
141 const SnesPalette& palette);
142
150 BppFormat DetectFormat(const std::vector<uint8_t>& data, int width, int height);
151
160 BppFormat target_format,
161 const std::vector<int>& used_colors);
162
167 std::unordered_map<std::string, int> GetConversionStats() const;
168
172 void ClearCache();
173
178 std::pair<size_t, size_t> GetMemoryStats() const;
179
180 private:
181 BppFormatManager() = default;
182 ~BppFormatManager() = default;
183
184 // Format information storage
185 std::unordered_map<BppFormat, BppFormatInfo> format_info_;
186
187 // Conversion cache for performance
188 std::unordered_map<std::string, std::vector<uint8_t>> conversion_cache_;
189
190 // Analysis cache
191 std::unordered_map<int, GraphicsSheetAnalysis> analysis_cache_;
192
193 // Statistics tracking
194 std::unordered_map<std::string, int> conversion_stats_;
195
196 // Memory usage tracking
199
200 // Helper methods
202 std::string GenerateCacheKey(const std::vector<uint8_t>& data,
203 BppFormat from_format, BppFormat to_format,
204 int width, int height);
205 BppFormat AnalyzeColorDepth(const std::vector<uint8_t>& data, int width, int height);
206 std::vector<uint8_t> Convert2BppTo8Bpp(const std::vector<uint8_t>& data, int width, int height);
207 std::vector<uint8_t> Convert3BppTo8Bpp(const std::vector<uint8_t>& data, int width, int height);
208 std::vector<uint8_t> Convert4BppTo8Bpp(const std::vector<uint8_t>& data, int width, int height);
209 std::vector<uint8_t> Convert8BppTo2Bpp(const std::vector<uint8_t>& data, int width, int height);
210 std::vector<uint8_t> Convert8BppTo3Bpp(const std::vector<uint8_t>& data, int width, int height);
211 std::vector<uint8_t> Convert8BppTo4Bpp(const std::vector<uint8_t>& data, int width, int height);
212
213 // Analysis helpers
214 int CountUsedColors(const std::vector<uint8_t>& data, int max_colors);
215 float CalculateCompressionRatio(const std::vector<uint8_t>& original,
216 const std::vector<uint8_t>& compressed);
217 std::vector<int> AnalyzeTileUsagePattern(const std::vector<uint8_t>& data,
218 int width, int height, int tile_size);
219};
220
225 public:
226 BppConversionScope(BppFormat from_format, BppFormat to_format, int width, int height);
228
229 std::vector<uint8_t> Convert(const std::vector<uint8_t>& data);
230
231 private:
236 std::string operation_name_;
238};
239
240} // namespace gfx
241} // namespace yaze
242
243#endif // YAZE_APP_GFX_BPP_FORMAT_MANAGER_H
RAII wrapper for BPP format conversion operations.
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)
Main namespace for the application.
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.