Skip to content

Commit

Permalink
meta: remove support for imagemagick
Browse files Browse the repository at this point in the history
  • Loading branch information
cthbleachbit committed Jun 5, 2024
1 parent 721f959 commit 8457800
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 39 deletions.
1 change: 0 additions & 1 deletion .ci/linux-mingw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja \
-DSYSTEM_NBTP=OFF \
-DCMAKE_INSTALL_PREFIX=/ \
-DUSE_GRAPHICSMAGICK=ON \
-DUSE_CCACHE=ON \
-DMINEMAP_ENABLE_LTO=ON \
-DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}"/scripts/buildsystems/vcpkg.cmake \
Expand Down
14 changes: 4 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ else ()
endif ()

add_compile_definitions(MINEMAP_APP_VER=\"${CMAKE_PROJECT_VERSION}\")
option(USE_GRAPHICSMAGICK "Use GraphicsMagick instead of ImageMagick" ON)
option(USE_GETTEXT "Use GNU GetText for localization (Linux / Mac only)" OFF)
option(GLIBCXX_ASSERTIONS "Enable assertions in glibc++ standard library (For debugging use)" OFF)
option(BUILD_TESTS "Build library test harness" OFF)
Expand All @@ -35,16 +34,11 @@ if (USE_GETTEXT)
endif()
endif()

if (USE_GRAPHICSMAGICK)
if (VCPKG_TARGET_TRIPLET)
find_package(unofficial-graphicsmagick CONFIG REQUIRED)
set(ImageMagick_LIBRARIES unofficial::graphicsmagick::graphicsmagick)
else ()
pkg_check_modules(ImageMagick REQUIRED GraphicsMagick++)
endif ()
add_compile_definitions(USE_GM)
if (VCPKG_TARGET_TRIPLET)
find_package(unofficial-graphicsmagick CONFIG REQUIRED)
set(ImageMagick_LIBRARIES unofficial::graphicsmagick::graphicsmagick)
else ()
pkg_check_modules(ImageMagick REQUIRED Magick++-7.Q16HDRI)
pkg_check_modules(ImageMagick REQUIRED GraphicsMagick++)
endif ()

if (WIN32)
Expand Down
4 changes: 0 additions & 4 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ inline void initializeLocale() {
#define VERSION_RANGE _("\t\t\t{:>8} for game version from {} to {}\n")
#define VERSION_OLDER_UNSUPPORTED _("\t\tOlder versions are not supported.\n\n")

#ifdef USE_GM
#define MINEMAP_MAGICK_IMPLEMENTATION "GraphicsMagick"
#else
#define MINEMAP_MAGICK_IMPLEMENTATION "ImageMagick"
#endif
#define VERSION_MESSAGE "Application version " MINEMAP_APP_VER " with " MINEMAP_MAGICK_IMPLEMENTATION

#endif /* MINEMAP_CONSTANTS_H */
29 changes: 5 additions & 24 deletions src/libminemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ namespace Minemap {
NBTP::BytesTag *colors_tag) {
size_t width = input_img.columns();
size_t height = input_img.rows();
#ifdef USE_GM

// FIXME: GraphicsMagick Image::pixelColor() for some reason does not contain alpha channel
bool has_alpha = input_img.matte();
// FIXME: Have to map low level access
const Magick::PixelPacket *input_img_cache = input_img.getConstPixels(0, 0, width, height);
#else
bool has_alpha = input_img.alpha();
#endif

// Count partially transparent pixels
int partially_transparent_count = 0;
Expand All @@ -37,29 +34,17 @@ namespace Minemap {
ssize_t col = i % width;
ssize_t row = i / height;
Magick::Color mapped_pix = mapped_img.pixelColor(col, row);
#ifdef USE_GM

const Magick::PixelPacket *input_pix = input_img_cache + i;
// WTF? Alpha in GM is exactly opposite - alpha = 65535 under 16b <=> transparent
// alpha = 0 <=> completely opaque
// GraphicsMagick - alpha = 65535 under 16b <=> transparent
// alpha = 0 <=> completely opaque
double quantum_alpha = input_pix->opacity;
if (quantum_alpha < TransparentOpacity && quantum_alpha != OpaqueOpacity) {
partially_transparent_count++;
}
// Pixels that are not fully opaque are forced to be fully transparent
bool is_transparent_input = quantum_alpha != 0;
bool is_transparent = has_alpha && is_transparent_input;
#else
Magick::Color input_pix = input_img.pixelColor(col, row);
// Imagemagick 7: alpha = 0 <=> transparent
// alpha = QuantumRange = 65535 <=> fully opaque
auto quantum_alpha = input_img.pixelColor(col, row).quantumAlpha();
if (quantum_alpha < QuantumRange && quantum_alpha > 0.0f) {
partially_transparent_count++;
}
// Pixels that are not fully opaque are forced to be fully transparent
bool is_transparent_input = (quantum_alpha != QuantumRange);
bool is_transparent = has_alpha && is_transparent_input;
#endif

std::optional<MapColorCode> colorCode;
if (is_transparent) {
Expand Down Expand Up @@ -104,11 +89,7 @@ namespace Minemap {
pixel_array[i * 4] = rgb->r;
pixel_array[i * 4 + 1] = rgb->g;
pixel_array[i * 4 + 2] = rgb->b;
#ifdef USE_GM
pixel_array[i * 4 + 3] = colorIndex < 4 ? 0 : MaxRGBDouble;
#else
pixel_array[i * 4 + 3] = colorIndex < 4 ? 0 : 1.0;
#endif
}
return pixel_store;
}
Expand All @@ -118,4 +99,4 @@ namespace Minemap {
const std::shared_ptr<ColorMap> &palette_lookup_table) {
return _clone_tag_to_pixelstore(colors_tag, palette_lookup_table);
}
}
}

0 comments on commit 8457800

Please sign in to comment.