Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
tga.h File Reference

Jo Engine Truevision Targa format support. More...

Go to the source code of this file.

Macros

#define JO_TGA_TRANSPARENT_INDEX(INDEX)
 The transparent_color of a 8 bits TGA to make a color of its palette transparent.

Typedefs

typedef jo_palette *(*) jo_tga_palette_handling_callback(void)
 Function prototype for ().

Enumerations

enum  t_tga_error_code { JO_TGA_OK , JO_TGA_FILE_NOT_FOUND , JO_TGA_UNSUPPORTED_FORMAT , JO_TGA_OUT_OF_MEMORY }
 tga error code More...

Functions

void jo_set_tga_palette_handling (jo_tga_palette_handling_callback callback)
 Set the callback to handle TGA palette for 8 bits image.
void jo_set_tga_default_palette (jo_palette *palette)
 Set the palette to use for 8 bits image.
t_tga_error_code jo_tga_loader_from_stream (jo_img *img, char *stream, const jo_color transparent_color)
 Load a TGA image from stream.
int jo_sprite_add_tga_from_stream (char *stream, const jo_color transparent_color)
 Add a sprite from a TGA stream.
int jo_sprite_add_tga (const char *const sub_dir, const char *const filename, const jo_color transparent_color)
 Add a sprite from a TGA file.
t_tga_error_code jo_tga_loader (jo_img *img, const char *const sub_dir, const char *const filename, const jo_color transparent_color)
 Load a TGA image.
bool jo_set_background_tga (const char *const sub_dir, const char *const filename, const jo_color transparent_color)
 Load a TGA image (15, 24 or 32 bits) and show it on the background (NBG1) at the top left of the screen.
t_tga_error_code jo_tga_8bits_loader (jo_img_8bits *img, const char *const sub_dir, const char *const filename, const int transparent_color_index_in_palette)
 Load a 8 bits 255 colors max TGA image.
t_tga_error_code jo_tga_8bits_loader_from_stream (jo_img_8bits *img, char *stream, const int transparent_color_index_in_palette)
 Load a 8 bits 255 colors max TGA image.
t_tga_error_code jo_tga_8bits_tileset_loader (const char *const sub_dir, const char *const filename, const jo_color transparent_color, const jo_tile *const tileset, const unsigned int tile_count, jo_raw_img *output_tiles)
 Load a tileset TGA image.
int jo_sprite_add_tga_tileset (const char *const sub_dir, const char *const filename, const jo_color transparent_color, const jo_tile *const tileset, const unsigned int tile_count)
 Add tileset sprites from a TGA file.

Detailed Description

Jo Engine Truevision Targa format support.

Author
Johannes Fetz
Remarks
8 bits (color mapped), 24 and 32 bits (true color), raw or compressed (RLE), rows from the bottom or the top
Bug
jo_tga_tileset_loader is not tested

Macro Definition Documentation

◆ JO_TGA_TRANSPARENT_INDEX

#define JO_TGA_TRANSPARENT_INDEX ( INDEX)

The transparent_color of a 8 bits TGA to make a color of its palette transparent.

Parameters
INDEXIndex of the color in the palette of the TGA file (0 to 254)

The pixels of a 8 bits TGA are stored with their index + 1 (the value 0 is transparent on the Saturn), so the transparent color is given with the same + 1. 0 (JO_COLOR_Transparent) adds no transparent color. Example: jo_sprite_add_tga("TEX", "SON8.TGA", JO_TGA_TRANSPARENT_INDEX(0)) (the color 0 of the palette transparent)

Warning
The index 255 is always transparent (255 + 1 is 0 in 8 bits) and its color is not loaded

Typedef Documentation

◆ jo_tga_palette_handling_callback

typedef jo_palette *(*) jo_tga_palette_handling_callback(void)

Function prototype for ().

Enumeration Type Documentation

◆ t_tga_error_code

tga error code

Enumerator
JO_TGA_OK 
JO_TGA_FILE_NOT_FOUND 
JO_TGA_UNSUPPORTED_FORMAT 
JO_TGA_OUT_OF_MEMORY 

Function Documentation

