SPECK wavelet codec


Data Structures

struct  pixel_set_tag

Defines

#define TYPE_POINT   0
#define TYPE_S   1
#define TYPE_I   2
#define TYPE_EMPTY   3
#define STAGE_S   0
#define STAGE_I   1
#define MIN_SPECK_BUF_SIZE   1
#define THRESHOLD_BITS   6
#define PIXEL_SET(_set)   ((pixel_set *) (_set->data))
#define SLOT_INDEX(_set)   (number_of_bits(MIN(_set->width, _set->height)) - 1)
#define BREAK_IF_OVERFLOW(_x)   if (_x == BIT_BUFFER_OVERFLOW) break
#define RETURN_IF_OVERFLOW(_x)   if (_x == BIT_BUFFER_OVERFLOW) return _x
#define BREAK_IF_UNDERFLOW(_x)   if (_x == BIT_BUFFER_UNDERFLOW) break
#define RETURN_IF_UNDERFLOW(_x)   if (_x == BIT_BUFFER_UNDERFLOW) return _x
#define CONTINUE_IF_EMPTY(_x)   if (LIST_IS_EMPTY(_x)) continue

Typedefs

typedef struct pixel_set_tag pixel_set

Functions

local int max_coeff (int **channel, int channel_size)
local int validate_set (pixel_set *set, int channel_size)
local int significance_test (pixel_set *set, int threshold, int **channel, int channel_size)
local void select_part_type (pixel_set *set)
local void split_set (pixel_set *set, pixel_set *part1, pixel_set *part2, pixel_set *part3, pixel_set *part4, int channel_size)
local linked_list ** alloc_LIS_slots (int channel_size)
local void free_LIS_slots (linked_list **LIS_slots, int channel_size)
local void assign_set (list_node *node, pixel_set *set)
local void zero_channel (int **channel, int channel_size)
local int speck_encode_S (int **channel, int channel_size, pixel_set *set, linked_list **LIS_slots, linked_list *LSP, bit_buffer *bb, int threshold)
local int speck_process_S (int **channel, int channel_size, list_node *node, linked_list *slot, linked_list **LIS_slots, linked_list *LSP, bit_buffer *bb, int threshold, int coding_stage)
local int speck_encode_I (int **channel, int channel_size, pixel_set *I, linked_list **LIS_slots, linked_list *LSP, bit_buffer *bb, int threshold)
local int speck_process_I (int **channel, int channel_size, pixel_set *I, linked_list **LIS_slots, linked_list *LSP, bit_buffer *bb, int threshold)
local int encode_sorting_pass (int **channel, int channel_size, linked_list **LIS_slots, linked_list *LSP, pixel_set *I, bit_buffer *bb, int threshold)
local int encode_refinement_pass (int **channel, linked_list *LSP, bit_buffer *bb, int threshold)
local int speck_decode_S (int **channel, int channel_size, pixel_set *set, linked_list **LIS_slots, linked_list *LSP, bit_buffer *bb, int threshold)
local int speck_unprocess_S (int **channel, int channel_size, list_node *node, linked_list *slot, linked_list **LIS_slots, linked_list *LSP, bit_buffer *bb, int threshold, int coding_stage)
local int speck_decode_I (int **channel, int channel_size, pixel_set *I, linked_list **LIS_slots, linked_list *LSP, bit_buffer *bb, int threshold)
local int speck_unprocess_I (int **channel, int channel_size, pixel_set *I, linked_list **LIS_slots, linked_list *LSP, bit_buffer *bb, int threshold)
local int decode_sorting_pass (int **channel, int channel_size, linked_list **LIS_slots, linked_list *LSP, pixel_set *I, bit_buffer *bb, int threshold)
local int decode_refinement_pass (int **channel, linked_list *LSP, bit_buffer *bb, int threshold)
local void speck_init (linked_list **LIS_slots, pixel_set *I, int channel_size, int mode)
int speck_encode (int **channel, int channel_size, unsigned char *buf, int buf_size)
void speck_decode (unsigned char *buf, int buf_size, int **channel, int channel_size)

Detailed Description


Define Documentation

#define TYPE_POINT   0

#define TYPE_S   1

Pixel set of type 'S'

Referenced by select_part_type(), significance_test(), speck_init(), split_set(), and validate_set().

#define TYPE_I   2

Pixel set of type 'I'

