Files
ptprnt/src/graphics/Bitmap.hpp
Moritz Martinius 05cd9d244c
All checks were successful
Build ptprnt / build (push) Successful in 3m41s
Generate labels with pangocairo (#8)
Goal of this PR is to have some basic labels generated with pangocairo
- size of the canvas should be matching the input text and grow/shrink accordingly
- basic formatting options like fontsize and align should be working

Reviewed-on: moritz/ptouch-prnt#8
2025-10-12 20:07:18 +00:00

63 lines
2.0 KiB
C++

/*
ptrnt - print labels on linux
Copyright (C) 2023-2025 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#include <memory>
#include <span>
#include <vector>
namespace ptprnt::graphics {
using ALPHA8 = std::uint8_t; // Alpha only, 8 bit per pixel
using RGBX8 = std::uint32_t; // RGB, least significant byte unused, 8 bit per channel
using RGBA8 = std::uint32_t; // RGB, least significant byte alpha, 8 bit per channel
using ARGB8 = std::uint32_t; // RGB, most significant byte alpha, 8 bit per channel
template <class T>
class Bitmap {
public:
Bitmap(uint16_t width, uint16_t height);
~Bitmap() = default;
Bitmap(const Bitmap&) = default;
Bitmap& operator=(const Bitmap&) = default;
Bitmap(Bitmap&&) = default;
Bitmap& operator=(Bitmap&&) = default;
[[nodiscard]] uint16_t getWidth() const;
[[nodiscard]] uint16_t getHeight() const;
bool setPixels(const std::vector<T>& pixels);
[[nodiscard]] std::vector<T> getPixelsCpy() const;
[[nodiscard]] std::vector<T> getLine(uint16_t line) const;
[[nodiscard]] std::vector<T> getCol(uint16_t col) const;
void visualize() const;
private:
uint16_t mWidth;
uint16_t mHeight;
std::vector<T> mPixels;
};
// force compiler to generate class for type ALPHA8 and RGBX8
template class Bitmap<ALPHA8>;
template class Bitmap<RGBX8>;
} // namespace ptprnt::graphics