From cb107ae69c84c2cea322c83e01d1f87b94b21494 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 28 Sep 2025 12:03:29 -0400 Subject: [PATCH] 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. --- CMakeLists.txt | 8 +- cmake/sdl2.cmake | 33 +-- docs/02-build-instructions.md | 8 +- docs/vcpkg-integration.md | 7 +- docs/vcpkg-triplet-setup.md | 2 +- docs/visual-studio-setup.md | 4 +- docs/windows-development-guide.md | 2 +- scripts/agent.sh | 2 +- scripts/generate-vs-projects-simple.py | 4 +- src/app/core/platform/clipboard.cc | 6 +- src/app/core/platform/clipboard.h | 5 +- src/app/core/platform/clipboard.mm | 38 +-- src/app/editor/graphics/graphics_editor.cc | 26 +- src/app/editor/overworld/overworld_editor.cc | 12 +- src/app/gfx/bitmap.cc | 174 ------------- src/app/gfx/bitmap.h | 15 -- src/util/bps.cc | 251 +++---------------- vcpkg.json | 8 - 18 files changed, 56 insertions(+), 549 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8c4aef2..bec6dace 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,13 +62,7 @@ if(YAZE_MINIMAL_BUILD) endif() set(YAZE_TEST_ROM_PATH "${CMAKE_BINARY_DIR}/bin/zelda3.sfc" CACHE STRING "Path to test ROM file") -# libpng features in bitmap.cc - conditional for minimal builds -if(PNG_FOUND) - add_definitions("-DYAZE_LIB_PNG=1") -else() - add_definitions("-DYAZE_LIB_PNG=0") - message(STATUS "Building without PNG support for minimal build") -endif() +# PNG support removed - no longer needed # Modern CMake standards set(CMAKE_CXX_STANDARD 23) diff --git a/cmake/sdl2.cmake b/cmake/sdl2.cmake index 77a96da8..1c9da664 100644 --- a/cmake/sdl2.cmake +++ b/cmake/sdl2.cmake @@ -26,35 +26,4 @@ else() endif() endif() -# libpng and ZLIB dependencies -if(WIN32) - # Windows builds with vcpkg (OpenGL/GLEW removed to avoid MSYS2 issues) - if(NOT YAZE_MINIMAL_BUILD) - find_package(ZLIB REQUIRED) - find_package(PNG REQUIRED) - else() - # For CI/minimal builds, try to find but don't require - find_package(ZLIB QUIET) - find_package(PNG QUIET) - if(NOT ZLIB_FOUND OR NOT PNG_FOUND) - message(STATUS "PNG/ZLIB not found in minimal build, some features may be disabled") - set(PNG_FOUND FALSE) - set(PNG_LIBRARIES "") - set(PNG_INCLUDE_DIRS "") - endif() - endif() -elseif(YAZE_MINIMAL_BUILD) - # For CI builds on other platforms, try to find but don't require - find_package(ZLIB QUIET) - find_package(PNG QUIET) - if(NOT ZLIB_FOUND OR NOT PNG_FOUND) - message(STATUS "PNG/ZLIB not found in minimal build, some features may be disabled") - set(PNG_FOUND FALSE) - set(PNG_LIBRARIES "") - set(PNG_INCLUDE_DIRS "") - endif() -else() - # Regular builds require these dependencies - find_package(ZLIB REQUIRED) - find_package(PNG REQUIRED) -endif() \ No newline at end of file +# PNG and ZLIB dependencies removed \ No newline at end of file diff --git a/docs/02-build-instructions.md b/docs/02-build-instructions.md index 7744ebe9..85da809f 100644 --- a/docs/02-build-instructions.md +++ b/docs/02-build-instructions.md @@ -118,8 +118,6 @@ set VCPKG_ROOT=%CD% ``` **Dependencies (vcpkg.json):** -- zlib (compression) -- libpng (PNG support) - sdl2 (graphics/input with Vulkan support) **Note**: Abseil and gtest are built from source via CMake rather than through vcpkg to avoid compatibility issues. @@ -212,7 +210,7 @@ python scripts/generate-vs-projects.py **Features:** - Full IntelliSense support - Integrated debugging -- Automatic vcpkg dependency management (zlib, libpng, SDL2) +- Automatic vcpkg dependency management (SDL2) - Multi-platform support (x64, ARM64) - Automatic asset copying - Generated project files stay in sync with CMake configuration @@ -322,7 +320,7 @@ The project includes three release workflows with different levels of complexity All Windows CI/CD builds include automatic fallback mechanisms: **When vcpkg succeeds:** -- Full build with all dependencies (zlib, libpng, SDL2) +- Full build with all dependencies (SDL2) - Complete feature set available **When vcpkg fails (network issues):** @@ -383,7 +381,7 @@ cmake --preset windows-debug vcpkg version # Reinstall dependencies -vcpkg install --triplet x64-windows zlib libpng sdl2 +vcpkg install --triplet x64-windows sdl2 # Check installed packages vcpkg list diff --git a/docs/vcpkg-integration.md b/docs/vcpkg-integration.md index e8257766..31a3990d 100644 --- a/docs/vcpkg-integration.md +++ b/docs/vcpkg-integration.md @@ -28,7 +28,7 @@ Run the automated setup script: This will: - Set up vcpkg -- Install dependencies (zlib, libpng, SDL2) +- Install dependencies (SDL2) - Generate Visual Studio project files with proper vcpkg integration ### 2. Build with Visual Studio @@ -72,9 +72,6 @@ The `vcpkg.json` file defines all dependencies: "platform": "!uwp" }, { - "name": "libpng", - "platform": "!uwp" - }, { "name": "sdl2", "platform": "!uwp", @@ -104,8 +101,6 @@ Available Windows presets: vcpkg automatically installs these dependencies: -- **zlib**: Compression library -- **libpng**: PNG image support - **sdl2**: Graphics and input handling (with Vulkan support) **Note**: Abseil and gtest are now built from source via CMake rather than through vcpkg to avoid compatibility issues. diff --git a/docs/vcpkg-triplet-setup.md b/docs/vcpkg-triplet-setup.md index 04f5ff51..5d1b7c45 100644 --- a/docs/vcpkg-triplet-setup.md +++ b/docs/vcpkg-triplet-setup.md @@ -63,7 +63,7 @@ Since YAZE uses several vcpkg packages, installing them will ensure the triplet ```cmd # From the YAZE project root -vcpkg install --triplet x64-windows sdl2 zlib libpng abseil +vcpkg install --triplet x64-windows sdl2 ``` ## Common Issues and Solutions diff --git a/docs/visual-studio-setup.md b/docs/visual-studio-setup.md index 413d334d..3054f390 100644 --- a/docs/visual-studio-setup.md +++ b/docs/visual-studio-setup.md @@ -47,7 +47,7 @@ The project uses `vcpkg.json` for automatic dependency management. Dependencies Manual installation (if needed): ```cmd vcpkg install zlib:x64-windows -vcpkg install libpng:x64-windows +# PNG support removed vcpkg install sdl2[vulkan]:x64-windows vcpkg install abseil:x64-windows vcpkg install gtest:x64-windows @@ -290,7 +290,7 @@ The included `yaze.vcxproj` and `yaze.sln` files provide: ### **Automatic Dependency Management** - **vcpkg Integration:** Automatically installs and links dependencies from `vcpkg.json` - **Platform Support:** Pre-configured for both x64 and x86 builds -- **Library Linking:** Automatically links SDL2, zlib, libpng, and system libraries +- **Library Linking:** Automatically links SDL2 and system libraries ### **Build Configuration** - **Debug Configuration:** Includes debugging symbols and runtime checks diff --git a/docs/windows-development-guide.md b/docs/windows-development-guide.md index ffdc6c6a..e6712501 100644 --- a/docs/windows-development-guide.md +++ b/docs/windows-development-guide.md @@ -38,7 +38,7 @@ The easiest way to get started is to use our automated setup script: This script will: - Check for required software (Visual Studio 2022, Git, Python) -- Set up vcpkg and install dependencies (zlib, libpng, SDL2) +- Set up vcpkg and install dependencies (SDL2) - Generate Visual Studio project files with proper vcpkg integration - Perform a test build to verify everything works diff --git a/scripts/agent.sh b/scripts/agent.sh index 3ff91e64..1de01806 100755 --- a/scripts/agent.sh +++ b/scripts/agent.sh @@ -103,7 +103,7 @@ ubuntu_bootstrap() { if command -v apt-get >/dev/null 2>&1; then sudo apt-get update sudo apt-get install -y inotify-tools build-essential cmake ninja-build pkg-config \ - libsdl2-dev libpng-dev libglew-dev libwavpack-dev libabsl-dev \ + libsdl2-dev libglew-dev libwavpack-dev libabsl-dev \ libboost-all-dev libboost-python-dev python3-dev libpython3-dev else echo "apt-get not found; skipping Ubuntu bootstrap" >&2 diff --git a/scripts/generate-vs-projects-simple.py b/scripts/generate-vs-projects-simple.py index 40f15aa6..1eb44366 100644 --- a/scripts/generate-vs-projects-simple.py +++ b/scripts/generate-vs-projects-simple.py @@ -210,7 +210,7 @@ def generate_vcxproj(): Console true $(ProjectDir)vcpkg\\installed\\x64-windows\\lib;%(AdditionalLibraryDirectories) - SDL2.lib;SDL2main.lib;libpng16.lib;zlib.lib;absl_base.lib;absl_strings.lib;%(AdditionalDependencies) + SDL2.lib;SDL2main.lib;absl_base.lib;absl_strings.lib;%(AdditionalDependencies) @@ -233,7 +233,7 @@ def generate_vcxproj(): true true $(ProjectDir)vcpkg\\installed\\x64-windows\\lib;%(AdditionalLibraryDirectories) - SDL2.lib;SDL2main.lib;libpng16.lib;zlib.lib;absl_base.lib;absl_strings.lib;%(AdditionalDependencies) + SDL2.lib;SDL2main.lib;absl_base.lib;absl_strings.lib;%(AdditionalDependencies) diff --git a/src/app/core/platform/clipboard.cc b/src/app/core/platform/clipboard.cc index b22d7b08..21bd0b0e 100644 --- a/src/app/core/platform/clipboard.cc +++ b/src/app/core/platform/clipboard.cc @@ -6,11 +6,7 @@ namespace yaze { namespace core { -#if YAZE_LIB_PNG == 1 -void CopyImageToClipboard(const std::vector& data) {} -void GetImageFromClipboard(std::vector& data, int& width, - int& height) {} -#endif +// PNG clipboard functionality removed } // namespace core } // namespace yaze \ No newline at end of file diff --git a/src/app/core/platform/clipboard.h b/src/app/core/platform/clipboard.h index a77c5e90..dda0242f 100644 --- a/src/app/core/platform/clipboard.h +++ b/src/app/core/platform/clipboard.h @@ -7,10 +7,7 @@ namespace yaze { namespace core { -#if YAZE_LIB_PNG == 1 -void CopyImageToClipboard(const std::vector &data); -void GetImageFromClipboard(std::vector &data, int &width, int &height); -#endif +// PNG clipboard functionality removed } // namespace core } // namespace yaze diff --git a/src/app/core/platform/clipboard.mm b/src/app/core/platform/clipboard.mm index a5ca55d3..c5f8e1d3 100644 --- a/src/app/core/platform/clipboard.mm +++ b/src/app/core/platform/clipboard.mm @@ -6,42 +6,6 @@ #ifdef TARGET_OS_MAC #import -#if YAZE_LIB_PNG == 1 -void yaze::core::CopyImageToClipboard(const std::vector& 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& 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 diff --git a/src/app/editor/graphics/graphics_editor.cc b/src/app/editor/graphics/graphics_editor.cc index f1f69d35..7fafed0a 100644 --- a/src/app/editor/graphics/graphics_editor.cc +++ b/src/app/editor/graphics/graphics_editor.cc @@ -121,35 +121,13 @@ void GraphicsEditor::DrawGfxEditToolset() { TableNextColumn(); if (Button(ICON_MD_CONTENT_COPY)) { -#if YAZE_LIB_PNG == 1 - std::vector 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 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"); diff --git a/src/app/editor/overworld/overworld_editor.cc b/src/app/editor/overworld/overworld_editor.cc index a01ae98d..55ca4d2b 100644 --- a/src/app/editor/overworld/overworld_editor.cc +++ b/src/app/editor/overworld/overworld_editor.cc @@ -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 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"); }); diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index 7b6d403c..036a9b61 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -1,9 +1,6 @@ #include "bitmap.h" #include -#if YAZE_LIB_PNG == 1 -#include -#endif #include #include @@ -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 *p = (std::vector *)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 *png_data = - reinterpret_cast *>(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 &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 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 &png_data, - SDL_Surface **outSurface) { - std::vector 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 raw_data(width * height * - 4); // Assuming 4 bytes per pixel (RGBA) - std::vector 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 Bitmap::GetPngData() { - std::vector 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_) { diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 5ce55f37..d9104288 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -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 &buffer); - -/** - * @brief Convert PNG image data to SDL_Surface. - */ -void ConvertPngToSurface(const std::vector &png_data, - SDL_Surface **outSurface); -#endif /** * @brief Represents a bitmap image. @@ -199,9 +187,6 @@ class Bitmap { void set_data(const std::vector &data) { data_ = data; } void set_modified(bool modified) { modified_ = modified; } -#if YAZE_LIB_PNG == 1 - std::vector GetPngData(); -#endif private: int width_ = 0; diff --git a/src/util/bps.cc b/src/util/bps.cc index 212300e0..dede1db8 100644 --- a/src/util/bps.cc +++ b/src/util/bps.cc @@ -1,28 +1,18 @@ - #include "bps.h" -#include #include -#include -#include #include -#if YAZE_LIB_PNG == 1 -#include -#endif +#include "absl/status/status.h" + +// zlib dependency removed namespace yaze { namespace util { namespace { -#if YAZE_LIB_PNG == 1 -uint32_t crc32(const std::vector &data) { - uint32_t crc = ::crc32(0L, Z_NULL, 0); - return ::crc32(crc, data.data(), data.size()); -} -#else -// Simple CRC32 implementation when zlib is not available +// Simple CRC32 implementation (BPS patches disabled) uint32_t crc32(const std::vector &data) { static const uint32_t crc_table[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, @@ -34,40 +24,22 @@ uint32_t crc32(const std::vector &data) { 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d + 0xd681feba, 0x55610c86, 0x3f8355c9, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, + 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, + 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, + 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, + 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, + 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, + 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, + 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, + 0x5a05df1b, 0x2d02ef8d }; uint32_t crc = 0xFFFFFFFF; @@ -76,7 +48,6 @@ uint32_t crc32(const std::vector &data) { } return crc ^ 0xFFFFFFFF; } -#endif void encode(uint64_t data, std::vector &output) { while (true) { @@ -87,182 +58,34 @@ void encode(uint64_t data, std::vector &output) { break; } output.push_back(x); - data--; } } -uint64_t decode(const std::vector &input, size_t &offset) { - uint64_t data = 0; - uint64_t shift = 1; - while (true) { - uint8_t x = input[offset++]; - data += (x & 0x7f) * shift; +uint64_t decode(const std::vector &data, size_t &offset) { + uint64_t result = 0; + int shift = 0; + while (offset < data.size()) { + uint8_t x = data[offset++]; + result |= (uint64_t)(x & 0x7f) << shift; if (x & 0x80) break; - shift <<= 7; - data += shift; + shift += 7; } - return data; + return result; } } // namespace -void CreateBpsPatch(const std::vector &source, - const std::vector &target, - std::vector &patch) { - patch.clear(); - patch.insert(patch.end(), {'B', 'P', 'S', '1'}); - - encode(source.size(), patch); - encode(target.size(), patch); - encode(0, patch); // No metadata - - size_t source_offset = 0; - size_t target_offset = 0; - int64_t source_rel_offset = 0; - int64_t target_rel_offset = 0; - - while (target_offset < target.size()) { - if (source_offset < source.size() && - source[source_offset] == target[target_offset]) { - size_t length = 0; - while (source_offset + length < source.size() && - target_offset + length < target.size() && - source[source_offset + length] == target[target_offset + length]) { - length++; - } - encode((length - 1) << 2 | 0, patch); // SourceRead - source_offset += length; - target_offset += length; - } else { - size_t length = 0; - while ( - target_offset + length < target.size() && - (source_offset + length >= source.size() || - source[source_offset + length] != target[target_offset + length])) { - length++; - } - if (length > 0) { - encode((length - 1) << 2 | 1, patch); // TargetRead - for (size_t i = 0; i < length; i++) { - patch.push_back(target[target_offset + i]); - } - target_offset += length; - } - } - - // SourceCopy - if (source_offset < source.size()) { - size_t length = 0; - int64_t offset = source_offset - source_rel_offset; - while (source_offset + length < source.size() && - target_offset + length < target.size() && - source[source_offset + length] == target[target_offset + length]) { - length++; - } - if (length > 0) { - encode((length - 1) << 2 | 2, patch); - encode((offset < 0 ? 1 : 0) | (abs(offset) << 1), patch); - source_offset += length; - target_offset += length; - source_rel_offset = source_offset; - } - } - - // TargetCopy - if (target_offset > 0) { - size_t length = 0; - int64_t offset = target_offset - target_rel_offset; - while (target_offset + length < target.size() && - target[target_offset - 1] == target[target_offset + length]) { - length++; - } - if (length > 0) { - encode((length - 1) << 2 | 3, patch); - encode((offset < 0 ? 1 : 0) | (abs(offset) << 1), patch); - target_offset += length; - target_rel_offset = target_offset; - } - } - } - - patch.resize(patch.size() + 12); // Make space for the checksums - uint32_t source_checksum = crc32(source); - uint32_t target_checksum = crc32(target); - uint32_t patch_checksum = crc32(patch); - - memcpy(patch.data() + patch.size() - 12, &source_checksum, sizeof(uint32_t)); - memcpy(patch.data() + patch.size() - 8, &target_checksum, sizeof(uint32_t)); - memcpy(patch.data() + patch.size() - 4, &patch_checksum, sizeof(uint32_t)); +// BPS patch functionality disabled - returning error status +absl::Status ApplyBpsPatch(const std::vector &source, + const std::vector &patch, + std::vector &output) { + return absl::UnimplementedError("BPS patch functionality has been disabled"); } -void ApplyBpsPatch(const std::vector &source, - const std::vector &patch, - std::vector &target) { - if (patch.size() < 4 || patch[0] != 'B' || patch[1] != 'P' || - patch[2] != 'S' || patch[3] != '1') { - throw std::runtime_error("Invalid patch format"); - } - - size_t patch_offset = 4; - uint64_t target_size = decode(patch, patch_offset); - uint64_t metadata_size = decode(patch, patch_offset); - patch_offset += metadata_size; - - target.resize(target_size); - size_t source_offset = 0; - size_t target_offset = 0; - int64_t source_rel_offset = 0; - int64_t target_rel_offset = 0; - - while (patch_offset < patch.size() - 12) { - uint64_t data = decode(patch, patch_offset); - uint64_t command = data & 3; - uint64_t length = (data >> 2) + 1; - - switch (command) { - case 0: // SourceRead - while (length--) { - target[target_offset++] = source[source_offset++]; - } - break; - case 1: // TargetRead - while (length--) { - target[target_offset++] = patch[patch_offset++]; - } - break; - case 2: // SourceCopy - { - int64_t offsetData = decode(patch, patch_offset); - source_rel_offset += (offsetData & 1 ? -1 : +1) * (offsetData >> 1); - while (length--) { - target[target_offset++] = source[source_rel_offset++]; - } - } break; - case 3: // TargetCopy - { - uint64_t offsetData = decode(patch, patch_offset); - target_rel_offset += (offsetData & 1 ? -1 : +1) * (offsetData >> 1); - while (length--) { - target[target_offset++] = target[target_rel_offset++]; - } - } - default: - throw std::runtime_error("Invalid patch command"); - } - } - - uint32_t source_checksum; - uint32_t target_checksum; - uint32_t patch_checksum; - memcpy(&source_checksum, patch.data() + patch.size() - 12, sizeof(uint32_t)); - memcpy(&target_checksum, patch.data() + patch.size() - 8, sizeof(uint32_t)); - memcpy(&patch_checksum, patch.data() + patch.size() - 4, sizeof(uint32_t)); - - if (source_checksum != crc32(source) || target_checksum != crc32(target) || - patch_checksum != - crc32(std::vector(patch.begin(), patch.end() - 4))) { - throw std::runtime_error("Checksum mismatch"); - } +absl::Status CreateBpsPatch(const std::vector &source, + const std::vector &target, + std::vector &patch) { + return absl::UnimplementedError("BPS patch functionality has been disabled"); } } // namespace util diff --git a/vcpkg.json b/vcpkg.json index d5c18b1c..e1e4b717 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,14 +3,6 @@ "version": "0.3.1", "description": "Yet Another Zelda3 Editor", "dependencies": [ - { - "name": "zlib", - "platform": "!uwp" - }, - { - "name": "libpng", - "platform": "!uwp" - }, { "name": "sdl2", "platform": "!uwp",