charcoal/OpenGLEngine/ImageLoader.h

50 lines
989 B
C++

#pragma once
#include <vector>
namespace charcoal
{
namespace image_loader
{
struct ImageRGBA
{
std::vector<unsigned char> data;
unsigned int width;
unsigned int height;
void get_pixel(
unsigned int x,
unsigned int y,
unsigned char& red,
unsigned char& green,
unsigned char& blue,
unsigned char& alpha
) const
{
unsigned int target_index = (y * width + x) * 4;
red = data[target_index + 0];
green = data[target_index + 1];
blue = data[target_index + 2];
alpha = data[target_index + 3];
}
void set_pixel(
unsigned int x,
unsigned int y,
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha
)
{
unsigned int target_index = (y * width + x) * 4;
data[target_index + 0] = red;
data[target_index + 1] = green;
data[target_index + 2] = blue;
data[target_index + 3] = alpha;
}
};
ImageRGBA load_file(const std::string& filename);
}
}