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

UYVY-to-RGB888 conversion and 0/90/180/270 SDRAM image production. More...

#include "cam_image.h"
#include <stdint.h>
#include "ra8_cache.h"
#include "ra8_check.h"
Include dependency graph for cam_image.c:

Go to the source code of this file.

Data Structures

struct  cam_rgb_t
 One RGB888 pixel used while scattering the four orientations. More...

Enumerations

enum  cam_image_align_t : uint32_t { k_cam_image_cache_line_bytes = 32U }
 Cache-line alignment shared by the SDRAM buffers and cache API. More...
enum  cam_image_yuv_coeff_t : int32_t {
  k_cam_yuv_luma_black = 16 ,
  k_cam_yuv_chroma_mid = 128 ,
  k_cam_yuv_luma_scale = 298 ,
  k_cam_yuv_red_cr = 409 ,
  k_cam_yuv_green_cb = 100 ,
  k_cam_yuv_green_cr = 208 ,
  k_cam_yuv_blue_cb = 516 ,
  k_cam_yuv_rounding = 128 ,
  k_cam_yuv_shift = 8
}
 BT.601 limited-range fixed-point YCbCr-to-RGB coefficients. More...

Functions

static uint8_t cam_image_clamp (int32_t component)
 Clamp a signed RGB component to one byte.
static cam_rgb_t cam_image_ycbcr_to_rgb (uint8_t y, uint8_t cb, uint8_t cr)
 Convert one limited-range YCbCr pixel to RGB888.
static void cam_image_scatter (uint32_t x, uint32_t y, cam_rgb_t rgb)
 Write one RGB pixel to all four rotated row-major destinations.
static void cam_image_convert (const uint8_t *uyvy)
 Convert one complete UYVY frame into all four RGB orientations.
static ra8_err_t cam_image_clean_outputs (void)
 Clean all generated RGB views from the data cache.
ra8_err_t cam_image_generate (const uint8_t *uyvy, uint32_t source_bytes)
 Convert one packed Cb-Y0-Cr-Y1 VGA frame into all four RGB views.

Variables

uint8_t g_cam_rgb_0 [k_cam_rgb_frame_bytes]
 Unrotated 640x480 RGB888 image in external SDRAM.
uint8_t g_cam_rgb_90 [k_cam_rgb_frame_bytes]
 Clockwise-90-degree 480x640 RGB888 image in external SDRAM.
uint8_t g_cam_rgb_180 [k_cam_rgb_frame_bytes]
 Clockwise-180-degree 640x480 RGB888 image in external SDRAM.
uint8_t g_cam_rgb_270 [k_cam_rgb_frame_bytes]
 Clockwise-270-degree 480x640 RGB888 image in external SDRAM.
const uint32_t g_cam_rgb_frame_bytes = (uint32_t)k_cam_rgb_frame_bytes
 Stable byte count of each exported RGB888 buffer.

Detailed Description

UYVY-to-RGB888 conversion and 0/90/180/270 SDRAM image production.

Converts one module-owned packed VGA frame into four statically allocated, cache-aligned RGB888 SDRAM views and performs cache maintenance for debugger-side validation.

Tag
[Ring 6 / APP] {World: S}
Since
0.1.0

Definition in file cam_image.c.

Enumeration Type Documentation

◆ cam_image_align_t

enum cam_image_align_t : uint32_t

Cache-line alignment shared by the SDRAM buffers and cache API.

Enumerator
k_cam_image_cache_line_bytes 

Cortex-M85 data-cache line size.

Definition at line 24 of file cam_image.c.

◆ cam_image_yuv_coeff_t

enum cam_image_yuv_coeff_t : int32_t

BT.601 limited-range fixed-point YCbCr-to-RGB coefficients.

Enumerator
k_cam_yuv_luma_black 

Limited-range black luma code.

k_cam_yuv_chroma_mid 

Neutral limited-range chroma code.

k_cam_yuv_luma_scale 

BT.601 fixed-point luma coefficient.

k_cam_yuv_red_cr 