◆ jo_set_background_tga()

bool jo_set_background_tga ( const char *const sub_dir,
const char *const filename,
const jo_color transparent_color )

Load a TGA image (15, 24 or 32 bits) and show it on the background (NBG1) at the top left of the screen.

Parameters
sub_dirSub directory name (use JO_ROOT_DIR if the file is on the root directory)
filenameFilename (upper case and shorter as possible like "BG.TGA")
transparent_colorTransparent color. Use JO_COLOR_Transparent by default
Returns
true if the image is shown, false if it is not loaded (see jo_get_last_error())
Remarks
jo_tga_loader() + jo_set_background_sprite() + jo_free_img(): the image is copied to the VRAM of the VDP2, the memory of the work RAM is freed. For another position, load the image and call jo_set_background_sprite()

◆ jo_set_tga_default_palette()

void jo_set_tga_default_palette ( jo_palette * palette)

Set the palette to use for 8 bits image.

Parameters
paletteThe Palette
Warning
This function is mandatory if you use 8 bits TGA (but you can use jo_set_tga_palette_handling() instead)
The content of the palette will be filled when the image is loaded

◆ jo_set_tga_palette_handling()

void jo_set_tga_palette_handling ( jo_tga_palette_handling_callback callback)

Set the callback to handle TGA palette for 8 bits image.

Parameters
callbackThe callback
Warning
This function is mandatory if you use 8 bits TGA (but you can use jo_set_tga_default_palette() instead)

◆ jo_sprite_add_tga()

int jo_sprite_add_tga ( const char *const sub_dir,
const char *const filename,
const jo_color transparent_color )

Add a sprite from a TGA file.

Parameters
sub_dirSub directory name (use JO_ROOT_DIR if the file is on the root directory)
filenameFilename (upper case and shorter as possible like "A.TGA")
transparent_colorTransparent color or palette index for 8 bits image. Use JO_COLOR_Transparent by default
Warning
8 bits TGA: pass JO_TGA_TRANSPARENT_INDEX(index), the index in the palette of the TGA file + 1, not the index itself (the first color is 1 not 0); 0 (JO_COLOR_Transparent) adds no transparent color
8 bits TGA: 255 colors max (index 0 to 254), the index 255 is always transparent
Returns
Sprite Id or -1 if failed

◆ jo_sprite_add_tga_from_stream()

int jo_sprite_add_tga_from_stream ( char * stream,
const jo_color transparent_color )

Add a sprite from a TGA stream.

Parameters
streamRaw TGA contents
transparent_colorTransparent color (see colors.h), or JO_TGA_TRANSPARENT_INDEX(index in the palette) for a 8 bits image. Use JO_COLOR_Transparent by default
Returns
Sprite Id or -1 if failed

◆ jo_sprite_add_tga_tileset()

int jo_sprite_add_tga_tileset ( const char *const sub_dir,
const char *const filename,
const jo_color transparent_color,
const jo_tile *const tileset,
const unsigned int tile_count )

Add tileset sprites from a TGA file.

Parameters
sub_dirSub directory name (use JO_ROOT_DIR if the file is on the root directory)
filenameFilename (upper case and shorter as possible like "A.TGA")
transparent_colorTransparent color or palette index for 8 bits image. Use JO_COLOR_Transparent by default
tilesetTileset definition
tile_countNumber of tile in the entire image
Warning
8 bits TGA: pass JO_TGA_TRANSPARENT_INDEX(index), the index in the palette of the TGA file + 1, not the index itself (the first color is 1 not 0); 0 (JO_COLOR_Transparent) adds no transparent color
8 bits TGA: 255 colors max (index 0 to 254), the index 255 is always transparent
Returns
Sprite Id of the first image or -1 if failed

◆ jo_tga_8bits_loader()

t_tga_error_code jo_tga_8bits_loader ( jo_img_8bits * img,
const char *const sub_dir,
const char *const filename,
const int transparent_color_index_in_palette )

Load a 8 bits 255 colors max TGA image.

Parameters
imgImage (set data to NULL for dynamic allocation)
sub_dirSub directory name (use JO_ROOT_DIR if the file is on the root directory)
filenameFilename (upper case and shorter as possible like "A.TGA")
transparent_color_index_in_paletteJO_TGA_TRANSPARENT_INDEX(index in the palette of the TGA file), or 0 for no transparent color
Warning
8 bits TGA: pass JO_TGA_TRANSPARENT_INDEX(index), the index in the palette of the TGA file + 1, not the index itself (the first color is 1 not 0); 0 (JO_COLOR_Transparent) adds no transparent color
8 bits TGA: 255 colors max (index 0 to 254), the index 255 is always transparent
Returns
t_tga_error_code

◆ jo_tga_8bits_loader_from_stream()

t_tga_error_code jo_tga_8bits_loader_from_stream ( jo_img_8bits * img,
char * stream,
const int transparent_color_index_in_palette )

Load a 8 bits 255 colors max TGA image.

Parameters
imgImage (set data to NULL for dynamic allocation)
streamRaw TGA contents
transparent_color_index_in_paletteJO_TGA_TRANSPARENT_INDEX(index in the palette of the TGA file), or 0 for no transparent color
Warning
8 bits TGA: pass JO_TGA_TRANSPARENT_INDEX(index), the index in the palette of the TGA file + 1, not the index itself (the first color is 1 not 0); 0 (JO_COLOR_Transparent) adds no transparent color
8 bits TGA: 255 colors max (index 0 to 254), the index 255 is always transparent
Returns
t_tga_error_code

◆ jo_tga_8bits_tileset_loader()

t_tga_error_code jo_tga_8bits_tileset_loader ( const char *const sub_dir,
const char *const filename,
const jo_color transparent_color,
const jo_tile *const tileset,
const unsigned int tile_count,
jo_raw_img * output_tiles )

Load a tileset TGA image.

Parameters
sub_dirSub directory name (use JO_ROOT_DIR if the file is on the root directory)
filenameFilename (upper case and shorter as possible like "A.TGA")
transparent_colorTransparent color or palette index for 8 bits image. Use JO_COLOR_Transparent by default
tilesetTileset definition
tile_countNumber of tile in the entire image
output_tilesan array of tile_count * jo_raw_img.
Warning
8 bits TGA: pass JO_TGA_TRANSPARENT_INDEX(index), the index in the palette of the TGA file + 1, not the index itself (the first color is 1 not 0); 0 (JO_COLOR_Transparent) adds no transparent color
8 bits TGA: 255 colors max (index 0 to 254), the index 255 is always transparent
Returns
t_tga_error_code

◆ jo_tga_loader()

t_tga_error_code jo_tga_loader ( jo_img * img,
const char *const sub_dir,
const char *const filename,
const jo_color transparent_color )

Load a TGA image.

Parameters
imgImage (set data to NULL for dynamic allocation)
sub_dirSub directory name (use JO_ROOT_DIR if the file is on the root directory)
filenameFilename (upper case and shorter as possible like "A.TGA")
transparent_colorTransparent color or palette index for 8 bits image. Use JO_COLOR_Transparent by default
Warning
8 bits TGA: pass JO_TGA_TRANSPARENT_INDEX(index), the index in the palette of the TGA file + 1, not the index itself (the first color is 1 not 0); 0 (JO_COLOR_Transparent) adds no transparent color
8 bits TGA: 255 colors max (index 0 to 254), the index 255 is always transparent
Returns
t_tga_error_code

◆ jo_tga_loader_from_stream()

t_tga_error_code jo_tga_loader_from_stream ( jo_img * img,
char * stream,
const jo_color transparent_color )

Load a TGA image from stream.

Parameters
imgImage (set data to NULL for dynamic allocation)
streamRaw TGA contents
transparent_colorTransparent color or palette index for 8 bits image. Use JO_COLOR_Transparent by default
Warning
8 bits TGA: pass JO_TGA_TRANSPARENT_INDEX(index), the index in the palette of the TGA file + 1, not the index itself (the first color is 1 not 0); 0 (JO_COLOR_Transparent) adds no transparent color
8 bits TGA: 255 colors max (index 0 to 254), the index 255 is always transparent
Returns
t_tga_error_code