Mage GM work again

This commit is contained in:
emeric
2022-01-30 21:31:31 +01:00
parent 3049babd41
commit 9cd17d3204
10 changed files with 42 additions and 106 deletions
@@ -19,11 +19,11 @@
#include "JPEGImage.hpp"
#include "Exception.hpp"
#include "RawImage.hpp"
#include "image/Exception.hpp"
#include "utils/Logger.hpp"
namespace CoverArt::GraphicsMagick
namespace Image::GraphicsMagick
{
JPEGImage::JPEGImage(const RawImage& rawImage, unsigned quality)
{
@@ -25,9 +25,9 @@
#include <Magick++.h>
#include "cover/IEncodedImage.hpp"
#include "image/IEncodedImage.hpp"
namespace CoverArt::GraphicsMagick
namespace Image::GraphicsMagick
{
class RawImage;
class JPEGImage : public IEncodedImage
+24 -22
View File
@@ -21,41 +21,43 @@
#include <magick/resource.h>
#include "utils/Logger.hpp"
#include "JPEGImage.hpp"
#include "Exception.hpp"
#include "image/Exception.hpp"
#include "utils/Logger.hpp"
namespace Image::GraphicsMagick
namespace Image
{
std::unique_ptr<IRawImage> decodeImage(const std::byte* encodedData, std::size_t encodedDataSize)
{
return std::make_unique<RawImage>(encodedData, encodedDataSize);
return std::make_unique<GraphicsMagick::RawImage>(encodedData, encodedDataSize);
}
std::unique_ptr<IRawImage> decodeImage(const std::filesystem::path& path)
{
return std::make_unique<RawImage>(path)
return std::make_unique<GraphicsMagick::RawImage>(path);
}
void
init(const std::filesystem::path& path)
{
Magick::InitializeMagick(path.string().c_str());
if (auto nbThreads {MagickLib::GetMagickResourceLimit(MagickLib::ThreadsResource)}; nbThreads != 1)
LMS_LOG(COVER, WARNING) << "Consider setting env var OMP_NUM_THREADS=1 to save resources";
if (!MagickLib::SetMagickResourceLimit(MagickLib::ThreadsResource, 1))
LMS_LOG(COVER, ERROR) << "Cannot set Magick thread resource limit to 1!";
if (!MagickLib::SetMagickResourceLimit(MagickLib::DiskResource, 0))
LMS_LOG(COVER, ERROR) << "Cannot set Magick disk resource limit to 0!";
LMS_LOG(COVER, INFO) << "Magick threads resource limit = " << GetMagickResourceLimit(MagickLib::ThreadsResource);
LMS_LOG(COVER, INFO) << "Magick Disk resource limit = " << GetMagickResourceLimit(MagickLib::DiskResource);
}
}
void
init(const std::filesystem::path& path)
namespace Image::GraphicsMagick
{
Magick::InitializeMagick(path.string().c_str());
if (auto nbThreads {MagickLib::GetMagickResourceLimit(MagickLib::ThreadsResource)}; nbThreads != 1)
LMS_LOG(COVER, WARNING) << "Consider setting env var OMP_NUM_THREADS=1 to save resources";
if (!MagickLib::SetMagickResourceLimit(MagickLib::ThreadsResource, 1))
LMS_LOG(COVER, ERROR) << "Cannot set Magick thread resource limit to 1!";
if (!MagickLib::SetMagickResourceLimit(MagickLib::DiskResource, 0))
LMS_LOG(COVER, ERROR) << "Cannot set Magick disk resource limit to 0!";
LMS_LOG(COVER, INFO) << "Magick threads resource limit = " << GetMagickResourceLimit(MagickLib::ThreadsResource);
LMS_LOG(COVER, INFO) << "Magick Disk resource limit = " << GetMagickResourceLimit(MagickLib::DiskResource);
}
RawImage::RawImage(const std::byte* encodedData, std::size_t encodedDataSize)
{
@@ -28,14 +28,12 @@
#include <cstddef>
#include <filesystem>
#include "cover/IEncodedImage.hpp"
#include "IRawImage.hpp"
#include "image/IEncodedImage.hpp"
#include "image/IRawImage.hpp"
namespace CoverArt::GraphicsMagick
namespace Image::GraphicsMagick
{
void init(const std::filesystem::path& path);
class RawImage : IRawImage
class RawImage : public IRawImage
{
public:
RawImage(const std::byte* encodedData, std::size_t encodedDataSize);
+6
View File
@@ -43,6 +43,12 @@ namespace Image
{
return std::make_unique<STB::RawImage>(path);
}
void
init(const std::filesystem::path& path)
{
}
{
}
namespace Image::STB
@@ -19,6 +19,7 @@
#pragma once
#include <filesystem>
#include <memory>
#include "image/IEncodedImage.hpp"
@@ -33,6 +34,7 @@ namespace Image
virtual std::unique_ptr<IEncodedImage> encodeToJPEG(unsigned quality) const = 0;
};
void init(const std::filesystem::path& path);
std::unique_ptr<IRawImage> decodeImage(const std::byte* encodedData, std::size_t encodedDataSize);
std::unique_ptr<IRawImage> decodeImage(const std::filesystem::path& path);
}