Refactored namespaces
This commit is contained in:
@@ -12,7 +12,7 @@ target_include_directories(lmsimage PRIVATE
|
||||
)
|
||||
|
||||
target_link_libraries(lmsimage PUBLIC
|
||||
lmsutils
|
||||
lmscore
|
||||
std::filesystem
|
||||
)
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
|
||||
#include "RawImage.hpp"
|
||||
#include "image/Exception.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
#include "core/ILogger.hpp"
|
||||
|
||||
namespace Image::GraphicsMagick
|
||||
namespace lms::image::GraphicsMagick
|
||||
{
|
||||
JPEGImage::JPEGImage(const RawImage& rawImage, unsigned quality)
|
||||
{
|
||||
@@ -37,7 +37,7 @@ namespace Image::GraphicsMagick
|
||||
catch (Magick::Exception& e)
|
||||
{
|
||||
LMS_LOG(COVER, ERROR, "Caught Magick exception: " << e.what());
|
||||
throw ImageException {std::string {"Magick read error: "} + e.what()};
|
||||
throw Exception {std::string {"Magick read error: "} + e.what()};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "image/IEncodedImage.hpp"
|
||||
|
||||
namespace Image::GraphicsMagick
|
||||
namespace lms::image::GraphicsMagick
|
||||
{
|
||||
class RawImage;
|
||||
class JPEGImage : public IEncodedImage
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
#include "JPEGImage.hpp"
|
||||
#include "image/Exception.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
#include "core/ILogger.hpp"
|
||||
|
||||
namespace Image
|
||||
namespace lms::image
|
||||
{
|
||||
std::unique_ptr<IRawImage> decodeImage(const std::byte* encodedData, std::size_t encodedDataSize)
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace Image
|
||||
}
|
||||
}
|
||||
|
||||
namespace Image::GraphicsMagick
|
||||
namespace lms::image::GraphicsMagick
|
||||
{
|
||||
|
||||
RawImage::RawImage(const std::byte* encodedData, std::size_t encodedDataSize)
|
||||
@@ -73,12 +73,12 @@ RawImage::RawImage(const std::byte* encodedData, std::size_t encodedDataSize)
|
||||
catch (Magick::Warning& e)
|
||||
{
|
||||
LMS_LOG(COVER, WARNING, "Caught Magick warning: " << e.what());
|
||||
throw ImageException {std::string {"Magick read warning: "} + e.what()};
|
||||
throw Exception {std::string {"Magick read warning: "} + e.what()};
|
||||
}
|
||||
catch (Magick::Exception& e)
|
||||
{
|
||||
LMS_LOG(COVER, ERROR, "Caught Magick exception: " << e.what());
|
||||
throw ImageException {std::string {"Magick read error: "} + e.what()};
|
||||
throw Exception {std::string {"Magick read error: "} + e.what()};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,12 +95,12 @@ RawImage::RawImage(const std::filesystem::path& p)
|
||||
catch (Magick::Warning& e)
|
||||
{
|
||||
LMS_LOG(COVER, WARNING, "Caught Magick warning: " << e.what());
|
||||
throw ImageException {std::string {"Magick read warning: "} + e.what()};
|
||||
throw Exception {std::string {"Magick read warning: "} + e.what()};
|
||||
}
|
||||
catch (Magick::Exception& e)
|
||||
{
|
||||
LMS_LOG(COVER, ERROR, "Caught Magick exception: " << e.what());
|
||||
throw ImageException {std::string {"Magick read error: "} + e.what()};
|
||||
throw Exception {std::string {"Magick read error: "} + e.what()};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ RawImage::resize(ImageSize width)
|
||||
catch (Magick::Exception& e)
|
||||
{
|
||||
LMS_LOG(COVER, ERROR, "Caught Magick exception while resizing: " << e.what());
|
||||
throw ImageException {std::string {"Magick resize error: "} + e.what()};
|
||||
throw Exception {std::string {"Magick resize error: "} + e.what()};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,5 +130,5 @@ RawImage::getMagickImage() const
|
||||
return _image;
|
||||
}
|
||||
|
||||
} // namespace Image::GraphicsMagick
|
||||
} // namespace lms::image::GraphicsMagick
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "image/IEncodedImage.hpp"
|
||||
#include "image/IRawImage.hpp"
|
||||
|
||||
namespace Image::GraphicsMagick
|
||||
namespace lms::image::GraphicsMagick
|
||||
{
|
||||
class RawImage : public IRawImage
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "image/Exception.hpp"
|
||||
#include "RawImage.hpp"
|
||||
|
||||
namespace Image::STB
|
||||
namespace lms::image::STB
|
||||
{
|
||||
JPEGImage::JPEGImage(const RawImage& rawImage, unsigned quality)
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace Image::STB
|
||||
if (stbi_write_jpg_to_func(writeCb, &_data, rawImage.getWidth(), rawImage.getHeight(), 3, rawImage.getData(), quality) == 0)
|
||||
{
|
||||
_data.clear();
|
||||
throw ImageException {"Failed to export in jpeg format!"};
|
||||
throw Exception {"Failed to export in jpeg format!"};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "image/IEncodedImage.hpp"
|
||||
|
||||
namespace Image::STB
|
||||
namespace lms::image::STB
|
||||
{
|
||||
class RawImage;
|
||||
class JPEGImage : public IEncodedImage
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#include "image/Exception.hpp"
|
||||
|
||||
namespace Image
|
||||
namespace lms::image
|
||||
{
|
||||
std::unique_ptr<IRawImage> decodeImage(const std::byte* encodedData, std::size_t encodedDataSize)
|
||||
{
|
||||
@@ -51,14 +51,14 @@ namespace Image
|
||||
}
|
||||
}
|
||||
|
||||
namespace Image::STB
|
||||
namespace lms::image::STB
|
||||
{
|
||||
RawImage::RawImage(const std::byte* encodedData, std::size_t encodedDataSize)
|
||||
{
|
||||
int n;
|
||||
_data = UniquePtrFree{ ::stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(encodedData), encodedDataSize, &_width, &_height, &n, 3), std::free };
|
||||
if (!_data)
|
||||
throw ImageException{ "Cannot load image from memory: " + std::string{ ::stbi_failure_reason() } };
|
||||
throw Exception{ "Cannot load image from memory: " + std::string{ ::stbi_failure_reason() } };
|
||||
}
|
||||
|
||||
RawImage::RawImage(const std::filesystem::path& p)
|
||||
@@ -66,7 +66,7 @@ namespace Image::STB
|
||||
int n;
|
||||
_data = UniquePtrFree{ stbi_load(p.string().c_str(), &_width, &_height, &n, 3), std::free };
|
||||
if (!_data)
|
||||
throw ImageException{ "Cannot load image from file: " + std::string{ ::stbi_failure_reason() } };
|
||||
throw Exception{ "Cannot load image from file: " + std::string{ ::stbi_failure_reason() } };
|
||||
}
|
||||
|
||||
void RawImage::resize(ImageSize width)
|
||||
@@ -88,13 +88,13 @@ namespace Image::STB
|
||||
|
||||
UniquePtrFree resizedData{ reinterpret_cast<unsigned char*>(malloc(width * height * 3)), std::free };
|
||||
if (!resizedData)
|
||||
throw ImageException{ "Cannot allocate memory for resized image!" };
|
||||
throw Exception{ "Cannot allocate memory for resized image!" };
|
||||
|
||||
if (::stbir_resize_uint8_srgb(reinterpret_cast<const unsigned char*>(_data.get()), _width, _height, 0,
|
||||
reinterpret_cast<unsigned char*>(resizedData.get()), width, height, 0,
|
||||
3, STBIR_ALPHA_CHANNEL_NONE, 0) == 0)
|
||||
{
|
||||
throw ImageException{ "Failed to resize image:" + std::string{ ::stbi_failure_reason() } };
|
||||
throw Exception{ "Failed to resize image:" + std::string{ ::stbi_failure_reason() } };
|
||||
}
|
||||
|
||||
_data = std::move(resizedData);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "image/IEncodedImage.hpp"
|
||||
#include "image/IRawImage.hpp"
|
||||
|
||||
namespace Image::STB
|
||||
namespace lms::image::STB
|
||||
{
|
||||
class RawImage : public IRawImage
|
||||
{
|
||||
|
||||
@@ -19,16 +19,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/Exception.hpp"
|
||||
#include "core/Exception.hpp"
|
||||
|
||||
namespace Image
|
||||
namespace lms::image
|
||||
{
|
||||
// internal use only
|
||||
class ImageException : public LmsException
|
||||
class Exception : public core::LmsException
|
||||
{
|
||||
public:
|
||||
using LmsException::LmsException;
|
||||
};
|
||||
|
||||
} // namespace Cover
|
||||
} // namespace lms::cover
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <cstddef>
|
||||
#include <string_view>
|
||||
|
||||
namespace Image
|
||||
namespace lms::image
|
||||
{
|
||||
using ImageSize = std::size_t;
|
||||
|
||||
@@ -35,6 +35,5 @@ namespace Image
|
||||
virtual std::size_t getDataSize() const = 0;
|
||||
virtual std::string_view getMimeType() const = 0;
|
||||
};
|
||||
|
||||
} // namespace Cover
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "image/IEncodedImage.hpp"
|
||||
|
||||
namespace Image
|
||||
namespace lms::image
|
||||
{
|
||||
class IRawImage
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user