AnimaEngine  1.0.0
Nintendo DS Pokemon Black, White, Black 2, and White 2 sprite extraction and preview toolchain
Macros | Functions
sprite_composer.c File Reference

Implementations of NDS OAM, NCER cell, and NANR animation compositor and affine renderer. More...

#include "sprite_composer.h"
#include "coords.h"
#include <math.h>

Macros

#define M_PI   3.14159265358979323846
 
#define MAX_GLOBAL_OAMS   2048
 
#define COMPOSITE_MARGIN   8
 

Functions

static double NanrScaleToDouble (int scale)
 Converts a NANR fixed-point scale factor to double precision. More...
 
static void Composer_SetParentTransform (GlobalOam *goam, const ComposerTransform *parent_transform)
 Applies parent affine transform context variables to a global OAM sprite definition. More...
 
static void ParentTransformPoint (const GlobalOam *goam, double child_x, double child_y, double *out_x, double *out_y)
 Transforms a local point using the parent layout's scale, rotation, and translation. More...
 
static void ParentInverseTransformPoint (const GlobalOam *goam, double world_x, double world_y, double *out_child_x, double *out_child_y)
 Inverts a world coordinate to its corresponding local coordinate relative to the parent transform. More...
 
static int RoundDoubleToInt (double value)
 Rounds a double precision float value to the nearest integer. More...
 
static void GlobalOamTransformPoint (const GlobalOam *goam, double local_x, double local_y, double *out_x, double *out_y)
 Transforms a local OAM source coordinate to screen/world space by applying local and parent transformations. More...
 
static void GlobalOamInverseTransformPoint (const GlobalOam *goam, double world_x, double world_y, double *out_local_x, double *out_local_y)
 Inverse-transforms a screen/world coordinate back to local OAM texture space. More...
 
static void GlobalOamTransformedBounds (const GlobalOam *goam, double *out_min_x, double *out_min_y, double *out_max_x, double *out_max_y)
 Computes bounds of a global OAM by transforming all four corners into world space. More...
 
static void ApplyType3CoordOffset (const NmcrRecord *record, const NanrFrame *frame, const NcerCell *cell, const CoordFile *coords, int *translate_x, int *translate_y)
 Applies coordinate offset constraints specific to type-3 cells. More...
 
static int BuildGlobalOamsForFrame (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *map, int tick, const char *label, GlobalOam *global_oams, int max_global_oams, const CoordFile *coords, const ComposerTransform *parent_transform)
 Constructs the list of global OAM definitions representing a specific frame. More...
 
static void SortGlobalOams (GlobalOam *global_oams, int global_oam_count)
 Sorts global OAM sprites by priority (depth layering) and original definition index. More...
 
static int SampleGlobalOamColorIndex (const NcgrImage *image, const NclrPalette *palette, const GlobalOam *goam, int src_x, int src_y, int tile_stride)
 Samples a single pixel from the NCGR tile image for a given OAM layout. More...
 
static void BlitGlobalOamToRgbaCanvas (const NcgrImage *image, const NclrPalette *palette, RgbaColor *canvas, int canvas_width, int canvas_height, int world_origin_x, int world_origin_y, const GlobalOam *goam, int tile_stride)
 Blits a transformed OAM to an RGBA destination canvas. More...
 
static void BlitGlobalOamToIndexedCanvas (const NcgrImage *image, const NclrPalette *palette, u8 *canvas, int canvas_width, int canvas_height, int world_origin_x, int world_origin_y, const GlobalOam *goam, int tile_stride)
 Blits a transformed OAM to an indexed 8-bit destination palette index canvas. More...
 
void Composer_ClearPixels (RgbaColor *pixels, int width, int height)
 Fills the RGBA canvas with transparent pixels. More...
 
void Composer_ComputeBoundsWithTransform (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *map, int tick, int *out_min_x, int *out_min_y, int *out_max_x, int *out_max_y, const CoordFile *coords, const ComposerTransform *parent_transform)
 Bounding box calculator with parent timeline transformations. More...
 
