GUI/src/Image.cpp

30 lines
1006 B
C++

#include <FL/fl_draw.H>
#include <vkvm.hpp>
#include "Image.hpp"
/** Image
* The Image-class draws the bitmap that it get from the Shared Memory.
* @param *buf: A pointer to the bitmap, that the image-class has to draw. Three chars are needed to get the RGB-value of a pixel, so the size equals window_height * window_width * 3.
*/
//Function to draw a bitmap
auto Image::draw() -> void {
fl_draw_image(buf, x(), y(), w(), h());
}
Image::Image(int x, int y, int w, int h) :
Fl_Widget(x, y, w, h, nullptr) {
buf = new uchar[w * h * 3];
}
/*A function to change the colors of the image-class. It reads the colors from the Shared Memory-Class*/
auto Image::getPixels() -> void {
for (int i = 0; i < h(); i++) {
for (int j = 0; j < w(); j++) {
vkvm::Color c = vkvm::getPixel(j, i);
buf[(i * w() + j) * 3 + 0] = c.getRed();
buf[(i * w() + j) * 3 + 1] = c.getGreen();
buf[(i * w() + j) * 3 + 2] = c.getBlue();
}
}
}