Add BPP format management and optimization features

- Introduced BPPFormatManager for handling various bitmap formats (2BPP, 3BPP, 4BPP, 8BPP) with conversion capabilities.
- Enhanced AtlasRenderer to support bitmap addition with BPP format optimization and added methods for optimized rendering.
- Implemented GraphicsOptimizer for analyzing and optimizing graphics sheets based on BPP formats, including memory and performance considerations.
- Developed BppFormatUI for user interface interactions related to BPP format selection and conversion previews.
- Integrated BPP format management into the canvas system, allowing for format selection and conversion within the GUI.
- Updated CMake configuration to include new source files related to BPP management and optimization.
This commit is contained in:
scawful
2025-09-29 21:21:49 -04:00
parent 100fc23a2e
commit 9e0f614ce8
12 changed files with 2469 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
#include <cmath>
#include <string>
#include "app/gfx/bpp_format_manager.h"
#include "app/core/window.h"
#include "app/gfx/atlas_renderer.h"
@@ -1440,4 +1441,77 @@ void Canvas::ShowScalingControls() {
// Old ROM palette management methods removed - now handled by EnhancedPaletteEditor
// BPP format management methods
void Canvas::ShowBppFormatSelector() {
if (!bpp_format_ui_) {
bpp_format_ui_ = std::make_unique<gui::BppFormatUI>(canvas_id_ + "_bpp_format");
}
if (bitmap_) {
bpp_format_ui_->RenderFormatSelector(bitmap_, bitmap_->palette(),
[this](gfx::BppFormat format) {
ConvertBitmapFormat(format);
});
}
}
void Canvas::ShowBppAnalysis() {
if (!bpp_format_ui_) {
bpp_format_ui_ = std::make_unique<gui::BppFormatUI>(canvas_id_ + "_bpp_format");
}
if (bitmap_) {
bpp_format_ui_->RenderAnalysisPanel(*bitmap_, bitmap_->palette());
}
}
void Canvas::ShowBppConversionDialog() {
if (!bpp_conversion_dialog_) {
bpp_conversion_dialog_ = std::make_unique<gui::BppConversionDialog>(canvas_id_ + "_bpp_conversion");
}
if (bitmap_) {
bpp_conversion_dialog_->Show(*bitmap_, bitmap_->palette(),
[this](gfx::BppFormat format, bool preserve_palette) {
ConvertBitmapFormat(format);
});
}
bpp_conversion_dialog_->Render();
}
bool Canvas::ConvertBitmapFormat(gfx::BppFormat target_format) {
if (!bitmap_) return false;
gfx::BppFormat current_format = GetCurrentBppFormat();
if (current_format == target_format) {
return true; // No conversion needed
}
try {
// Convert the bitmap data
auto converted_data = gfx::BppFormatManager::Get().ConvertFormat(
bitmap_->vector(), current_format, target_format,
bitmap_->width(), bitmap_->height());
// Update the bitmap with converted data
bitmap_->set_data(converted_data);
// Update the renderer
core::Renderer::Get().UpdateBitmap(bitmap_);
return true;
} catch (const std::exception& e) {
SDL_Log("Failed to convert bitmap format: %s", e.what());
return false;
}
}
gfx::BppFormat Canvas::GetCurrentBppFormat() const {
if (!bitmap_) return gfx::BppFormat::kBpp8;
return gfx::BppFormatManager::Get().DetectFormat(
bitmap_->vector(), bitmap_->width(), bitmap_->height());
}
} // namespace yaze::gui