ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_camera_codec_jpeg_sw.c File Reference

ra8_jpeg_sw adapter for the generic camera codec facade. More...

#include "ra8_camera_codec_jpeg_sw.h"
#include <stddef.h>
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_camera_internal.h"
#include "ra8_err.h"
#include "ra8_jpeg_sw.h"
Include dependency graph for ra8_camera_codec_jpeg_sw.c:

Go to the source code of this file.

Enumerations

enum  camera_jpeg_color_t : int32_t {
  k_camera_jpeg_luma_black = 16 ,
  k_camera_jpeg_chroma_mid = 128 ,
  k_camera_jpeg_luma_scale = 298 ,
  k_camera_jpeg_red_cr = 409 ,
  k_camera_jpeg_green_cb = 100 ,
  k_camera_jpeg_green_cr = 208 ,
  k_camera_jpeg_blue_cb = 516 ,
  k_camera_jpeg_rounding = 128 ,
  k_camera_jpeg_shift = 8 ,
  k_camera_jpeg_u8_max = 255
}
 BT.601 limited-range fixed-point conversion constants. More...

Functions

static uint8_t internal_jpeg_sw_clamp (int32_t component)
 Clamp a signed RGB component to one byte.
static void internal_jpeg_sw_ycbcr_to_rgb (uint8_t y, uint8_t cb, uint8_t cr, uint8_t *output)
 Convert one limited-range YCbCr pixel to packed RGB888.
static void internal_jpeg_sw_read_rgb (const ra8_camera_frame_t *input, uint32_t x, uint32_t y, uint8_t *output)
 Read one source pixel as RGB888.
static void internal_jpeg_sw_prepare_rgb (const ra8_camera_codec_jpeg_sw_state_t *state, const ra8_camera_frame_t *input)
 Nearest-neighbour sample input into the configured RGB workspace.
static ra8_err_t internal_jpeg_sw_encode (void *ctx, const ra8_camera_frame_t *input, const ra8_camera_buffer_t *output_buffer, ra8_camera_frame_t *out_frame)
 Convert and encode one raw frame with ra8_jpeg_sw.
ra8_err_t ra8_camera_codec_jpeg_sw_init (ra8_camera_codec_t *codec, ra8_camera_codec_jpeg_sw_state_t *state, const ra8_camera_codec_jpeg_sw_cfg_t *cfg)
 Bind the software baseline-JPEG encoder backend.

Variables

static const ra8_camera_codec_iface_t s_jpeg_sw_codec_iface
 Software JPEG codec vtable.

Detailed Description

ra8_jpeg_sw adapter for the generic camera codec facade.

Tag
[Ring 4 / Service] {World: NS}

Samples RGB888 or UYVY422 into the configured packed-RGB workspace, delegates baseline-JPEG encoding, and translates the produced byte count into a generic JPEG frame view.

Since
0.1.0

Definition in file ra8_camera_codec_jpeg_sw.c.

Enumeration Type Documentation

◆ camera_jpeg_color_t

enum camera_jpeg_color_t : int32_t

BT.601 limited-range fixed-point conversion constants.

Enumerator
k_camera_jpeg_luma_black 

Limited-range black level.

k_camera_jpeg_chroma_mid 

Neutral chroma level.

k_camera_jpeg_luma_scale 

Fixed-point luma scale.

k_camera_jpeg_red_cr 

Cr contribution to red.

k_camera_jpeg_green_cb 

Cb subtraction from green.

k_camera_jpeg_green_cr 

Cr subtraction from green.

k_camera_jpeg_blue_cb 

Cb contribution to blue.

k_camera_jpeg_rounding 

Fixed-point rounding bias.

k_camera_jpeg_shift 

Fixed-point fractional-bit count.

k_camera_jpeg_u8_max 

Maximum packed RGB channel value.

Definition at line 29 of file ra8_camera_codec_jpeg_sw.c.

Function Documentation

◆ internal_jpeg_sw_clamp()

uint8_t internal_jpeg_sw_clamp ( int32_t component)
static

Clamp a signed RGB component to one byte.

Saturates a fixed-point conversion result into packed RGB range.

Parameters
[in]componentSigned channel value.
Returns
Clamped channel byte.
Return values
0Component was below the packed range.
255Component was above the packed range.
Precondition
component is a completed fixed-point channel calculation.
No global state is required.
Postcondition
The result is in the inclusive range 0..255.
No state is modified.
Note
Thread-safe and deterministic.
Since
0.1.0

