OpenJPH: /build/openjph/src/OpenJPH/src/core/codestream/ojph_codestream_gen.cpp Source File

OpenJPH Open-source implementation of JPEG2000 Part-15

Loading...
Searching...
No Matches
ojph_codestream_gen.cpp
Go to the documentation of this file.
1//***************************************************************************/
2// This software is released under the 2-Clause BSD license, included
3// below.
4//
5// Copyright (c) 2022, Aous Naman
6// Copyright (c) 2022, Kakadu Software Pty Ltd, Australia
7// Copyright (c) 2022, The University of New South Wales, Australia
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13// 1. Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
16// 2. Redistributions in binary form must reproduce the above copyright
17// notice, this list of conditions and the following disclaimer in the
18// documentation and/or other materials provided with the distribution.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//***************************************************************************/
32// This file is part of the OpenJPH software implementation.
33// File: ojph_codestream_gen.cpp
34// Author: Aous Naman
35// Date: 15 May 2022
36//***************************************************************************/
37
38#include <climits>
39
40#include "ojph_defs.h"
41#include "ojph_arch.h"
42
43namespace ojph {
44 namespace local {
45
47 void gen_mem_clear(void* addr, size_t count)
48 {
49 si64* p = (si64*)addr;
50 for (size_t i = 0; i < count; i += 8)
51 *p++ = 0;
52 }
53
55 ui32 gen_find_max_val32(ui32* addr) { return addr[0]; }
56
58 ui64 gen_find_max_val64(ui64* addr) { return addr[0]; }
59
61 void gen_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
62 float delta_inv, ui32 count,
63 ui32* max_val)
64 {
65 ojph_unused(delta_inv);
66 ui32 shift = 31 - K_max;
67 // convert to sign and magnitude and keep max_val
68 ui32 tmax = *max_val;
69 si32 *p = (si32*)sp;
70 for (ui32 i = count; i > 0; --i)
71 {
72 si32 v = *p++;
73 ui32 sign = v >= 0 ? 0U : 0x80000000U;
74 ui32 val = (ui32)(v >= 0 ? v : -v);
75 val <<= shift;
76 *dp++ = sign | val;
77 tmax |= val; // it is more efficient to use or than max
78 }
79 *max_val = tmax;
80 }
81
83 void gen_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max,
84 float delta_inv, ui32 count,
85 ui64* max_val)
86 {
87 ojph_unused(delta_inv);
88 ui32 shift = 63 - K_max;
89 // convert to sign and magnitude and keep max_val
90 ui64 tmax = *max_val;
91 si64 *p = (si64*)sp;
92 for (ui32 i = count; i > 0; --i)
93 {
94 si64 v = *p++;
95 ui64 sign = v >= 0 ? 0ULL : 0x8000000000000000ULL;
96 ui64 val = (ui64)(v >= 0 ? v : -v);
97 val <<= shift;
98 *dp++ = sign | val;
99 tmax |= val; // it is more efficient to use or than max
100 }
101 *max_val = tmax;
102 }
103
105 void gen_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
106 float delta_inv, ui32 count,
107 ui32* max_val)
108 {
109 ojph_unused(K_max);
110 //quantize and convert to sign and magnitude and keep max_val
111 ui32 tmax = *max_val;
112 float *p = (float*)sp;
113 for (ui32 i = count; i > 0; --i)
114 {
115 float v = *p++;
116 si32 t = ojph_trunc(v * delta_inv);
117 ui32 sign = t >= 0 ? 0U : 0x80000000U;
118 ui32 val = (ui32)(t >= 0 ? t : -t);
119 *dp++ = sign | val;
120 tmax |= val; // it is more efficient to use or than max
121 }
122 *max_val = tmax;
123 }
124
126 void gen_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
127 float delta, ui32 count)
128 {
129 ojph_unused(delta);
130 ui32 shift = 31 - K_max;
131 //convert to sign and magnitude
132 si32 *p = (si32*)dp;
133 for (ui32 i = count; i > 0; --i)
134 {
135 ui32 v = *sp++;
136 si32 val = (v & 0x7FFFFFFFU) >> shift;
137 *p++ = (v & 0x80000000U) ? -val : val;
138 }
139 }
140
142 void gen_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max,
143 float delta, ui32 count)
144 {
145 ojph_unused(delta);
146 ui32 shift = 63 - K_max;
147 //convert to sign and magnitude
148 si64 *p = (si64*)dp;
149 for (ui32 i = count; i > 0; --i)
150 {
151 ui64 v = *sp++;
152 si64 val = (v & 0x7FFFFFFFFFFFFFFFULL) >> shift;
153 *p++ = (v & 0x8000000000000000ULL) ? -val : val;
154 }
155 }
156
158 void gen_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
159 float delta, ui32 count)
160 {
161 ojph_unused(K_max);
162 //convert to sign and magnitude
163 float *p = (float*)dp;
164 for (ui32 i = count; i > 0; --i)
165 {
166 ui32 v = *sp++;
167 float val = (float)(v & 0x7FFFFFFFU) * delta;
168 *p++ = (v & 0x80000000U) ? -val : val;
169 }
170 }
171
173 void gen_irv_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max,
174 float delta, ui32 count)
175 {
176 ojph_unused(K_max);
177 //convert to sign and magnitude
178 float *p = (float*)dp;
179 for (ui32 i = count; i > 0; --i)
180 {
181 ui64 v = *sp++;
182 float val = (float)(v & LLONG_MAX) * delta;
183 *p++ = (v & (ui64)LLONG_MIN) ? -val : val;
184 }
185 }
186
187 }
188}
ojph::local
Definition ojph_bitbuffer_read.h:52
ojph::local::gen_irv_tx_from_cb64
void gen_irv_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max, float delta, ui32 count)
Definition ojph_codestream_gen.cpp:173
ojph::local::gen_rev_tx_to_cb64
void gen_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max, float delta_inv, ui32 count, ui64 *max_val)
Definition ojph_codestream_gen.cpp:83
ojph::local::gen_irv_tx_from_cb32
void gen_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
Definition ojph_codestream_gen.cpp:158
ojph::local::gen_irv_tx_to_cb32
void gen_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
Definition ojph_codestream_gen.cpp:105
ojph::local::gen_mem_clear
void gen_mem_clear(void *addr, size_t count)
Definition ojph_codestream_gen.cpp:47
ojph::local::gen_rev_tx_from_cb64
void gen_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max, float delta, ui32 count)
Definition ojph_codestream_gen.cpp:142
ojph::local::gen_find_max_val64
ui64 gen_find_max_val64(ui64 *address)
Definition ojph_codestream_gen.cpp:58
ojph::local::gen_rev_tx_from_cb32
void gen_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
Definition ojph_codestream_gen.cpp:126
ojph::local::gen_rev_tx_to_cb32
void gen_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
Definition ojph_codestream_gen.cpp:61
ojph::local::gen_find_max_val32
ui32 gen_find_max_val32(ui32 *address)
Definition ojph_codestream_gen.cpp:55
ojph
Definition ojph_img_io.h:52
ojph::si64
int64_t si64
Definition ojph_defs.h:57
ojph::ui64
uint64_t ui64
Definition ojph_defs.h:56
ojph::ojph_trunc
static si32 ojph_trunc(float val)
Definition ojph_arch.h:271
ojph::si32
int32_t si32
Definition ojph_defs.h:55
ojph::ui32
uint32_t ui32
Definition ojph_defs.h:54
ojph_arch.h
ojph_defs.h
ojph_unused
#define ojph_unused(x)
Definition ojph_defs.h:78