Referenced by significance_test(), speck_init(), split_set(), and validate_set().

#define TYPE_EMPTY   3

#define STAGE_S   0

Processing sets of type 'S'

Referenced by decode_sorting_pass(), encode_sorting_pass(), speck_process_S(), and speck_unprocess_S().

#define STAGE_I   1

Processing sets of type 'I'

Referenced by speck_decode_I(), speck_encode_I(), speck_process_S(), and speck_unprocess_S().

#define MIN_SPECK_BUF_SIZE   1

Minimal SPECK buffer size

Referenced by speck_decode(), and speck_encode().

#define THRESHOLD_BITS   6

Reserve 6 bits for theshold_bits parameter

Referenced by speck_decode(), and speck_encode().

#define PIXEL_SET ( _set   )     ((pixel_set *) (_set->data))

#define SLOT_INDEX ( _set   )     (number_of_bits(MIN(_set->width, _set->height)) - 1)

Select inserting index for array of LIS slots

Referenced by speck_decode_S(), speck_encode_S(), speck_process_S(), and speck_unprocess_S().

#define BREAK_IF_OVERFLOW ( _x   )     if (_x == BIT_BUFFER_OVERFLOW) break

Break if buffer is full

Referenced by speck_encode().

#define RETURN_IF_OVERFLOW ( _x   )     if (_x == BIT_BUFFER_OVERFLOW) return _x

#define BREAK_IF_UNDERFLOW ( _x   )     if (_x == BIT_BUFFER_UNDERFLOW) break

Break if buffer is empty

Referenced by speck_decode().

#define RETURN_IF_UNDERFLOW ( _x   )     if (_x == BIT_BUFFER_UNDERFLOW) return _x

Return if buffer is empty

Referenced by decode_sorting_pass(), speck_decode_S(), speck_unprocess_I(), and speck_unprocess_S().

#define CONTINUE_IF_EMPTY ( _x   )     if (LIST_IS_EMPTY(_x)) continue

Contunue if list is empty

Referenced by decode_sorting_pass(), and encode_sorting_pass().


Typedef Documentation

typedef struct pixel_set_tag pixel_set

This structure represents pixel_set


Function Documentation

local int max_coeff ( int **  channel,
int  channel_size 
)

Find maximal coefficient

This function returns absolute value of maximal wavelet coefficient.

Parameters:
channel Channel
channel_size Channel size
Returns:
Maximal coefficient value

References ABS.

Referenced by speck_encode().

local int validate_set ( pixel_set set,
int  channel_size 
)

Validate set

The process of splitting, moving and testing sets in the SPECK algorithm is a bit tricky. This function can be thought as a very strict validation tool.

Parameters:
set Set to validate
channel_size Channel size
Returns:
1 for valid sets and 0 for invalid ones

References is_power_of_two(), number_of_bits(), TYPE_I, TYPE_POINT, and TYPE_S.

Referenced by significance_test(), and split_set().

local int significance_test ( pixel_set set,
int  threshold,
int **  channel,
int  channel_size 
)

Significance test

The purpose of this function is to compare set against threshold. If the set have a coefficient greater than or equal to threshold, then it is said that the set is significant. If all coefficients of the set are below threshold, then it is said that the set is insignificant.

Parameters:
set Set to test
threshold Threshold to compare against
channel Channel
channel_size Channel size
Returns:
1 for significant sets and 0 for insignificant ones

References ABS, TYPE_I, TYPE_POINT, TYPE_S, and validate_set().

Referenced by speck_encode_S(), speck_process_I(), and speck_process_S().

local void select_part_type ( pixel_set set  ) 

Select partition type

This function selects type of the set.

Parameters:
set Set
Returns:
VOID

References TYPE_EMPTY, TYPE_POINT, and TYPE_S.

Referenced by split_set().

local void split_set ( pixel_set set,
pixel_set part1,
pixel_set part2,
pixel_set part3,
pixel_set part4,
int  channel_size 
)

Split set

This function splits the set into pieces. Actual splitting rule is defined within SPECK algorithm.

Parameters:
set Set to split
part1 First part
part2 Second part
part3 Third part
part4 Fourth part
channel_size Channel size
Returns:
VOID

References pixel_set_tag::height, number_of_bits(), select_part_type(), pixel_set_tag::type, TYPE_EMPTY, TYPE_I, TYPE_S, validate_set(), pixel_set_tag::width, pixel_set_tag::x, and pixel_set_tag::y.

Referenced by speck_decode_I(), speck_decode_S(), speck_encode_I(), and speck_encode_S().

local linked_list** alloc_LIS_slots ( int  channel_size  ) 

Allocate array of LIS slots

This function allocates array of LIS slots.

Parameters:
channel_size Channel size
Returns:
Pointer to newly allocated structure

References alloc_linked_list(), number_of_bits(), and xmalloc().

Referenced by speck_decode(), and speck_encode().

local void free_LIS_slots ( linked_list **  LIS_slots,
int  channel_size 
)

Release array of LIS slots

This function releases array of LIS slots.

Parameters:
LIS_slots Array of LIS slots
channel_size Channel size
Returns:
VOID

References free_linked_list(), and number_of_bits().

Referenced by speck_decode(), and speck_encode().

local void assign_set ( list_node node,
pixel_set set 
)

Assign set attributes

This function assigns set attributes to the node.

Parameters:
node Destination node
set Source set
Returns:
VOID

References PIXEL_SET.

Referenced by speck_decode_I(), speck_decode_S(), speck_encode_I(), and speck_encode_S().

local void zero_channel ( int **  channel,
int  channel_size 
)

Reset channel

This function resets all channel components to zero.

Parameters:
channel Channel
channel_size Channel size
Returns:
VOID

Referenced by speck_decode().

local int speck_encode_S ( int **  channel,
int  channel_size,
pixel_set set,
linked_list **  LIS_slots,
linked_list LSP,
bit_buffer bb,
int  threshold 
)

Encode set of type 'S'

This function encodes set of type 'S'.

Parameters:
channel Channel
channel_size Channel size
set Set to encode
LIS_slots Array of LIS slots
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_OVERFLOW

References alloc_list_node(), append_list_node(), assign_set(), BIT_BUFFER_OK, prepend_list_node(), RETURN_IF_OVERFLOW, significance_test(), SLOT_INDEX, speck_encode_S(), split_set(), TYPE_EMPTY, TYPE_POINT, write_0, write_1, pixel_set_tag::x, and pixel_set_tag::y.

Referenced by speck_encode_S(), and speck_process_S().

local int speck_process_S ( int **  channel,
int  channel_size,
list_node node,
linked_list slot,
linked_list **  LIS_slots,
linked_list LSP,
bit_buffer bb,
int  threshold,
int  coding_stage 
)

Process set of type 'S'

This function extracts pixel_set structure from the node, and encodes it using speck_encode_S function.

Parameters:
channel Channel
channel_size Channel size
node Current node
slot Current LIS slot
LIS_slots Array of LIS slots
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
coding_stage Either STAGE_S or STAGE_I
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_OVERFLOW

References append_list_node(), BIT_BUFFER_OK, free_list_node(), PIXEL_SET, prepend_list_node(), remove_list_node(), remove_list_node_link(), RETURN_IF_OVERFLOW, significance_test(), SLOT_INDEX, speck_encode_S(), STAGE_I, STAGE_S, TYPE_POINT, write_0, and write_1.

Referenced by encode_sorting_pass(), and speck_encode_I().

local int speck_encode_I ( int **  channel,
int  channel_size,
pixel_set I,
linked_list **  LIS_slots,
linked_list LSP,
bit_buffer bb,
int  threshold 
)

Encode set of type 'I'

This function encodes set of type 'I'.

Parameters:
channel Channel
channel_size Channel size
I Set of type I
LIS_slots Array of LIS slots
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_OVERFLOW

References alloc_list_node(), assign_set(), BIT_BUFFER_OVERFLOW, free_list_node(), speck_process_I(), speck_process_S(), split_set(), and STAGE_I.

Referenced by speck_process_I().

local int speck_process_I ( int **  channel,
int  channel_size,
pixel_set I,
linked_list **  LIS_slots,
linked_list LSP,
bit_buffer bb,
int  threshold 
)

Process set of type 'I'

This function encodes set I using speck_encode_I function.

Parameters:
channel Channel
channel_size Channel size
I Set of type I
LIS_slots Array of LIS slots
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_OVERFLOW

References BIT_BUFFER_OK, RETURN_IF_OVERFLOW, significance_test(), speck_encode_I(), pixel_set_tag::type, TYPE_EMPTY, write_0, and write_1.

