OpenJPH
Open-source implementation of JPEG2000 Part-15
ojph_codeblock.cpp
Go to the documentation of this file.
1
2//***************************************************************************/
3// This software is released under the 2-Clause BSD license, included
4// below.
5//
6// Copyright (c) 2019, Aous Naman
7// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
8// Copyright (c) 2019, The University of New South Wales, Australia
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//***************************************************************************/
33// This file is part of the OpenJPH software implementation.
34// File: ojph_codeblock.cpp
35// Author: Aous Naman
36// Date: 28 August 2019
37//***************************************************************************/
38
39
40#include <climits>
41#include <cmath>
42
43#include "ojph_mem.h"
44#include "ojph_params.h"
46#include "ojph_codeblock.h"
47#include "ojph_subband.h"
48
49namespace ojph {
50
51 namespace local
52 {
53
56 const size& nominal)
57 {
59
60 assert(byte_alignment / sizeof(ui32) > 1);
61 const ui32 f = byte_alignment / sizeof(ui32) - 1;
62 ui32 stride = (nominal.w + f) & ~f; // a multiple of 8
63 allocator->pre_alloc_data<ui32>(nominal.h * stride, 0);
64 }
65
68 subband *parent, const size& nominal,
69 const size& cb_size,
70 coded_cb_header* coded_cb,
71 ui32 K_max, int line_offset)
72 {
74
75 const ui32 f = byte_alignment / sizeof(ui32) - 1;
76 this->stride = (nominal.w + f) & ~f; // a multiple of 8
77 this->buf_size = this->stride * nominal.h;
78 this->buf = allocator->post_alloc_data<ui32>(this->buf_size, 0);
79
80 this->nominal_size = nominal;
81 this->cb_size = cb_size;
82 this->parent = parent;
83 this->line_offset = line_offset;
84 this->cur_line = 0;
85 this->delta = parent->get_delta();
86 this->delta_inv = 1.0f / this->delta;
87 this->K_max = K_max;
88 for (int i = 0; i < 8; ++i)
89 this->max_val[i] = 0;
91 this->reversible = cod.is_reversible();
92 this->resilient = codestream->is_resilient();
94 this->zero_block = false;
95 this->coded_cb = coded_cb;
96
98 }
99
102 {
103 // convert to sign and magnitude and keep max_val
104 const si32 *sp = line->i32 + line_offset;
105 ui32 *dp = buf + cur_line * stride;
107 max_val);
108 ++cur_line;
109 }
110
113 {
115 if (mv >= 1u<<(31 - K_max))
116 {
118 assert(coded_cb->missing_msbs > 0);
119 assert(coded_cb->missing_msbs < K_max);
120 coded_cb->num_passes = 1;
121
124 elastic, coded_cb->next_coded);
125 }
126 }
127
129 void codeblock::recreate(const size &cb_size, coded_cb_header* coded_cb)
130 {
131 assert(cb_size.h * stride <= buf_size && cb_size.w <= stride);
132 this->cb_size = cb_size;
133 this->coded_cb = coded_cb;
134 this->cur_line = 0;
135 for (int i = 0; i < 8; ++i)
136 this->max_val[i] = 0;
137 this->zero_block = false;
138 }
139
142 {
143 if (coded_cb->pass_length[0] > 0 && coded_cb->num_passes > 0 &&
144 coded_cb->next_coded != NULL)
145 {
146 bool result = this->codeblock_functions.decode_cb(
151
152 if (result == false)
153 {
154 if (resilient == true)
155 zero_block = true;
156 else
157 OJPH_ERROR(0x000300A1, "Error decoding a codeblock\n");
158 }
159 }
160 else
161 zero_block = true;
162 }
163
164
167 {
168 si32 *dp = line->i32 + line_offset;
169 if (!zero_block)
170 {
171 //convert to sign and magnitude
172 const ui32 *sp = buf + cur_line * stride;
174 }
175 else
176 this->codeblock_functions.mem_clear(dp, cb_size.w * sizeof(*dp));
177 ++cur_line;
178 assert(cur_line <= cb_size.h);
179 }
180
181 }
182}
static void pre_alloc(codestream *codestream, const size &nominal)
coded_cb_header * coded_cb
void push(line_buf *line)
void encode(mem_elastic_allocator *elastic)
void recreate(const size &cb_size, coded_cb_header *coded_cb)
void finalize_alloc(codestream *codestream, subband *parent, const size &nominal, const size &cb_size, coded_cb_header *coded_cb, ui32 K_max, int tbx0)
codeblock_fun codeblock_functions
void pull_line(line_buf *line)
mem_fixed_allocator * get_allocator()
void pre_alloc_data(size_t num_ele, ui32 pre_size)
Definition: ojph_mem.h:66
T * post_alloc_data(size_t num_ele, ui32 pre_size)
Definition: ojph_mem.h:89
OJPH_EXPORT bool is_reversible() const
OJPH_EXPORT bool get_block_vertical_causality() const
const ui32 byte_alignment
Definition: ojph_arch.h:200
int32_t si32
Definition: ojph_defs.h:55
uint32_t ui32
Definition: ojph_defs.h:54
#define OJPH_ERROR(t,...)
Definition: ojph_message.h:131
si32 * i32
Definition: ojph_mem.h:155
static const int prefix_buf_size
ui32 w
Definition: ojph_base.h:50
ui32 h
Definition: ojph_base.h:51