Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
scene_image.hpp
Go to the documentation of this file.
1// SceneImage — retained image / bitmap node.
2//
3// The actual pixel source is provided by the caller as either a decoded
4// RGBA byte buffer (CPU-side) or a path to a file the underlying Canvas
5// backend will decode on demand. The node carries a destination rect;
6// the walker emits the matching
7// `Canvas::draw_image_from_*` call.
8#pragma once
9
11
12#include <cstddef>
13#include <cstdint>
14#include <string>
15#include <vector>
16
17namespace pulp::canvas {
18
19class SceneImage : public SceneNode {
20public:
22
23 void set_rect(float x, float y, float w, float h) {
24 if (x == x_ && y == y_ && w == w_ && h == h_) return;
25 x_ = x; y_ = y; w_ = w; h_ = h;
26 mark_dirty();
27 }
28
29 float x() const { return x_; }
30 float y() const { return y_; }
31 float w() const { return w_; }
32 float h() const { return h_; }
33
37 void set_rgba_pixels(std::vector<uint8_t> rgba, int pixel_width,
38 int pixel_height) {
39 rgba_pixels_ = std::move(rgba);
40 pixel_width_ = pixel_width;
41 pixel_height_ = pixel_height;
42 encoded_bytes_.clear();
43 encoded_key_.clear();
44 file_path_.clear();
45 mark_dirty();
46 }
47
52 void set_encoded_bytes(std::vector<uint8_t> bytes);
53
55 void set_file_path(std::string path) {
56 file_path_ = std::move(path);
57 rgba_pixels_.clear();
58 encoded_bytes_.clear();
59 encoded_key_.clear();
60 pixel_width_ = 0;
61 pixel_height_ = 0;
62 mark_dirty();
63 }
64
65 const std::vector<uint8_t>& rgba_pixels() const { return rgba_pixels_; }
66 const std::vector<uint8_t>& encoded_bytes() const { return encoded_bytes_; }
68 const std::string& encoded_bytes_key() const {
69 return encoded_key_;
70 }
71 const std::string& file_path() const { return file_path_; }
72 int pixel_width() const { return pixel_width_; }
73 int pixel_height() const { return pixel_height_; }
74
75 // ── SceneNode overrides ──────────────────────────────────────────────
76 SceneRect local_bounds() const override { return {x_, y_, w_, h_}; }
77 void paint_geometry(Canvas& canvas) const override;
78
79private:
80 float x_ = 0, y_ = 0, w_ = 0, h_ = 0;
81 std::vector<uint8_t> rgba_pixels_;
82 std::vector<uint8_t> encoded_bytes_;
83 std::string encoded_key_;
84 std::string file_path_;
85 int pixel_width_ = 0;
86 int pixel_height_ = 0;
87};
88
89} // namespace pulp::canvas
Definition canvas.hpp:240
void set_file_path(std::string path)
Attach a path to an encoded image on disk.
Definition scene_image.hpp:55
void set_encoded_bytes(std::vector< uint8_t > bytes)
Attach an encoded image blob (PNG/JPEG bytes).
int pixel_width() const
Definition scene_image.hpp:72
float y() const
Definition scene_image.hpp:30
int pixel_height() const
Definition scene_image.hpp:73
float h() const
Definition scene_image.hpp:32
void set_rgba_pixels(std::vector< uint8_t > rgba, int pixel_width, int pixel_height)
Attach a decoded RGBA byte buffer.
Definition scene_image.hpp:37
float w() const
Definition scene_image.hpp:31
float x() const
Definition scene_image.hpp:29
const std::vector< uint8_t > & encoded_bytes() const
Definition scene_image.hpp:66
void set_rect(float x, float y, float w, float h)
Definition scene_image.hpp:23
SceneImage()
Definition scene_image.hpp:21
const std::string & file_path() const
Definition scene_image.hpp:71
SceneRect local_bounds() const override
Local-coordinate bounding box (pre-transform, pre-opacity).
Definition scene_image.hpp:76
void paint_geometry(Canvas &canvas) const override
Paint this node (and its sub-tree) into canvas.
const std::vector< uint8_t > & rgba_pixels() const
Definition scene_image.hpp:65
const std::string & encoded_bytes_key() const
Lowercase hex SHA-256 of encoded_bytes(); empty when none are set.
Definition scene_image.hpp:68
void mark_dirty()
Mark this node and (recursively) every ancestor dirty.
SceneNode(SceneNodeKind kind)
Definition scene_node.hpp:108
Definition affine_transform.hpp:24
SceneNodeKind
Kind discriminator — keeps dynamic_cast off the hot path.
Definition scene_node.hpp:91
@ image
Definition scene_node.hpp:95
@ path
Definition scene_node.hpp:93
Axis-aligned bounding box used for repaint-rect math.
Definition scene_node.hpp:27