added missing files
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "datatypes.cpp"
|
||||
#include "helpers.cpp"
|
||||
|
||||
namespace UwU {
|
||||
// Buffer object - can be a wayland surface or a virtual buffer
|
||||
class Buffer {
|
||||
public:
|
||||
Buffer(uint16_t width, uint16_t height) {
|
||||
uint8_t pixels[width * height * 4];
|
||||
this->pixels = pixels;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->stride = width * 4;
|
||||
}
|
||||
// Buffer(uint8_t* pixels, uint16_t width, uint16_t height, uint16_t stride) {
|
||||
// this->pixels = pixels;
|
||||
// this->width = width;
|
||||
// this->height = height;
|
||||
// this->stride = stride;
|
||||
// }
|
||||
Buffer() {}
|
||||
uint8_t* pixels;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t stride;
|
||||
|
||||
void drawPixel(Coord2 coord, Color color) {
|
||||
size_t i = (size_t)coord.y * stride + (size_t)coord.x * 4;
|
||||
uint8_t b0 = pixels[i + 0];
|
||||
uint8_t g0 = pixels[i + 1];
|
||||
uint8_t r0 = pixels[i + 2];
|
||||
uint8_t b = Helpers::lerp8(b0, color.b, color.a);
|
||||
uint8_t g = Helpers::lerp8(g0, color.g, color.a);
|
||||
uint8_t r = Helpers::lerp8(r0, color.r, color.a);
|
||||
pixels[i + 0] = b; // B
|
||||
pixels[i + 1] = g; // G
|
||||
pixels[i + 2] = r; // R
|
||||
pixels[i + 3] = 0xff; // A
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user