Grok  7.6.0
Public Member Functions | Private Member Functions | Private Attributes
grk::sparse_array Class Reference

#include <sparse_array.h>

Public Member Functions

 sparse_array (uint32_t width, uint32_t height, uint32_t block_width, uint32_t block_height)
 Creates a new sparse array. More...
 
 ~sparse_array ()
 Frees a sparse array. More...
 
bool read (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, int32_t *dest, const uint32_t dest_col_stride, const uint32_t dest_line_stride, bool forgiving)
 Read the content of a rectangular region of the sparse array into a user buffer. More...
 
bool read (grk_rect_u32 region, int32_t *dest, const uint32_t dest_col_stride, const uint32_t dest_line_stride, bool forgiving)
 Read the content of a rectangular region of the sparse array into a user buffer. More...
 
bool write (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const int32_t *src, const uint32_t src_col_stride, const uint32_t src_line_stride, bool forgiving)
 Write the content of a rectangular region into the sparse array from a user buffer. More...
 
bool alloc (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
 Allocate all blocks for a rectangular region into the sparse array from a user buffer. More...
 

Private Member Functions

bool is_region_valid (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
 Returns whether region bounds are valid (non empty and within array bounds) More...
 
bool read_or_write (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, int32_t *buf, const uint32_t buf_col_stride, const uint32_t buf_line_stride, bool forgiving, bool is_read_op)
 

Private Attributes

uint32_t width
 
uint32_t height
 
uint32_t block_width
 
uint32_t block_height
 
uint32_t block_count_hor
 
uint32_t block_count_ver
 
int32_t ** data_blocks
 

Constructor & Destructor Documentation

◆ sparse_array()

grk::sparse_array::sparse_array ( uint32_t  width,
uint32_t  height,
uint32_t  block_width,
uint32_t  block_height 
)

Creates a new sparse array.

Parameters
widthtotal width of the array.
heighttotal height of the array
block_widthwidth of a block.
block_heightheight of a block.
Returns
a new sparse array instance, or NULL in case of failure.

◆ ~sparse_array()

grk::sparse_array::~sparse_array ( )

Frees a sparse array.

Member Function Documentation

◆ alloc()

bool grk::sparse_array::alloc ( uint32_t  x0,
uint32_t  y0,
uint32_t  x1,
uint32_t  y1 
)

Allocate all blocks for a rectangular region into the sparse array from a user buffer.

Blocks intersecting the region are allocated

Parameters
x0left x coordinate of the region to write into the sparse array.
y0top x coordinate of the region to write into the sparse array.
x1right x coordinate (not included) of the region to write into the sparse array. Must be greater than x0.
y1bottom y coordinate (not included) of the region to write into the sparse array. Must be greater than y0.
Returns
true in case of success.

◆ is_region_valid()

bool grk::sparse_array::is_region_valid ( uint32_t  x0,
uint32_t  y0,
uint32_t  x1,
uint32_t  y1 
)
private

Returns whether region bounds are valid (non empty and within array bounds)

Parameters
x0left x coordinate of the region.
y0top x coordinate of the region.
x1right x coordinate (not included) of the region. Must be greater than x0.
y1bottom y coordinate (not included) of the region. Must be greater than y0.
Returns
true or false.

◆ read() [1/2]

bool grk::sparse_array::read ( grk_rect_u32  region,
int32_t *  dest,
const uint32_t  dest_col_stride,
const uint32_t  dest_line_stride,
bool  forgiving 
)

Read the content of a rectangular region of the sparse array into a user buffer.

Regions not written with write() are read as 0.

Parameters
regionregion to read in the sparse array.
destuser buffer to fill. Must be at least sizeof(int32) * ( (y1 - y0 - 1) * dest_line_stride + (x1 - x0 - 1) * dest_col_stride + 1) bytes large.
dest_col_stridespacing (in elements, not in bytes) in x dimension between consecutive elements of the user buffer.
dest_line_stridespacing (in elements, not in bytes) in y dimension between consecutive elements of the user buffer.
forgivingif set to TRUE and the region is invalid, true will still be returned.
Returns
true in case of success.

◆ read() [2/2]

bool grk::sparse_array::read ( uint32_t  x0,
uint32_t  y0,
uint32_t  x1,
uint32_t  y1,
int32_t *  dest,
const uint32_t  dest_col_stride,
const uint32_t  dest_line_stride,
bool  forgiving 
)

Read the content of a rectangular region of the sparse array into a user buffer.

Regions not written with write() are read as 0.

Parameters
x0left x coordinate of the region to read in the sparse array.
y0top x coordinate of the region to read in the sparse array.
x1right x coordinate (not included) of the region to read in the sparse array. Must be greater than x0.
y1bottom y coordinate (not included) of the region to read in the sparse array. Must be greater than y0.
destuser buffer to fill. Must be at least sizeof(int32) * ( (y1 - y0 - 1) * dest_line_stride + (x1 - x0 - 1) * dest_col_stride + 1) bytes large.
dest_col_stridespacing (in elements, not in bytes) in x dimension between consecutive elements of the user buffer.
dest_line_stridespacing (in elements, not in bytes) in y dimension between consecutive elements of the user buffer.
forgivingif set to TRUE and the region is invalid, true will still be returned.
Returns
true in case of success.

◆ read_or_write()

bool grk::sparse_array::read_or_write ( uint32_t  x0,
uint32_t  y0,
uint32_t  x1,
uint32_t  y1,
int32_t *  buf,
const uint32_t  buf_col_stride,
const uint32_t  buf_line_stride,
bool  forgiving,
bool  is_read_op 
)
private

◆ write()

bool grk::sparse_array::write ( uint32_t  x0,
uint32_t  y0,
uint32_t  x1,
uint32_t  y1,
const int32_t *  src,
const uint32_t  src_col_stride,
const uint32_t  src_line_stride,
bool  forgiving 
)

Write the content of a rectangular region into the sparse array from a user buffer.

Blocks intersecting the region are allocated, if not already done.

Parameters
x0left x coordinate of the region to write into the sparse array.
y0top x coordinate of the region to write into the sparse array.
x1right x coordinate (not included) of the region to write into the sparse array. Must be greater than x0.
y1bottom y coordinate (not included) of the region to write into the sparse array. Must be greater than y0.
srcuser buffer to fill. Must be at least sizeof(int32) * ( (y1 - y0 - 1) * src_line_stride + (x1 - x0 - 1) * src_col_stride + 1) bytes large.
src_col_stridespacing (in elements, not in bytes) in x dimension between consecutive elements of the user buffer.
src_line_stridespacing (in elements, not in bytes) in y dimension between consecutive elements of the user buffer.
forgivingif set to TRUE and the region is invalid, true will still be returned.
Returns
true in case of success.

Field Documentation

◆ block_count_hor

uint32_t grk::sparse_array::block_count_hor
private

◆ block_count_ver

uint32_t grk::sparse_array::block_count_ver
private

◆ block_height

uint32_t grk::sparse_array::block_height
private

◆ block_width

uint32_t grk::sparse_array::block_width
private

◆ data_blocks

int32_t** grk::sparse_array::data_blocks
private

◆ height

uint32_t grk::sparse_array::height
private

◆ width

uint32_t grk::sparse_array::width
private

The documentation for this class was generated from the following file: