OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
ojph_params_local.h
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) 2019, Aous Naman
6
// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
7
// Copyright (c) 2019, 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_params_local.h
34
// Author: Aous Naman
35
// Date: 28 August 2019
36
//***************************************************************************/
37
38
39
#ifndef OJPH_PARAMS_LOCAL_H
40
#define OJPH_PARAMS_LOCAL_H
41
42
#include <cstring>
43
#include <cassert>
44
45
#include "
ojph_defs.h
"
46
#include "
ojph_base.h
"
47
#include "
ojph_arch.h
"
48
#include "
ojph_message.h
"
49
50
namespace
ojph
{
51
53
class
outfile_base;
54
class
infile_base;
55
57
enum
PROGRESSION_ORDER
:
si32
58
{
59
OJPH_PO_LRCP
= 0,
60
OJPH_PO_RLCP
= 1,
61
OJPH_PO_RPCL
= 2,
62
OJPH_PO_PCRL
= 3,
63
OJPH_PO_CPRL
= 4
64
};
65
67
const
char
OJPH_PO_STRING_LRCP
[] =
"LRCP"
;
68
const
char
OJPH_PO_STRING_RLCP
[] =
"RLCP"
;
69
const
char
OJPH_PO_STRING_RPCL
[] =
"RPCL"
;
70
const
char
OJPH_PO_STRING_PCRL
[] =
"PCRL"
;
71
const
char
OJPH_PO_STRING_CPRL
[] =
"CPRL"
;
72
74
enum
OJPH_PROFILE_NUM
:
si32
75
{
76
OJPH_PN_UNDEFINED
= 0,
77
OJPH_PN_PROFILE0
= 1,
78
OJPH_PN_PROFILE1
= 2,
79
OJPH_PN_CINEMA2K
= 3,
80
OJPH_PN_CINEMA4K
= 4,
81
OJPH_PN_CINEMAS2K
= 5,
82
OJPH_PN_CINEMAS4K
= 6,
83
OJPH_PN_BROADCAST
= 7,
84
OJPH_PN_IMF
= 8
85
};
86
88
const
char
OJPH_PN_STRING_PROFILE0
[] =
"PROFILE0"
;
89
const
char
OJPH_PN_STRING_PROFILE1
[] =
"PROFILE1"
;
90
const
char
OJPH_PN_STRING_CINEMA2K
[] =
"CINEMA2K"
;
91
const
char
OJPH_PN_STRING_CINEMA4K
[] =
"CINEMA4K"
;
92
const
char
OJPH_PN_STRING_CINEMAS2K
[] =
"CINEMAS2K"
;
93
const
char
OJPH_PN_STRING_CINEMAS4K
[] =
"CINEMAS4K"
;
94
const
char
OJPH_PN_STRING_BROADCAST
[] =
"BROADCAST"
;
95
const
char
OJPH_PN_STRING_IMF
[] =
"IMF"
;
96
98
enum
OJPH_TILEPART_DIVISIONS
:
ui32
{
99
OJPH_TILEPART_NO_DIVISIONS
= 0x0,
// no divisions to tile parts
100
OJPH_TILEPART_RESOLUTIONS
= 0x1,
101
OJPH_TILEPART_COMPONENTS
= 0x2,
102
OJPH_TILEPART_LAYERS
= 0x4,
// these are meaningless with HTJ2K
103
OJPH_TILEPART_MASK
= 0x3,
// mask used for testing
104
};
105
106
namespace
local {
107
108
//defined here
109
struct
param_siz;
110
struct
param_cod;
111
struct
param_qcd;
112
struct
param_cap;
113
struct
param_sot;
114
struct
param_tlm;
115
struct
param_dfs;
116
struct
param_atk;
117
119
enum
JP2K_MARKER
:
ui16
120
{
121
SOC
= 0xFF4F,
//start of codestream (required)
122
CAP
= 0xFF50,
//extended capability
123
SIZ
= 0xFF51,
//image and tile size (required)
124
COD
= 0xFF52,
//coding style default (required)
125
COC
= 0xFF53,
//coding style component
126
TLM
= 0xFF55,
//tile-part lengths
127
PRF
= 0xFF56,
//profile
128
PLM
= 0xFF57,
//packet length, main header
129
PLT
= 0xFF58,
//packet length, tile-part header
130
CPF
= 0xFF59,
//corresponding profile values
131
QCD
= 0xFF5C,
//qunatization default (required)
132
QCC
= 0xFF5D,
//quantization component
133
RGN
= 0xFF5E,
//region of interest
134
POC
= 0xFF5F,
//progression order change
135
PPM
= 0xFF60,
//packed packet headers, main header
136
PPT
= 0xFF61,
//packed packet headers, tile-part header
137
CRG
= 0xFF63,
//component registration
138
COM
= 0xFF64,
//comment
139
DFS
= 0xFF72,
//downsampling factor styles
140
ADS
= 0xFF73,
//arbitrary decomposition styles
141
NLT
= 0xFF76,
//non-linearity point transformation
142
ATK
= 0xFF79,
//arbitrary transformation kernels
143
SOT
= 0xFF90,
//start of tile-part
144
SOP
= 0xFF91,
//start of packet
145
EPH
= 0xFF92,
//end of packet
146
SOD
= 0xFF93,
//start of data
147
EOC
= 0xFFD9,
//end of codestream (required)
148
};
149
151
//
152
//
153
//
154
//
155
//
157
struct
siz_comp_info
158
{
159
ui8
SSiz
;
160
ui8
XRsiz
;
161
ui8
YRsiz
;
162
};
163
165
struct
param_siz
166
{
167
friend ::ojph::param_siz;
168
169
public
:
170
enum :
ui16
{
171
RSIZ_NLT_FLAG
= 0x200,
172
RSIZ_HT_FLAG
= 0x4000,
173
RSIZ_EXT_FLAG
= 0x8000,
174
};
175
176
public
:
177
param_siz
()
178
{
179
Lsiz
=
Csiz
= 0;
180
Xsiz
=
Ysiz
=
XOsiz
=
YOsiz
=
XTsiz
=
YTsiz
=
XTOsiz
=
YTOsiz
= 0;
181
skipped_resolutions
= 0;
182
memset(
store
, 0,
sizeof
(
store
));
183
ws_kern_support_needed
=
dfs_support_needed
=
false
;
184
cod
= NULL;
185
dfs
= NULL;
186
Rsiz
=
RSIZ_HT_FLAG
;
187
cptr
=
store
;
188
old_Csiz
= 4;
189
}
190
191
~param_siz
()
192
{
193
if
(
cptr
!=
store
)
delete
[]
cptr
;
194
}
195
196
void
set_num_components
(
ui32
num_comps)
197
{
198
Csiz
= (
ui16
)num_comps;
199
if
(
Csiz
>
old_Csiz
)
200
{
201
if
(
cptr
!=
store
)
202
delete
[]
cptr
;
203
cptr
=
new
siz_comp_info
[num_comps];
204
old_Csiz
=
Csiz
;
205
}
206
memset(
cptr
, 0,
sizeof
(
local::siz_comp_info
) * num_comps);
207
}
208
209
void
set_comp_info
(
ui32
comp_num,
const
point
& downsampling,
210
ui32
bit_depth,
bool
is_signed
)
211
{
212
assert(comp_num <
Csiz
);
213
assert(downsampling.
x
!= 0 && downsampling.
y
!= 0);
214
cptr
[comp_num].
SSiz
= (
ui8
)(bit_depth - 1 + (
is_signed
? 0x80 : 0));
215
cptr
[comp_num].
XRsiz
= (
ui8
)downsampling.
x
;
216
cptr
[comp_num].
YRsiz
= (
ui8
)downsampling.
y
;
217
}
218
219
void
check_validity
(
const
param_cod
&
cod
)
220
{
221
this->cod = &
cod
;
222
223
if
(
XTsiz
== 0 &&
YTsiz
== 0)
224
{
XTsiz
=
Xsiz
+
XOsiz
;
YTsiz
=
Ysiz
+
YOsiz
; }
225
if
(
Xsiz
== 0 ||
Ysiz
== 0 ||
XTsiz
== 0 ||
YTsiz
== 0)
226
OJPH_ERROR
(0x00040001,
227
"You cannot set image extent nor tile size to zero"
);
228
if
(
XTOsiz
>
XOsiz
||
YTOsiz
>
YOsiz
)
229
OJPH_ERROR
(0x00040002,
230
"tile offset has to be smaller than image offset"
);
231
if
(
XTsiz
+
XTOsiz
<=
XOsiz
||
YTsiz
+
YTOsiz
<=
YOsiz
)
232
OJPH_ERROR
(0x00040003,
233
"the top left tile must intersect with the image"
);
234
}
235
236
ui16
get_num_components
()
const
{
return
Csiz
; }
237
ui32
get_bit_depth
(
ui32
comp_num)
const
238
{
239
assert(comp_num <
Csiz
);
240
return
(
cptr
[comp_num].SSiz & 0x7F) + 1u;
241
}
242
bool
is_signed
(
ui32
comp_num)
const
243
{
244
assert(comp_num <
Csiz
);
245
return
(
cptr
[comp_num].SSiz & 0x80) != 0;
246
}
247
point
get_downsampling
(
ui32
comp_num)
const
248
{
249
assert(comp_num <
Csiz
);
250
return
point
(
cptr
[comp_num].XRsiz,
cptr
[comp_num].YRsiz);
251
}
252
253
bool
write
(
outfile_base
*file);
254
void
read
(
infile_base
*file);
255
256
void
link
(
const
param_cod
*
cod
)
257
{ this->cod =
cod
; }
258
259
void
link
(
const
param_dfs
*
dfs
)
260
{ this->dfs =
dfs
; }
261
262
void
set_skipped_resolutions
(
ui32
skipped_resolutions
)
263
{ this->skipped_resolutions =
skipped_resolutions
; }
264
265
ui32
get_width
(
ui32
comp_num)
const
266
{
267
assert(comp_num <
get_num_components
());
268
ui32
ds = (
ui32
)
cptr
[comp_num].XRsiz;
269
ui32
t =
ojph_div_ceil
(
Xsiz
, ds) -
ojph_div_ceil
(
XOsiz
, ds);
270
return
t;
271
}
272
273
ui32
get_height
(
ui32
comp_num)
const
274
{
275
assert(comp_num <
get_num_components
());
276
ui32
ds = (
ui32
)
cptr
[comp_num].YRsiz;
277
ui32
t =
ojph_div_ceil
(
Ysiz
, ds) -
ojph_div_ceil
(
YOsiz
, ds);
278
return
t;
279
}
280
281
point
get_recon_downsampling
(
ui32
comp_num)
const
;
282
point
get_recon_size
(
ui32
comp_num)
const
;
283
ui32
get_recon_width
(
ui32
comp_num)
const
284
{
return
get_recon_size
(comp_num).
x
; }
285
ui32
get_recon_height
(
ui32
comp_num)
const
286
{
return
get_recon_size
(comp_num).
y
; }
287
288
bool
is_ws_kern_support_needed
() {
return
ws_kern_support_needed
; }
289
bool
is_dfs_support_needed
() {
return
dfs_support_needed
; }
290
291
void
set_Rsiz_flag
(
ui16
flag)
292
{
Rsiz
|= flag; }
293
void
reset_Rsiz_flag
(
ui16
flag)
294
{
Rsiz
= (
ui16
)(
Rsiz
& ~flag); }
295
296
private
:
297
ui16
Lsiz
;
298
ui16
Rsiz
;
299
ui32
Xsiz
;
300
ui32
Ysiz
;
301
ui32
XOsiz
;
302
ui32
YOsiz
;
303
ui32
XTsiz
;
304
ui32
YTsiz
;
305
ui32
XTOsiz
;
306
ui32
YTOsiz
;
307
ui16
Csiz
;
308
siz_comp_info
*
cptr
;
309
310
private
:
311
ui32
skipped_resolutions
;
312
int
old_Csiz
;
313
siz_comp_info
store
[4];
314
bool
ws_kern_support_needed
;
315
bool
dfs_support_needed
;
316
const
param_cod
*
cod
;
317
const
param_dfs
*
dfs
;
318
param_siz
(
const
param_siz
&) =
delete
;
//prevent copy constructor
319
param_siz
&
operator=
(
const
param_siz
&) =
delete
;
//prevent copy
320
};
321
323
//
324
//
325
//
326
//
327
//
329
struct
cod_SPcod
330
{
331
cod_SPcod
() {
332
num_decomp
= 5;
333
block_width
= 4;
// 64
334
block_height
= 4;
// 64
335
block_style
= 0x40;
// HT mode
336
wavelet_trans
= 0;
// reversible 5 / 3
337
memset(
precinct_size
, 0,
sizeof
(
precinct_size
));
338
}
339
340
ui8
num_decomp
;
341
ui8
block_width
;
342
ui8
block_height
;
343
ui8
block_style
;
344
ui8
wavelet_trans
;
345
ui8
precinct_size
[33];
//num_decomp is in [0,32]
346
347
size
get_log_block_dims
()
const
348
{
return
size
(
block_width
+ 2,
block_height
+ 2); }
349
size
get_block_dims
()
const
350
{
size
t =
get_log_block_dims
();
return
size
(1 << t.
w
, 1 << t.
h
); }
351
size
get_log_precinct_size
(
ui32
res_num)
const
352
{
353
assert(res_num <=
num_decomp
);
354
size
ps(
precinct_size
[res_num] & 0xF,
precinct_size
[res_num] >> 4);
355
return
ps;
356
}
357
};
358
360
struct
cod_SGcod
361
{
362
cod_SGcod
() :
prog_order
(
OJPH_PO_RPCL
),
num_layers
(1),
mc_trans
(0) {}
363
ui8
prog_order
;
364
ui16
num_layers
;
365
ui8
mc_trans
;
366
};
367
369
struct
param_cod
370
{
371
// serves for both COD and COC markers
372
friend ::ojph::param_cod;
373
enum
default_comp_num
:
ui16
{
374
OJPH_COD_UNKNOWN
= 65534,
375
OJPH_COD_DEFAULT
= 65535
376
};
377
379
enum
BLOCK_CODING_STYLES
{
380
VERT_CAUSAL_MODE
= 0x8,
381
HT_MODE
= 0x40
382
};
384
enum
cod_type
:
ui8
{
385
UNDEFINED
= 0,
386
COD_MAIN
= 1,
387
COC_MAIN
= 2,
388
COD_TILE
= 3,
// not implemented
389
COC_TILE
= 4
// not implemented
390
};
392
enum
dwt_type
:
ui8
{
393
DWT_IRV97
= 0,
394
DWT_REV53
= 1,
395
};
396
397
public
:
// COD_MAIN and COC_MAIN common functions
399
param_cod
(
param_cod
*
top_cod
= NULL,
ui16
comp_idx
=
OJPH_COD_DEFAULT
)
400
{
401
type
=
top_cod
?
COC_MAIN
:
COD_MAIN
;
402
Lcod
= 0;
403
Scod
= 0;
404
next
= NULL;
405
atk
= NULL;
406
this->
top_cod
=
top_cod
;
407
this->
comp_idx
=
comp_idx
;
408
}
409
411
~param_cod
() {
412
if
(
next
) {
413
delete
next
;
414
next
= NULL;
415
}
416
}
417
419
void
set_reversible
(
bool
reversible)
420
{
421
assert(
type
==
UNDEFINED
||
type
==
COD_MAIN
||
type
==
COC_MAIN
);
422
SPcod
.