Grok 20.3.2
ISparseCanvas.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2026 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
18#pragma once
19
20#include <cstdint>
21#include <algorithm>
22
23// SparseCanvas stores blocks in the canvas coordinate system. It covers the active sub-bands for
24// all (reduced) resolutions
25
26/***
27 *
28 * SparseCanvas stores blocks of size LBW x LBH in canvas coordinate system (with offset)
29 * Blocks are only allocated for active sub-bands for reduced resolutions
30 *
31 * Data is passed in and out in a linear array, chunked either along the y axis
32 * or along the x axis, depending on whether we are working with a horizontal strip
33 * or a vertical strip of data.
34 *
35 *
36 */
37
38namespace grk
39{
40template<typename T>
42{
43public:
44 virtual ~ISparseCanvas() = default;
48 virtual bool read(uint8_t resno, Rect32 window, T* dest, const uint32_t destChunkY,
49 const uint32_t destChunkX) = 0;
53 virtual bool write(uint8_t resno, Rect32 window, const T* src, const uint32_t srcChunkY,
54 const uint32_t srcChunkX) = 0;
55
56 virtual bool alloc(Rect32 window, bool zeroOutBuffer) = 0;
57};
58template<typename T>
60{
61 SparseBlock(void) : data(nullptr) {}
63 {
64 delete[] data;
65 }
66 void alloc(uint32_t block_area, bool zeroOutBuffer)
67 {
68 data = new T[block_area];
69 if(zeroOutBuffer)
70 memset(data, 0, (size_t)block_area * sizeof(T));
71 }
72 T* data;
73};
74
75} // namespace grk
Definition ISparseCanvas.h:42
virtual bool read(uint8_t resno, Rect32 window, T *dest, const uint32_t destChunkY, const uint32_t destChunkX)=0
Read window of data into dest buffer.
virtual bool alloc(Rect32 window, bool zeroOutBuffer)=0
virtual ~ISparseCanvas()=default
virtual bool write(uint8_t resno, Rect32 window, const T *src, const uint32_t srcChunkY, const uint32_t srcChunkX)=0
Write window of data from src buffer.
ResWindow.
Definition CompressedChunkCache.h:36
Rect< uint32_t > Rect32
Definition geometry.h:64
T * data
Definition ISparseCanvas.h:72
void alloc(uint32_t block_area, bool zeroOutBuffer)
Definition ISparseCanvas.h:66
~SparseBlock()
Definition ISparseCanvas.h:62
SparseBlock(void)
Definition ISparseCanvas.h:61