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

@ -1,7 +1,8 @@
#include "ImageLoader.h"
#include <cstring>
#include <Spectre/System/Log.h>
#include <Spectre/Graphics/Image.h>
#include "ImageLoader.h"
static ImageLoader _loader;
@ -93,7 +94,7 @@ unsigned int Image::getBpp() const
case PixelFormat::PF_RGBA : return 32;
case PixelFormat::PF_RGB : return 24;
case PixelFormat::PF_Alpha : return 8;
case PixelFormat::PF_Unknown :
case PixelFormat::PF_Unknown :
default : break;
}
return 0;
@ -154,7 +155,7 @@ Color Image::getPixel(unsigned x, unsigned y) const
{
Color c;
const unsigned char *base = m_pixels.data() + ((getBpp() / 8) * ((y * m_size.x) + x));
// RGB / RGBA formats.
if (m_format == PixelFormat::PF_RGB || m_format == PixelFormat::PF_RGBA) {
c.r = base[0];
@ -165,7 +166,7 @@ Color Image::getPixel(unsigned x, unsigned y) const
} else {
c.a = 255;
}
}
}
// Alpha, single channel format.
else if (m_format == PixelFormat::PF_Alpha) {
c = Color(0, 0, 0, base[0]);
@ -191,12 +192,12 @@ void Image::flipY()
}
}
void Image::setPixels(const void *pixels)
void Image::setPixels(const void *pixels)
{
unsigned int size = m_size.y * getStride();
m_pixels.resize(size);
std::memcpy(&m_pixels[0], pixels, m_pixels.size());
memcpy(&m_pixels[0], pixels, m_pixels.size());
}
const unsigned char* Image::getPixels() const

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;