void Composer_ComputeBounds (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *map, int tick, int *out_min_x, int *out_min_y, int *out_max_x, int *out_max_y, const CoordFile *coords)
 Calculates the extreme bounding box coordinates for a specific animation frame tick. More...
 
void Composer_ComputeBoundsRange (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *map, int start_frame, int frame_count, int *out_min_x, int *out_min_y, int *out_max_x, int *out_max_y, const CoordFile *coords, int delay_cs)
 Calculates bounding box encapsulating a full range of animation frames. More...
 
int Composer_RenderFrameIndexedWithTransform (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *map, const NcgrImage *ncgr, const NclrPalette *palette, int tick, int tile_stride, int min_x, int min_y, int width, int height, int margin, u8 *out_indices, const CoordFile *coords, const ComposerTransform *parent_transform)
 Composites a transformed frame into an 8bpp color-indexed layout canvas. More...
 
int Composer_RenderFrameIndexed (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *map, const NcgrImage *ncgr, const NclrPalette *palette, int tick, int tile_stride, int min_x, int min_y, int width, int height, int margin, u8 *out_indices, const CoordFile *coords)
 Composites a frame into an indexed 8-bit color-indexed layout canvas. More...
 
int Composer_RenderFrameRgba (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *map, const NcgrImage *ncgr, const NclrPalette *palette, int tick, int tile_stride, const char *label, RgbaColor **out_pixels, int *out_width, int *out_height, const CoordFile *coords)
 Renders a composite frame directly into a 32-bit RGBA pixel array. More...
 
int Composer_CropIndexedFrames (const u8 *frames, int frame_count, int width, int height, u8 **out_frames, int *out_width, int *out_height)
 Crops transparent margins from index-compiled spritesheet animation loops. More...
 
void Composer_ComputeUnionBounds (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *map_a, int map_a_frame_count, const NmcrMap *map_b, int map_b_frame_count, int *out_min_x, int *out_min_y, int *out_max_x, int *out_max_y, const CoordFile *coords, int delay_cs)
 Computes combined bounding box that fits two animation sets sharing a unified canvas space. More...
 
static int Composer_NmarAnimationIsUsable (const NmarFile *nmar, const NmcrFile *nmcr, int animation_index)
 
static int Composer_NmarFrameCount (const NmarFile *nmar, const NmcrFile *nmcr, const NanrFile *nanr, int animation_index, int delay_cs)
 
static void Composer_TransformFromNmarFrame (const NmarFrame *frame, ComposerTransform *out_transform)
 
static int Composer_ComputeTimelineOrMapBounds (const NcerFile *ncer, const NanrFile *nanr, const NmcrFile *nmcr, const NmarFile *nmar, const NmcrMap *fallback_map, int animation_index, int use_timeline, int frame_count, int delay_cs, int *out_min_x, int *out_min_y, int *out_max_x, int *out_max_y, const CoordFile *coords)
 
static int Composer_RenderTimelineOrMapFrame (const NcerFile *ncer, const NanrFile *nanr, const NmcrFile *nmcr, const NmarFile *nmar, const NmcrMap *fallback_map, int animation_index, int use_timeline, const NcgrImage *ncgr, const NclrPalette *palette, int frame_index, int delay_cs, int tile_stride, int min_x, int min_y, int width, int height, int margin, u8 *out_indices, const CoordFile *coords)
 
int Composer_RenderComposedAnimation (const NcerFile *ncer, const NanrFile *nanr, const NmcrMap *idle_map, const NmcrMap *break_map, const NcgrImage *ncgr, const NclrPalette *palette, int idle_repetitions, int tile_stride, int margin, u8 **out_frames, int *out_frame_count, int *out_width, int *out_height, const CoordFile *coords, int delay_cs)
 Renders a complete loop merging a base idle animation and a break sequence. More...
 
