Remove PNG and ZLIB support from the project
- Eliminated all references to PNG and ZLIB dependencies in CMake configuration and project files. - Updated documentation to reflect the removal of PNG support and related functionalities. - Adjusted build scripts and source files to remove unused code related to PNG handling, ensuring a cleaner codebase.
This commit is contained in:
@@ -6,11 +6,7 @@
|
||||
namespace yaze {
|
||||
namespace core {
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
void CopyImageToClipboard(const std::vector<uint8_t>& data) {}
|
||||
void GetImageFromClipboard(std::vector<uint8_t>& data, int& width,
|
||||
int& height) {}
|
||||
#endif
|
||||
// PNG clipboard functionality removed
|
||||
|
||||
} // namespace core
|
||||
} // namespace yaze
|
||||
@@ -7,10 +7,7 @@
|
||||
namespace yaze {
|
||||
namespace core {
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
void CopyImageToClipboard(const std::vector<uint8_t> &data);
|
||||
void GetImageFromClipboard(std::vector<uint8_t> &data, int &width, int &height);
|
||||
#endif
|
||||
// PNG clipboard functionality removed
|
||||
|
||||
} // namespace core
|
||||
} // namespace yaze
|
||||
|
||||
@@ -6,42 +6,6 @@
|
||||
#ifdef TARGET_OS_MAC
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
void yaze::core::CopyImageToClipboard(const std::vector<uint8_t>& pngData) {
|
||||
NSData* data = [NSData dataWithBytes:pngData.data() length:pngData.size()];
|
||||
NSImage* image = [[NSImage alloc] initWithData:data];
|
||||
|
||||
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
||||
[pasteboard clearContents];
|
||||
[pasteboard writeObjects:@[ image ]];
|
||||
}
|
||||
|
||||
void yaze::core::GetImageFromClipboard(std::vector<uint8_t>& pixel_data, int& width, int& height) {
|
||||
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
||||
NSArray* classArray = [NSArray arrayWithObject:[NSImage class]];
|
||||
NSDictionary* options = [NSDictionary dictionary];
|
||||
|
||||
NSImage* image = [pasteboard readObjectsForClasses:classArray options:options].firstObject;
|
||||
if (!image) {
|
||||
width = height = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Assuming the image is in an RGBA format
|
||||
CGImageRef cgImage = [image CGImageForProposedRect:nil context:nil hints:nil];
|
||||
width = (int)CGImageGetWidth(cgImage);
|
||||
height = (int)CGImageGetHeight(cgImage);
|
||||
|
||||
size_t bytesPerRow = 4 * width;
|
||||
size_t totalBytes = bytesPerRow * height;
|
||||
pixel_data.resize(totalBytes);
|
||||
|
||||
CGContextRef context = CGBitmapContextCreate(
|
||||
pixel_data.data(), width, height, 8, bytesPerRow, CGColorSpaceCreateDeviceRGB(),
|
||||
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
|
||||
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
|
||||
CGContextRelease(context);
|
||||
}
|
||||
#endif // YAZE_LIB_PNG
|
||||
// PNG clipboard functionality removed
|
||||
|
||||
#endif // TARGET_OS_MAC
|
||||
|
||||
@@ -121,35 +121,13 @@ void GraphicsEditor::DrawGfxEditToolset() {
|
||||
|
||||
TableNextColumn();
|
||||
if (Button(ICON_MD_CONTENT_COPY)) {
|
||||
#if YAZE_LIB_PNG == 1
|
||||
std::vector<uint8_t> png_data =
|
||||
gfx::Arena::Get().gfx_sheets().at(current_sheet_).GetPngData();
|
||||
core::CopyImageToClipboard(png_data);
|
||||
#else
|
||||
// PNG support disabled - show message or alternative action
|
||||
status_ = absl::UnimplementedError("PNG export not available in this build");
|
||||
#endif
|
||||
status_ = absl::UnimplementedError("PNG export functionality removed");
|
||||
}
|
||||
HOVER_HINT("Copy to Clipboard");
|
||||
|
||||
TableNextColumn();
|
||||
if (Button(ICON_MD_CONTENT_PASTE)) {
|
||||
#if YAZE_LIB_PNG == 1
|
||||
std::vector<uint8_t> png_data;
|
||||
int width, height;
|
||||
core::GetImageFromClipboard(png_data, width, height);
|
||||
if (png_data.size() > 0) {
|
||||
gfx::Arena::Get()
|
||||
.mutable_gfx_sheets()
|
||||
->at(current_sheet_)
|
||||
.Create(width, height, 8, png_data);
|
||||
Renderer::Get().UpdateBitmap(
|
||||
&gfx::Arena::Get().mutable_gfx_sheets()->at(current_sheet_));
|
||||
}
|
||||
#else
|
||||
// PNG support disabled - show message or alternative action
|
||||
status_ = absl::UnimplementedError("PNG import not available in this build");
|
||||
#endif
|
||||
status_ = absl::UnimplementedError("PNG import functionality removed");
|
||||
}
|
||||
HOVER_HINT("Paste from Clipboard");
|
||||
|
||||
|
||||
@@ -124,17 +124,7 @@ void OverworldEditor::Initialize() {
|
||||
});
|
||||
gui::AddTableColumn(toolset_table_, "##CopyMap", [&]() {
|
||||
if (Button(ICON_MD_CONTENT_COPY)) {
|
||||
#if YAZE_LIB_PNG == 1
|
||||
std::vector<uint8_t> png_data = maps_bmp_[current_map_].GetPngData();
|
||||
if (png_data.size() > 0) {
|
||||
core::CopyImageToClipboard(png_data);
|
||||
} else {
|
||||
status_ = absl::InternalError(
|
||||
"Failed to convert overworld map surface to PNG");
|
||||
}
|
||||
#else
|
||||
status_ = absl::UnimplementedError("PNG export not available in this build");
|
||||
#endif
|
||||
status_ = absl::UnimplementedError("PNG export functionality removed");
|
||||
}
|
||||
HOVER_HINT("Copy Map to Clipboard");
|
||||
});
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#include "bitmap.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#if YAZE_LIB_PNG == 1
|
||||
#include <png.h>
|
||||
#endif
|
||||
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
@@ -15,170 +12,6 @@
|
||||
namespace yaze {
|
||||
namespace gfx {
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
|
||||
namespace png_internal {
|
||||
|
||||
void PngWriteCallback(png_structp png_ptr, png_bytep data, png_size_t length) {
|
||||
std::vector<uint8_t> *p = (std::vector<uint8_t> *)png_get_io_ptr(png_ptr);
|
||||
p->insert(p->end(), data, data + length);
|
||||
}
|
||||
|
||||
void PngReadCallback(png_structp png_ptr, png_bytep outBytes,
|
||||
png_size_t byteCountToRead) {
|
||||
png_voidp io_ptr = png_get_io_ptr(png_ptr);
|
||||
if (!io_ptr) return;
|
||||
|
||||
std::vector<uint8_t> *png_data =
|
||||
reinterpret_cast<std::vector<uint8_t> *>(io_ptr);
|
||||
static size_t pos = 0; // Position to read from
|
||||
|
||||
if (pos + byteCountToRead <= png_data->size()) {
|
||||
memcpy(outBytes, png_data->data() + pos, byteCountToRead);
|
||||
pos += byteCountToRead;
|
||||
} else {
|
||||
png_error(png_ptr, "Read error in PngReadCallback");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace png_internal
|
||||
|
||||
bool ConvertSurfaceToPng(SDL_Surface *surface, std::vector<uint8_t> &buffer) {
|
||||
png_structp png_ptr = png_create_write_struct("1.6.40", NULL, NULL, NULL);
|
||||
if (!png_ptr) {
|
||||
SDL_Log("Failed to create PNG write struct");
|
||||
return false;
|
||||
}
|
||||
|
||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||
SDL_Log("Failed to create PNG info struct");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
SDL_Log("Error during PNG write");
|
||||
return false;
|
||||
}
|
||||
|
||||
png_set_write_fn(png_ptr, &buffer, png_internal::PngWriteCallback, NULL);
|
||||
|
||||
png_colorp pal_ptr;
|
||||
|
||||
/* Prepare chunks */
|
||||
int colortype = PNG_COLOR_MASK_COLOR;
|
||||
int i = 0;
|
||||
SDL_Palette *pal;
|
||||
if (surface->format->BytesPerPixel > 0 &&
|
||||
surface->format->BytesPerPixel <= 8 && (pal = surface->format->palette)) {
|
||||
SDL_Log("Writing PNG image with palette");
|
||||
colortype |= PNG_COLOR_MASK_PALETTE;
|
||||
pal_ptr = (png_colorp)malloc(pal->ncolors * sizeof(png_color));
|
||||
for (i = 0; i < pal->ncolors; i++) {
|
||||
pal_ptr[i].red = pal->colors[i].r;
|
||||
pal_ptr[i].green = pal->colors[i].g;
|
||||
pal_ptr[i].blue = pal->colors[i].b;
|
||||
}
|
||||
png_set_PLTE(png_ptr, info_ptr, pal_ptr, pal->ncolors);
|
||||
free(pal_ptr);
|
||||
}
|
||||
|
||||
if (surface->format->Amask) { // Check for alpha channel
|
||||
colortype |= PNG_COLOR_MASK_ALPHA;
|
||||
}
|
||||
|
||||
auto depth = surface->format->BitsPerPixel;
|
||||
|
||||
// Set image attributes.
|
||||
png_set_IHDR(png_ptr, info_ptr, surface->w, surface->h, depth, colortype,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
png_set_bgr(png_ptr);
|
||||
|
||||
// Write the image data.
|
||||
std::vector<png_bytep> row_pointers(surface->h);
|
||||
for (int y = 0; y < surface->h; ++y) {
|
||||
row_pointers[y] = (png_bytep)(surface->pixels) + y * surface->pitch;
|
||||
}
|
||||
|
||||
png_set_rows(png_ptr, info_ptr, row_pointers.data());
|
||||
|
||||
SDL_Log("Writing PNG image...");
|
||||
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
|
||||
SDL_Log("PNG image write complete");
|
||||
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConvertPngToSurface(const std::vector<uint8_t> &png_data,
|
||||
SDL_Surface **outSurface) {
|
||||
std::vector<uint8_t> data(png_data);
|
||||
png_structp png_ptr = png_create_read_struct("1.6.40", NULL, NULL, NULL);
|
||||
if (!png_ptr) {
|
||||
throw std::runtime_error("Failed to create PNG read struct");
|
||||
}
|
||||
|
||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
throw std::runtime_error("Failed to create PNG info struct");
|
||||
}
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
throw std::runtime_error("Error during PNG read");
|
||||
}
|
||||
|
||||
// Set our custom read function
|
||||
png_set_read_fn(png_ptr, &data, png_internal::PngReadCallback);
|
||||
|
||||
// Read the PNG info
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
uint32_t width = png_get_image_width(png_ptr, info_ptr);
|
||||
uint32_t height = png_get_image_height(png_ptr, info_ptr);
|
||||
png_byte color_type = png_get_color_type(png_ptr, info_ptr);
|
||||
png_byte bit_depth = png_get_bit_depth(png_ptr, info_ptr);
|
||||
|
||||
// Apply necessary transformations...
|
||||
// (Same as in your existing code)
|
||||
|
||||
// Update info structure with transformations
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
// Read the file
|
||||
std::vector<uint8_t> raw_data(width * height *
|
||||
4); // Assuming 4 bytes per pixel (RGBA)
|
||||
std::vector<png_bytep> row_pointers(height);
|
||||
for (size_t y = 0; y < height; y++) {
|
||||
row_pointers[y] = raw_data.data() + y * width * 4;
|
||||
}
|
||||
|
||||
png_read_image(png_ptr, row_pointers.data());
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
|
||||
// Create an SDL_Surface
|
||||
*outSurface = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32,
|
||||
SDL_PIXELFORMAT_RGBA32);
|
||||
if (*outSurface == nullptr) {
|
||||
SDL_Log("SDL_CreateRGBSurfaceWithFormat failed: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy the raw data into the SDL_Surface
|
||||
SDL_LockSurface(*outSurface);
|
||||
memcpy((*outSurface)->pixels, raw_data.data(), raw_data.size());
|
||||
SDL_UnlockSurface(*outSurface);
|
||||
|
||||
SDL_Log("Successfully created SDL_Surface from PNG data");
|
||||
}
|
||||
|
||||
#endif // YAZE_LIB_PNG
|
||||
|
||||
class BitmapError : public std::runtime_error {
|
||||
public:
|
||||
@@ -553,13 +386,6 @@ void Bitmap::Get16x16Tile(int tile_x, int tile_y,
|
||||
}
|
||||
}
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
std::vector<uint8_t> Bitmap::GetPngData() {
|
||||
std::vector<uint8_t> png_data;
|
||||
ConvertSurfaceToPng(surface_, png_data);
|
||||
return png_data;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Bitmap::SetPixel(int x, int y, const SnesColor& color) {
|
||||
if (x < 0 || x >= width_ || y < 0 || y >= height_) {
|
||||
|
||||
@@ -35,18 +35,6 @@ enum BitmapFormat {
|
||||
k8bpp = 2,
|
||||
};
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
/**
|
||||
* @brief Convert SDL_Surface to PNG image data.
|
||||
*/
|
||||
bool ConvertSurfaceToPng(SDL_Surface *surface, std::vector<uint8_t> &buffer);
|
||||
|
||||
/**
|
||||
* @brief Convert PNG image data to SDL_Surface.
|
||||
*/
|
||||
void ConvertPngToSurface(const std::vector<uint8_t> &png_data,
|
||||
SDL_Surface **outSurface);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Represents a bitmap image.
|
||||
@@ -199,9 +187,6 @@ class Bitmap {
|
||||
void set_data(const std::vector<uint8_t> &data) { data_ = data; }
|
||||
void set_modified(bool modified) { modified_ = modified; }
|
||||
|
||||
#if YAZE_LIB_PNG == 1
|
||||
std::vector<uint8_t> GetPngData();
|
||||
#endif
|
||||
|
||||
private:
|
||||
int width_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user