Referenced by encode_sorting_pass(), and speck_encode_I().

local int encode_sorting_pass ( int **  channel,
int  channel_size,
linked_list **  LIS_slots,
linked_list LSP,
pixel_set I,
bit_buffer bb,
int  threshold 
)

Encode sorting pass

The SPECK encoding algorithm alternates two types of passes through the data: sorting pass and refinement pass. This function implements the first one.

Parameters:
channel Channel
channel_size Channel size
LIS_slots Array of LIS slots
LSP List of Significant Pixels
I Set of type I
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_OVERFLOW

References CONTINUE_IF_EMPTY, linked_list_tag::first, list_node_tag::next, number_of_bits(), RETURN_IF_OVERFLOW, speck_process_I(), speck_process_S(), and STAGE_S.

Referenced by speck_encode().

local int encode_refinement_pass ( int **  channel,
linked_list LSP,
bit_buffer bb,
int  threshold 
)

Encode refinement pass

The SPECK encoding algorithm alternates two types of passes through the data: sorting pass and refinement pass. This function implements the second one.

Parameters:
channel Channel
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_OVERFLOW

References ABS, BIT_BUFFER_OK, linked_list_tag::first, list_node_tag::next, PIXEL_SET, RETURN_IF_OVERFLOW, write_0, and write_1.

Referenced by speck_encode().

local int speck_decode_S ( int **  channel,
int  channel_size,
pixel_set set,
linked_list **  LIS_slots,
linked_list LSP,
bit_buffer bb,
int  threshold 
)

Decode set of type 'S'

This function is inverse to speck_encode_S.

Parameters:
channel Channel
channel_size Channel size
set Set to decode
LIS_slots Array of LIS slots
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_UNDERFLOW

References alloc_list_node(), append_list_node(), assign_set(), BIT_BUFFER_OK, prepend_list_node(), read_bit, RETURN_IF_UNDERFLOW, SLOT_INDEX, speck_decode_S(), split_set(), TYPE_EMPTY, TYPE_POINT, pixel_set_tag::x, and pixel_set_tag::y.

Referenced by speck_decode_S(), and speck_unprocess_S().

local int speck_unprocess_S ( int **  channel,
int  channel_size,
list_node node,
linked_list slot,
linked_list **  LIS_slots,
linked_list LSP,
bit_buffer bb,
int  threshold,
int  coding_stage 
)

Unprocess set of type 'S'

This function is inverse to speck_process_S.

Parameters:
channel Channel
channel_size Channel size
node Current node
slot Current LIS slot
LIS_slots Array of LIS slots
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
coding_stage Either STAGE_S or STAGE_I
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_UNDERFLOW

References append_list_node(), BIT_BUFFER_OK, free_list_node(), PIXEL_SET, prepend_list_node(), read_bit, remove_list_node(), remove_list_node_link(), RETURN_IF_UNDERFLOW, SLOT_INDEX, speck_decode_S(), STAGE_I, STAGE_S, and TYPE_POINT.

Referenced by decode_sorting_pass(), and speck_decode_I().

local int speck_decode_I ( int **  channel,
int  channel_size,
pixel_set I,
linked_list **  LIS_slots,
linked_list LSP,
bit_buffer bb,
int  threshold 
)

Decode set of type 'I'

This function is inverse to speck_encode_I.

Parameters:
channel Channel
channel_size Channel size
I Set of type I
LIS_slots Array of LIS slots
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_UNDERFLOW

References alloc_list_node(), assign_set(), BIT_BUFFER_UNDERFLOW, free_list_node(), speck_unprocess_I(), speck_unprocess_S(), split_set(), and STAGE_I.

Referenced by speck_unprocess_I().

local int speck_unprocess_I ( int **  channel,
int  channel_size,
pixel_set I,
linked_list **  LIS_slots,
linked_list LSP,
bit_buffer bb,
int  threshold 
)

Unprocess set of type 'I'

This function is inverse to speck_process_I.

Parameters:
channel Channel
channel_size Channel size
I Set of type I
LIS_slots Array of LIS slots
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_UNDERFLOW

References BIT_BUFFER_OK, read_bit, RETURN_IF_UNDERFLOW, speck_decode_I(), pixel_set_tag::type, and TYPE_EMPTY.

Referenced by decode_sorting_pass(), and speck_decode_I().

