2. Library Functions

N64 JPEG library includes following functions.

2.1 Encode


njpgHuffEncode(3P)

Function Name

njpgHuffEncode --> function to encode and compress data using Huffman encoding

Syntax

#include <n64jpeg.h>
u32 njpgHuffEncode(u8 *indata, u8 *outdata, u32 size);

Parameter

indata The pointer to the input data buffer
outdata The pointer to the output data buffer
size The size of the encoding data

Description

The Huffman method encodes the output data by using the njpgespMain microcode. The address of the input/output data buffer must be 4byte aligned. Also, the input data size needs to be a multiple of 768byte (8x8( unit process matrix)x2(byte)x6). (The output data from the njpgespMain microcode is usually this size.)

The output data size of the njpgespMain microcode is one and a half times the size of the original image. The value should be (the width of the original image) x (the height of the original image) x 2 (byte)x1.5.

Return value of the function is the data size after compression.


2.2 Decode


njpgHuffDecode(3P)

Function Name

njpgHuffDecode --> function to decompress data that was compressed by the Huffman encoding method.

Syntax

#include <n64jpeg.h>
s32 njpgHuffDecode(u8 *indata, u8 *outdata);

Parameter

indata The pointer to the input data buffer
outdata The pointer to the output data buffer

Description

This function decompresses the Huffman-encoded compression data. The address of the input/output buffer must be 4byte aligned.

If a function is called successfully, 0 is returned. If the call is unsuccessful, -1 is returned. The data which was output will be decoded again using the njpgdsMain microcode.

You should check the return value to see if the decoding process failed because the original data (the compressed data) may have been destroyed; for example, you could have saved the compression data on a disk or Controller Pak whose data was later destroyed.

To be sure the file is valid, check to see if the first 4 bytes of the compression data is the recognition header "HUFF"(ASCII: 0x48554646), and check the number of the following 2byte macro block (block which is set to 16x16 dod )

Please refer to "5.2.2 Data from njpgCompress tool" for details about the data format.

Example

if(*((u32*)indata) != 0x4e485546){
	/* Error process */
}

if(*((u32*)(indata + 4)) != IMAGE_SIZE){
	/* Error process */
}

njpgNonhuffDecode(indata, outdata);

/* Decoding by njpgdspMain microcode */