AnimaEngine  1.0.0
Nintendo DS Pokemon Black, White, Black 2, and White 2 sprite extraction and preview toolchain
Functions
ncer.c File Reference
#include "ncer.h"
#include "file_util.h"
#include "nitro_util.h"

Functions

static int DecodeSignedX (int raw)
 
static int DecodeSignedY (int raw)
 
static int DecodeObjSize (int shape, int size, int *out_w, int *out_h)
 
static int DecodeOam (const u8 *data, size_t size, size_t offset, NcerOam *out_oam)
 
void Ncer_GetOamDrawOrigin (const NcerOam *oam, int *out_x, int *out_y)
 Calculates resolved horizontal and vertical origins for drawing an OAM. More...
 
static int SortOamsByPriority (const NcerOam *oams, int count, int *indices)
 
int Ncer_Parse (const u8 *data, size_t size, NcerFile *out_ncer)
 Parses an unpacked .NCER cell layout block from raw bytes. More...
 
void Ncer_Free (NcerFile *ncer)
 Deallocates all resources held inside an NcerFile structure. More...
 
void Ncer_PrintInfo (const NcerFile *ncer)
 Prints parsed .NCER layout metadata to stdout. More...
 
int Ncer_RenderCellToImage (const NcerFile *ncer, int cell_index, const NcgrImage *ncgr, const NclrPalette *palette, RgbaColor **out_pixels, int *out_width, int *out_height)
 Renders a composite cell into a raw RGBA pixels buffer. More...
 
int Ncer_RenderCellToImageWithTileStride (const NcerFile *ncer, int cell_index, const NcgrImage *ncgr, const NclrPalette *palette, int tile_stride, RgbaColor **out_pixels, int *out_width, int *out_height)
 Renders a composite cell using specific tile character width stride formatting constraints. More...
 
void Ncer_CellBounds (const NcerCell *cell, int *out_min_x, int *out_min_y, int *out_max_x, int *out_max_y)
 Computes bounding box limits for a cell. More...
 

Function Documentation

◆ DecodeOam()

static int DecodeOam ( const u8 data,
size_t  size,
size_t  offset,
NcerOam out_oam 
)
static

◆ DecodeObjSize()

static int DecodeObjSize ( int  shape,
int  size,
int *  out_w,
int *  out_h 
)
static

◆ DecodeSignedX()

static int DecodeSignedX ( int  raw)
static

◆ DecodeSignedY()

static int DecodeSignedY ( int  raw)
static

◆ Ncer_CellBounds()

void Ncer_CellBounds ( const NcerCell cell,
int *  out_min_x,
int *  out_min_y,
int *  out_max_x,
int *  out_max_y 
)

Computes bounding box limits for a cell.

Parameters
cellCell structure.
out_min_xMinimum horizontal coordinate.
out_min_yMinimum vertical coordinate.
out_max_xMaximum horizontal coordinate.
out_max_yMaximum vertical coordinate.

◆ Ncer_Free()

void Ncer_Free ( NcerFile ncer)

Deallocates all resources held inside an NcerFile structure.

Parameters
ncerPointer to structure.

◆ Ncer_GetOamDrawOrigin()

void Ncer_GetOamDrawOrigin ( const NcerOam oam,
int *  out_x,
int *  out_y 
)

Calculates resolved horizontal and vertical origins for drawing an OAM.

Parameters
oamSub-sprite structure.
out_xOutput coordinate (horizontal).
out_yOutput coordinate (vertical).

◆ Ncer_Parse()

int Ncer_Parse ( const u8 data,
size_t  size,
NcerFile out_ncer 
)

Parses an unpacked .NCER cell layout block from raw bytes.

Parameters
dataPointer to raw binary file data buffer.
sizeBuffer size in bytes.
out_ncerDestination structure.
Returns
0 on success; negative value on formatting or invalid signature errors.

◆ Ncer_PrintInfo()

void Ncer_PrintInfo ( const NcerFile ncer)

Prints parsed .NCER layout metadata to stdout.

Parameters
ncerPointer to parsed NCER file.

◆ Ncer_RenderCellToImage()

int Ncer_RenderCellToImage ( const NcerFile ncer,
int  cell_index,
const NcgrImage ncgr,
const NclrPalette palette,
RgbaColor **  out_pixels,
int *  out_width,
int *  out_height 
)

Renders a composite cell into a raw RGBA pixels buffer.

Parameters
ncerNCER resource.
cell_indexIndex of the cell to draw.
ncgrNCGR tile graphic resource.
paletteNCLR palette resource.
out_pixelsOutput pointer to destination buffer, allocated inside this function.
out_widthWidth of rendered cell.
out_heightHeight of rendered cell.
Returns
0 on success; negative value on failure.

◆ Ncer_RenderCellToImageWithTileStride()

int Ncer_RenderCellToImageWithTileStride ( const NcerFile ncer,
int  cell_index,
const NcgrImage ncgr,
const NclrPalette palette,
int  tile_stride,
RgbaColor **  out_pixels,
int *  out_width,
int *  out_height 
)

Renders a composite cell using specific tile character width stride formatting constraints.

Parameters
ncerNCER resource.
cell_indexIndex of the cell to draw.
ncgrNCGR tile graphic resource.
paletteNCLR palette resource.
tile_strideWidth stride (in tiles) of NCGR image data.
out_pixelsOutput pointer to destination buffer.
out_widthWidth of rendered cell.
out_heightHeight of rendered cell.
Returns
0 on success; negative value on failure.

◆ SortOamsByPriority()

static int SortOamsByPriority ( const NcerOam oams,
int  count,
int *  indices 
)
static