sp500/letterbox.h File Reference

sp500/letterbox.h File Reference#

Mobilint REGULUS: sp500/letterbox.h File Reference
Mobilint REGULUS v4.1
SP500 DSP API
letterbox.h File Reference

Aspect-preserving resize with constant padding, on the SP500 DSP. More...

#include <sp500/dsp.h>

Go to the source code of this file.

Data Structures

struct  sp500_letterbox_params
 Letterbox geometry and options. More...
struct  sp500_letterbox_result
 Values the DSP computed for a letterbox call. More...

Enumerations

enum  {
  SP500_RESIZE_NEAREST = 0 ,
  SP500_RESIZE_BILINEAR = 1 ,
  SP500_RESIZE_BICUBIC = 2 ,
  SP500_RESIZE_LANCZOS = 3
}
 Interpolation used by the resize, for sp500_letterbox_params::interp. More...

Functions

void sp500_letterbox_params_init (sp500_letterbox_params *params)
 Fill params with the defaults documented above.
sp500_status sp500_letterbox (const sp500_buffer *src, const sp500_letterbox_params *params, sp500_buffer *dst, sp500_letterbox_result *result)
 Letterbox an 8-bit HWC frame on the DSP.

Detailed Description

Aspect-preserving resize with constant padding, on the SP500 DSP.

This is the "letterbox" step that prepares a camera frame as a fixed-size model input. The source is scaled by r = min(dst_w/src_w, dst_h/src_h) so it fits the destination without distortion, and the remaining border is filled with a constant value.

The applied scale and the top-left padding are returned so detections can be mapped back to source coordinates:

src_x = (dst_x - result.pad_x) / result.scale;
src_y = (dst_y - result.pad_y) / result.scale;

Frames are 8-bit interleaved HWC with no row padding: a row is exactly width * channels bytes.

Example
p.src_w = 1920; p.src_h = 1080;
p.dst_w = 640; p.dst_h = 640;
sp500_buffer src = sp500_buffer_wrap(frame, 1920 * 1080 * 3);
if(sp500_letterbox(&src, &p, &dst, &r) == SP500_OK)
{
// dst.data holds the 640x640x3 model input; r.scale / r.pad_x / r.pad_y
// map detections back to the 1920x1080 frame.
}
sp500_buffer sp500_buffer_alloc(uint32_t size, uint32_t alignment)
Allocate a zero-copy buffer in shared memory.
Definition dsp.h:286
@ SP500_OK
Definition dsp.h:87
sp500_status sp500_dsp_open(uint32_t timeout_ms)
Attach to the DSP. Must succeed before any other DSP call.
void sp500_buffer_release(sp500_buffer *buffer)
Release a buffer and reset it to unused.
Definition dsp.h:316
#define SP500_ALIGN_NPU
Alignment to use for a buffer that the NPU also reads or writes.
Definition dsp.h:195
sp500_buffer sp500_buffer_wrap(void *data, uint32_t size)
Wrap memory you already own. The call stages one copy in each direction; nothing is taken over and no...
Definition dsp.h:302
void sp500_letterbox_params_init(sp500_letterbox_params *params)
Fill params with the defaults documented above.
sp500_status sp500_letterbox(const sp500_buffer *src, const sp500_letterbox_params *params, sp500_buffer *dst, sp500_letterbox_result *result)
Letterbox an 8-bit HWC frame on the DSP.
A tensor handed to or received from the DSP.
Definition dsp.h:261
Letterbox geometry and options.
Definition letterbox.h:67
Values the DSP computed for a letterbox call.
Definition letterbox.h:89

Definition in file letterbox.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Interpolation used by the resize, for sp500_letterbox_params::interp.

Enumerator
SP500_RESIZE_NEAREST 0 

nearest neighbour

SP500_RESIZE_BILINEAR 1 

bilinear (the default)

SP500_RESIZE_BICUBIC 2 

bicubic, a = -0.75

SP500_RESIZE_LANCZOS 3 

Lanczos4, 8 tap

Definition at line 51 of file letterbox.h.

Function Documentation

◆ sp500_letterbox()

sp500_status sp500_letterbox ( const sp500_buffer * src,
const sp500_letterbox_params * params,
sp500_buffer * dst,
sp500_letterbox_result * result )

Letterbox an 8-bit HWC frame on the DSP.

Parameters
srcSource frame; at least src_w * src_h * channels bytes.
paramsGeometry and options; see sp500_letterbox_params.
dstDestination frame; at least dst_w * dst_h * channels bytes. Allocating it with sp500_buffer_alloc() lets the NPU consume the model input directly, with no copy.
resultReceives the scale and padding. May be NULL if you do not need to map coordinates back.
Returns
SP500_OK on success. SP500_ERR_INVALID_ARG for a bad parameter, SP500_ERR_BUFFER_TOO_SMALL for an undersized frame, SP500_ERR_UNSUPPORTED for an unknown interpolation, SP500_ERR_NOT_READY if sp500_dsp_open() has not succeeded, SP500_ERR_TIMEOUT or SP500_ERR_DSP if the DSP call failed. result is only meaningful when the call returned SP500_OK.