Various minor cleanup

This commit is contained in:
emeric
2024-12-05 20:09:14 +01:00
parent 76b9c1fe10
commit 45175a721c
35 changed files with 104 additions and 137 deletions
+1
View File
@@ -19,6 +19,7 @@
#include "SvgImage.hpp"
#include <filesystem>
#include <fstream>
#include "core/ITraceLogger.hpp"
+3 -5
View File
@@ -19,8 +19,6 @@
#pragma once
#include <filesystem>
#include <memory>
#include <vector>
#include "image/IEncodedImage.hpp"
@@ -33,9 +31,9 @@ namespace lms::image
SvgImage(std::vector<std::byte>&& data)
: _data{ std::move(data) } {}
const std::byte* getData() const { return &_data.front(); }
std::size_t getDataSize() const { return _data.size(); }
std::string_view getMimeType() const { return "image/svg+xml"; }
const std::byte* getData() const override { return &_data.front(); }
std::size_t getDataSize() const override { return _data.size(); }
std::string_view getMimeType() const override { return "image/svg+xml"; }
private:
const std::vector<std::byte> _data;
+2 -4
View File
@@ -47,8 +47,7 @@ namespace lms::image::STB
}
}
const std::byte*
JPEGImage::getData() const
const std::byte* JPEGImage::getData() const
{
if (_data.empty())
return nullptr;
@@ -56,8 +55,7 @@ namespace lms::image::STB
return &_data.front();
}
std::size_t
JPEGImage::getDataSize() const
std::size_t JPEGImage::getDataSize() const
{
return _data.size();
}
+2 -2
View File
@@ -45,7 +45,7 @@ namespace lms::image::STB
{
RawImage::RawImage(const std::byte* encodedData, std::size_t encodedDataSize)
{
int n;
int n{};
_data = UniquePtrFree{ ::stbi_load_from_memory(reinterpret_cast<const stbi_uc*>(encodedData), encodedDataSize, &_width, &_height, &n, 3), std::free };
if (!_data)
throw Exception{ "Cannot load image from memory: " + std::string{ ::stbi_failure_reason() } };
@@ -78,7 +78,7 @@ namespace lms::image::STB
width = (size_t)((float)height / _height * _width);
}
UniquePtrFree resizedData{ reinterpret_cast<unsigned char*>(malloc(width * height * 3)), std::free };
UniquePtrFree resizedData{ static_cast<unsigned char*>(malloc(width * height * 3)), std::free };
if (!resizedData)
throw Exception{ "Cannot allocate memory for resized image!" };
+6 -2
View File
@@ -33,6 +33,10 @@ namespace lms::image::STB
RawImage(const std::byte* encodedData, std::size_t encodedDataSize);
RawImage(const std::filesystem::path& path);
~RawImage() override = default;
RawImage(const RawImage&) = delete;
RawImage& operator=(const RawImage&) = delete;
ImageSize getWidth() const override;
ImageSize getHeight() const override;
@@ -42,8 +46,8 @@ namespace lms::image::STB
const std::byte* getData() const;
private:
int _width;
int _height;
int _width{};
int _height{};
using UniquePtrFree = std::unique_ptr<unsigned char, decltype(&std::free)>;
UniquePtrFree _data{ nullptr, std::free };
};
@@ -19,6 +19,8 @@
#pragma once
#include <memory>
#include "image/IEncodedImage.hpp"
namespace lms::image