BT.601 red-from-Cr coefficient.

k_cam_yuv_green_cb 

BT.601 green-from-Cb coefficient.

k_cam_yuv_green_cr 

BT.601 green-from-Cr coefficient.

k_cam_yuv_blue_cb 

BT.601 blue-from-Cb coefficient.

k_cam_yuv_rounding 

Fixed-point rounding bias.

k_cam_yuv_shift 

Fixed-point fractional-bit count.

Definition at line 29 of file cam_image.c.

Function Documentation

◆ cam_image_clamp()

uint8_t cam_image_clamp ( int32_t component)
static

Clamp a signed RGB component to one byte.

Saturates negative and over-range fixed-point conversion results.

Parameters
[in]componentSigned RGB channel value.
Returns
Saturated channel byte.
Return values
0The component was negative.
UINT8_MAXThe component exceeded one byte.
Precondition
component is a completed fixed-point conversion result.
No mutable image state is required.
Postcondition
The return value lies in the inclusive byte range.
No global storage is modified.
Note
In-range values are converted without scaling.
Since
0.1.0

Definition at line 73 of file cam_image.c.

Referenced by cam_image_ycbcr_to_rgb().

◆ cam_image_clean_outputs()

ra8_err_t cam_image_clean_outputs ( void )
static

Clean all generated RGB views from the data cache.

Returns
Status of the first failed cache-clean operation.
Return values
k_ra8_okAll four image ranges were cleaned.
Precondition
cam_image_convert populated every RGB view.
Postcondition
Successful completion makes every RGB view visible outside the CPU.
Note
Thread safety: not thread-safe; operates on module-owned buffers.
Since
0.1.0

Definition at line 194 of file cam_image.c.

References g_cam_rgb_0, g_cam_rgb_180, g_cam_rgb_270, g_cam_rgb_90, k_cam_rgb_frame_bytes, ra8_cache_dcache_clean_by_addr(), and RA8_RETURN_ON_ERROR.

Referenced by cam_image_generate().

◆ cam_image_convert()

void cam_image_convert ( const uint8_t * uyvy)
static

Convert one complete UYVY frame into all four RGB orientations.

Parameters
[in]uyvyComplete VGA UYVY source frame.
Precondition
uyvy points to at least k_cam_uyvy_frame_bytes readable bytes.
Postcondition
All four statically allocated RGB buffers contain complete views.
Note
Thread safety: not thread-safe; writes module-owned image buffers.
Since
0.1.0

Definition at line 167 of file cam_image.c.

References cam_image_scatter(), cam_image_ycbcr_to_rgb(), k_cam_image_height_px, and k_cam_image_width_px.

Referenced by cam_image_generate().

◆ cam_image_generate()

ra8_err_t cam_image_generate ( const uint8_t * uyvy,
uint32_t source_bytes )

Convert one packed Cb-Y0-Cr-Y1 VGA frame into all four RGB views.

Performs fixed-point YCbCr conversion and scatters each pixel into caller-observable SDRAM buffers for the four clockwise orientations.

Parameters
[in]uyvySource VGA frame in packed UYVY byte order.
[in]source_bytesValid bytes at uyvy; must equal 614400.
Returns
Error code from validation or cache maintenance.
Return values
k_ra8_okFour complete RGB888 buffers are visible to SWD.
k_ra8_err_null_ptruyvy was NULL.
k_ra8_err_invalid_argsource_bytes was not one VGA UYVY frame.
Precondition
External SDRAM was initialized by ra8_sdramc_init.
uyvy contains a completed, cache-coherent CEU capture.
Postcondition
All four exported buffers contain the same frame at 0/90/180/270.
Dirty D-cache lines covering the four buffers are written to SDRAM.
Note
Rotation angles are clockwise. Not thread-safe.
Since
0.1.0

Definition at line 209 of file cam_image.c.

References cam_image_clean_outputs(), cam_image_convert(), k_cam_uyvy_frame_bytes, k_ra8_err_invalid_arg, and RA8_CHECK_NULL_PTR.

