2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
20 #include "image_loader.h"
\r
22 #include <common/exception/Exceptions.h>
\r
23 #include <common/utility/string.h>
\r
25 #if defined(_MSC_VER)
\r
26 #pragma warning (disable : 4714) // marked as __forceinline not inlined
\r
29 #include <boost/exception/errinfo_file_name.hpp>
\r
30 #include <boost/filesystem.hpp>
\r
32 namespace caspar { namespace image {
\r
34 std::shared_ptr<FIBITMAP> load_image(const std::string& filename)
\r
36 if(!boost::filesystem::exists(filename))
\r
37 BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(filename));
\r
39 FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
\r
40 fif = FreeImage_GetFileType(filename.c_str(), 0);
\r
41 if(fif == FIF_UNKNOWN)
\r
42 fif = FreeImage_GetFIFFromFilename(filename.c_str());
\r
44 if(fif == FIF_UNKNOWN || !FreeImage_FIFSupportsReading(fif))
\r
45 BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format."));
\r
47 auto bitmap = std::shared_ptr<FIBITMAP>(FreeImage_Load(fif, filename.c_str(), 0), FreeImage_Unload);
\r
49 if(FreeImage_GetBPP(bitmap.get()) != 32)
\r
51 bitmap = std::shared_ptr<FIBITMAP>(FreeImage_ConvertTo32Bits(bitmap.get()), FreeImage_Unload);
\r
53 BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format."));
\r
59 std::shared_ptr<FIBITMAP> load_image(const std::wstring& filename)
\r
61 return load_image(narrow(filename));
\r