summaryrefslogtreecommitdiff
path: root/src/image.h
blob: 838180c2c027ef2da851d52c85c4f36916403ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#include <QElapsedTimer>

#include "constants.h"
#include "pixels.h"
#include "typedefs.h"

#define USER_PTR

class Pixels;

// TODO: template
struct Image
{
    Image() = default;
    Image(Image &other) = delete;
    Image(Image &&other) = delete;
    Image &operator=(Image &&other) = default;

    using radxa_row_t = std::array<uint8_t, radxa_raw_img_stride>;
    using radxa_data_t = std::array<radxa_row_t, img_height>;

    using row_t = std::array<uint8_t, img_width>;
    using data_t = std::array<row_t, img_height>;

    using rotated_row_t = std::array<uint8_t, img_height>;
    using column_t = rotated_row_t;
    using rotated_data_t = std::array<column_t, img_width>;

    alignas(128) data_t data;
    alignas(128) rotated_data_t rotated_cw;
    std::optional<Pixels> pixels{};

    uint16_t width{0};
    uint16_t height{0};

    libcamera::PixelFormat pixelFormat{0};
    Counters counters{};
    bool hasInputData{false};
    QElapsedTimer t;

    void rotate();

    // std::shared_ptr<Pixels> sharedPixels();
    // FIXME: is not thread-safe: processing can be triggered from multiple
    // threads at the same time
    Pixels &getPixels();
    void copyFromData(const void* src, size_t size);

    /*!
     * \brief reset - reset counters and invalidate pixels
     */
    void reset();

    static void copy(data_t &dst, const radxa_data_t &src);

private:
    Image &operator=(Image &other) = delete;
};