first successful print of gibberish

This commit is contained in:
2023-09-24 11:49:57 +02:00
parent 29a609e855
commit 7905f37150
5 changed files with 71 additions and 36 deletions

View File

@@ -20,6 +20,7 @@
#include "Bitmap.hpp"
#include <algorithm>
#include <spdlog/spdlog.h>
#include <iterator>
#include <optional>
@@ -40,6 +41,17 @@ uint16_t Bitmap<T>::getHeight() {
return mHeight;
}
template <class T>
bool Bitmap<T>::setPixels(const std::vector<T>& pixels) {
if (pixels.size() != mPixels.size()) {
spdlog::error("Invalid pixel buffer size.");
return false;
}
mPixels = pixels;
return true;
}
template <class T>
std::optional<std::vector<T>> Bitmap<T>::getLine(uint16_t line) {
if (line >= mHeight) {
@@ -53,22 +65,22 @@ std::optional<std::vector<T>> Bitmap<T>::getLine(uint16_t line) {
}
template <class T>
std::optional<std::vector<T>> Bitmap<T>::getRow(uint16_t row) {
if (row >= mWidth) {
std::optional<std::vector<T>> Bitmap<T>::getCol(uint16_t col) {
if (col >= mWidth) {
// out of bound
return std::nullopt;
}
// first pixel is always beginning of the row
std::vector<T> rowPixels(mHeight);
auto it = mPixels.begin() + row;
// first pixel is always beginning of the col
std::vector<T> colPixels(mHeight);
auto it = mPixels.begin() + col;
for (auto& rowElement : rowPixels) {
rowElement = *it;
for (auto& colElement : colPixels) {
colElement = *it;
it += mWidth;
}
return rowPixels;
return colPixels;
}
} // namespace ptprnt::graphics