local int decode_sorting_pass ( int **  channel,
int  channel_size,
linked_list **  LIS_slots,
linked_list LSP,
pixel_set I,
bit_buffer bb,
int  threshold 
)

Decode sorting pass

The SPECK decoding algorithm alternates two types of passes through the data: sorting pass and refinement pass. This function implements the first one.

Parameters:
channel Channel
channel_size Channel size
LIS_slots Array of LIS slots
LSP List of Significant Pixels
I Set of type I
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_UNDERFLOW

References CONTINUE_IF_EMPTY, linked_list_tag::first, list_node_tag::next, number_of_bits(), RETURN_IF_UNDERFLOW, speck_unprocess_I(), speck_unprocess_S(), and STAGE_S.

Referenced by speck_decode().

local int decode_refinement_pass ( int **  channel,
linked_list LSP,
bit_buffer bb,
int  threshold 
)

Decode refinement pass

The SPECK decoding algorithm alternates two types of passes through the data: sorting pass and refinement pass. This function implements the second one.

Parameters:
channel Channel
LSP List of Significant Pixels
bb Bit-buffer
threshold Threshold
Returns:
Either BIT_BUFFER_OK or BIT_BUFFER_UNDERFLOW

References ABS, BIT_BUFFER_OK, linked_list_tag::first, list_node_tag::next, PIXEL_SET, read_bit, and RETURN_IF_OVERFLOW.

Referenced by speck_decode().

local void speck_init ( linked_list **  LIS_slots,
pixel_set I,
int  channel_size,
int  mode 
)

Initialize SPECK encoder or decoder

This function initializes SPECK encoder or decoder.

Parameters:
LIS_slots Array of LIS slots
I Set of type I
channel_size Channel size
mode Either MODE_NORMAL or MODE_OTLPF
Returns:
VOID

References alloc_list_node(), pixel_set_tag::height, MODE_NORMAL, PIXEL_SET, prepend_list_node(), pixel_set_tag::type, TYPE_I, TYPE_POINT, TYPE_S, pixel_set_tag::width, pixel_set_tag::x, and pixel_set_tag::y.

Referenced by speck_decode(), and speck_encode().

int speck_encode ( int **  channel,
int  channel_size,
unsigned char *  buf,
int  buf_size 
)

Encode channel using SPECK algorithm

This function encodes channel of size channel_size into the buffer buf of size buf_size.

Note:
Depending on encoding mode, minimal channel size is 2 (for MODE_NORMAL) or 3 (for MODE_OTLPF).

Minimal buffer size is MIN_SPECK_BUF_SIZE

Parameters:
channel Channel
channel_size Channel size
buf Buffer
buf_size Buffer size
Returns:
Number of bytes in buf actualy used by encoder

References alloc_linked_list(), alloc_LIS_slots(), BREAK_IF_OVERFLOW, encode_refinement_pass(), encode_sorting_pass(), flush_bits(), free_linked_list(), free_LIS_slots(), init_bits(), max_coeff(), MIN_SPECK_BUF_SIZE, bit_buffer_tag::next, number_of_bits(), speck_init(), bit_buffer_tag::start, THRESHOLD_BITS, write_bits(), and xmalloc().

Referenced by eps_encode_grayscale_block(), and eps_encode_truecolor_block().

void speck_decode ( unsigned char *  buf,
int  buf_size,
int **  channel,
int  channel_size 
)

Decode channel using SPECK algorithm

This function decodes channel of size channel_size from the buffer buf of size buf_size.

Note:
Depending on encoding mode, minimal channel size is 2 (for MODE_NORMAL) or 3 (for MODE_OTLPF).

Minimal buffer size is MIN_SPECK_BUF_SIZE

Parameters:
buf Buffer
buf_size Buffer size
channel Channel
channel_size Channel size
Returns:
VOID

References alloc_linked_list(), alloc_LIS_slots(), BREAK_IF_UNDERFLOW, decode_refinement_pass(), decode_sorting_pass(), free_linked_list(), free_LIS_slots(), init_bits(), MIN_SPECK_BUF_SIZE, read_bits(), speck_init(), THRESHOLD_BITS, xmalloc(), and zero_channel().

Referenced by eps_decode_grayscale_block(), and eps_decode_truecolor_block().


Generated on Fri May 27 14:50:00 2011 for EPSILON by  doxygen 1.5.6