Definition at line 57 of file ra8_camera_codec_jpeg_sw.c.

References k_camera_jpeg_u8_max, and RA8_INTERNAL.

Referenced by internal_jpeg_sw_ycbcr_to_rgb().

◆ internal_jpeg_sw_encode()

ra8_err_t internal_jpeg_sw_encode ( void * ctx,
const ra8_camera_frame_t * input,
const ra8_camera_buffer_t * output_buffer,
ra8_camera_frame_t * out_frame )
static

Convert and encode one raw frame with ra8_jpeg_sw.

Converts or samples the input into caller-owned RGB workspace, then writes a baseline JPEG into the per-call output buffer.

Parameters
[in]ctxBound software-JPEG state.
[in]inputValid RGB888 or UYVY422 frame.
[in]output_bufferCaller-owned JPEG destination.
[out]out_frameReceives the encoded JPEG view.
Returns
ra8_err_t Error code.
Return values
k_ra8_okJPEG encoded.
k_ra8_err_null_ptrRequired state, frame, or buffer pointer is NULL.
k_ra8_err_not_supportedInput format is not raw RGB888 or UYVY422.
otherForwarded from ra8_jpeg_sw_encode.
Precondition
Input passes generic frame validation.
Workspace and output buffer do not overlap readable input storage.
Postcondition
On success out_frame->data == output_buffer->data.
On success the returned dimensions match configured output geometry.
Note
Not thread-safe with respect to state workspace or output buffer.
Since
0.1.0

Definition at line 193 of file ra8_camera_codec_jpeg_sw.c.

References ra8_camera_buffer_t::capacity, ra8_camera_codec_jpeg_sw_state_t::cfg, ra8_camera_buffer_t::data, ra8_camera_frame_t::format, internal_jpeg_sw_prepare_rgb(), k_ra8_camera_format_jpeg, k_ra8_camera_format_rgb888, k_ra8_camera_format_uyvy422, k_ra8_err_not_supported, k_ra8_err_null_ptr, k_ra8_ok, ra8_camera_codec_jpeg_sw_cfg_t::output_height, ra8_camera_codec_jpeg_sw_cfg_t::output_width, ra8_camera_codec_jpeg_sw_cfg_t::quality, RA8_INTERNAL, ra8_jpeg_sw_encode(), and ra8_camera_codec_jpeg_sw_cfg_t::rgb_workspace.

◆ internal_jpeg_sw_prepare_rgb()

void internal_jpeg_sw_prepare_rgb ( const ra8_camera_codec_jpeg_sw_state_t * state,
const ra8_camera_frame_t * input )
static

Nearest-neighbour sample input into the configured RGB workspace.

Maps each configured output coordinate into the source frame and materializes a tightly packed RGB image for the JPEG encoder.

Parameters
[in]stateBackend state holding output geometry and workspace.
[in]inputValid RGB888 or UYVY422 input frame.
Precondition
State configuration passed backend initialization.
Input storage remains readable throughout conversion.
Postcondition
The complete configured RGB workspace prefix is initialized.
Input storage and backend configuration are unchanged.
Note
Not thread-safe with respect to the shared workspace.
Since
0.1.0

Definition at line 155 of file ra8_camera_codec_jpeg_sw.c.

References ra8_camera_codec_jpeg_sw_state_t::cfg, ra8_camera_frame_t::height, internal_jpeg_sw_read_rgb(), ra8_camera_codec_jpeg_sw_cfg_t::output_height, ra8_camera_codec_jpeg_sw_cfg_t::output_width, RA8_INTERNAL, ra8_camera_codec_jpeg_sw_cfg_t::rgb_workspace, and ra8_camera_frame_t::width.

Referenced by internal_jpeg_sw_encode().

◆ internal_jpeg_sw_read_rgb()

void internal_jpeg_sw_read_rgb ( const ra8_camera_frame_t * input,
uint32_t x,
uint32_t y,
uint8_t * output )
static

Read one source pixel as RGB888.

Copies RGB input directly or decodes the selected pixel from its shared UYVY chroma pair.

Parameters
[in]inputValid RGB888 or UYVY422 frame.
[in]xSource column.
[in]ySource row.
[out]outputReceives packed red, green, and blue bytes.
Precondition
x < input->width and y < input->height.
output addresses at least three writable bytes.
Postcondition
Exactly three output bytes are written.
Input bytes are unchanged.
Note
Thread-safe with respect to immutable input storage.
Since
0.1.0

