From 7ce9055272c8fb48b2860367e8f8751700b2d688 Mon Sep 17 00:00:00 2001 From: Christophe Meneboeuf Date: Sat, 18 Jun 2022 14:53:44 +0200 Subject: [PATCH] cleanup --- Readme.md | 49 +++++++-------------- Rgb2Hires_PC/CMakeLists.txt | 2 +- Rgb2Hires_PC/src/App_Picture.cpp | 75 +++++++++++++++++--------------- Rgb2Hires_PC/src/App_Tile.cpp | 35 +++++++++------ Rgb2Hires_PC/src/HiRes.h | 2 +- 5 files changed, 80 insertions(+), 83 deletions(-) diff --git a/Readme.md b/Readme.md index 38662cd..7f568f7 100644 --- a/Readme.md +++ b/Readme.md @@ -22,7 +22,7 @@ This repository contains three "PC" projects: * **Picture**: a program to convert a RGB png to a binary or an ASM excerpt, that can be loaded to the HIRES memory pages of an Apple II. An optional **live preview** can be displayed: its window will simulate an RGB monitor and will show the result, including color clashing and artifacts. * Source image must be 140x192. Pixels are anamorphic: they will be displayed twice wider than tall. * Source image must contains six colors : BLACK, WHITE, ORANGE, GREEN, BLUE and PURPLE. The color may be approximation of the Apple II 6 colors. Please refer to the provided pic. -* **Tile**: given a RGB png tile sheet that satisfies the same requirements as above, it extracts a 14x16 tile and converts it to ASM data. This data **is not interleaved**. +* **Tile**: given a RGB png tile sheet that satisfies the same requirements as above, it extracts a 14x16 tile and converts it to ASM data. The lines forming the tile data **are not interleaved** as in a HIRES framebuffer. And one Apple II project: * **Loader**: a program that will load and display a picture generated by the *Picture* program. A bash scripts is provided as an exemple to load the picture and the loader on an image disk. [AppleCommander](https://applecommander.github.io/) is required to do so. Once in ProDOS, just type *-DISPLAY*. @@ -32,40 +32,19 @@ __Note:__ For more information about the "Hires" format and its limitations, you ## Build from sources -This project has been tested with VisualStudio 2019, Gcc 9 (Ubuntu 20.04) and Gcc8.3.0 (Debian 10). ### Dependencies -* **Magick++** from ImageMagick 6 and **SDL2** - * On **Windows** - * ImageMagick - * Download ImageMagick 6 from the [official website](https://legacy.imagemagick.org/script/install-source.php). - * Compile it in *Dynamic Multithreaded*. - * Provide an environment variable called *MAGICK_HOME* and pointing to the root ImageMagick folder. - * Copy *ImageMagick-config* from the *script/* folder to *MAGICK_HOME*. - * SDL2 - * Download the latest version of the *development library* from the [official website](https://www.libsdl.org/download-2.0.php) and unarchive it. - * Provide an environment variable called *SDL2_HOME* and pointing to the root of the SDL2 library. - - * On **Linux**, install libmagick++-dev for version 6 and libsdl2-dev - - > sudo apt install libmagick++-6.q16-dev libsdl2-dev - - Depending on your Linux distribution, you may have to set an environment variable *sdl2_DIR*, pointing to the directory hosting SDL2's cmake configuration, before running cmake. - - Example on Debian: - - > export sdl2_DIR=/usr/lib/x86_64-linux-gnu/cmake/SDL2/ +The dependencies are managed by [conan.io](https://conan.io/). Please refer to (their documentation)[https://docs.conan.io/en/latest/installation.html] for installation instructions. +The build system is managed by CMake. ### How to build -* **Linux** a CMakeList is provided: - > mkdir build && cd build - - > cmake .. - - > cmake --build . --config release - -* **Windows** a VisualStudio solution is provided +```bash +mkdir build && cd build +conan install .. +cmake .. -DCMAKE_BUILD_TYPE=RELEASE +cmake --build . --config release -j +``` ## Apple II project (Loader) @@ -73,13 +52,17 @@ This project has been tested with VisualStudio 2019, Gcc 9 (Ubuntu 20.04) and Gc * [CC65](https://cc65.github.io/cc65/) * The crosscompiler suit. Please provide an environment variable, *CC65_HOME* pointing to your CC65 folder. -### Build +### How to build - > make +A make file is provided. Just run +```bash +make +``` ## Test -A correct source image, *test.png*, is provided as an example. Convert it using Picture, then copy it on a dsk image along with the Apple II loader. You can use or refer to the provided script in the *Loader_Apple2* folder. +* A correct source image, *testPiceture.png*, is provided as an example. Convert it using the application *Picture*, then copy it on a dsk image along with the Apple II loader. You can use or refer to the provided script in the *Loader_Apple2* folder. +* Another source image *testTile.png* is provided to test that the correct tile is converted and extracted using the application *Tile*. ### Demo diff --git a/Rgb2Hires_PC/CMakeLists.txt b/Rgb2Hires_PC/CMakeLists.txt index e182ab0..04a14b5 100644 --- a/Rgb2Hires_PC/CMakeLists.txt +++ b/Rgb2Hires_PC/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 3.19) cmake_policy(SET CMP0074 NEW) -project (Rgb2Hires-SDL) +project (Rgb2Hires) # flags not compatibles with magick++ if(WIN32) diff --git a/Rgb2Hires_PC/src/App_Picture.cpp b/Rgb2Hires_PC/src/App_Picture.cpp index da6bb27..761b4fe 100644 --- a/Rgb2Hires_PC/src/App_Picture.cpp +++ b/Rgb2Hires_PC/src/App_Picture.cpp @@ -89,47 +89,54 @@ int main( int argc, char *argv[] ) ExitOnError("No input path provided.\n"); } - - const auto filepath = imagePath.getValue(); - if (!exists(filepath)) { - ExitOnError("Cannot read " + filepath); - } - std::vector surfaces; - SDL_Surface* surfaceRgb = IMG_Load(filepath.c_str()); - surfaces.push_back(surfaceRgb); - if (surfaceRgb == nullptr) + try { - ExitOnError("Cannot decode " + filepath, surfaces); - } - const ImageQuantized imageHiRes{ surfaceRgb }; + const auto filepath = imagePath.getValue(); + if (!exists(filepath)) { + ExitOnError("Cannot read " + filepath); + } - // Preview - if (preview.getValue()) - { - if (assembly.getValue() == true) + SDL_Surface* surfaceRgb = IMG_Load(filepath.c_str()); + surfaces.push_back(surfaceRgb); + if (surfaceRgb == nullptr) { - std::cout << "\nIgnoring --asm option.\n"; + ExitOnError("Cannot decode " + filepath, surfaces); } - const auto bytes = imageHiRes.getHiresBuffer(); - Display::Window::GetInstance()->display(filepath, bytes->data()); - } - // Convertion to disk - else - { - if (outputPath.getValue().size() == 0) { - ExitOnError("No output path provided.\n"); + const ImageQuantized imageHiRes{ surfaceRgb }; + + // Preview + if (preview.getValue()) + { + if (assembly.getValue() == true) + { + std::cout << "\nIgnoring --asm option.\n"; + } + const auto bytes = imageHiRes.getHiresBuffer(); + Display::Window::GetInstance()->display(filepath, bytes->data()); + } + // Convertion to disk + else + { + if (outputPath.getValue().size() == 0) { + ExitOnError("No output path provided.\n"); + } + + if (assembly.getValue() == true) { //Ouput in ASM + ofstream output(outputPath.getValue()); + output << imageHiRes.getHiresAsm(); + } + else { //Binary output + ofstream output(outputPath.getValue(), ios::binary); + const auto bytes = imageHiRes.getHiresBuffer(); + output.write(reinterpret_cast(bytes.get()), bytes->size()); + } } - if (assembly.getValue() == true) { //Ouput in ASM - ofstream output(outputPath.getValue()); - output << imageHiRes.getHiresAsm(); - } - else { //Binary output - ofstream output(outputPath.getValue(), ios::binary); - const auto bytes = imageHiRes.getHiresBuffer(); - output.write(reinterpret_cast(bytes.get()), bytes->size()); - } + } + catch (const std::exception& e) + { + ExitOnError(e.what(), surfaces); } for (auto surface : surfaces) diff --git a/Rgb2Hires_PC/src/App_Tile.cpp b/Rgb2Hires_PC/src/App_Tile.cpp index 0ce5898..25c9274 100644 --- a/Rgb2Hires_PC/src/App_Tile.cpp +++ b/Rgb2Hires_PC/src/App_Tile.cpp @@ -89,22 +89,29 @@ int main( int argc, char *argv[] ) const auto filepath = imagePath.getValue(); if (!exists(filepath)) { - throw runtime_error("Cannot read " + filepath); + ExitOnError("Cannot read " + filepath); } - std::vector surfaces; - SDL_Surface* surfaceRgb = IMG_Load(filepath.c_str()); - surfaces.push_back(surfaceRgb); - if (surfaceRgb == nullptr) - { - ExitOnError("Cannot decode " + filepath, surfaces); - } - const ImageQuantized imageHiRes{ surfaceRgb }; - const auto tileHiRes = imageHiRes.getTile(column.getValue(), line.getValue()); - - // Always output in asm - ofstream output(outputPath.getValue()); - output << tileHiRes; + std::vector surfaces; + try + { + SDL_Surface* surfaceRgb = IMG_Load(filepath.c_str()); + surfaces.push_back(surfaceRgb); + if (surfaceRgb == nullptr) + { + ExitOnError("Cannot decode " + filepath, surfaces); + } + const ImageQuantized imageHiRes{ surfaceRgb }; + const auto tileHiRes = imageHiRes.getTile(column.getValue(), line.getValue()); + + // Always output in asm + ofstream output(outputPath.getValue()); + output << tileHiRes; + } + catch (const std::exception& e) + { + ExitOnError(e.what(), surfaces); + } for (auto surface : surfaces) { diff --git a/Rgb2Hires_PC/src/HiRes.h b/Rgb2Hires_PC/src/HiRes.h index ad5a54a..cc70303 100644 --- a/Rgb2Hires_PC/src/HiRes.h +++ b/Rgb2Hires_PC/src/HiRes.h @@ -25,7 +25,7 @@ #include #include -#include +#include namespace RgbToHires {