/* 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 . */ #pragma once #include #include #include #include "graphics/Bitmap.hpp" namespace ptprnt::graphics { enum class Orientation { LANDSCAPE = 0, // 0 degrees PORTRAIT = 1, // 90 degrees clockwise LANDSCAPE_FLIPPED = 2, // 180 degrees PORTRAIT_FLIPPED = 3 // 270 degrees clockwise (90 counter-clockwise) }; class MonochromeData { public: // Constructors MonochromeData() : stride(0), orientation(Orientation::LANDSCAPE), width(0), height(0) {} MonochromeData(std::vector data, uint32_t stride_bytes, Orientation orient = Orientation::LANDSCAPE, uint32_t w = 0, uint32_t h = 0) : bytes(std::move(data)), stride(stride_bytes), orientation(orient), width(w), height(h) {} // Constructor from grayscale data (replaces old Monochrome class) MonochromeData(const std::vector& grayscale, uint32_t width, uint32_t height, Orientation orient = Orientation::LANDSCAPE); MonochromeData(const std::span grayscale, uint32_t width, uint32_t height, Orientation orient = Orientation::LANDSCAPE); ~MonochromeData() = default; // Copy constructor and assignment MonochromeData(const MonochromeData&) = default; MonochromeData& operator=(const MonochromeData&) = default; // Move constructor and assignment MonochromeData(MonochromeData&&) = default; MonochromeData& operator=(MonochromeData&&) = default; // Configuration methods void setThreshold(uint8_t threshold); void invert(bool shouldInvert); // Get processed monochrome data MonochromeData get(); // Transform the image data to the target orientation void transformTo(Orientation targetOrientation); // Visualize the monochrome data on stdout void visualize() const; // Helper methods for orientation transformations [[nodiscard]] bool getBit(uint32_t x, uint32_t y) const; void setBit(uint32_t x, uint32_t y, bool value); [[nodiscard]] std::vector createRotatedData(Orientation targetOrientation) const; // Public member access for backward compatibility std::vector bytes; uint32_t stride; Orientation orientation; uint32_t width; // Width in pixels uint32_t height; // Height in pixels private: // Processing parameters (for old Monochrome class compatibility) std::vector mPixels; // Original grayscale pixels uint8_t mThreshold = UINT8_MAX / 2; bool mShouldInvert = false; bool mIsProcessed = false; // Flag to indicate if conversion has been done // Helper method to convert grayscale to monochrome void processGrayscaleToMonochrome(); }; // For backward compatibility, create a type alias using Monochrome = MonochromeData; } // namespace ptprnt::graphics