Definition at line 123 of file ra8_camera_codec_jpeg_sw.c.

References ra8_camera_frame_t::data, ra8_camera_frame_t::format, internal_jpeg_sw_ycbcr_to_rgb(), k_ra8_camera_format_rgb888, and ra8_camera_frame_t::stride_bytes.

Referenced by internal_jpeg_sw_prepare_rgb().

◆ internal_jpeg_sw_ycbcr_to_rgb()

void internal_jpeg_sw_ycbcr_to_rgb ( uint8_t y,
uint8_t cb,
uint8_t cr,
uint8_t * output )
static

Convert one limited-range YCbCr pixel to packed RGB888.

Applies the integer BT.601 limited-range transform and saturation.

Parameters
[in]yLuma sample.
[in]cbBlue-difference chroma sample.
[in]crRed-difference chroma sample.
[out]outputReceives packed red, green, and blue bytes.
Precondition
output addresses at least three writable bytes.
Input samples are complete unsigned bytes.
Postcondition
Exactly three output bytes are written.
Every output channel is in the inclusive range 0..255.
Note
Thread-safe; uses no mutable shared state.
Since
0.1.0

Definition at line 84 of file ra8_camera_codec_jpeg_sw.c.

References internal_jpeg_sw_clamp(), k_camera_jpeg_blue_cb, k_camera_jpeg_chroma_mid, k_camera_jpeg_green_cb, k_camera_jpeg_green_cr, k_camera_jpeg_luma_black, k_camera_jpeg_luma_scale, k_camera_jpeg_red_cr, k_camera_jpeg_rounding, and k_camera_jpeg_shift.

Referenced by internal_jpeg_sw_read_rgb().

◆ ra8_camera_codec_jpeg_sw_init()

ra8_err_t ra8_camera_codec_jpeg_sw_init ( ra8_camera_codec_t * codec,
ra8_camera_codec_jpeg_sw_state_t * state,
const ra8_camera_codec_jpeg_sw_cfg_t * cfg )
nodiscard

Bind the software baseline-JPEG encoder backend.

Parameters
[out]codecCaller-owned codec handle to bind.
[out]stateCaller-owned backend state to populate.
[in]cfgOutput geometry, quality, and RGB workspace.
Returns
ra8_err_t Error code.
Return values
k_ra8_okCodec bound.
k_ra8_err_null_ptrAn argument or cfg->rgb_workspace was NULL.
k_ra8_err_invalid_argQuality or output geometry was invalid.
k_ra8_err_invalid_sizeRGB workspace was too small.
Precondition
codec and state out-live every codec operation.
No other call mutates them while encoding.
Postcondition
On success RGB888 and UYVY422 inputs can be encoded as JPEG.
On error codec and state are unchanged.
Note
Independent state objects are thread-safe; ra8_jpeg_sw_encode is re-entrant.
Since
0.1.0

Definition at line 250 of file ra8_camera_codec_jpeg_sw.c.

References ra8_camera_codec_jpeg_sw_state_t::cfg, ra8_camera_codec_t::ctx, ra8_camera_codec_t::iface, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_err_null_ptr, k_ra8_jpeg_sw_quality_max, k_ra8_jpeg_sw_quality_min, k_ra8_ok, ra8_camera_codec_jpeg_sw_cfg_t::output_height, ra8_camera_codec_jpeg_sw_cfg_t::output_width, ra8_camera_codec_jpeg_sw_cfg_t::quality, ra8_camera_codec_jpeg_sw_cfg_t::rgb_workspace, ra8_camera_codec_jpeg_sw_cfg_t::rgb_workspace_capacity, and s_jpeg_sw_codec_iface.

Referenced by c6_cam_camera_init().

Variable Documentation

◆ s_jpeg_sw_codec_iface

const ra8_camera_codec_iface_t s_jpeg_sw_codec_iface
static
Initial value:
= {
}
static ra8_err_t internal_jpeg_sw_encode(void *ctx, const ra8_camera_frame_t *input, const ra8_camera_buffer_t *output_buffer, ra8_camera_frame_t *out_frame)
Convert and encode one raw frame with ra8_jpeg_sw.

Software JPEG codec vtable.

Definition at line 246 of file ra8_camera_codec_jpeg_sw.c.

Referenced by ra8_camera_codec_jpeg_sw_init().