API Subsonic: first working version, still WIP (missing commands, no authentication)
This commit is contained in:
+28
-10
@@ -83,15 +83,22 @@ Image::load(boost::filesystem::path p)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Image::scale(std::size_t size)
|
||||
Geometry
|
||||
Image::getSize() const
|
||||
{
|
||||
if (!size)
|
||||
Magick::Geometry geometry {_image.size()};
|
||||
return {geometry.width(), geometry.height()};
|
||||
}
|
||||
|
||||
bool
|
||||
Image::scale(Geometry geometry)
|
||||
{
|
||||
if (geometry.width == 0 || geometry.height == 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
_image.resize( Magick::Geometry(size, size ) );
|
||||
_image.resize( Magick::Geometry(geometry.width, geometry.height ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -105,16 +112,27 @@ Image::scale(std::size_t size)
|
||||
std::vector<uint8_t>
|
||||
Image::save(Format format) const
|
||||
{
|
||||
Magick::Image outputImage(_image);
|
||||
std::vector<uint8_t> res;
|
||||
|
||||
outputImage.magick( format_to_magick(format));
|
||||
try
|
||||
{
|
||||
Magick::Image outputImage(_image);
|
||||
|
||||
Magick::Blob blob;
|
||||
outputImage.write(&blob);
|
||||
outputImage.magick( format_to_magick(format));
|
||||
|
||||
auto begin = static_cast<const uint8_t*>(blob.data());
|
||||
Magick::Blob blob;
|
||||
outputImage.write(&blob);
|
||||
|
||||
return std::vector<uint8_t>(begin, begin + blob.length());
|
||||
auto begin = static_cast<const uint8_t*>(blob.data());
|
||||
std::copy(begin, begin + blob.length(), std::back_inserter(res));
|
||||
return res;
|
||||
}
|
||||
catch (Magick::Exception& e)
|
||||
{
|
||||
LMS_LOG(COVER, ERROR) << "Caught Magick exception during save:" << e.what();
|
||||
res.clear();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Image
|
||||
|
||||
+9
-1
@@ -37,6 +37,12 @@ std::string format_to_mimeType(Format format);
|
||||
|
||||
void init(const char *path);
|
||||
|
||||
struct Geometry
|
||||
{
|
||||
std::size_t width;
|
||||
std::size_t height;
|
||||
};
|
||||
|
||||
class Image
|
||||
{
|
||||
public:
|
||||
@@ -45,8 +51,10 @@ class Image
|
||||
bool load(const std::vector<unsigned char>& rawData);
|
||||
bool load(boost::filesystem::path p);
|
||||
|
||||
Geometry getSize() const;
|
||||
|
||||
// Operations
|
||||
bool scale(std::size_t size);
|
||||
bool scale(Geometry geometry);
|
||||
|
||||
// output
|
||||
std::vector<uint8_t> save(Format format) const;
|
||||
|
||||
Reference in New Issue
Block a user