AnimaEngine  1.0.0
Nintendo DS Pokemon Black, White, Black 2, and White 2 sprite extraction and preview toolchain
Data Structures | Typedefs | Functions
sprite_composer.h File Reference

Layout compositing, affine transformations, and frame rendering engine. More...

#include "common.h"
#include "ppm.h"
#include "ncer.h"
#include "nanr.h"
#include "nmcr.h"
#include "nmar.h"
#include "ncgr.h"
#include "nclr.h"
#include "coords.h"

Go to the source code of this file.

Data Structures

struct  GlobalOam
 Assembled global OAM record with complete transformations applied. More...
 
struct  ComposerTransform
 Affine transformation parameters passed down during scene orchestration. More...
 

Typedefs

typedef struct GlobalOam GlobalOam
 Assembled global OAM record with complete transformations applied. More...
 
typedef struct ComposerTransform ComposerTransform
 Affine transformation parameters passed down during scene orchestration. More...
 

Functions

void Composer_ClearPixels (RgbaColor *pixels, int width, int height)
 Fills the RGBA canvas with transparent pixels. 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_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_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_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_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_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...
 
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

Layout compositing, affine transformations, and frame rendering engine.

This module performs sprite compositing (OAM blitting) by reading cell layout tables (NCER), mapping tiles (NCGR) and palettes (NCLR), applying animation keyframes (NANR), and combining multi-sprite scene positioning records (NMCR) and timeline events (NMAR).

Typedef Documentation

◆ ComposerTransform

Affine transformation parameters passed down during scene orchestration.

◆ GlobalOam

typedef struct GlobalOam GlobalOam

Assembled global OAM record with complete transformations applied.

Function Documentation

◆ 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_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_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.