Switched from gil to imagemagick++
This commit is contained in:
+2
-1
@@ -105,5 +105,6 @@ MOSTLYCLEANFILES = \
|
||||
|
||||
endif
|
||||
|
||||
lms_CXXFLAGS=-DBOOST_LOG_DYN_LINK -std=c++11 -Wall -I$(top_srcdir)/third-party -I$(srcdir)/ui -I$(srcdir)/lms-api
|
||||
lms_CXXFLAGS=-std=c++11 -Wall -I$(top_srcdir)/third-party -I$(srcdir)/ui -I$(srcdir)/lms-api $(MAGICKXX_CFLAGS)
|
||||
|
||||
lms_LDADD=$(MAGICKXX_LIBS)
|
||||
|
||||
+56
-42
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
* Copyright (C) 2015 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
@@ -16,65 +16,79 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/gil/image.hpp>
|
||||
#include <boost/gil/typedefs.hpp>
|
||||
#include <boost/gil/extension/io/jpeg_io.hpp>
|
||||
#include <boost/gil/extension/numeric/sampler.hpp>
|
||||
#include <boost/gil/extension/numeric/resample.hpp>
|
||||
#include <boost/gil/extension/io_new/jpeg_all.hpp>
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "CoverArt.hpp"
|
||||
|
||||
|
||||
namespace CoverArt {
|
||||
|
||||
static
|
||||
std::string format_to_magick(Format format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case Format::JPEG: return "JPEG";
|
||||
}
|
||||
|
||||
return "JPEG";
|
||||
}
|
||||
|
||||
std::string format_to_mimeType(Format format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case Format::JPEG: return "JPEG";
|
||||
}
|
||||
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
||||
void
|
||||
CoverArt::init(const char *path)
|
||||
{
|
||||
Magick::InitializeMagick(path);
|
||||
}
|
||||
|
||||
CoverArt::CoverArt(const std::vector<unsigned char>& rawData)
|
||||
{
|
||||
Magick::Blob blob(&rawData[0], rawData.size());
|
||||
_image.read(blob);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CoverArt::scale(std::size_t size)
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
if (!size)
|
||||
return false;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
_image.resize( Magick::Geometry(size, size ) );
|
||||
|
||||
boost::gil::rgb8_image_t source;
|
||||
boost::gil::rgb8_image_t dest(size, size);
|
||||
|
||||
// Read source
|
||||
{
|
||||
std::istringstream iss( std::string(_data.begin(), _data.end()));
|
||||
boost::gil::read_image(iss, source, boost::gil::jpeg_tag());
|
||||
}
|
||||
|
||||
if (source.width() == static_cast<int>(size)
|
||||
&& source.height() == static_cast<int>(size))
|
||||
return true;
|
||||
|
||||
// Resize
|
||||
boost::gil::resize_view(boost::gil::const_view(source),
|
||||
boost::gil::view(dest),
|
||||
boost::gil::bilinear_sampler());
|
||||
|
||||
// Output to dest
|
||||
{
|
||||
std::ostringstream oss;
|
||||
boost::gil::write_view(oss, boost::gil::const_view(dest), boost::gil::jpeg_tag());
|
||||
|
||||
std::string output = oss.str();
|
||||
_data.assign(output.begin(), output.end());
|
||||
}
|
||||
|
||||
res = true;
|
||||
return true;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
catch (Magick::Exception& e)
|
||||
{
|
||||
LMS_LOG(COVER, ERROR) << "Caught exception: " << e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
void
|
||||
CoverArt::getData(std::vector<unsigned char>& data, Format format) const
|
||||
{
|
||||
|
||||
Magick::Image outputImage(_image);
|
||||
|
||||
outputImage.magick( format_to_magick(format));
|
||||
|
||||
Magick::Blob blob;
|
||||
outputImage.write(&blob);
|
||||
|
||||
unsigned char *charBuf = (unsigned char*)blob.data();
|
||||
data.assign( charBuf, charBuf + blob.length() );
|
||||
}
|
||||
|
||||
} // namespace CoverArt
|
||||
|
||||
+15
-11
@@ -23,30 +23,34 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <Magick++.h>
|
||||
|
||||
namespace CoverArt
|
||||
{
|
||||
|
||||
enum class Format
|
||||
{
|
||||
JPEG,
|
||||
};
|
||||
|
||||
std::string format_to_mimeType(Format format);
|
||||
|
||||
class CoverArt
|
||||
{
|
||||
public:
|
||||
typedef std::vector<unsigned char> data_type;
|
||||
static void init(const char *path);
|
||||
|
||||
CoverArt() {}
|
||||
CoverArt(const std::string& mime, const data_type& data) : _mimeType(mime), _data(data) {}
|
||||
|
||||
const std::string& getMimeType() const { return _mimeType; }
|
||||
const data_type& getData() const { return _data; }
|
||||
|
||||
void setMimeType(const std::string& mimeType) { _mimeType = mimeType;}
|
||||
void setData(const data_type& data) { _data = data; }
|
||||
CoverArt(const std::vector<unsigned char>& rawData);
|
||||
|
||||
// Operations on cover arts
|
||||
bool scale(std::size_t size);
|
||||
|
||||
private:
|
||||
// output
|
||||
void getData(std::vector<unsigned char>& data, Format format) const;
|
||||
|
||||
std::string _mimeType;
|
||||
data_type _data;
|
||||
private:
|
||||
Magick::Image _image;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ getFromAvMediaFile(const Av::MediaFile& input, std::size_t nbMaxCovers)
|
||||
std::vector<CoverArt> res;
|
||||
|
||||
for (Av::Picture& picture : input.getAttachedPictures(nbMaxCovers))
|
||||
res.push_back( CoverArt(picture.mimeType, picture.data) );
|
||||
res.push_back( CoverArt(picture.data) );
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -83,8 +83,7 @@ Grabber::getFromDirectory(const boost::filesystem::path& p, std::size_t nbMaxCov
|
||||
while (file.get(c))
|
||||
data.push_back(c);
|
||||
|
||||
// TODO handle other formats
|
||||
res.push_back(CoverArt("image/jpeg", data));
|
||||
res.push_back(CoverArt(data));
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -44,6 +44,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
CoverArt::CoverArt::init(argv[0]);
|
||||
Wt::WServer server(argv[0]);
|
||||
server.setServerConfiguration (argc, argv);
|
||||
|
||||
|
||||
@@ -199,12 +199,9 @@ LmsApplication::handleAuthEvent(void)
|
||||
audio = new Desktop::Audio();
|
||||
|
||||
leftMenu->addItem("Audio", audio);
|
||||
|
||||
#if defined HAVE_VIDEO
|
||||
VideoWidget *videoWidget = new VideoWidget();
|
||||
leftMenu->addItem("Video", videoWidget);
|
||||
leftMenu->addItem("Video", new VideoWidget());
|
||||
#endif
|
||||
|
||||
leftMenu->addItem("Settings", new Settings::Settings());
|
||||
|
||||
// Setup a Right-aligned menu.
|
||||
|
||||
@@ -49,7 +49,6 @@ CoverResource::getDefaultCover(std::size_t size)
|
||||
{
|
||||
// Load default cover art for this size
|
||||
|
||||
CoverArt::CoverArt defaultCover;
|
||||
|
||||
std::vector<unsigned char> data;
|
||||
{
|
||||
@@ -59,8 +58,8 @@ CoverResource::getDefaultCover(std::size_t size)
|
||||
data.push_back(c);
|
||||
}
|
||||
|
||||
defaultCover.setData(data);
|
||||
defaultCover.setMimeType("image/jpeg");
|
||||
CoverArt::CoverArt defaultCover(data);
|
||||
|
||||
defaultCover.scale(size);
|
||||
|
||||
auto res = _defaultCovers.insert(std::make_pair(size, defaultCover));
|
||||
@@ -91,9 +90,12 @@ CoverResource::getUnknownTrackUrl(size_t size) const
|
||||
void
|
||||
CoverResource::putCover(Wt::Http::Response& response, const CoverArt::CoverArt& cover)
|
||||
{
|
||||
response.setMimeType( cover.getMimeType() );
|
||||
BOOST_FOREACH(unsigned char c, cover.getData())
|
||||
response.out().put( c );
|
||||
response.setMimeType( format_to_mimeType(CoverArt::Format::JPEG) );
|
||||
|
||||
std::vector<unsigned char> data;
|
||||
cover.getData(data, CoverArt::Format::JPEG);
|
||||
|
||||
response.out().write(reinterpret_cast<const char *>(&data[0]), data.size());
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
#include <Wt/WMediaPlayer>
|
||||
#include <Wt/WFileResource>
|
||||
|
||||
#include "transcode/Parameters.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
#include "VideoDatabaseWidget.hpp"
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
#include <Wt/WStringListModel>
|
||||
#include <Wt/WString>
|
||||
|
||||
#include "transcode/Parameters.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
|
||||
class VideoParametersDialog : public Wt::WDialog
|
||||
|
||||
Reference in New Issue
Block a user