Grok  7.6.0
sparse_array.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2020 Grok Image Compression Inc.
3  *
4  * This source code is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License, version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This source code is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  *
17  * This source code incorporates work covered by the following copyright and
18  * permission notice:
19  *
20  * The copyright in this software is being made available under the 2-clauses
21  * BSD License, included below. This software may be subject to other third
22  * party and contributor rights, including patent rights, and no such rights
23  * are granted under this license.
24  *
25  * Copyright (c) 2017, IntoPix SA <contact@intopix.com>
26  * All rights reserved.
27  *
28  * Redistribution and use in source and binary forms, with or without
29  * modification, are permitted provided that the following conditions
30  * are met:
31  * 1. Redistributions of source code must retain the above copyright
32  * notice, this list of conditions and the following disclaimer.
33  * 2. Redistributions in binary form must reproduce the above copyright
34  * notice, this list of conditions and the following disclaimer in the
35  * documentation and/or other materials provided with the distribution.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
38  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
41  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47  * POSSIBILITY OF SUCH DAMAGE.
48  */
49 
50 #pragma once
51 
67 
68 namespace grk {
69 
70 class sparse_array {
71 
72 public:
73 
83  sparse_array(uint32_t width,
84  uint32_t height,
85  uint32_t block_width,
86  uint32_t block_height);
87 
92 
108  bool read(uint32_t x0,
109  uint32_t y0,
110  uint32_t x1,
111  uint32_t y1,
112  int32_t* dest,
113  const uint32_t dest_col_stride,
114  const uint32_t dest_line_stride,
115  bool forgiving);
116 
129  bool read(grk_rect_u32 region,
130  int32_t* dest,
131  const uint32_t dest_col_stride,
132  const uint32_t dest_line_stride,
133  bool forgiving);
134 
135 
151  bool write(uint32_t x0,
152  uint32_t y0,
153  uint32_t x1,
154  uint32_t y1,
155  const int32_t* src,
156  const uint32_t src_col_stride,
157  const uint32_t src_line_stride,
158  bool forgiving);
159 
171  bool alloc( uint32_t x0,
172  uint32_t y0,
173  uint32_t x1,
174  uint32_t y1);
175 
176 private:
177 
185  bool is_region_valid( uint32_t x0,
186  uint32_t y0,
187  uint32_t x1,
188  uint32_t y1);
189 
190  bool read_or_write(uint32_t x0,
191  uint32_t y0,
192  uint32_t x1,
193  uint32_t y1,
194  int32_t* buf,
195  const uint32_t buf_col_stride,
196  const uint32_t buf_line_stride,
197  bool forgiving,
198  bool is_read_op);
199 
200  uint32_t width;
201  uint32_t height;
202  uint32_t block_width;
203  uint32_t block_height;
204  uint32_t block_count_hor;
205  uint32_t block_count_ver;
206  int32_t** data_blocks;
207 };
208 
209 }
210 
grk::sparse_array::block_count_hor
uint32_t block_count_hor
Definition: sparse_array.h:204
grk::grk_rectangle< uint32_t >
grk::sparse_array::~sparse_array
~sparse_array()
Frees a sparse array.
grk::sparse_array::read
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.
grk::sparse_array::block_count_ver
uint32_t block_count_ver
Definition: sparse_array.h:205
grk::sparse_array::write
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.
grk::sparse_array::block_height
uint32_t block_height
Definition: sparse_array.h:203
grk::sparse_array::read_or_write
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)
grk::sparse_array::block_width
uint32_t block_width
Definition: sparse_array.h:202
grk::sparse_array::data_blocks
int32_t ** data_blocks
Definition: sparse_array.h:206
grk::sparse_array::read
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.
grk::sparse_array::height
uint32_t height
Definition: sparse_array.h:201
grk
Copyright (C) 2016-2020 Grok Image Compression Inc.
Definition: BitIO.h:27
grk::sparse_array::is_region_valid
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)
grk::sparse_array::alloc
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.
grk::sparse_array::sparse_array
sparse_array(uint32_t width, uint32_t height, uint32_t block_width, uint32_t block_height)
Creates a new sparse array.
grk::sparse_array::width
uint32_t width
Definition: sparse_array.h:200
grk::sparse_array
Definition: sparse_array.h:70