Symbian platform (C++)
SDK native APIs, runtime and tooling
Loading...
Searching...
No Matches
frame.h
Go to the documentation of this file.
1// Copyright 2026 The Symbian SDK Authors.
2// Licensed under the Apache License, Version 2.0.
3
4#ifndef SYMBIAN_API_CAMERA_FRAME_H_
5#define SYMBIAN_API_CAMERA_FRAME_H_
6
7#include <array>
8#include <cstddef>
9#include <cstdint>
10#include <functional>
11#include <span>
12
13#include <absl/base/nullability.h>
14
15#include "absl/status/status.h"
16#include "absl/status/statusor.h"
17
18namespace symbian::api::camera {
19
20enum class PixelFormat {
21 kGray8,
22 kRgb565,
25 // ECam's packed RGB formats place red in the least significant bits.
26 kBgr565,
28 // Little-endian 16-bit samples. The significant bit count is in bit_depth;
29 // unused high bits are zero. These layouts preserve 10/12/16-bit capture.
30 kGray16,
33 // One 16-bit sample per sensor photosite. This is a raw mosaic, not RGB.
35 // Byte order B, G, R, unused on little-endian EColor16MU bitmap memory.
37};
38
40
48
49// Mapped memory can be an ECam RChunk; a texture or native image remains
50// opaque. No operation silently maps or downloads an opaque image.
52
54 int width = 0;
55 int height = 0;
57 std::array<int, 3> stride_bytes{};
59 // Set to 10..16 for 16-bit sample formats. Zero means the format's fixed
60 // precision. No implicit tone mapping or transfer function is assumed.
61 int bit_depth = 0;
63};
64
66 std::uint64_t sequence = 0;
67 std::int64_t capture_time_ns = 0;
69};
70
71// The producer owns this storage until its frame lease is released. For GLES2,
72// handle is a texture name and device identifies its current GL context;
73// native images use an adapter-defined handle/device pair. Opaque images have
74// empty planes. The ready/completion ordering is the backend's contract.
75struct FrameView {
79 std::array<std::span<const std::byte>, 3> planes{};
80 std::uintptr_t handle = 0;
81 std::uintptr_t device = 0;
82};
83
87 std::array<std::span<std::byte>, 3> planes{};
88 std::uintptr_t handle = 0;
89 std::uintptr_t device = 0;
90};
91
92// A movable frame keeps a native producer buffer borrowed until destruction.
93// Release happens on the thread that destroys the lease. A backend that needs
94// thread affinity must arrange for that destruction on its owning thread.
95class FrameLease final {
96 public:
97 using Release = std::function<void()>;
98
99 FrameLease() = default;
101 FrameLease(const FrameLease&) = delete;
102 FrameLease& operator=(const FrameLease&) = delete;
103 FrameLease(FrameLease&& other) noexcept;
104 FrameLease& operator=(FrameLease&& other) noexcept;
105 ~FrameLease();
106
107 const FrameView& view() const { return view_; }
108
109 void Reset();
110
111 private:
112 FrameView view_;
113 Release release_;
114};
115
117
118// Presentation transform for a fixed camera frame. This changes sampling
119// coordinates only; no rotated source buffer is allocated.
121
122struct FrameRect {
123 int x = 0;
124 int y = 0;
125 int width = 0;
126 int height = 0;
127};
128
129// Detect symmetric, nearly black side margins in a CPU-accessible packed
130// preview frame. Returns the complete frame when the margins are uncertain or
131// the format is unsupported. This is a presentation hint, not a sensor crop.
133
134// Center-crop to the destination aspect ratio, preserving the source's full
135// height for a tall destination or full width for a wide destination.
136absl::StatusOr<FrameRect> CenteredAspectCrop(int source_width,
137 int source_height,
138 int destination_width,
139 int destination_height);
140
141// Fits every source pixel into a destination without changing its aspect
142// ratio. The returned rectangle is centered in destination coordinates.
143absl::StatusOr<FrameRect> CenteredAspectFit(int source_width,
144 int source_height,
145 int destination_width,
146 int destination_height);
147
148// Borrows a rectangular region of a linear or mapped frame without copying.
149// Chroma-subsampled frames require even crop boundaries and dimensions.
150absl::StatusOr<FrameView> CropFrameView(const FrameView& source,
151 FrameRect crop);
152
153// Device backends implement direct texture/native transfers, scaling and
154// synchronization. They may return Unimplemented for unsupported pairs. The
155// caller supplies one when either frame is opaque; linear/mapped frames use
156// the common stride-aware implementation without an intermediate allocation.
158 // The captured backend owner must outlive this view and every transform.
159 std::function<absl::Status(const FrameView&, const MutableFrameView&,
161};
162
163// A nonzero rotation is sampled directly into a linear or mapped RGB565
164// destination, without a rotated source allocation. Opaque frames rotate in
165// their presentation backend (for GLES2, use Gles2TexturePresenter).
166absl::Status TransformFrame(const FrameView& source,
167 const MutableFrameView& destination,
168 ResampleFilter filter,
169 FrameBackend* absl_nullable backend = nullptr,
171
172// Decide whether an already available frame is still useful at the next
173// presentation deadline. This does not own a timer or block a capture thread.
174bool FrameIsFresh(FrameIdentity frame, std::int64_t presentation_time_ns,
175 std::int64_t maximum_age_ns);
176
177} // namespace symbian::api::camera
178
179#endif // SYMBIAN_API_CAMERA_FRAME_H_
const FrameView & view() const
Definition frame.h:107
void Reset()
Definition frame.cc:686
FrameLease(const FrameLease &)=delete
FrameLease & operator=(const FrameLease &)=delete
std::function< void()> Release
Definition frame.h:97
~FrameLease()
Definition frame.cc:682
Definition camera.cc:9
ResampleFilter
Definition frame.h:116
PixelFormat
Definition frame.h:20
BayerPattern
Definition frame.h:39
absl::StatusOr< FrameView > CropFrameView(const FrameView &source, FrameRect crop)
Definition frame.cc:814
FrameRect DetectSolidSideMargins(const FrameView &source)
Definition frame.cc:694
FrameRotation
Definition frame.h:120
ClockDomain
Definition frame.h:47
absl::Status TransformFrame(const FrameView &source, const MutableFrameView &destination, ResampleFilter filter, FrameBackend *absl_nullable backend, FrameRotation rotation)
Definition frame.cc:848
MemoryKind
Definition frame.h:51
absl::StatusOr< FrameRect > CenteredAspectFit(int source_width, int source_height, int destination_width, int destination_height)
Definition frame.cc:788
absl::StatusOr< FrameRect > CenteredAspectCrop(int source_width, int source_height, int destination_width, int destination_height)
Definition frame.cc:761
YuvEncoding
Definition frame.h:41
bool FrameIsFresh(FrameIdentity frame, std::int64_t presentation_time_ns, std::int64_t maximum_age_ns)
Definition frame.cc:980
std::function< absl::Status(const FrameView &, const MutableFrameView &, ResampleFilter)> transform
Definition frame.h:160
std::int64_t capture_time_ns
Definition frame.h:67
ClockDomain clock
Definition frame.h:68
std::uint64_t sequence
Definition frame.h:66
int height
Definition frame.h:55
BayerPattern bayer
Definition frame.h:62
int width
Definition frame.h:54
PixelFormat format
Definition frame.h:56
YuvEncoding yuv
Definition frame.h:58
int bit_depth
Definition frame.h:61
std::array< int, 3 > stride_bytes
Definition frame.h:57
Definition frame.h:122
int x
Definition frame.h:123
int height
Definition frame.h:126
int y
Definition frame.h:124
int width
Definition frame.h:125
Definition frame.h:75
FrameLayout layout
Definition frame.h:76
std::array< std::span< const std::byte >, 3 > planes
Definition frame.h:79
std::uintptr_t device
Definition frame.h:81
MemoryKind memory
Definition frame.h:78
std::uintptr_t handle
Definition frame.h:80
FrameIdentity identity
Definition frame.h:77
std::uintptr_t device
Definition frame.h:89
std::uintptr_t handle
Definition frame.h:88
std::array< std::span< std::byte >, 3 > planes
Definition frame.h:87
MemoryKind memory
Definition frame.h:86
FrameLayout layout
Definition frame.h:85