6#include "dawn/prog/saturate.hxx"
11#include "dawn/debug.hxx"
12#include "dawn/io/common.hxx"
13#include "dawn/io/ddata.hxx"
20static T bound(uint32_t raw,
bool set, T limit)
22 return set ?
static_cast<T
>(
static_cast<int32_t
>(raw)) : limit;
27static float bound(uint32_t raw,
bool set,
float limit)
32static double bound(uint32_t raw,
bool set,
double limit)
46 DAWNERR(
"saturate: invalid config size %u\n", item->
cfgid.
s.
size);
54 minRaw = item->
data[0];
61 maxRaw = item->
data[0];
75 if (data ==
nullptr || len != 1)
104 const size_t items = data->
getItems();
106 const size_t first = data->
getBatch() - batches;
110 for (
size_t b = 0; b < batches; b++)
112 for (
size_t i = 0; i < items; i++)
114 outputData->
get<T>(i, b) = std::min(std::max(data->
get<T>(i, first + b), lo), hi);
125 const uint32_t lo = minRaw;
126 const uint32_t hi = maxRaw;
133 DAWNERR(
"saturate: output dtype %d differs from input dtype %d\n",
141#ifdef CONFIG_DAWN_DTYPE_BOOL
145 data, outputData, bound<uint8_t>(lo, hasMin, 0), bound<uint8_t>(hi, hasMax, 1));
150#ifdef CONFIG_DAWN_DTYPE_INT8
155 bound<int8_t>(lo, hasMin, INT8_MIN),
156 bound<int8_t>(hi, hasMax, INT8_MAX));
161#ifdef CONFIG_DAWN_DTYPE_UINT8
165 data, outputData, bound<uint8_t>(lo, hasMin, 0), bound<uint8_t>(hi, hasMax, UINT8_MAX));
170#ifdef CONFIG_DAWN_DTYPE_INT16
175 bound<int16_t>(lo, hasMin, INT16_MIN),
176 bound<int16_t>(hi, hasMax, INT16_MAX));
181#ifdef CONFIG_DAWN_DTYPE_UINT16
184 clamp<uint16_t>(data,
186 bound<uint16_t>(lo, hasMin, 0),
187 bound<uint16_t>(hi, hasMax, UINT16_MAX));
192#ifdef CONFIG_DAWN_DTYPE_INT32
197 bound<int32_t>(lo, hasMin, INT32_MIN),
198 bound<int32_t>(hi, hasMax, INT32_MAX));
203#ifdef CONFIG_DAWN_DTYPE_UINT32
206 clamp<uint32_t>(data,
208 bound<uint32_t>(lo, hasMin, 0),
209 bound<uint32_t>(hi, hasMax, UINT32_MAX));
214#ifdef CONFIG_DAWN_DTYPE_B16
221 bound<int32_t>(lo, hasMin, INT32_MIN),
222 bound<int32_t>(hi, hasMax, INT32_MAX));
227#ifdef CONFIG_DAWN_DTYPE_FLOAT
232 bound(lo, hasMin, std::numeric_limits<float>::lowest()),
233 bound(hi, hasMax, std::numeric_limits<float>::max()));
238#ifdef CONFIG_DAWN_DTYPE_DOUBLE
243 bound(lo, hasMin, std::numeric_limits<double>::lowest()),
244 bound(hi, hasMax, std::numeric_limits<double>::max()));
251 DAWNERR(
"saturate: unsupported dtype %d\n", data->
getDtype());
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
int setData(IODataCmn &data, size_t offset=0)
Set data for I/O (public interface with stats tracking).
@ PROG_SATURATE_CFG_MAX
Upper bound.
@ PROG_SATURATE_CFG_MIN
Lower bound.
void handle(CIOCommon *output, io_ddata_t *data, io_ddata_t *ioData, io_ddata_t *outputData, bool &initsample)
Process incoming sample.
int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Pre-update hook for runtime configuration writes.
int configureExtraCfgItem(const CDescObject &desc, const SObjectCfg::SObjectCfgItem *item, size_t &offset)
Parse program-specific config item (optional extension hook).
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
static float cfgToF(ObjectCfgData_t x)
Convert ObjectCfgData_t to float.
static uint8_t objectCfgGetId(const ObjectCfgId objcfg)
Extract configuration identifier from ConfigID.
Out-of-tree user-extension hooks for Dawn.
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
@ DTYPE_FLOAT
IEEE 754 single-precision floating point (32-bit).
@ DTYPE_INT32
Signed 32-bit integer (-2147483648 to 2147483647).
@ DTYPE_UINT8
Unsigned 8-bit integer (0 to 255).
@ DTYPE_INT16
Signed 16-bit integer (-32768 to 32767).
@ DTYPE_INT8
Signed 8-bit integer (-128 to 127).
@ DTYPE_UINT16
Unsigned 16-bit integer (0 to 65535).
@ DTYPE_DOUBLE
IEEE 754 double-precision floating point (64-bit).
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
@ DTYPE_BOOL
Boolean data type (stored in 32-bit container).
@ DTYPE_B16
Signed 16.16 fixed-point (32-bit).
Heap-allocated dynamic I/O data buffer.
uint8_t getDtype() const
Get data type enum for introspection.
size_t getItems()
Get number of items per batch.
T & get(size_t index, size_t batch=0)
Get data element by index and batch (type-safe).
size_t getBatch()
Get number of batches.
uint32_t id
Configuration identifier (bits 0-4, max 31).
struct dawn::SObjectCfg::UObjectCfgId::@334307326077356333363326153167141302007100111136 s
Bit-field structure for named member access.
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).