mirror of
https://github.com/audacity/linuxdeploy.git
synced 2025-12-12 16:14:55 -06:00
Replace ImageMagick with CImg
For now, it is known to support JPEG and PNG files. Fixes #3.
This commit is contained in:
parent
ce4abed0fa
commit
76d27a352c
@ -7,8 +7,7 @@ addons:
|
|||||||
packages:
|
packages:
|
||||||
- libboost-regex1.55-dev
|
- libboost-regex1.55-dev
|
||||||
- libboost-filesystem1.55-dev
|
- libboost-filesystem1.55-dev
|
||||||
- libmagick++-dev
|
- cimg-dev
|
||||||
- libmagic-dev
|
|
||||||
- automake # required for patchelf
|
- automake # required for patchelf
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
|||||||
22
cmake/Modules/FindCImg.cmake
Normal file
22
cmake/Modules/FindCImg.cmake
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# required for PNG imported target
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
message(STATUS "Searching for CImg")
|
||||||
|
|
||||||
|
find_path(CIMG_H_DIR
|
||||||
|
NAMES CImg.h
|
||||||
|
HINTS ${CMAKE_INSTALL_PREFIX}
|
||||||
|
PATH_SUFFIXES include include/linux
|
||||||
|
)
|
||||||
|
|
||||||
|
if(NOT CIMG_H_DIR)
|
||||||
|
message(FATAL_ERROR "CImg.h not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(PNG REQUIRED)
|
||||||
|
find_package(JPEG REQUIRED)
|
||||||
|
|
||||||
|
add_library(CImg INTERFACE IMPORTED)
|
||||||
|
set_property(TARGET CImg PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CIMG_H_DIR};${JPEG_INCLUDE_DIR}")
|
||||||
|
set_property(TARGET CImg PROPERTY INTERFACE_LINK_LIBRARIES "PNG::PNG;${JPEG_LIBRARIES}")
|
||||||
|
set_property(TARGET CImg PROPERTY INTERFACE_COMPILE_DEFINITIONS "cimg_display=0;cimg_use_png=1;cimg_use_jpeg=1")
|
||||||
@ -7,10 +7,9 @@ file(GLOB HEADERS ${PROJECT_SOURCE_DIR}/include/linuxdeploy/core/*.h)
|
|||||||
|
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
|
|
||||||
find_package(LibMagic)
|
find_package(LibMagic REQUIRED)
|
||||||
|
|
||||||
find_package(PkgConfig)
|
find_package(CImg REQUIRED)
|
||||||
pkg_check_modules(magick++ REQUIRED IMPORTED_TARGET Magick++)
|
|
||||||
|
|
||||||
message(STATUS "Generating excludelist")
|
message(STATUS "Generating excludelist")
|
||||||
execute_process(
|
execute_process(
|
||||||
@ -19,7 +18,7 @@ execute_process(
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_library(linuxdeploy_core STATIC elf.cpp log.cpp appdir.cpp desktopfile.cpp ${HEADERS})
|
add_library(linuxdeploy_core STATIC elf.cpp log.cpp appdir.cpp desktopfile.cpp ${HEADERS})
|
||||||
target_link_libraries(linuxdeploy_core PUBLIC linuxdeploy_plugin linuxdeploy_util ${BOOST_LIBS} subprocess cpp-feather-ini-parser PkgConfig::magick++ libmagic_static ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(linuxdeploy_core PUBLIC linuxdeploy_plugin linuxdeploy_util ${BOOST_LIBS} subprocess cpp-feather-ini-parser CImg libmagic_static ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_include_directories(linuxdeploy_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
target_include_directories(linuxdeploy_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
target_include_directories(linuxdeploy_core PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
target_include_directories(linuxdeploy_core PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||||
target_compile_definitions(linuxdeploy_core PUBLIC -DBOOST_NO_CXX11_SCOPED_ENUMS)
|
target_compile_definitions(linuxdeploy_core PUBLIC -DBOOST_NO_CXX11_SCOPED_ENUMS)
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
// library headers
|
// library headers
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <Magick++.h>
|
#include <CImg.h>
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <subprocess.hpp>
|
#include <subprocess.hpp>
|
||||||
|
|
||||||
@ -19,6 +19,7 @@
|
|||||||
using namespace linuxdeploy::core;
|
using namespace linuxdeploy::core;
|
||||||
using namespace linuxdeploy::core::log;
|
using namespace linuxdeploy::core::log;
|
||||||
|
|
||||||
|
using namespace cimg_library;
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
|
|
||||||
namespace linuxdeploy {
|
namespace linuxdeploy {
|
||||||
@ -340,44 +341,42 @@ namespace linuxdeploy {
|
|||||||
if (util::strLower(path.filename().extension().string()) == ".svg") {
|
if (util::strLower(path.filename().extension().string()) == ".svg") {
|
||||||
resolution = "scalable";
|
resolution = "scalable";
|
||||||
} else {
|
} else {
|
||||||
Magick::Image image;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
image.read(path.string());
|
CImg<unsigned char> image(path.c_str());
|
||||||
} catch (const Magick::Exception& e) {
|
|
||||||
ldLog() << LD_ERROR << "Magick error: " << e.what() << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto xRes = image.columns();
|
auto xRes = image.width();
|
||||||
auto yRes = image.rows();
|
auto yRes = image.height();
|
||||||
|
|
||||||
if (xRes != yRes) {
|
if (xRes != yRes) {
|
||||||
ldLog() << LD_WARNING << "x and y resolution of icon are not equal:" << path;
|
ldLog() << LD_WARNING << "x and y resolution of icon are not equal:" << path;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolution = std::to_string(xRes) + "x" + std::to_string(yRes);
|
resolution = std::to_string(xRes) + "x" + std::to_string(yRes);
|
||||||
|
|
||||||
// otherwise, test resolution against "known good" values, and reject invalid ones
|
// otherwise, test resolution against "known good" values, and reject invalid ones
|
||||||
const auto knownResolutions = {8, 16, 20, 22, 24, 32, 48, 64, 72, 96, 128, 192, 256, 512};
|
const auto knownResolutions = {8, 16, 20, 22, 24, 32, 48, 64, 72, 96, 128, 192, 256, 512};
|
||||||
|
|
||||||
// assume invalid
|
// assume invalid
|
||||||
bool invalidXRes = true, invalidYRes = true;
|
bool invalidXRes = true, invalidYRes = true;
|
||||||
|
|
||||||
for (const auto res : knownResolutions) {
|
for (const auto res : knownResolutions) {
|
||||||
if (xRes == res)
|
if (xRes == res)
|
||||||
invalidXRes = false;
|
invalidXRes = false;
|
||||||
if (yRes == res)
|
if (yRes == res)
|
||||||
invalidYRes = false;
|
invalidYRes = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invalidXRes) {
|
if (invalidXRes) {
|
||||||
ldLog() << LD_ERROR << "Icon" << path << "has invalid x resolution:" << xRes;
|
ldLog() << LD_ERROR << "Icon" << path << "has invalid x resolution:" << xRes;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invalidYRes) {
|
if (invalidYRes) {
|
||||||
ldLog() << LD_ERROR << "Icon" << path << "has invalid x resolution:" << xRes;
|
ldLog() << LD_ERROR << "Icon" << path << "has invalid x resolution:" << xRes;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (const CImgException& e) {
|
||||||
|
ldLog() << LD_ERROR << "CImg error: " << e.what() << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user