151{
153
154 boost::system::error_code ec;
155 if (!boost::filesystem::is_regular_file(path, ec))
156 return false;
157
159 if (bytes.empty())
160 return false;
161
162 std::vector<DecodedFrame> frames;
164
167 BOOST_LOG_TRIVIAL(error) << "AnimatedTexture: cannot decode GIF " << path;
168 return false;
169 }
170 } else {
171 wxLogNull no_log;
172 wxImage image;
173 wxMemoryInputStream stream(bytes.data(), bytes.size());
174 if (!image.LoadFile(stream, wxBITMAP_TYPE_ANY) || !image.IsOk()) {
175 BOOST_LOG_TRIVIAL(error) << "AnimatedTexture: cannot decode image " << path;
176 return false;
177 }
178 width = image.GetWidth();
179 height = image.GetHeight();
181 }
182
186 for (DecodedFrame &frame : frames) {
187 auto texture = std::make_unique<GLTexture>();
188
189
190 if (!texture->load_from_raw_data(std::move(frame.rgba), (
unsigned int)
width, (
unsigned int)
height,
false,
191 true)) {
192 BOOST_LOG_TRIVIAL(error) << "AnimatedTexture: cannot upload " << path;
194 return false;
195 }
198 }
199 return true;
200}
int width() const
Definition AnimatedTexture.hpp:37
int height() const
Definition AnimatedTexture.hpp:38
void reset()
Definition AnimatedTexture.cpp:202
int m_width
Definition AnimatedTexture.hpp:54
bool has_gif_signature(const std::vector< unsigned char > &bytes)
Definition AnimatedTexture.cpp:38
bool decode_gif(const std::vector< unsigned char > &bytes, int &width, int &height, std::vector< DecodedFrame > &out)
Definition AnimatedTexture.cpp:75
std::vector< unsigned char > image_to_rgba(const wxImage &image)
Definition AnimatedTexture.cpp:45
std::vector< unsigned char > read_file_bytes(const std::string &path)
Definition AnimatedTexture.cpp:32