[ Home ]

wolfcore_gfx.c File Reference

Wolfenstein 3-D GFX file decoder. More...

#include <stdio.h>
#include <string.h>
#include "../../common/platform.h"
#include "../../common/common_utils.h"
#include "../../string/wtstring.h"
#include "../../memory/memory.h"
#include "../../filesys/file.h"
#include "../../loaders/tga.h"

Include dependency graph for wolfcore_gfx.c:


Data Structures

struct  huffnode
struct  pictable_t
struct  fontstruct

Defines

#define NUM_CHUNKS   256

Functions

PRIVATE SW32 getGFXFilePosition (W32 chunk)
 Calculate graphic file position.
PRIVATE SW32 getGFXChunkLength (W32 chunk)
 Calculate length of compressed graphic chunk.
PRIVATE void HuffExpand (const W8 *source, W8 *destination, W32 length, huffnode *hufftable)
 Expand Huffman compressed data.
PRIVATE SW32 expandGFXChunk (W32 chunk, const W8 *source)
 Expand compressed graphic chunk.
PUBLIC SW32 GFXFile_cacheChunk (W32 chunkId)
 Load graphic chunk into memory.
PUBLIC wtBoolean GFXFile_Setup (const char *dictfname, const char *headfname, const char *graphfname)
 Setup graphic files for decoding.
PUBLIC void GFXFile_Shutdown (void)
 Shutdown graphic files.
PUBLIC void GFXFile_printPicTable (void)
 Prints out graphic header information [Used for debugging].
PUBLIC void * GFXFile_getChunk (W32 chunkId)
 Get raw data.
PUBLIC void * GFXFile_decodeChunk_RGB24 (W32 chunkId, W32 *width_out, W32 *height_out, W8 *palette)
 Decode graphic chunk into RGB24 image data.
PUBLIC void * GFXFile_decodeChunk_RGB32 (W32 chunkId, W32 *width_out, W32 *height_out, W8 *palette)
 Decode graphic chunk into RGB32 image data.
PUBLIC void GFXFile_setStartPicValue (W32 startpic)
 Set startpic value.
PUBLIC W32 GFXFile_getStartPicValue (void)
 Get startpic value.
PUBLIC void GFXFile_decodeFont (W32 fontId, W32 font_width, W32 font_height, const char *path)
 Extract and save font as TGA file.
PUBLIC wtBoolean GFXFile_decodeScript (W32 textId_start, W32 textId_end, const char *path)
 Extract and save game script to file.
PUBLIC wtBoolean GFXFile_decodeGFX (W32 start, W32 end, W8 *palette, const char *path)
 Decode gfx data into TGA files.

Variables

PRIVATE pictable_t * pictable
PRIVATE huffnode grhuffman [255]
PRIVATE FILE * file_handle_gfx
PRIVATE SW32 * grstarts
PRIVATE W32 numImages
PRIVATE W32 start_pics = 3
PRIVATE void * graphic_segments [NUM_CHUNKS]

Detailed Description

Wolfenstein 3-D GFX file decoder.

Author:
Michael Liebscher
Date:
2006-2007
Note:
Portion of this code was derived from Wolfenstein 3-D, and was originally written by Id Software, Inc.

Function Documentation

PRIVATE SW32 expandGFXChunk ( W32  chunk,
const W8 *  source 
)

Expand compressed graphic chunk.

Parameters:
[in] chunk Chunk number to expand.
[in] source Pointer to compressed data.
Returns:
On success the size of the expaned chunk in bytes, otherwise -1.

Here is the call graph for this function:

Here is the caller graph for this function:

PRIVATE SW32 getGFXChunkLength ( W32  chunk  ) 

Calculate length of compressed graphic chunk.

Parameters:
[in] chunk Chunk number to calculate file offset.
Returns:
The length of the compressed graphic chunk.
Note:
Gets the length of an explicit length chunk (not tiles). The file pointer is positioned so the compressed data can be read in next.

Here is the call graph for this function:

Here is the caller graph for this function:

PRIVATE SW32 getGFXFilePosition ( W32  chunk  ) 

Calculate graphic file position.

Parameters:
[in] chunk Chunk number to calculate file offset.
Returns:
File offset value or -1 for sparse tile.
Note:
grstarts must be allocated and initialized before call. Uses global variable grstarts.

