Index

Run Length Encoding Compression

The mousetrap library currently supports one type of compression for the mousetrap information, Run Length Encoding(RLE). The library can be extended with no external api changes to implement other types of compression, but it as not as easy at this point as adding a new mousetrap source type.

See src/library_support/libsdl/libsdl_surface_support.* for a working example that makes a mousetrap based on SDL surface information.


RLE Buffer Format and Data Structures

#include <mousetrap/rle_buffer.h>
typedef struct _RLENode_t {
  int start;
  unsigned int object_id;
  struct _RLENode_t *next;
} RLENode_t;
 
typedef struct {
  int height, width;  
  trap_t type;
  unsigned int id;
  RLENode_t **rle_lines;
} RLEBuff_t;
The RLE buffer (RLEBuff_t) is a struct that contains the data for a run length encoded rectangular mask. The buffer contains a linked list for each horizontal row.

The nodes (RLENode_t) in the linked list contain all the identifiers and transparency information that appears in the line. The last node in these lists is denoted by a NULL value. The last node in a line's start member should be less than the width specified in the containing RLE buffer.


RLE Buffer Functions

Name

rle_buffer_create_blank -- creates an RLE buffer with no mask data

Synopsis


#include <mousetrap/rle_internals.h>

RLEBuff_t* rle_buffer_create_blank(int width, int height);

Description

This function creates an RLE buffer of the specified width and height with no mask data. The data member rle_lines of the returned RLE buffer can then be populated with data read from the mask source.

Name

rle_node_create -- creates a node to represent run length encoded data in a linked list.

Synopsis


#include <mousetrap/rle_internals.h>

RLENode_t* rle_node_create(int start, unsigned int id);

Description

This function creates a node for use in the mask data of an RLE buffer. The start parameter represents the x location of the node in its destination RLE buffer. The id parameter populates the node's identifier field and is used for storing the identifier of the area it represents. This is the identifier that is retrieved by mousetrap_lookup_id. The node's next pointer is initialized as NULL.

Name

rle_buffer_validate -- verifies the integrity of an RLE buffer.

Synopsis


#include <mousetrap/rle_internals.h>

int rle_buffer_validate(RLEBuff_t *rle_buffer);

Description

This function returns 1 if rle_buffer passes a sanity check, or 0 if it does not. If the buffer does not pass a test, the buffer is printed in its compressed and uncompressed forms. The buffer is tested to ensure that the contained lines do not extend beyond the width specified by the buffer.
Copyright © 2001 Ben Smith