int Composer_RenderComposedAnimationTimeline (const NcerFile *ncer, const NanrFile *nanr, const NmcrFile *nmcr, const NmarFile *nmar, const NmcrMap *idle_map, const NmcrMap *break_map, int idle_animation_index, int break_animation_index, const NcgrImage *ncgr, const NclrPalette *palette, int idle_repetitions, int tile_stride, int margin, u8 **out_frames, int *out_frame_count, int *out_width, int *out_height, const CoordFile *coords, int delay_cs)
 Timeline-driven composed loop renderer that applies full parent translation transforms. More...
 
int Composer_ComputeIdleRepetitions (const NanrFile *nanr, const NmcrMap *idle_map)
 Computes optimal number of idle loops before transition so loop length is ~3 seconds. More...
 
int Composer_ComputeNmarIdleRepetitions (const NmarFile *nmar, int animation_index)
 Timeline-driven optimal idle loops counter before playing break sequence. More...
 

Detailed Description

Implementations of NDS OAM, NCER cell, and NANR animation compositor and affine renderer.

Macro Definition Documentation

◆ COMPOSITE_MARGIN

#define COMPOSITE_MARGIN   8

◆ M_PI

#define M_PI   3.14159265358979323846

◆ MAX_GLOBAL_OAMS

#define MAX_GLOBAL_OAMS   2048

Function Documentation

◆ ApplyType3CoordOffset()

static void ApplyType3CoordOffset ( const NmcrRecord record,
const NanrFrame frame,
const NcerCell cell,
const CoordFile coords,
int *  translate_x,
int *  translate_y 
)
static

Applies coordinate offset constraints specific to type-3 cells.

Parameters
recordLayout map record.
frameActive anim timeline frame.
cellActive sprite cell metadata.
coordsCoordinate catalog data.
translate_xPointer to X translation accumulator.
translate_yPointer to Y translation accumulator.

◆ BlitGlobalOamToIndexedCanvas()

static void BlitGlobalOamToIndexedCanvas ( const NcgrImage image,
const NclrPalette palette,
u8 canvas,
int  canvas_width,
int  canvas_height,
int  world_origin_x,
int  world_origin_y,
const GlobalOam goam,
int  tile_stride 
)
static

Blits a transformed OAM to an indexed 8-bit destination palette index canvas.

Parameters
imageNCGR tile data.
paletteNCLR palette data.
canvasDestination index buffer.
canvas_widthCanvas width.
canvas_heightCanvas height.
world_origin_xWorld space origin X.
world_origin_yWorld space origin Y.
goamSource transformed OAM context.
tile_strideNCGR stride width in tiles.

◆ BlitGlobalOamToRgbaCanvas()

static void BlitGlobalOamToRgbaCanvas ( const NcgrImage image,
const NclrPalette palette,
RgbaColor canvas,
int  canvas_width,
int  canvas_height,
int  world_origin_x,
int  world_origin_y,
const GlobalOam goam,
int  tile_stride 
)
static

Blits a transformed OAM to an RGBA destination canvas.

Parameters
imageNCGR tile data.
paletteNCLR palette data.
canvasDestination buffer of RGBA pixels.
canvas_widthCanvas width in pixels.
canvas_heightCanvas height in pixels.
world_origin_xWorld space origin offset X.
world_origin_yWorld space origin offset Y.
goamSource transformed OAM context.
tile_strideNCGR stride width in tiles.

◆ BuildGlobalOamsForFrame()

static int BuildGlobalOamsForFrame ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap map,
int  tick,
const char *  label,
GlobalOam global_oams,
int  max_global_oams,
const CoordFile coords,
const ComposerTransform parent_transform 
)
static

Constructs the list of global OAM definitions representing a specific frame.

Parameters
ncerNCER cell resource.
nanrNANR animation resource.
mapNMCR mapping layout.
tickActive timeline animation tick.
labelOptional debug print prefix.
global_oamsDestination global OAM array.
max_global_oamsMax capacity of OAM array.
coordsCoordinate file database.
parent_transformOptional parent transform attributes.
Returns
Resolved count of global OAM components created.

◆ Composer_ClearPixels()

void Composer_ClearPixels ( RgbaColor pixels,
int  width,
int  height 
)

Fills the RGBA canvas with transparent pixels.

Parameters
pixelsTarget pixel buffer.
widthCanvas width.
heightCanvas height.

◆ Composer_ComputeBounds()

void Composer_ComputeBounds ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap map,
int  tick,
int *  out_min_x,
int *  out_min_y,
int *  out_max_x,
int *  out_max_y,
const CoordFile coords 
)

Calculates the extreme bounding box coordinates for a specific animation frame tick.

Parameters
ncerParsed Cell file.
nanrParsed Animation sequence.
mapScreen layout composite map.
tickCurrent animation frame index/tick.
out_min_xOutput for minimum horizontal bound.
out_min_yOutput for minimum vertical bound.
out_max_xOutput for maximum horizontal bound.
out_max_yOutput for maximum vertical bound.
coordsBattle coordinates offset configuration (unused in placement checks).

◆ Composer_ComputeBoundsRange()

void Composer_ComputeBoundsRange ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap map,
int  start_frame,
int  frame_count,
int *  out_min_x,
int *  out_min_y,
int *  out_max_x,
int *  out_max_y,
const CoordFile coords,
int  delay_cs 
)

Calculates bounding box encapsulating a full range of animation frames.

Parameters
ncerCell metadata.
nanrAnimation sequence.
mapMap layout.
start_frameBeginning index.
frame_countAmount of frames to scan.
out_min_xOutput minimum horizontal coordinate.
out_min_yOutput minimum vertical coordinate.
out_max_xOutput maximum horizontal coordinate.
out_max_yOutput maximum vertical coordinate.
coordsCoordinate metadata anchors.
delay_csBase frame duration delay in centiseconds.

◆ Composer_ComputeBoundsWithTransform()

void Composer_ComputeBoundsWithTransform ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap map,
int  tick,
int *  out_min_x,
int *  out_min_y,
int *  out_max_x,
int *  out_max_y,
const CoordFile coords,
const ComposerTransform parent_transform 
)

Bounding box calculator with parent timeline transformations.

Parameters
ncerCell details.
nanrAnimation details.
mapMap layout.
tickAnimation frame tick.
out_min_xMinimum X coordinate bound output.
out_min_yMinimum Y coordinate bound output.
out_max_xMaximum X coordinate bound output.
out_max_yMaximum Y coordinate bound output.
coordsBattle coordinates.
parent_transformActive parent scaling and rotation matrices.

◆ Composer_ComputeIdleRepetitions()

int Composer_ComputeIdleRepetitions ( const NanrFile nanr,
const NmcrMap idle_map 
)

Computes optimal number of idle loops before transition so loop length is ~3 seconds.

Parameters
nanrAnimation frames sequence.
idle_mapDefault battle idle map.
Returns
Repetitions value (clamped between 1 and 10).

◆ Composer_ComputeNmarIdleRepetitions()

int Composer_ComputeNmarIdleRepetitions ( const NmarFile nmar,
int  animation_index 
)

Timeline-driven optimal idle loops counter before playing break sequence.

Parameters
nmarTimeline track details.
animation_indexLabeled idle animation timeline track index.
Returns
Repetitions count (clamped 1 to 10).

◆ Composer_ComputeTimelineOrMapBounds()

static int Composer_ComputeTimelineOrMapBounds ( const NcerFile ncer,
const NanrFile nanr,
const NmcrFile nmcr,
const NmarFile nmar,
const NmcrMap fallback_map,
int  animation_index,
int  use_timeline,
int  frame_count,
int  delay_cs,
int *  out_min_x,
int *  out_min_y,
int *  out_max_x,
int *  out_max_y,
const CoordFile coords 
)
static

◆ Composer_ComputeUnionBounds()

void Composer_ComputeUnionBounds ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap map_a,
int  map_a_frame_count,
const NmcrMap map_b,
int  map_b_frame_count,
int *  out_min_x,
int *  out_min_y,
int *  out_max_x,
int *  out_max_y,
const CoordFile coords,
int  delay_cs 
)