Here is the caller graph for this function:

PUBLIC SW32 GFXFile_cacheChunk ( W32  chunkId  ) 

Load graphic chunk into memory.

Parameters:
[in] chunkId Chunk number to cache.
Returns:
On success the length of the chunk in bytes, otherwise -1.

Here is the call graph for this function:

Here is the caller graph for this function:

PUBLIC void* GFXFile_decodeChunk_RGB24 ( W32  chunkId,
W32 *  width_out,
W32 *  height_out,
W8 *  palette 
)

Decode graphic chunk into RGB24 image data.

Parameters:
[in] chunkId Graphic chunk to decode.
[out] width_out Width of image in pixels.
[out] height_out Height of image in pixels.
[in] palette Pointer to image palette (Must have 768 entries).
Returns:
Pointer to RGB24 image data on success, otherwise NULL.
Note:
Caller is responsible for freeing allocated data by calling MM_FREE()

Here is the caller graph for this function:

PUBLIC void* GFXFile_decodeChunk_RGB32 ( W32  chunkId,
W32 *  width_out,
W32 *  height_out,
W8 *  palette 
)

Decode graphic chunk into RGB32 image data.

Parameters:
[in] chunkId Graphic chunk to decode.
[out] width_out Width of image in pixels.
[out] height_out Height of image in pixels.
[in] palette Pointer to image palette (Must have 768 entries).
Returns:
Pointer to RGB32 image data on success, otherwise NULL.
Note:
Caller is responsible for freeing allocated data by calling MM_FREE()

Here is the caller graph for this function:

PUBLIC void GFXFile_decodeFont ( W32  fontId,
W32  font_width,
W32  font_height,
const char *  path 
)

Extract and save font as TGA file.

Parameters:
[in] fontId Font chunk to save.
[in] font_width Width of font slate in pixels.
[in] font_height Height of font slate in pixels.
[in] path Path to save font files to.
Returns:
Nothing.

Here is the call graph for this function:

Here is the caller graph for this function:

PUBLIC wtBoolean GFXFile_decodeGFX ( W32  start,
W32  end,
W8 *  palette,
const char *  path 
)

Decode gfx data into TGA files.

Parameters:
[in] start start offset.
[in] end end offset.
[in] palette Pointer to palette array.
[in] path Directory path to save files to.
Returns:
On success true, otherwise false.

Here is the call graph for this function:

Here is the caller graph for this function:

PUBLIC wtBoolean GFXFile_decodeScript ( W32  textId_start,
W32  textId_end,
const char *  path 
)

Extract and save game script to file.

Parameters:
[in] textId_start Text start identifier.
[in] textId_end Text end identifier.
[in] path Path to save script into.
Returns:
Nothing.

Here is the call graph for this function:

Here is the caller graph for this function:

PUBLIC void* GFXFile_getChunk ( W32  chunkId  ) 

Get raw data.

Parameters:
[in] chunkId Graphic chunk number.
Returns:
Pointer to raw data on success, otherwise NULL.

Here is the caller graph for this function:

PUBLIC W32 GFXFile_getStartPicValue ( void   ) 

Get startpic value.

Returns:
startpic value..

PUBLIC void GFXFile_setStartPicValue ( W32  startpic  ) 

Set startpic value.

Parameters:
[in] startpic startpic value.
Returns:
Nothing.

Here is the caller graph for this function:

PUBLIC wtBoolean GFXFile_Setup ( const char *  dictfname,
const char *  headfname,
const char *  graphfname 
)

Setup graphic files for decoding.

Parameters:
[in] dictfname Huffman dictionary file name.
[in] headfname Graphic header file name.
[in] graphfname Graphic data file name.
Returns:
On success true, otherwise false.

Here is the call graph for this function:

Here is the caller graph for this function:

PRIVATE void HuffExpand ( const W8 *  source,
W8 *  destination,
W32  length,
huffnode *  hufftable 
)

Expand Huffman compressed data.

Parameters:
[in] source Pointer to compressed data.
[out] destination Pointer to hold decompressed data.
[in] length Length of expanded data in bytes.
[in] hufftable Huffman dictionary data.
Returns:
Nothing.
Note:
Uses classic Huffman node tree (not optimized).

Here is the caller graph for this function: