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

Functions

int Ncgr_Parse (const u8 *data, size_t size, NcgrImage *out_image)
 Parses character graphics tiles from raw binary stream. More...
 
void Ncgr_Free (NcgrImage *image)
 Deallocates local buffers inside NcgrImage structure. More...
 
void Ncgr_PrintInfo (const NcgrImage *image)
 Debug prints character graphics metadata to stdout. More...
 
static int GetPixelIndex4bpp (const u8 *tile, int x, int y)
 
static int GetPixelIndex8bpp (const u8 *tile, int x, int y)
 
int Ncgr_GetPixelIndex (const NcgrImage *image, int tile_index, int x, int y)
 Retrieves the color index offset for a pixel coordinate inside a specific 8x8 tile. More...
 
void Ncgr_BlitObjToCanvas (const NcgrImage *image, const NclrPalette *palette, RgbaColor *canvas, int canvas_width, int canvas_height, int dst_x, int dst_y, int tile_index, int obj_width, int obj_height, int palette_index, int flip_h, int flip_v)
 Blits a sub-sprite object onto an RGBA canvas. More...
 
void Ncgr_BlitObjToCanvasWithTileStride (const NcgrImage *image, const NclrPalette *palette, RgbaColor *canvas, int canvas_width, int canvas_height, int dst_x, int dst_y, int tile_index, int obj_width, int obj_height, int palette_index, int flip_h, int flip_v, int tile_stride)
 Blits a sub-sprite object onto canvas using specific width tile character stride constraints. More...
 
int Ncgr_RenderTilesToImage (const NcgrImage *image, const NclrPalette *palette, int tiles_per_row, RgbaColor **out_pixels, int *out_width, int *out_height)
 Renders sequential list of tiles directly to a grid sheet RGBA image. More...
 

Function Documentation

◆ GetPixelIndex4bpp()

static int GetPixelIndex4bpp ( const u8 tile,
int  x,
int  y 
)
static

◆ GetPixelIndex8bpp()

static int GetPixelIndex8bpp ( const u8 tile,
int  x,
int  y 
)
static

◆ Ncgr_BlitObjToCanvas()

void Ncgr_BlitObjToCanvas ( const NcgrImage image,
const NclrPalette palette,
RgbaColor canvas,
int  canvas_width,
int  canvas_height,
int  dst_x,
int  dst_y,
int  tile_index,
int  obj_width,
int  obj_height,
int  palette_index,
int  flip_h,
int  flip_v 
)

Blits a sub-sprite object onto an RGBA canvas.

Parameters
imagePointer to NCGR image.
palettePalette resource containing colors.
canvasDestination RGBA pixel canvas buffer.
canvas_widthWidth of destination canvas in pixels.
canvas_heightHeight of destination canvas in pixels.
dst_xHorizontal canvas offset coordinates to start rendering.
dst_yVertical canvas offset coordinates to start rendering.
tile_indexInitial NCGR tile index.
obj_widthWidth of active sub-sprite in pixels.
obj_heightHeight of active sub-sprite in pixels.
palette_indexPalette page offset selection.
flip_h1 to mirror graphics horizontally.
flip_v1 to mirror graphics vertically.

◆ Ncgr_BlitObjToCanvasWithTileStride()

void Ncgr_BlitObjToCanvasWithTileStride ( const NcgrImage image,
const NclrPalette palette,
RgbaColor canvas,
int  canvas_width,
int  canvas_height,
int  dst_x,
int  dst_y,
int  tile_index,
int  obj_width,
int  obj_height,
int  palette_index,
int  flip_h,
int  flip_v,
int  tile_stride 
)

Blits a sub-sprite object onto canvas using specific width tile character stride constraints.

Parameters
imagePointer to NCGR image.
palettePalette resource.
canvasDestination RGBA canvas buffer.
canvas_widthCanvas width in pixels.
canvas_heightCanvas height in pixels.
dst_xHorizontal canvas offset.
dst_yVertical canvas offset.
tile_indexInitial NCGR tile index.
obj_widthWidth of active sub-sprite.
obj_heightHeight of active sub-sprite.
palette_indexPalette page offset.
flip_h1 to mirror horizontally.
flip_v1 to mirror vertically.
tile_strideWidth stride (in tiles) of NCGR image data.

◆ Ncgr_Free()

void Ncgr_Free ( NcgrImage image)

Deallocates local buffers inside NcgrImage structure.

Parameters
imagePointer to NCGR image.

◆ Ncgr_GetPixelIndex()

int Ncgr_GetPixelIndex ( const NcgrImage image,
int  tile_index,
int  x,
int  y 
)

Retrieves the color index offset for a pixel coordinate inside a specific 8x8 tile.

Parameters
imagePointer to NCGR image.
tile_indexIndex of the target tile.
xHorizontal pixel coordinate relative to tile origin (0 to 7).
yVertical pixel coordinate relative to tile origin (0 to 7).
Returns
Palette color index value.

◆ Ncgr_Parse()

int Ncgr_Parse ( const u8 data,
size_t  size,
NcgrImage out_image 
)

Parses character graphics tiles from raw binary stream.

Parameters
dataRaw binary input.
sizeInput stream size in bytes.
out_imageDestination struct.
Returns
0 on success; negative value on formatting or invalid signature errors.

◆ Ncgr_PrintInfo()

void Ncgr_PrintInfo ( const NcgrImage image)

Debug prints character graphics metadata to stdout.

Parameters
imagePointer to NCGR image.

◆ Ncgr_RenderTilesToImage()

int Ncgr_RenderTilesToImage ( const NcgrImage image,
const NclrPalette palette,
int  tiles_per_row,
RgbaColor **  out_pixels,
int *  out_width,
int *  out_height 
)

Renders sequential list of tiles directly to a grid sheet RGBA image.

Parameters
imagePointer to NCGR image.
palettePalette resource.
tiles_per_rowGrid width columns.
out_pixelsOutput destination RGBA pixels buffer.
out_widthWidth of generated sheet image.
out_heightHeight of generated sheet image.
Returns
0 on success; negative value on error.