1
0
Fork 0

source/Graphics: do not prefix standard c functions with "std::", also include the right files.

This commit is contained in:
Henrik Hautakoski 2019-05-31 20:14:47 +02:00
parent ba11d5002b
commit f3a3a6aa4d
2 changed files with 16 additions and 14 deletions

View file

@ -16,8 +16,9 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include <string.h>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
bool ImageLoader::loadFromFile(const char *filename, Image& img)
@ -34,7 +35,7 @@ bool ImageLoader::loadFromFile(const char *filename, Image& img)
// loaded into memory. now decode.
if (decode((const char*)&buf[0], buf.size(), img) == false) {
log("ImageLoader: could not load file '%s'. Reason: %s",
log("ImageLoader: could not load file '%s'. Reason: %s",
filename, m_error);
return false;
}
@ -42,7 +43,7 @@ bool ImageLoader::loadFromFile(const char *filename, Image& img)
}
log("ImageLoader: could not open file '%s'. Reason: %s",
filename, std::strerror(errno));
filename, strerror(errno));
return false;
}
@ -50,7 +51,7 @@ bool ImageLoader::loadFromMemory(const void *data, unsigned size, Image& img)
{
//std::vector<unsigned char> buf;
//buf.assign(((unsigned char*) data), ((unsigned char*) data) + size);
//buf.assign(((unsigned char*) data), ((unsigned char*) data) + size);
return decode((const char*) data, size, img);
}
@ -64,7 +65,7 @@ bool ImageLoader::saveToFile(const Image& img, const char *filename)
if (ext == "png") {
if (!encodePNG(img, encoded_data)) {
log("ImageLoader: failed to save file '%s'. Reason: \n",
log("ImageLoader: failed to save file '%s'. Reason: \n",
filename, m_error);
}
@ -118,9 +119,9 @@ bool ImageLoader::encodePNG(const Image& img, std::vector<unsigned char>& data)
buf = stbi_write_png_to_mem(raw, img.getStride(), img.getWidth(), img.getHeight(), img.getBpp() / 8, &buf_len);
if (buf && buf_len > 0) {
data.resize(buf_len);
std::memcpy(&data[0], buf, buf_len);
memcpy(&data[0], buf, buf_len);
STBIW_FREE(buf);
return true;