OpenJPH
Open-source implementation of JPEG2000 Part-15
Toggle main menu visibility
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
43
namespace
ojph
{
44
namespace
local
{
45
47
void
gen_mem_clear
(
void
* addr,
size_t
count)
48
{
49
memset(addr, 0, count);
50
}
51
53
ui32
gen_find_max_val32
(
ui32
* addr) {
return
addr[0]; }
54
56
ui64
gen_find_max_val64
(
ui64
* addr) {
return
addr[0]; }
57
59
void
gen_rev_tx_to_cb32
(
const
void
*sp,
ui32
*dp,
ui32
K_max,
60
float
delta_inv,
ui32
count,
61
ui32
* max_val)
62
{
63
ojph_unused
(delta_inv);
64
ui32
shift = 31 - K_max;
65
// convert to sign and magnitude and keep max_val
66
ui32
tmax = *max_val;
67
si32
*p = (
si32
*)sp;
68
for
(
ui32
i = count; i > 0; --i)
69
{
70
si32
v = *p++;
71
ui32
sign = v >= 0 ? 0U : 0x80000000U;
72
ui32
val = (
ui32
)(v >= 0 ? v : -v);
73
val <<= shift;
74
*dp++ = sign | val;
75
tmax |= val;
// it is more efficient to use or than max
76
}
77
*max_val = tmax;
78
}
79
81
void
gen_rev_tx_to_cb64
(
const
void
*sp,
ui64
*dp,
ui32
K_max,
82
float
delta_inv,
ui32
count,
83
ui64
* max_val)
84
{
85
ojph_unused
(delta_inv);
86
ui32
shift = 63 - K_max;
87
// convert to sign and magnitude and keep max_val
88
ui64
tmax = *max_val;
89
si64
*p = (
si64
*)sp;
90
for
(
ui32
i = count; i > 0; --i)
91
{
92
si64
v = *p++;
93
ui64
sign = v >= 0 ? 0ULL : 0x8000000000000000ULL;
94
ui64
val = (
ui64
)(v >= 0 ? v : -v);
95
val <<= shift;
96
*dp++ = sign | val;
97
tmax |= val;
// it is more efficient to use or than max
98
}
99
*max_val = tmax;
100
}
101
103
void
gen_irv_tx_to_cb32
(
const
void
*sp,
ui32
*dp,
ui32
K_max,
104
float
delta_inv,
ui32
count,
105
ui32
* max_val)
106
{
107
ojph_unused
(K_max);
108
//quantize and convert to sign and magnitude and keep max_val
109
ui32
tmax = *max_val;
110
float
*p = (
float
*)sp;
111
for
(
ui32
i = count; i > 0; --i)
112
{
113
float
v = *p++;
114
si32
t = ojph_trunc(v * delta_inv);
115
ui32
sign = t >= 0 ? 0U : 0x80000000U;
116
ui32
val = (
ui32
)(t >= 0 ? t : -t);
117
*dp++ = sign | val;
118
tmax |= val;
// it is more efficient to use or than max
119
}
120
*max_val = tmax;
121
}
122
124
void
gen_rev_tx_from_cb32
(
const
ui32
*sp,
void
*dp,
ui32
K_max,
125
float
delta,
ui32
count)
126
{
127
ojph_unused
(delta);
128
ui32
shift = 31 - K_max;
129
//convert to sign and magnitude
130
si32
*p = (
si32
*)dp;
131
for
(
ui32
i = count; i > 0; --i)
132
{
133
ui32
v = *sp++;
134
si32
val = (v & 0x7FFFFFFFU) >> shift;
135
*p++ = (v & 0x80000000U) ? -val : val;
136
}
137
}
138
140
void
gen_rev_tx_from_cb64
(
const
ui64
*sp,
void
*dp,
ui32
K_max,
141
float
delta,
ui32
count)
142
{
143
ojph_unused
(delta);
144
ui32
shift = 63 - K_max;
145
//convert to sign and magnitude
146
si64
*p = (
si64
*)dp;
147
for
(
ui32
i = count; i > 0; --i)
148
{
149
ui64
v = *sp++;
150
si64
val = (v & 0x7FFFFFFFFFFFFFFFULL) >> shift;
151
*p++ = (v & 0x8000000000000000ULL) ? -val : val;
152
}
153
}
154
156
void
gen_irv_tx_from_cb32
(
const
ui32
*sp,
void
*dp,
ui32
K_max,
157
float
delta,
ui32
count)
158
{
159
ojph_unused
(K_max);
160
//convert to sign and magnitude
161
float
*p = (
float
*)dp;
162
for
(
ui32
i = count; i > 0; --i)
163
{
164
ui32
v = *sp++;
165
float
val = (float)(v & 0x7FFFFFFFU) * delta;
166
*p++ = (v & 0x80000000U) ? -val : val;
167
}
168
}
169
171
void
gen_irv_tx_from_cb64
(
const
ui64
*sp,
void
*dp,
ui32
K_max,
172
float
delta,
ui32
count)
173
{
174
ojph_unused
(K_max);
175
//convert to sign and magnitude
176
float
*p = (
float
*)dp;
177
for
(
ui32
i = count; i > 0; --i)
178
{
179
ui64
v = *sp++;
180
float
val = (float)(v & LLONG_MAX) * delta;
181
*p++ = (v & (
ui64
)LLONG_MIN) ? -val : val;
182
}
183
}
184
185
}
186
}
ojph::local
Definition
ojph_bitbuffer_read.h:53
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:171
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:81
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:156
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:103
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:140
ojph::local::gen_find_max_val64
ui64 gen_find_max_val64(ui64 *address)
Definition
ojph_codestream_gen.cpp:56
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:124
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:59
ojph::local::gen_find_max_val32
ui32 gen_find_max_val32(ui32 *address)
Definition
ojph_codestream_gen.cpp:53
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::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
src
core
codestream
ojph_codestream_gen.cpp
Generated by
1.18.0