Computes combined bounding box that fits two animation sets sharing a unified canvas space.

Parameters
ncerCell details.
nanrAnimation details.
map_aFirst map configuration.
map_a_frame_countFrame count of map A.
map_bSecond map configuration.
map_b_frame_countFrame count of map B.
out_min_xOutput minimum X bound.
out_min_yOutput minimum Y bound.
out_max_xOutput maximum X bound.
out_max_yOutput maximum Y bound.
coordsCoordinate metadata anchors.
delay_csBase timeline centisecond step.

◆ Composer_CropIndexedFrames()

int Composer_CropIndexedFrames ( const u8 frames,
int  frame_count,
int  width,
int  height,
u8 **  out_frames,
int *  out_width,
int *  out_height 
)

Crops transparent margins from index-compiled spritesheet animation loops.

Parameters
framesMulti-frame sequential 8bpp color buffer.
frame_countNumber of frames inside the buffer.
widthRaw source canvas width.
heightRaw source canvas height.
out_framesNewly allocated cropped multi-frame indexed buffer output.
out_widthWidth of the cropped bounding box.
out_heightHeight of the cropped bounding box.
Returns
0 on success; negative on invalid bounds or memory exception.

◆ Composer_NmarAnimationIsUsable()

static int Composer_NmarAnimationIsUsable ( const NmarFile nmar,
const NmcrFile nmcr,
int  animation_index 
)
static

◆ Composer_NmarFrameCount()

static int Composer_NmarFrameCount ( const NmarFile nmar,
const NmcrFile nmcr,
const NanrFile nanr,
int  animation_index,
int  delay_cs 
)
static

◆ Composer_RenderComposedAnimation()

int Composer_RenderComposedAnimation ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap idle_map,
const NmcrMap break_map,
const NcgrImage ncgr,
const NclrPalette palette,
int  idle_repetitions,
int  tile_stride,
int  margin,
u8 **  out_frames,
int *  out_frame_count,
int *  out_width,
int *  out_height,
const CoordFile coords,
int  delay_cs 
)

Renders a complete loop merging a base idle animation and a break sequence.

Parameters
ncerCell tables.
nanrAnimation sequences.
idle_mapBattle idle composite map.
break_mapBattle break candidate map.
ncgrTile pixels.
palettePalette data.
idle_repetitionsPre-calculated iterations of the idle loop before playing break.
tile_strideTarget tile stride.
marginSafety boundary padding.
out_framesNewly allocated cropped multi-frame indexed index buffer.
out_frame_countFrame count of generated loop.
out_widthBounded canvas width.
out_heightBounded canvas height.
coordsCoordinates anchors.
delay_csCentisecond duration.
Returns
0 on success; negative on rendering failure.

◆ Composer_RenderComposedAnimationTimeline()

int Composer_RenderComposedAnimationTimeline ( const NcerFile ncer,
const NanrFile nanr,
const NmcrFile nmcr,
const NmarFile nmar,
const NmcrMap idle_map,
const NmcrMap break_map,
int  idle_animation_index,
int  break_animation_index,
const NcgrImage ncgr,
const NclrPalette palette,
int  idle_repetitions,
int  tile_stride,
int  margin,
u8 **  out_frames,
int *  out_frame_count,
int *  out_width,
int *  out_height,
const CoordFile coords,
int  delay_cs 
)

Timeline-driven composed loop renderer that applies full parent translation transforms.

Parameters
ncerCell layouts.
nanrAnimation sequences.
nmcrDirect layouts map file.
nmarHigh-level animation timeline tracks.
idle_mapDefault idle map.
break_mapLabeled break map.
idle_animation_indexLabeled idle NMAR index.
break_animation_indexLabeled break NMAR index.
ncgrIndexed tile sheet.
paletteColor palettes.
idle_repetitionsDesired loops of idle sequence.
tile_strideNCGR stride.
marginBounding padding.
out_framesPointer to cropped multi-frame index buffer output.
out_frame_countFrame count of compiled timeline loop.
out_widthWidth of bounding canvas.
out_heightHeight of bounding canvas.
coordsCoordinates anchors.
delay_csTimeline time step.
Returns
0 on success; negative on rendering failure.

◆ Composer_RenderFrameIndexed()

int Composer_RenderFrameIndexed ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap map,
const NcgrImage ncgr,
const NclrPalette palette,
int  tick,
int  tile_stride,
int  min_x,
int  min_y,
int  width,
int  height,
int  margin,
u8 out_indices,
const CoordFile coords 
)

Composites a frame into an indexed 8-bit color-indexed layout canvas.

Parameters
ncerCells file.
nanrAnimations sequence.
mapLayout mapping.
ncgrCharacter tile image data.
palettePalettes array.
tickActive frame tick.
tile_strideTarget tile stride (e.g. 32).
min_xMinimum horizontal coordinate anchor.
min_yMinimum vertical coordinate anchor.
widthTarget canvas rendering width.
heightTarget canvas rendering height.
marginPixel safety margin size.
out_indicesPreallocated output buffer to receive color index bytes.
coordsCoordinate metadata.
Returns
0 on success; negative on rendering exception.

◆ Composer_RenderFrameIndexedWithTransform()

int Composer_RenderFrameIndexedWithTransform ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap map,
const NcgrImage ncgr,
const NclrPalette palette,
int  tick,
int  tile_stride,
int  min_x,
int  min_y,
int  width,
int  height,
int  margin,
u8 out_indices,
const CoordFile coords,
const ComposerTransform parent_transform 
)

Composites a transformed frame into an 8bpp color-indexed layout canvas.

Parameters
ncerCells file.
nanrAnimations file.
mapMap layout.
ncgrTile pixels.
palettePalettes bank.
tickActive tick.
tile_strideNCGR stride.
min_xHorizontal canvas rendering offset.
min_yVertical canvas rendering offset.
widthCanvas width.
heightCanvas height.
marginCanvas safety padding.
out_indicesOutput destination buffer for indexed color mapping.
coordsCoordinates anchors.
parent_transformActive timeline transforms.
Returns
0 on success; negative on rendering failure.

◆ Composer_RenderFrameRgba()

int Composer_RenderFrameRgba ( const NcerFile ncer,
const NanrFile nanr,
const NmcrMap map,
const NcgrImage ncgr,
const NclrPalette palette,
int  tick,
int  tile_stride,
const char *  label,
RgbaColor **  out_pixels,
int *  out_width,
int *  out_height,
const CoordFile coords 
)

Renders a composite frame directly into a 32-bit RGBA pixel array.

Parameters
ncerCell details.
nanrAnimation frames.
mapMap configurations.
ncgrTile pixels.
palettePalette registers.
tickFrame tick index.
tile_strideNCGR tile width stride.
labelDebug output identifier.
out_pixelsPointer filled with newly allocated RGBA pixel buffer on success.
out_widthWidth of generated RGBA frame.
out_heightHeight of generated RGBA frame.
coordsCoordinate metadata anchors.
Returns
0 on success; negative on rendering exception.

◆ Composer_RenderTimelineOrMapFrame()

static int Composer_RenderTimelineOrMapFrame ( const NcerFile ncer,
const NanrFile nanr,
const NmcrFile nmcr,
const NmarFile nmar,
const NmcrMap fallback_map,
int  animation_index,
int  use_timeline,
const NcgrImage ncgr,
const NclrPalette palette,
int  frame_index,
int  delay_cs,
int  tile_stride,
int  min_x,
int  min_y,
int  width,
int  height,
int  margin,
u8 out_indices,
const CoordFile coords 
)
static

◆ Composer_SetParentTransform()

static void Composer_SetParentTransform ( GlobalOam goam,
const ComposerTransform parent_transform 
)
static

Applies parent affine transform context variables to a global OAM sprite definition.

Parameters
goamTarget global OAM struct.
parent_transformParent transform context to inherit.

