The open imaging DSP library
Loading...
Searching...
No Matches
op.h
1
7#ifndef MPIX_OPERATION_H
8#define MPIX_OPERATION_H
9
10#include <assert.h>
11#include <stdbool.h>
12#include <stdio.h>
13
14#include <mpix/formats.h>
15#include <mpix/port.h>
16#include <mpix/ring.h>
17#include <mpix/utils.h>
18
31 const uint8_t *name;
33 uint32_t format_src;
35 uint32_t format_dst;
37 uint16_t width;
39 uint16_t height;
41 uint16_t line_offset;
43 uint16_t window_size;
45 uint16_t threshold;
47 bool is_heap;
51 void (*run)(struct mpix_base_op *op);
53 uint32_t start_time_us;
55 uint32_t total_time_us;
56};
57
63static inline size_t mpix_op_pitch(struct mpix_base_op *op)
64{
65 return op->width * mpix_bits_per_pixel(op->format_src) / BITS_PER_BYTE;
66}
67
76static inline void *mpix_op_by_format(void *list, uint32_t format_src, uint32_t format_dst)
77{
78 struct mpix_base_op **op_list = list;
79
80 for (size_t i = 0; op_list[i] != NULL; i++) {
81 if (op_list[i]->format_src == format_src &&
82 op_list[i]->format_dst == format_dst) {
83 return op_list[i];
84 }
85 }
86 return NULL;
87}
88
101static inline uint8_t *mpix_op_get_input_bytes(struct mpix_base_op *op, size_t sz)
102{
103 uint8_t *data;
104
105 data = mpix_ring_read(&op->ring, sz);
106 assert(data != NULL /* Asked for more input bytes than available in the buffer */);
107
108 return data;
109}
110
123static inline uint8_t *mpix_op_get_output_bytes(struct mpix_base_op *op, size_t sz)
124{
125 uint8_t *data;
126
127 assert(op->next != NULL /* Missing operation at the end, cannot get output buffer */);
128
129 data = mpix_ring_write(&op->next->ring, sz);
130 assert(data != NULL /* Asked for more output bytes than available in the buffer */);
131
132 return data;
133}
134
145static inline uint8_t *mpix_op_peek_input_bytes(struct mpix_base_op *op, size_t sz)
146{
147 uint8_t *data;
148
149 data = mpix_ring_peek(&op->ring, sz);
150 assert(data != NULL /* Asked for more input bytes than peekable in the buffer */);
151
152 return data;
153}
154
163static inline uint8_t *mpix_op_get_output_line(struct mpix_base_op *op)
164{
165 return mpix_op_get_output_bytes(op, mpix_op_pitch(op->next) * 1);
166}
167
176static inline const uint8_t *mpix_op_get_input_line(struct mpix_base_op *op)
177{
178 return mpix_op_get_input_bytes(op, mpix_op_pitch(op));
179}
180
189static inline uint8_t *mpix_op_peek_input_line(struct mpix_base_op *op)
190{
191 return mpix_op_peek_input_bytes(op, mpix_op_pitch(op->next) * 1);
192}
193
200static inline const uint8_t *mpix_op_get_all_input(struct mpix_base_op *op, size_t *sz)
201{
202 *sz = mpix_ring_tailroom(&op->ring);
203 return mpix_ring_read(&op->ring, *sz);
204}
205
217static inline uint8_t *mpix_op_peek_output(struct mpix_base_op *op, size_t *sz)
218{
219 *sz = mpix_ring_tailroom(&op->ring);
220 return op->ring.data + op->ring.head;
221}
222
223static inline void mpix_op_run(struct mpix_base_op *op)
224{
225 if (op != NULL && op->run != NULL) {
226 /* Start the counter of the next operation */
228
229 while (mpix_ring_total_used(&op->ring) >= op->threshold &&
230 op->line_offset < op->height) {
231 op->run(op);
232 }
233 }
234}
235
244static inline void mpix_op_done(struct mpix_base_op *op)
245{
246 uint32_t done_time_us = mpix_port_get_uptime_us();
247
248 /* Flush the timestamp to the counter */
249 op->total_time_us += (op->start_time_us == 0) ? (0) : (done_time_us - op->start_time_us);
250
251 /* Run the next operation in the chain now that more data is available */
252 mpix_op_run(op->next);
253
254 /* Resuming to this operation, reset the time counter */
256}
257
258#endif
uint32_t mpix_port_get_uptime_us(void)
Get the uptime in microsecond, used to compute performance statistics.
One step of a line operation pipeline.
Definition op.h:27
uint16_t threshold
Definition op.h:45
bool is_heap
Definition op.h:47
uint32_t format_src
Definition op.h:33
struct mpix_base_op * next
Definition op.h:29
uint16_t window_size
Definition op.h:43
uint16_t line_offset
Definition op.h:41
uint16_t width
Definition op.h:37
uint16_t height
Definition op.h:39
struct mpix_ring ring
Definition op.h:49
const uint8_t * name
Definition op.h:31
uint32_t total_time_us
Definition op.h:55
uint32_t format_dst
Definition op.h:35
void(* run)(struct mpix_base_op *op)
Definition op.h:51
uint32_t start_time_us
Definition op.h:53
Ring buffer of pixels.
Definition ring.h:16
uint8_t * data
Definition ring.h:18
size_t head
Definition ring.h:22