Referenced by cam_finish_verdict().

◆ cam_image_scatter()

void cam_image_scatter ( uint32_t x,
uint32_t y,
cam_rgb_t rgb )
static

Write one RGB pixel to all four rotated row-major destinations.

Computes the 0, 90, 180, and 270 degree row-major offsets once.

Parameters
[in]xSource-frame horizontal coordinate.
[in]ySource-frame vertical coordinate.
[in]rgbPixel value to scatter.
Precondition
x and y are inside the VGA source dimensions.
All four SDRAM output arrays are writable.
Postcondition
Each orientation receives exactly one RGB pixel.
No output byte outside the four computed pixels is modified.
Note
Rotation angles are clockwise.
Since
0.1.0

Definition at line 136 of file cam_image.c.

References cam_rgb_t::blue, g_cam_rgb_0, g_cam_rgb_180, g_cam_rgb_270, g_cam_rgb_90, cam_rgb_t::green, k_cam_image_height_px, k_cam_image_width_px, k_cam_rgb_bytes_per_px, and cam_rgb_t::red.

Referenced by cam_image_convert().

◆ cam_image_ycbcr_to_rgb()

cam_rgb_t cam_image_ycbcr_to_rgb ( uint8_t y,
uint8_t cb,
uint8_t cr )
static

Convert one limited-range YCbCr pixel to RGB888.

Applies fixed-point BT.601-style luma and chroma coefficients.

Parameters
[in]yLimited-range luma byte.
[in]cbBlue-difference chroma byte.
[in]crRed-difference chroma byte.
Returns
Converted RGB pixel.
Return values
cam_rgb_tSaturated red, green, and blue channels.
Precondition
Input components are sampled from one packed UYVY pair.
Fixed-point coefficient constants retain their configured scale.
Postcondition
Each returned channel lies in the byte range.
Input values and global buffers remain unchanged.
Note
Conversion uses integer arithmetic only.
Since
0.1.0

Definition at line 99 of file cam_image.c.

References cam_image_clamp(), k_cam_yuv_blue_cb, k_cam_yuv_chroma_mid, k_cam_yuv_green_cb, k_cam_yuv_green_cr, k_cam_yuv_luma_black, k_cam_yuv_luma_scale, k_cam_yuv_red_cr, k_cam_yuv_rounding, and k_cam_yuv_shift.

Referenced by cam_image_convert().

Variable Documentation

◆ g_cam_rgb_0

uint8_t g_cam_rgb_0[k_cam_rgb_frame_bytes]

Unrotated 640x480 RGB888 image in external SDRAM.

Since
0.1.0

Definition at line 49 of file cam_image.c.

Referenced by cam_image_clean_outputs(), and cam_image_scatter().

◆ g_cam_rgb_180

uint8_t g_cam_rgb_180[k_cam_rgb_frame_bytes]

Clockwise-180-degree 640x480 RGB888 image in external SDRAM.

Since
0.1.0

Definition at line 53 of file cam_image.c.

Referenced by cam_image_clean_outputs(), and cam_image_scatter().

◆ g_cam_rgb_270

uint8_t g_cam_rgb_270[k_cam_rgb_frame_bytes]

Clockwise-270-degree 480x640 RGB888 image in external SDRAM.

Since
0.1.0

Definition at line 55 of file cam_image.c.

Referenced by cam_image_clean_outputs(), and cam_image_scatter().

◆ g_cam_rgb_90

uint8_t g_cam_rgb_90[k_cam_rgb_frame_bytes]

Clockwise-90-degree 480x640 RGB888 image in external SDRAM.

Since
0.1.0

Definition at line 51 of file cam_image.c.

Referenced by cam_image_clean_outputs(), and cam_image_scatter().

◆ g_cam_rgb_frame_bytes

const uint32_t g_cam_rgb_frame_bytes = (uint32_t)k_cam_rgb_frame_bytes

Stable byte count of each exported RGB888 buffer.

Since
0.1.0

Definition at line 57 of file cam_image.c.

Referenced by cam_finish_verdict().