Skip to content

Commit cd8e6a4

Browse files
authored
Merge pull request #191 from aous72/placeholder_passes
Placeholder passes
2 parents 2ff2b1b + 4ca0a9d commit cd8e6a4

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

src/core/codestream/ojph_codeblock.h

Lines changed: 8 additions & 8 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
@@ -71,11 +71,11 @@ namespace ojph {
7171
};
7272

7373
public:
74-
static void pre_alloc(codestream *codestream, const size& nominal,
74+
static void pre_alloc(codestream *codestream, const size& nominal,
7575
ui32 precision);
7676
void finalize_alloc(codestream *codestream, subband* parent,
7777
const size& nominal, const size& cb_size,
78-
coded_cb_header* coded_cb, ui32 K_max,
78+
coded_cb_header* coded_cb, ui32 K_max,
7979
int tbx0, ui32 precision, ui32 comp_idx);
8080
void push(line_buf *line);
8181
void encode(mem_elastic_allocator *elastic);
@@ -115,7 +115,7 @@ namespace ojph {
115115
struct coded_cb_header
116116
{
117117
ui32 pass_length[2];
118-
ui32 num_passes;
118+
ui32 num_passes; // number of passes to be decoded
119119
ui32 Kmax;
120120
ui32 missing_msbs;
121121
coded_lists *next_coded;

src/core/codestream/ojph_precinct.cpp

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
// This software is released under the 2-Clause BSD license, included
33
// below.
44
//
5-
// Copyright (c) 2019, Aous Naman
5+
// Copyright (c) 2019, Aous Naman
66
// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
77
// Copyright (c) 2019, The University of New South Wales, Australia
8-
//
8+
//
99
// Redistribution and use in source and binary forms, with or without
1010
// modification, are permitted provided that the following conditions are
1111
// met:
12-
//
12+
//
1313
// 1. Redistributions of source code must retain the above copyright
1414
// notice, this list of conditions and the following disclaimer.
15-
//
15+
//
1616
// 2. Redistributions in binary form must reproduce the above copyright
1717
// notice, this list of conditions and the following disclaimer in the
1818
// documentation and/or other materials provided with the distribution.
19-
//
19+
//
2020
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2121
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2222
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
@@ -254,7 +254,7 @@ namespace ojph {
254254
bits2 = 32 - (int)count_leading_zeros(cp->pass_length[1]);
255255
int bits = ojph_max(bits1, bits2 - extra_bit) - 3;
256256
bits = ojph_max(bits, 0);
257-
bb_put_bits(&bb, 0xFFFFFFFEu, bits+1,
257+
bb_put_bits(&bb, 0xFFFFFFFEu, bits+1,
258258
elastic, cur_coded_list, ph_bytes);
259259

260260
bb_put_bits(&bb, cp->pass_length[0], bits+3,
@@ -463,37 +463,53 @@ namespace ojph {
463463
}
464464
cp->num_passes = num_passes;
465465

466-
//parse pass lengths
467-
//for one pass, one length, but for 2 or 3 passes, two lengths
468-
int extra_bit = cp->num_passes > 2 ? 1 : 0;
469-
int bits1 = 3;
466+
// Parse pass lengths
467+
// When number of passes is one, one length.
468+
// When number of passes is two or three, two lengths.
469+
// When number of passes > 3, we have place holder passes;
470+
// In this case, subtract multiples of 3 from the number of
471+
// passes; for example, if we have 10 passes, we subtract 9,
472+
// producing 1 pass.
473+
474+
// 1 => 1, 2 => 2, 3 => 3, 4 => 1, 5 => 2, 6 => 3
475+
ui32 num_phld_passes = (num_passes - 1) / 3;
476+
cp->missing_msbs += num_phld_passes;
477+
478+
num_phld_passes *= 3;
479+
cp->num_passes = num_passes - num_phld_passes;
480+
cp->pass_length[0] = cp->pass_length[1] = 0;
481+
482+
int Lblock = 3;
470483
bit = 1;
471484
while (bit)
472485
{
486+
// add any extra bits here
473487
if (bb_read_bit(&bb, bit) == false)
474488
{ data_left = 0; throw "error reading from file p8"; }
475-
bits1 += bit;
489+
Lblock += bit;
476490
}
477491

478-
if (bb_read_bits(&bb, bits1, bit) == false)
492+
int bits = Lblock + 31 - count_leading_zeros(num_phld_passes + 1);
493+
if (bb_read_bits(&bb, bits, bit) == false)
479494
{ data_left = 0; throw "error reading from file p9"; }
480-
if (bit < 2) {
495+
if (bit < 2)
481496
throw "The cleanup segment of an HT codeblock cannot contain "
482497
"less than 2 bytes";
483-
}
484-
if (bit >= 65535) {
498+
if (bit >= 65535)
485499
throw "The cleanup segment of an HT codeblock must contain "
486500
"less than 65535 bytes";
487-
}
488501
cp->pass_length[0] = bit;
489-
if (num_passes > 1)
502+
503+
if (cp->num_passes > 1)
490504
{
491-
if (bb_read_bits(&bb, bits1 + extra_bit, bit) == false)
505+
//bits = Lblock + 31 - count_leading_zeros(cp->num_passes - 1);
506+
// The following is simpler than the above, I think?
507+
bits = Lblock + (cp->num_passes > 2 ? 1 : 0);
508+
if (bb_read_bits(&bb, bits, bit) == false)
492509
{ data_left = 0; throw "error reading from file p10"; }
493-
if (bit >= 2047) {
510+
if (bit >= 2047)
494511
throw "The refinement segment (SigProp and MagRep passes) of "
495512
"an HT codeblock must contain less than 2047 bytes";
496-
}
497513
cp->pass_length[1] = bit;
498514
}
499515
}
@@ -532,7 +548,7 @@ namespace ojph {
532548
ui32 t = ojph_min(num_bytes, bb.bytes_left);
533549
file->seek(t, infile_base::OJPH_SEEK_CUR);
534550
ui32 bytes_read = (ui32)(file->tell() - cur_loc);
535-
cp->pass_length[0] = cp->pass_length[1] = 0;
551+
cp->pass_length[0] = cp->pass_length[1] = 0;
536552
bb.bytes_left -= bytes_read;
537553
assert(bytes_read == t || bb.bytes_left == 0);
538554
}

src/core/common/ojph_version.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
// This software is released under the 2-Clause BSD license, included
33
// below.
44
//
5-
// Copyright (c) 2019, Aous Naman
5+
// Copyright (c) 2019, Aous Naman
66
// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
77
// Copyright (c) 2019, The University of New South Wales, Australia
8-
//
8+
//
99
// Redistribution and use in source and binary forms, with or without
1010
// modification, are permitted provided that the following conditions are
1111
// met:
12-
//
12+
//
1313
// 1. Redistributions of source code must retain the above copyright
1414
// notice, this list of conditions and the following disclaimer.
15-
//
15+
//
1616
// 2. Redistributions in binary form must reproduce the above copyright
1717
// notice, this list of conditions and the following disclaimer in the
1818
// documentation and/or other materials provided with the distribution.
19-
//
19+
//
2020
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2121
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2222
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
@@ -35,4 +35,4 @@
3535

3636
#define OPENJPH_VERSION_MAJOR 0
3737
#define OPENJPH_VERSION_MINOR 21
38-
#define OPENJPH_VERSION_PATCH 3
38+
#define OPENJPH_VERSION_PATCH 4

0 commit comments

Comments
 (0)