Skip to content

Commit 871c6ad

Browse files
committed
Adds a check that we do not use reversible Sqcd/Sqcc with irreversible transform
1 parent e0ecd0d commit 871c6ad

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/core/codestream/ojph_params.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,11 +1421,15 @@ namespace ojph {
14211421

14221422
//////////////////////////////////////////////////////////////////////////
14231423
float param_qcd::get_irrev_delta(const param_dfs* dfs,
1424-
ui32 num_decompositions,
1424+
ui32 num_decompositions, ui32 comp_num,
14251425
ui32 resolution, ui32 subband) const
14261426
{
14271427
float arr[] = { 1.0f, 2.0f, 2.0f, 4.0f };
1428-
assert((Sqcd & 0x1F) == 2);
1428+
if ((Sqcd & 0x1F) != 2)
1429+
OJPH_ERROR(0x00050101, "There is something wrong in the configuration "
1430+
"of the codestream; for component %d, the codestream defines an "
1431+
"irreversible transform, for which the codestream provides a "
1432+
"reversible (no quantization) step sizes in Sqcd/Sqcc.", comp_num);
14291433

14301434
ui32 idx;
14311435
if (dfs != NULL && dfs->exists())

src/core/codestream/ojph_params_local.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ namespace ojph {
715715
ui32 resolution, ui32 subband) const;
716716
ui32 propose_precision(const param_cod* cod) const;
717717
float get_irrev_delta(const param_dfs* dfs,
718-
ui32 num_decompositions,
718+
ui32 num_decompositions, ui32 comp_num,
719719
ui32 resolution, ui32 subband) const;
720720
bool write(outfile_base *file);
721721
bool write_qcc(outfile_base *file, ui32 num_comps);

src/core/codestream/ojph_subband.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
// This software is released under the 2-Clause BSD license, included
44
// below.
55
//
6-
// Copyright (c) 2019, Aous Naman
6+
// Copyright (c) 2019, Aous Naman
77
// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
88
// Copyright (c) 2019, The University of New South Wales, Australia
9-
//
9+
//
1010
// Redistribution and use in source and binary forms, with or without
1111
// modification, are permitted provided that the following conditions are
1212
// met:
13-
//
13+
//
1414
// 1. Redistributions of source code must retain the above copyright
1515
// notice, this list of conditions and the following disclaimer.
16-
//
16+
//
1717
// 2. Redistributions in binary form must reproduce the above copyright
1818
// notice, this list of conditions and the following disclaimer in the
1919
// documentation and/or other materials provided with the distribution.
20-
//
20+
//
2121
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2222
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2323
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
@@ -127,7 +127,8 @@ namespace ojph {
127127
this->band_rect = band_rect;
128128
this->parent = res;
129129

130-
const param_cod* cdp = codestream->get_coc(parent->get_comp_num());
130+
ui32 comp_num = parent->get_comp_num();
131+
const param_cod* cdp = codestream->get_coc(comp_num);
131132
this->reversible = cdp->access_atk()->is_reversible();
132133
size log_cb = cdp->get_log_block_dims();
133134
log_PP = cdp->get_log_precinct_size(res_num);
@@ -149,14 +150,14 @@ namespace ojph {
149150
if (dfs != NULL)
150151
dfs = dfs->get_dfs(cdp->get_dfs_index());
151152
}
152-
ui32 comp_num = parent->get_comp_num();
153153
const param_qcd* qcd = codestream->access_qcd()->get_qcc(comp_num);
154154
ui32 num_decomps = cdp->get_num_decompositions();
155155
this->K_max = qcd->get_Kmax(dfs, num_decomps, this->res_num, band_num);
156156
if (!reversible)
157157
{
158-
float d =
159-
qcd->get_irrev_delta(dfs, num_decomps, res_num, subband_num);
158+
float d =
159+
qcd->get_irrev_delta(dfs, num_decomps,
160+
comp_num, res_num, subband_num);
160161
d /= (float)(1u << (31 - this->K_max));
161162
delta = d;
162163
delta_inv = (1.0f/d);
@@ -199,7 +200,7 @@ namespace ojph {
199200
ui32 cbx1 = ojph_min(tbx1, x_lower_bound + (i + 1) * nominal.w);
200201
cb_size.w = cbx1 - cbx0;
201202
blocks[i].finalize_alloc(codestream, this, nominal, cb_size,
202-
coded_cbs + i, K_max, line_offset,
203+
coded_cbs + i, K_max, line_offset,
203204
precision, comp_num);
204205
line_offset += cb_size.w;
205206
}
@@ -210,7 +211,7 @@ namespace ojph {
210211
ui32 width = band_rect.siz.w + 1;
211212
if (reversible)
212213
{
213-
if (precision <= 32)
214+
if (precision <= 32)
214215
lines->wrap(allocator->post_alloc_data<si32>(width, 1), width, 1);
215216
else
216217
lines->wrap(allocator->post_alloc_data<si64>(width, 1), width, 1);

0 commit comments

Comments
 (0)