◆ Composer_TransformFromNmarFrame()

static void Composer_TransformFromNmarFrame ( const NmarFrame frame,
ComposerTransform out_transform 
)
static

◆ GlobalOamInverseTransformPoint()

static void GlobalOamInverseTransformPoint ( const GlobalOam goam,
double  world_x,
double  world_y,
double *  out_local_x,
double *  out_local_y 
)
static

Inverse-transforms a screen/world coordinate back to local OAM texture space.

Parameters
goamOAM instance parameters.
world_xWorld X coordinate.
world_yWorld Y coordinate.
out_local_xDestination local texture X coordinate.
out_local_yDestination local texture Y coordinate.

◆ GlobalOamTransformedBounds()

static void GlobalOamTransformedBounds ( const GlobalOam goam,
double *  out_min_x,
double *  out_min_y,
double *  out_max_x,
double *  out_max_y 
)
static

Computes bounds of a global OAM by transforming all four corners into world space.

Parameters
goamOAM instance.
out_min_xOutput minimum X world coordinate.
out_min_yOutput minimum Y world coordinate.
out_max_xOutput maximum X world coordinate.
out_max_yOutput maximum Y world coordinate.

◆ GlobalOamTransformPoint()

static void GlobalOamTransformPoint ( const GlobalOam goam,
double  local_x,
double  local_y,
double *  out_x,
double *  out_y 
)
static

Transforms a local OAM source coordinate to screen/world space by applying local and parent transformations.

Parameters
goamOAM instance parameters.
local_xLocal coordinate relative to OAM corner.
local_yLocal coordinate relative to OAM corner.
out_xDestination world X coord.
out_yDestination world Y coord.

◆ NanrScaleToDouble()

static double NanrScaleToDouble ( int  scale)
static

Converts a NANR fixed-point scale factor to double precision.

Parameters
scaleFixed-point scale factor.
Returns
Double precision scale factor.

◆ ParentInverseTransformPoint()

static void ParentInverseTransformPoint ( const GlobalOam goam,
double  world_x,
double  world_y,
double *  out_child_x,
double *  out_child_y 
)
static

Inverts a world coordinate to its corresponding local coordinate relative to the parent transform.

Parameters
goamOAM instance parameters.
world_xWorld X coordinate.
world_yWorld Y coordinate.
out_child_xPointer to child X-coordinate.
out_child_yPointer to child Y-coordinate.

◆ ParentTransformPoint()

static void ParentTransformPoint ( const GlobalOam goam,
double  child_x,
double  child_y,
double *  out_x,
double *  out_y 
)
static

Transforms a local point using the parent layout's scale, rotation, and translation.

Parameters
goamOAM instance parameters containing parent transform attributes.
child_xX-coordinate in child space.
child_yY-coordinate in child space.
out_xPointer to destination transformed X world coordinate.
out_yPointer to destination transformed Y world coordinate.

◆ RoundDoubleToInt()

static int RoundDoubleToInt ( double  value)
static

Rounds a double precision float value to the nearest integer.

Parameters
valueFloat value.
Returns
Rounded integer.

◆ SampleGlobalOamColorIndex()

static int SampleGlobalOamColorIndex ( const NcgrImage image,
const NclrPalette palette,
const GlobalOam goam,
int  src_x,
int  src_y,
int  tile_stride 
)
static

Samples a single pixel from the NCGR tile image for a given OAM layout.

Parameters
imageNCGR source tile sheet image.
paletteNCLR source color palette.
goamActive OAM layout properties.
src_xTarget pixel coordinate X relative to OAM.
src_yTarget pixel coordinate Y relative to OAM.
tile_strideStride width of NCGR in tiles.
Returns
Palette color index, or negative if transparent or out of bounds.

◆ SortGlobalOams()

static void SortGlobalOams ( GlobalOam global_oams,
int  global_oam_count 
)
static

Sorts global OAM sprites by priority (depth layering) and original definition index.

Parameters
global_oamsArray of global OAM definitions.
global_oam_countArray length.