1
0
Fork 0

source/Graphics/ImageLoader.cpp: load .ico files.

This commit is contained in:
Henrik Hautakoski 2020-10-22 17:08:16 +02:00
parent 37d495fca3
commit acf96a0971

View file

@ -5,6 +5,8 @@
#include <Spectre/Graphics/Image.h>
#include "ImageLoader.h"
#include "Image/IcoFormat.h"
// Disable some file formats that we don't use.
#define STBI_NO_PSD
#define STBI_NO_PIC
@ -50,6 +52,15 @@ bool ImageLoader::loadFromMemory(const void *data, unsigned size, Image& img)
int w, h, n_comp;
const stbi_uc *ptr = (const stbi_uc *) data;
if (ptr[0] == 0x0) {
image::IcoFormat ico;
bool ret = ico.decode(img, ptr, size);
if (!ret) {
m_error = stbi_failure_reason();
}
return ret;
}
unsigned char *pixels = stbi_load_from_memory(ptr, size, &w, &h, &n_comp, 4);
if (pixels) {
@ -103,7 +114,7 @@ bool ImageLoader::encodePNG(const Image& img, std::vector<unsigned char>& data)
unsigned char *raw = (unsigned char*) img.getPixels();
unsigned char *buf;
buf = stbi_write_png_to_mem(raw, img.getStride(), img.getWidth(), img.getHeight(), img.getBpp() / 8, &buf_len);
buf = stbi_write_png_to_mem(raw, img.getStride(), img.getWidth(), img.getHeight(), img.getNumChannels(), &buf_len);
if (buf && buf_len > 0) {
data.resize(buf_len);