OpenJPH Open-source implementation of JPEG2000 Part-15

Loading...
Searching...
No Matches
ojph_codestream_local.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) 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_codestream_local.cpp
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38
39#include <climits>
40#include <cmath>
41
42#include "ojph_mem.h"
43#include "ojph_params.h"
44#include "ojph_codestream_local.h"
45#include "ojph_tile.h"
46
47#include "../transform/ojph_colour.h"
48#include "../transform/ojph_transform.h"
49
50 namespace ojph {
51
52 namespace local
53 {
54
56 codestream::codestream()
57 : precinct_scratch(NULL), allocator(NULL), elastic_alloc(NULL)
58 {
59 allocator = new mem_fixed_allocator;
60 elastic_alloc = new mem_elastic_allocator(1048576); // 1 megabyte
61
62 init_colour_transform_functions();
63 init_wavelet_transform_functions();
64
65 restart();
66 }
67
69 codestream::~codestream()
70 {
71 if (allocator)
72 delete allocator;
73 if (elastic_alloc)
74 delete elastic_alloc;
75 }
76
78 void codestream::restart()
79 {
80 tiles = NULL;
81 lines = NULL;
82 comp_size = NULL;
83 recon_comp_size = NULL;
84 outfile = NULL;
85 infile = NULL;
86
87 num_comps = 0;
88 employ_color_transform = false;
89 planar = -1;
90 profile = OJPH_PN_UNDEFINED;
91 tilepart_div = OJPH_TILEPART_NO_DIVISIONS;
92 need_tlm = false;
93
94 cur_comp = 0;
95 cur_line = 0;
96 cur_tile_row = 0;
97 resilient = false;
98 skipped_res_for_read = skipped_res_for_recon = 0;
99
100 precinct_scratch_needed_bytes = 0;
101
102 cod.restart();
103 qcd.restart();
104 nlt.restart();
105 dfs.restart();
106 atk.restart();
107
108 allocator->restart();
109 elastic_alloc->restart();
110 }
111
113 void codestream::pre_alloc()
114 {
115 ojph::param_siz sz = access_siz();
116 num_tiles.w = sz.get_image_extent().x - sz.get_tile_offset().x;
117 num_tiles.w = ojph_div_ceil(num_tiles.w, sz.get_tile_size().w);
118 num_tiles.h = sz.get_image_extent().y - sz.get_tile_offset().y;
119 num_tiles.h = ojph_div_ceil(num_tiles.h, sz.get_tile_size().h);
120 if (num_tiles.area() > 65535)
121 OJPH_ERROR(0x00030011, "the number of tiles cannot exceed 65535");
122 if (num_tiles.area() == 0)
123 OJPH_ERROR(0x00030012, "the number of tiles cannot be 0");
124
125 //allocate tiles
126 allocator->pre_alloc_obj<tile>((size_t)num_tiles.area());
127
128 ui32 num_tileparts = 0;
129 point index;
130 rect tile_rect, recon_tile_rect;
131 ui32 ds = 1 << skipped_res_for_recon;
132 for (index.y = 0; index.y < num_tiles.h; ++index.y)
133 {
134 ui32 y0 = sz.get_tile_offset().y
135 + index.y * sz.get_tile_size().h;
136 ui32 y1 = y0 + sz.get_tile_size().h; //end of tile
137
138 tile_rect.org.y = ojph_max(y0, sz.get_image_offset().y);
139 tile_rect.siz.h =
140 ojph_min(y1, sz.get_image_extent().y) - tile_rect.org.y;
141
142 recon_tile_rect.org.y = ojph_max(ojph_div_ceil(y0, ds),
143 ojph_div_ceil(sz.get_image_offset().y, ds));
144 recon_tile_rect.siz.h = ojph_min(ojph_div_ceil(y1, ds),
145 ojph_div_ceil(sz.get_image_extent().y, ds))
146 - recon_tile_rect.org.y;
147
148 for (index.x = 0; index.x < num_tiles.w; ++index.x)
149 {
150 ui32 x0 = sz.get_tile_offset().x
151 + index.x * sz.get_tile_size().w;
152 ui32 x1 = x0 + sz.get_tile_size().w;
153
154 tile_rect.org.x = ojph_max(x0, sz.get_image_offset().x);
155 tile_rect.siz.w =
156 ojph_min(x1, sz.get_image_extent().x) - tile_rect.org.x;
157
158 recon_tile_rect.org.x = ojph_max(ojph_div_ceil(x0, ds),
159 ojph_div_ceil(sz.get_image_offset().x, ds));
160 recon_tile_rect.siz.w = ojph_min(ojph_div_ceil(x1, ds),
161 ojph_div_ceil(sz.get_image_extent().x, ds))
162 - recon_tile_rect.org.x;
163
164 ui32 tps = 0; // number of tileparts for this tile
165 tile::pre_alloc(this, tile_rect, recon_tile_rect, tps);
166 num_tileparts += tps;
167 }
168 }
169
170 //allocate lines
171 //These lines are used by codestream to exchange data with external
172 // world
173 ui32 num_comps = sz.get_num_components();
174 allocator->pre_alloc_obj<line_buf>(num_comps);
175 allocator->pre_alloc_obj<size>(num_comps); //for *comp_size
176 allocator->pre_alloc_obj<size>(num_comps); //for *recon_comp_size
177 for (ui32 i = 0; i < num_comps; ++i)
178 allocator->pre_alloc_data<si32>(siz.get_recon_width(i), 0);
179
180 //allocate tlm
181 if (outfile != NULL && need_tlm)
182 allocator->pre_alloc_obj<param_tlm::Ttlm_Ptlm_pair>(num_tileparts);
183
184 //precinct scratch buffer
185 ui32 num_decomps = cod.get_num_decompositions();
186 size log_cb = cod.get_log_block_dims();
187
188 size ratio;
189 for (ui32 r = 0; r <= num_decomps; ++r)
190 {
191 size log_PP = cod.get_log_precinct_size(r);
192 ratio.w = ojph_max(ratio.w, log_PP.w - ojph_min(log_cb.w, log_PP.w));
193 ratio.h = ojph_max(ratio.h, log_PP.h - ojph_min(log_cb.h, log_PP.h));
194 }
195 ui32 max_ratio = ojph_max(ratio.w, ratio.h);
196 max_ratio = 1 << max_ratio;
197 // assuming that we have a hierarchy of n levels.
198 // This needs 4/3 times the area, rounded up
199 // (rounding up leaves one extra entry).
200 // This exta entry is necessary
201 // We need 4 such tables. These tables store
202 // 1. missing msbs and 2. their flags,
203 // 3. number of layers and 4. their flags
204 precinct_scratch_needed_bytes =
205 4 * ((max_ratio * max_ratio * 4 + 2) / 3);
206
207 allocator->pre_alloc_obj<ui8>(precinct_scratch_needed_bytes);
208 }
209
211 void codestream::finalize_alloc()
212 {
213 allocator->alloc();
214
215 //precinct scratch buffer
216 precinct_scratch =
217 allocator->post_alloc_obj<ui8>(precinct_scratch_needed_bytes);
218
219 //get tiles
220 tiles = this->allocator->post_alloc_obj<tile>((size_t)num_tiles.area());
221
222 ui32 num_tileparts = 0;
223 point index;
224 rect tile_rect;
225 ojph::param_siz sz = access_siz();
226 for (index.y = 0; index.y < num_tiles.h; ++index.y)
227 {
228 ui32 y0 = sz.get_tile_offset().y
229 + index.y * sz.get_tile_size().h;
230 ui32 y1 = y0 + sz.get_tile_size().h; //end of tile
231
232 tile_rect.org.y = ojph_max(y0, sz.get_image_offset().y);
233 tile_rect.siz.h =
234 ojph_min(y1, sz.get_image_extent().y) - tile_rect.org.y;
235
236 ui32 offset = 0;
237 for (index.x = 0; index.x < num_tiles.w; ++index.x)
238 {
239 ui32 x0 = sz.get_tile_offset().x
240 + index.x * sz.get_tile_size().w;
241 ui32 x1 = x0 + sz.get_tile_size().w;
242
243 tile_rect.org.x = ojph_max(x0, sz.get_image_offset().x);
244 tile_rect.siz.w =
245 ojph_min(x1, sz.get_image_extent().x) - tile_rect.org.x;
246
247 ui32 tps = 0; // number of tileparts for this tile
248 ui32 idx = index.y * num_tiles.w + index.x;
249 tiles[idx].finalize_alloc(this, tile_rect, idx, offset, tps);
250 num_tileparts += tps;
251 }
252 }
253
254 //allocate lines
255 //These lines are used by codestream to exchange data with external
256 // world
257 this->num_comps = sz.get_num_components();
258 lines = allocator->post_alloc_obj<line_buf>(this->num_comps);
259 comp_size = allocator->post_alloc_obj<size>(this->num_comps);
260 recon_comp_size = allocator->post_alloc_obj<size>(this->num_comps);
261 employ_color_transform = cod.is_employing_color_transform();
262 for (ui32 i = 0; i < this->num_comps; ++i)
263 {
264 comp_size[i].w = siz.get_width(i);
265 comp_size[i].h = siz.get_height(i);
266 ui32 cw = siz.get_recon_width(i);
267 recon_comp_size[i].w = cw;
268 recon_comp_size[i].h = siz.get_recon_height(i);
269 lines[i].wrap(allocator->post_alloc_data<si32>(cw, 0), cw, 0);
270 }
271
272 cur_comp = 0;
273 cur_line = 0;
274
275 //allocate tlm
276 if (outfile != NULL && need_tlm)
277 tlm.init(num_tileparts,
278 allocator->post_alloc_obj<param_tlm::Ttlm_Ptlm_pair>(num_tileparts));
279 }
280
281
283 void codestream::check_imf_validity()
284 {
285 //two possibilities lossy single tile or lossless
286 //For the following code, we use the least strict profile
287 ojph::param_siz sz(&siz);
288 ojph::param_cod cd(&cod);
289 bool reversible = cd.is_reversible();
290 bool imf2k = !reversible, imf4k = !reversible, imf8k = !reversible;
291 bool imf2kls = reversible, imf4kls = reversible, imf8kls = reversible;
292
293 if (reversible)
294 {
295 point ext = sz.get_image_extent();
296 if (ext.x <= 2048 && ext.y <= 1556)
297 imf2kls &= true;
298 if (ext.x <= 4096 && ext.y <= 3112)
299 imf4kls &= true;
300 if (ext.x <= 8192 && ext.y <= 6224)
301 imf8kls &= true;
302
303 if (!imf2kls && !imf4kls && !imf8kls)
304 OJPH_ERROR(0x000300C1,
305 "Image dimensions do not meet any of the lossless IMF profiles");
306 }
307 else
308 {
309 point ext = sz.get_image_extent();
310 if (ext.x <= 2048 && ext.y <= 1556)
311 imf2k &= true;
312 if (ext.x <= 4096 && ext.y <= 3112)
313 imf4k &= true;
314 if (ext.x <= 8192 && ext.y <= 6224)
315 imf8k &= true;
316
317 if (!imf2k && !imf4k && !imf8k)
318 OJPH_ERROR(0x000300C2,
319 "Image dimensions do not meet any of the lossy IMF profiles");
320 }
321
322
323 if (sz.get_image_offset().x != 0 || sz.get_image_offset().y != 0)
324 OJPH_ERROR(0x000300C3,
325 "For IMF profile, image offset (XOsiz, YOsiz) has to be 0.");
326 if (sz.get_tile_offset().x != 0 || sz.get_tile_offset().y != 0)
327 OJPH_ERROR(0x000300C4,
328 "For IMF profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
329 if (sz.get_num_components() > 3)
330 OJPH_ERROR(0x000300C5,
331 "For IMF profile, the number of components has to be less "
332 " or equal to 3");
333 bool test_ds1 = true, test_ds2 = true;
334 for (ojph::ui32 i = 0; i < sz.get_num_components(); ++i)
335 {
336 point downsamping = sz.get_downsampling(i);
337 test_ds1 &= downsamping.y == 1;
338 test_ds2 &= downsamping.y == 1;
339
340 test_ds1 &= downsamping.x == 1;
341 if (i == 1 || i == 2)
342 test_ds2 &= downsamping.x == 2;
343 else
344 test_ds2 &= downsamping.x == 1;
345 }
346 if (!test_ds1 && !test_ds2)
347 OJPH_ERROR(0x000300C6,
348 "For IMF profile, either no component downsampling is used,"
349 " or the x-dimension of the 2nd and 3rd components is downsampled"
350 " by 2.");
351
352 bool test_bd = true;
353 for (ojph::ui32 i = 0; i < sz.get_num_components(); ++i)
354 {
355 ui32 bit_depth = sz.get_bit_depth(i);
356 bool is_signed = sz.is_signed(i);
357 test_bd &= bit_depth >= 8 && bit_depth <= 16 && is_signed == false;
358 }
359 if (!test_bd)
360 OJPH_ERROR(0x000300C7,
361 "For IMF profile, compnent bit_depth has to be between"
362 " 8 and 16 bits inclusively, and the samples must be unsigned");
363
364 if (cd.get_log_block_dims().w != 5 || cd.get_log_block_dims().h != 5)
365 OJPH_ERROR(0x000300C8,
366 "For IMF profile, codeblock dimensions are restricted."
367 " Use \"-block_size {32,32}\" at the commandline");
368
369 ui32 num_decomps = cd.get_num_decompositions();
370 bool test_pz = cd.get_log_precinct_size(0).w == 7
371 && cd.get_log_precinct_size(0).h == 7;
372 for (ui32 i = 1; i <= num_decomps; ++i)
373 test_pz = cd.get_log_precinct_size(i).w == 8
374 && cd.get_log_precinct_size(i).h == 8;
375 if (!test_pz)
376 OJPH_ERROR(0x000300C9,
377 "For IMF profile, precinct sizes are restricted."
378 " Use \"-precincts {128,128},{256,256}\" at the commandline");
379
380 if (cd.get_progression_order() != OJPH_PO_CPRL)
381 OJPH_ERROR(0x000300CA,
382 "For IMF profile, the CPRL progression order must be used."
383 " Use \"-prog_order CPRL\".");
384
385 imf2k &= num_decomps <= 5;
386 imf2kls &= num_decomps <= 5;
387 imf4k &= num_decomps <= 6;
388 imf4kls &= num_decomps <= 6;
389 imf8k &= num_decomps <= 7;
390 imf8kls &= num_decomps <= 7;
391
392 if (num_decomps == 0 ||
393 (!imf2k && !imf4k && !imf8k && !imf2kls && !imf4kls && !imf8kls))
394 OJPH_ERROR(0x000300CB,
395 "Number of decompositions does not match the IMF profile"
396 " dictated by wavelet reversibility and image dimensions.");
397
398 ui32 tiles_w = sz.get_image_extent().x;
399 tiles_w = ojph_div_ceil(tiles_w, sz.get_tile_size().w);
400 ui32 tiles_h = sz.get_image_extent().y;
401 tiles_h = ojph_div_ceil(tiles_h, sz.get_tile_size().h);
402 ui32 total_tiles = tiles_w * tiles_h;
403
404 if (total_tiles > 1)
405 {
406 if (!reversible)
407 OJPH_ERROR(0x000300CC,
408 "Lossy IMF profile must have one tile.");
409
410 size tt = sz.get_tile_size();
411 imf2kls &= (tt.w == 1024 && tt.h == 1024);
412 imf2kls &= (tt.w >= 1024 && num_decomps <= 4)
413 || (tt.w >= 2048 && num_decomps <= 5);
414 imf4kls &= (tt.w == 1024 && tt.h == 1024)
415 || (tt.w == 2048 && tt.h == 2048);
416 imf4kls &= (tt.w >= 1024 && num_decomps <= 4)
417 || (tt.w >= 2048 && num_decomps <= 5)
418 || (tt.w >= 4096 && num_decomps <= 6);
419 imf8kls &= (tt.w == 1024 && tt.h == 1024)
420 || (tt.w == 2048 && tt.h == 2048)
421 || (tt.w == 4096 && tt.h == 4096);
422 imf8kls &= (tt.w >= 1024 && num_decomps <= 4)
423 || (tt.w >= 2048 && num_decomps <= 5)
424 || (tt.w >= 4096 && num_decomps <= 6)
425 || (tt.w >= 8192 && num_decomps <= 7);
426 if (!imf2kls && !imf4kls && !imf8kls)
427 OJPH_ERROR(0x000300CD,
428 "Number of decompositions does not match the IMF profile"
429 " dictated by wavelet reversibility and image dimensions and"
430 " tiles.");
431 }
432
433 need_tlm = true;
434 tilepart_div |= OJPH_TILEPART_COMPONENTS;
435 if (tilepart_div != OJPH_TILEPART_COMPONENTS)
436 {
437 tilepart_div = OJPH_TILEPART_COMPONENTS;
438 OJPH_WARN(0x000300C1,
439 "In IMF profile, tile part divisions at the component level must be "
440 "employed, while at the resolution level is not allowed. "
441 "This has been corrected.");
442 }
443 }
444
446 void codestream::check_broadcast_validity()
447 {
448 ojph::param_siz sz(&siz);
449 ojph::param_cod cd(&cod);
450
451 if (sz.get_image_offset().x != 0 || sz.get_image_offset().y != 0)
452 OJPH_ERROR(0x000300B1,
453 "For broadcast profile, image offset (XOsiz, YOsiz) has to be 0.");
454 if (sz.get_tile_offset().x != 0 || sz.get_tile_offset().y != 0)
455 OJPH_ERROR(0x000300B2,
456 "For broadcast profile, tile offset (XTOsiz, YTOsiz) has to be 0.");
457 if (sz.get_num_components() > 4)
458 OJPH_ERROR(0x000300B3,
459 "For broadcast profile, the number of components has to be less "
460 " or equal to 4");
461 bool test_ds1 = true, test_ds2 = true;
462 for (ojph::ui32 i = 0; i < sz.get_num_components(); ++i)
463 {
464 point downsamping = sz.get_downsampling(i);
465 test_ds1 &= downsamping.y == 1;
466 test_ds2 &= downsamping.y == 1;
467
468 test_ds1 &= downsamping.x == 1;
469 if (i == 1 || i == 2)
470 test_ds2 &= downsamping.x == 2;
471 else
472 test_ds2 &= downsamping.x == 1;
473 }
474 if (!test_ds1 && !test_ds2)
475 OJPH_ERROR(0x000300B4,
476 "For broadcast profile, either no component downsampling is used,"
477 " or the x-dimension of the 2nd and 3rd components is downsampled"
478 " by 2.");
479
480 bool test_bd = true;
481 for (ojph::ui32 i = 0; i < sz.get_num_components(); ++i)
482 {
483 ui32 bit_depth = sz.get_bit_depth(i);
484 bool is_signed = sz.is_signed(i);
485 test_bd &= bit_depth >= 8 && bit_depth <= 12 && is_signed == false;
486 }
487 if (!test_bd)
488 OJPH_ERROR(0x000300B5,
489 "For broadcast profile, compnent bit_depth has to be between"
490 " 8 and 12 bits inclusively, and the samples must be unsigned");
491
492 ui32 num_decomps = cd.get_num_decompositions();
493 if (num_decomps == 0 || num_decomps > 5)
494 OJPH_ERROR(0x000300B6,
495 "For broadcast profile, number of decompositions has to be between"
496 "1 and 5 inclusively.");
497
498 if (cd.get_log_block_dims().w < 5 || cd.get_log_block_dims().w > 7)
499 OJPH_ERROR(0x000300B7,
500 "For broadcast profile, codeblock dimensions are restricted such"
501 " that codeblock width has to be either 32, 64, or 128.");
502
503 if (cd.get_log_block_dims().h < 5 || cd.get_log_block_dims().h > 7)
504 OJPH_ERROR(0x000300B8,
505 "For broadcast profile, codeblock dimensions are restricted such"
506 " that codeblock height has to be either 32, 64, or 128.");
507
508 bool test_pz = cd.get_log_precinct_size(0).w == 7
509 && cd.get_log_precinct_size(0).h == 7;
510 for (ui32 i = 1; i <= num_decomps; ++i)
511 test_pz = cd.get_log_precinct_size(i).w == 8
512 && cd.get_log_precinct_size(i).h == 8;
513 if (!test_pz)
514 OJPH_ERROR(0x000300B9,
515 "For broadcast profile, precinct sizes are restricted."
516 " Use \"-precincts {128,128},{256,256}\" at the commandline");
517
518 if (cd.get_progression_order() != OJPH_PO_CPRL)
519 OJPH_ERROR(0x000300BA,
520 "For broadcast profile, the CPRL progression order must be used."
521 " Use \"-prog_order CPRL\".");
522
523 ui32 tiles_w = sz.get_image_extent().x;
524 tiles_w = ojph_div_ceil(tiles_w, sz.get_tile_size().w);
525 ui32 tiles_h = sz.get_image_extent().y;
526 tiles_h = ojph_div_ceil(tiles_h, sz.get_tile_size().h);
527 ui32 total_tiles = tiles_w * tiles_h;
528
529 if (total_tiles != 1 && total_tiles != 4)
530 OJPH_ERROR(0x000300BB,
531 "The broadcast profile can only have 1 or 4 tiles");
532
533 need_tlm = true;
534 tilepart_div |= OJPH_TILEPART_COMPONENTS;
535 if (tilepart_div != OJPH_TILEPART_COMPONENTS)
536 {
537 tilepart_div = OJPH_TILEPART_COMPONENTS;
538 OJPH_WARN(0x000300B1,
539 "In BROADCAST profile, tile part divisions at the component level "
540 "must be employed, while at the resolution level is not allowed. "
541 "This has been corrected.");
542 }
543 }
544
546 void codestream::write_headers(outfile_base *file,
547 const comment_exchange* comments,
548 ui32 num_comments)
549 {
550 //finalize
551 siz.set_cod(cod);
552 // set the tile size if it was not set by the user
553 size tile_size = siz.get_tile_size();
554 if (tile_size.h == 0 && tile_size.w == 0)
555 {
556 point img_offset = siz.get_image_offset();
557 point img_extent = siz.get_image_extent();
558 size t(img_extent.x + img_offset.x, img_extent.y + img_offset.y);
559 siz.set_tile_size(t);
560 }
561 siz.check_validity();
562 cod.check_validity(siz);
563 cod.update_atk(&atk);
564 qcd.check_validity(siz, cod);
565 cap.check_validity(cod, qcd);
566 nlt.check_validity(siz);
567 if (profile == OJPH_PN_IMF)
568 check_imf_validity();
569 else if (profile == OJPH_PN_BROADCAST)
570 check_broadcast_validity();
571
572 int po = ojph::param_cod(&cod).get_progression_order();
573 if ((po == OJPH_PO_LRCP || po == OJPH_PO_RLCP) &&
574 tilepart_div == OJPH_TILEPART_COMPONENTS)
575 {
576 tilepart_div |= OJPH_TILEPART_RESOLUTIONS;
577 OJPH_INFO(0x00030021,
578 "For LRCP and RLCP progression orders, tilepart divisions at the "
579 "component level, means that we have a tilepart for every "
580 "resolution and component.\n");
581 }
582 if (po == OJPH_PO_RPCL && (tilepart_div & OJPH_TILEPART_COMPONENTS) != 0)
583 {
584 tilepart_div &= ~OJPH_TILEPART_COMPONENTS;
585 OJPH_WARN(0x00030021,
586 "For RPCL progression, having tilepart divisions at the component "
587 "level means a tilepart for every precinct, which does not "
588 "make sense, since we can have no more than 255 tile parts. This "
589 "has been corrected by removing tilepart divisions at the component "
590 "level.");
591 }
592 if (po == OJPH_PO_PCRL && tilepart_div != 0)
593 {
594 tilepart_div = 0;
595 OJPH_WARN(0x00030022,
596 "For PCRL progression, having tilepart divisions at the component "
597 "level or the resolution level means a tile part for every "
598 "precinct, which does not make sense, since we can have no more "
599 "than 255 tile parts. This has been corrected by removing tilepart "
600 "divisions; use another progression if you want tileparts.");
601 }
602 if (po == OJPH_PO_CPRL && (tilepart_div & OJPH_TILEPART_RESOLUTIONS) != 0)
603 {
604 tilepart_div &= ~OJPH_TILEPART_RESOLUTIONS;
605 OJPH_WARN(0x00030023,
606 "For CPRL progression, having tilepart divisions at the resolution "
607 "level means a tile part for every precinct, which does not "
608 "make sense, since we can have no more than 255 tile parts. This "
609 "has been corrected by removing tilepart divisions at the "
610 "resolution level.");
611 }
612
613 if (planar == -1) //not initialized
614 planar = cod.is_employing_color_transform() ? 1 : 0;
615 else if (planar == 0) //interleaved is chosen
616 {
617 }
618 else if (planar == 1) //plannar is chosen
619 {
620 if (cod.is_employing_color_transform() == true)
621 OJPH_ERROR(0x00030021,
622 "the planar interface option cannot be used when colour "
623 "transform is employed");
624 }
625 else
626 assert(0);
627
628 assert(this->outfile == NULL);
629 this->outfile = file;
630 this->pre_alloc();
631 this->finalize_alloc();
632
633 ui16 t = swap_byte(JP2K_MARKER::SOC);
634 if (file->write(&t, 2) != 2)
635 OJPH_ERROR(0x00030022, "Error writing to file");
636
637 if (!siz.write(file))
638 OJPH_ERROR(0x00030023, "Error writing to file");
639
640 if (!cap.write(file))
641 OJPH_ERROR(0x00030024, "Error writing to file");
642
643 if (!cod.write(file))
644 OJPH_ERROR(0x00030025, "Error writing to file");
645
646 if (!cod.write_coc(file, num_comps))
647 OJPH_ERROR(0x0003002E, "Error writing to file");
648
649 if (!qcd.write(file))
650 OJPH_ERROR(0x00030026, "Error writing to file");
651
652 if (!qcd.write_qcc(file, num_comps))
653 OJPH_ERROR(0x0003002D, "Error writing to file");
654
655 if (!nlt.write(file))
656 OJPH_ERROR(0x00030027, "Error writing to file");
657
658 char buf[] = " OpenJPH Ver "
659 OJPH_INT_TO_STRING(OPENJPH_VERSION_MAJOR) "."
660 OJPH_INT_TO_STRING(OPENJPH_VERSION_MINOR) "."
661 OJPH_INT_TO_STRING(OPENJPH_VERSION_PATCH) ".";
662 size_t len = strlen(buf);
663 *(ui16*)buf = swap_byte(JP2K_MARKER::COM);
664 *(ui16*)(buf + 2) = swap_byte((ui16)(len - 2));
665 //1 for General use (IS 8859-15:1999 (Latin) values)
666 *(ui16*)(buf + 4) = swap_byte((ui16)(1));
667 if (file->write(buf, len) != len)
668 OJPH_ERROR(0x00030028, "Error writing to file");
669
670 if (comments != NULL) {
671 for (ui32 i = 0; i < num_comments; ++i)
672 {
673 t = swap_byte(JP2K_MARKER::COM);
674 if (file->write(&t, 2) != 2)
675 OJPH_ERROR(0x00030029, "Error writing to file");
676 t = swap_byte((ui16)(comments[i].len + 4));
677 if (file->write(&t, 2) != 2)
678 OJPH_ERROR(0x0003002A, "Error writing to file");
679 //1 for General use (IS 8859-15:1999 (Latin) values)
680 t = swap_byte(comments[i].Rcom);
681 if (file->write(&t, 2) != 2)
682 OJPH_ERROR(0x0003002B, "Error writing to file");
683 if (file->write(comments[i].data, comments[i].len)!=comments[i].len)
684 OJPH_ERROR(0x0003002C, "Error writing to file");
685 }
686 }
687 }
688
690 static
691 int find_marker(infile_base *f, const ui16* char_list, int list_len)
692 {
693 //returns the marker index in char_list, or -1
694 while (!f->eof())
695 {
696 ui8 new_char;
697 size_t num_bytes = f->read(&new_char, 1);
698 if (num_bytes != 1)
699 return -1;
700 if (new_char == 0xFF)
701 {
702 size_t num_bytes = f->read(&new_char, 1);
703
704 if (num_bytes != 1)
705 return -1;
706
707 for (int i = 0; i < list_len; ++i)
708 if (new_char == (char_list[i] & 0xFF))
709 return i;
710 }
711 }
712 return -1;
713 }
714
716 static
717 int skip_marker(infile_base *file, const char *marker,
718 const char *msg, int msg_level, bool resilient)
719 {
720 ojph_unused(marker);
721 ui16 com_len;
722 if (file->read(&com_len, 2) != 2)
723 {
724 if (resilient)
725 return -1;
726 else
727 OJPH_ERROR(0x00030041, "error reading marker");
728 }
729 com_len = swap_byte(com_len);
730 file->seek(com_len - 2, infile_base::OJPH_SEEK_CUR);
731 if (msg != NULL && msg_level != OJPH_MSG_NO_MSG)
732 {
733 if (msg_level == OJPH_MSG_INFO)
734 {
735 OJPH_INFO(0x00030001, "%s", msg);
736 }
737 else if (msg_level == OJPH_MSG_WARN)
738 {
739 OJPH_WARN(0x00030001, "%s", msg);
740 }
741 else if (msg_level == OJPH_MSG_ERROR)
742 {
743 OJPH_ERROR(0x00030001, "%s", msg);
744 }
745 else // there is the option of ALL_MSG but it should not be used here
746 assert(0);
747 }
748 return 0;
749 }
750
752 void codestream::read_headers(infile_base *file)
753 {
754 ui16 marker_list[20] = { SOC, SIZ, CAP, PRF, CPF, COD, COC, QCD, QCC,
755 RGN, POC, PPM, TLM, PLM, CRG, COM, DFS, ATK, NLT, SOT };
756 find_marker(file, marker_list, 1); //find SOC
757 find_marker(file, marker_list + 1, 1); //find SIZ
758 siz.read(file);
759 int marker_idx = 0;
760 int received_markers = 0; //check that COD, & QCD received
761 while (true)
762 {
763 marker_idx = find_marker(file, marker_list + 2, 18);
764 if (marker_idx == 0)
765 cap.read(file);
766 else if (marker_idx == 1)
767 //Skipping PRF marker segment; this should not cause any issues
768 skip_marker(file, "PRF", NULL, OJPH_MSG_NO_MSG, false);
769 else if (marker_idx == 2)
770 //Skipping CPF marker segment; this should not cause any issues
771 skip_marker(file, "CPF", NULL, OJPH_MSG_NO_MSG, false);
772 else if (marker_idx == 3)
773 {
774 cod.read(file);
775 received_markers |= 1;
776 ojph::param_cod c(&cod);
777 int num_qlayers = c.get_num_layers();
778 if (num_qlayers != 1)
779 OJPH_ERROR(0x00030053, "The current implementation supports "
780 "1 quality layer only. This codestream has %d quality layers",
781 num_qlayers);
782 }
783 else if (marker_idx == 4)
784 {
785 param_cod* p = cod.add_coc_object(param_cod::OJPH_COD_UNKNOWN);
786 p->read_coc(file, siz.get_num_components(), &cod);
787 if (p->get_comp_idx() >= siz.get_num_components())
788 OJPH_INFO(0x00030056, "The codestream carries a COC marker "
789 "segment for a component indexed by %d, which is more than the "
790 "allowed index number, since the codestream has %d components",
791 p->get_comp_idx(), num_comps);
792 param_cod *q = cod.get_coc(p->get_comp_idx());
793 if (p != q && p->get_comp_idx() == q->get_comp_idx())
794 OJPH_ERROR(0x00030057, "The codestream has two COC marker "
795 "segments for one component of index %d", p->get_comp_idx());
796 }
797 else if (marker_idx == 5)
798 {
799 qcd.read(file);
800 received_markers |= 2;
801 }
802 else if (marker_idx == 6)
803 {
804 param_qcd* p = qcd.add_qcc_object(param_qcd::OJPH_QCD_UNKNOWN);
805 p->read_qcc(file, siz.get_num_components());
806 if (p->get_comp_idx() >= siz.get_num_components())
807 OJPH_ERROR(0x00030054, "The codestream carries a QCC marker "
808 "segment for a component indexed by %d, which is more than the "
809 "allowed index number, since the codestream has %d components",
810 p->get_comp_idx(), num_comps);
811 param_qcd *q = qcd.get_qcc(p->get_comp_idx());
812 if (p != q && p->get_comp_idx() == q->get_comp_idx())
813 OJPH_ERROR(0x00030055, "The codestream has two QCC marker "
814 "segments for one component of index %d", p->get_comp_idx());
815 }
816 else if (marker_idx == 7)
817 skip_marker(file, "RGN", "RGN is not supported yet",
818 OJPH_MSG_WARN, false);
819 else if (marker_idx == 8)
820 skip_marker(file, "POC", "POC is not supported yet",
821 OJPH_MSG_WARN, false);
822 else if (marker_idx == 9)
823 skip_marker(file, "PPM", "PPM is not supported yet",
824 OJPH_MSG_WARN, false);
825 else if (marker_idx == 10)
826 //Skipping TLM marker segment; this should not cause any issues
827 skip_marker(file, "TLM", NULL, OJPH_MSG_NO_MSG, false);
828 else if (marker_idx == 11)
829 //Skipping PLM marker segment; this should not cause any issues
830 skip_marker(file, "PLM", NULL, OJPH_MSG_NO_MSG, false);
831 else if (marker_idx == 12)
832 //Skipping CRG marker segment;
833 skip_marker(file, "CRG", "CRG has been ignored; CRG is related to"
834 " where the Cb and Cr colour components are co-sited or located"
835 " with respect to the Y' luma component. Perhaps, it is better"
836 " to get the individual components and assemble the samples"
837 " according to your needs",
838 OJPH_MSG_INFO, false);
839 else if (marker_idx == 13)
840 skip_marker(file, "COM", NULL, OJPH_MSG_NO_MSG, false);
841 else if (marker_idx == 14)
842 dfs.read(file);
843 else if (marker_idx == 15)
844 atk.read(file);
845 else if (marker_idx == 16)
846 nlt.read(file);
847 else if (marker_idx == 17)
848 break;
849 else
850 OJPH_ERROR(0x00030051, "File ended before finding a tile segment");
851 }
852
853 cod.update_atk(&atk);
854 siz.link(&cod);
855 if (dfs.exists())
856 siz.link(&dfs);
857
858 if (received_markers != 3)
859 OJPH_ERROR(0x00030052, "markers error, COD and QCD are required");
860
861 this->infile = file;
862 planar = cod.is_employing_color_transform() ? 0 : 1;
863 }
864
866 void codestream::restrict_input_resolution(ui32 skipped_res_for_read,
867 ui32 skipped_res_for_recon)
868 {
869 if (skipped_res_for_read < skipped_res_for_recon)
870 OJPH_ERROR(0x000300A1,
871 "skipped_resolution for data %d must be equal or smaller than "
872 " skipped_resolution for reconstruction %d\n",
873 skipped_res_for_read, skipped_res_for_recon);
874 if (skipped_res_for_read > cod.get_num_decompositions())
875 OJPH_ERROR(0x000300A2,
876 "skipped_resolution for data %d must be smaller than "
877 " the number of decomposition levels %d\n",
878 skipped_res_for_read, cod.get_num_decompositions());
879
880 this->skipped_res_for_read = skipped_res_for_read;
881 this->skipped_res_for_recon = skipped_res_for_recon;
882 siz.set_skipped_resolutions(skipped_res_for_recon);
883 }
884
886 void codestream::enable_resilience()
887 {
888 if (infile != NULL)
889 OJPH_ERROR(0x000300A3, "Codestream resilience must be enabled before"
890 " reading file headers.\n");
891 this->resilient = true;
892 }
893
895 void codestream::read()
896 {
897 this->pre_alloc();
898 this->finalize_alloc();
899
900 while (true)
901 {
902 param_sot sot;
903 if (sot.read(infile, resilient))
904 {
905 ui64 tile_start_location = (ui64)infile->tell();
906 bool skip_tile = false;
907
908 if (sot.get_tile_index() >= (int)num_tiles.area())
909 {
910 if (resilient) {
911 OJPH_INFO(0x00030061, "wrong tile index")
912 skip_tile = true; // skip the faulty tile
913 }
914 else
915 OJPH_ERROR(0x00030061, "wrong tile index")
916 }
917
918 if (!skip_tile)
919 {
920 if (sot.get_tile_part_index())
921 { //tile part
922 if (sot.get_num_tile_parts() &&
923 sot.get_tile_part_index() >= sot.get_num_tile_parts())
924 {
925 if (resilient)
926 OJPH_INFO(0x00030062,
927 "error in tile part number, should be smaller than total"
928 " number of tile parts")
929 else
930 OJPH_ERROR(0x00030062,
931 "error in tile part number, should be smaller than total"
932 " number of tile parts")
933 }
934
935 bool sod_found = false;
936 ui16 other_tile_part_markers[7] = { SOT, POC, PPT, PLT, COM,
937 NLT, SOD };
938 while (true)
939 {
940 int marker_idx = 0;
941 int result = 0;
942 marker_idx = find_marker(infile, other_tile_part_markers+1, 6);
943 if (marker_idx == 0)
944 result = skip_marker(infile, "POC",
945 "POC marker segment in a tile is not supported yet",
946 OJPH_MSG_WARN, resilient);
947 else if (marker_idx == 1)
948 result = skip_marker(infile, "PPT",
949 "PPT marker segment in a tile is not supported yet",
950 OJPH_MSG_WARN, resilient);
951 else if (marker_idx == 2)
952 //Skipping PLT marker segment;this should not cause any issues
953 result = skip_marker(infile, "PLT", NULL,
954 OJPH_MSG_NO_MSG, resilient);
955 else if (marker_idx == 3)
956 result = skip_marker(infile, "COM", NULL,
957 OJPH_MSG_NO_MSG, resilient);
958 else if (marker_idx == 4)
959 result = skip_marker(infile, "NLT",
960 "NLT marker in tile is not supported yet",
961 OJPH_MSG_WARN, resilient);
962 else if (marker_idx == 5)
963 {
964 sod_found = true;
965 break;
966 }
967
968 if (marker_idx == -1) //marker not found
969 {
970 if (resilient)
971 OJPH_INFO(0x00030063,
972 "File terminated early before start of data is found"
973 " for tile indexed %d and tile part %d",
974 sot.get_tile_index(), sot.get_tile_part_index())
975 else
976 OJPH_ERROR(0x00030063,
977 "File terminated early before start of data is found"
978 " for tile indexed %d and tile part %d",
979 sot.get_tile_index(), sot.get_tile_part_index())
980 break;
981 }
982 if (result == -1) //file terminated during marker seg. skipping
983 {
984 if (resilient)
985 OJPH_INFO(0x00030064,
986 "File terminated during marker segment skipping")
987 else
988 OJPH_ERROR(0x00030064,
989 "File terminated during marker segment skipping")
990 break;
991 }
992 }
993 if (sod_found)
994 tiles[sot.get_tile_index()].parse_tile_header(sot, infile,
995 tile_start_location);
996 }
997 else
998 { //first tile part
999 bool sod_found = false;
1000 ui16 first_tile_part_markers[12] = { SOT, COD, COC, QCD, QCC, RGN,
1001 POC, PPT, PLT, COM, NLT, SOD };
1002 while (true)
1003 {
1004 int marker_idx = 0;
1005 int result = 0;
1006 marker_idx = find_marker(infile, first_tile_part_markers+1, 11);
1007 if (marker_idx == 0)
1008 result = skip_marker(infile, "COD",
1009 "COD marker segment in a tile is not supported yet",
1010 OJPH_MSG_WARN, resilient);
1011 else if (marker_idx == 1)
1012 result = skip_marker(infile, "COC",
1013 "COC marker segment in a tile is not supported yet",
1014 OJPH_MSG_WARN, resilient);
1015 else if (marker_idx == 2)
1016 result = skip_marker(infile, "QCD",
1017 "QCD marker segment in a tile is not supported yet",
1018 OJPH_MSG_WARN, resilient);
1019 else if (marker_idx == 3)
1020 result = skip_marker(infile, "QCC",
1021 "QCC marker segment in a tile is not supported yet",
1022 OJPH_MSG_WARN, resilient);
1023 else if (marker_idx == 4)
1024 result = skip_marker(infile, "RGN",
1025 "RGN marker segment in a tile is not supported yet",
1026 OJPH_MSG_WARN, resilient);
1027 else if (marker_idx == 5)
1028 result = skip_marker(infile, "POC",
1029 "POC marker segment in a tile is not supported yet",
1030 OJPH_MSG_WARN, resilient);
1031 else if (marker_idx == 6)
1032 result = skip_marker(infile, "PPT",
1033 "PPT marker segment in a tile is not supported yet",
1034 OJPH_MSG_WARN, resilient);
1035 else if (marker_idx == 7)
1036 //Skipping PLT marker segment;this should not cause any issues
1037 result = skip_marker(infile, "PLT", NULL,
1038 OJPH_MSG_NO_MSG, resilient);
1039 else if (marker_idx == 8)
1040 result = skip_marker(infile, "COM", NULL,
1041 OJPH_MSG_NO_MSG, resilient);
1042 else if (marker_idx == 9)
1043 result = skip_marker(infile, "NLT",
1044 "PPT marker segment in a tile is not supported yet",
1045 OJPH_MSG_WARN, resilient);
1046 else if (marker_idx == 10)
1047 {
1048 sod_found = true;
1049 break;
1050 }
1051
1052 if (marker_idx == -1) //marker not found
1053 {
1054 if (resilient)
1055 OJPH_INFO(0x00030065,
1056 "File terminated early before start of data is found"
1057 " for tile indexed %d and tile part %d",
1058 sot.get_tile_index(), sot.get_tile_part_index())
1059 else
1060 OJPH_ERROR(0x00030065,
1061 "File terminated early before start of data is found"
1062 " for tile indexed %d and tile part %d",
1063 sot.get_tile_index(), sot.get_tile_part_index())
1064 break;
1065 }
1066 if (result == -1) //file terminated during marker seg. skipping
1067 {
1068 if (resilient)
1069 OJPH_INFO(0x00030066,
1070 "File terminated during marker segment skipping")
1071 else
1072 OJPH_ERROR(0x00030066,
1073 "File terminated during marker segment skipping")
1074 break;
1075 }
1076 }
1077 if (sod_found)
1078 tiles[sot.get_tile_index()].parse_tile_header(sot, infile,
1079 tile_start_location);
1080 }
1081 }
1082 }
1083
1084 // check the next marker; either SOT or EOC,
1085 // if something is broken, just an end of file
1086 ui16 next_markers[2] = { SOT, EOC };
1087 int marker_idx = find_marker(infile, next_markers, 2);
1088 if (marker_idx == -1)
1089 {
1090 OJPH_INFO(0x00030067, "File terminated early");
1091 break;
1092 }
1093 else if (marker_idx == 0)
1094 ;
1095 else if (marker_idx == 1)
1096 break;
1097 }
1098 }
1099
1101 void codestream::set_planar(int planar)
1102 {
1103 this->planar = planar;
1104 }
1105
1107 void codestream::set_profile(const char *s)
1108 {
1109 size_t len = strlen(s);
1110 if (len == 9 && strncmp(s, OJPH_PN_STRING_BROADCAST, 9) == 0)
1111 profile = OJPH_PN_BROADCAST;
1112 else if (len == 3 && strncmp(s, OJPH_PN_STRING_IMF, 3) == 0)
1113 profile = OJPH_PN_IMF;
1114 else
1115 OJPH_ERROR(0x000300A1, "unkownn or unsupported profile");
1116 }
1117
1119 void codestream::set_tilepart_divisions(ui32 value)
1120 {
1121 tilepart_div = value;
1122 }
1123
1125 void codestream::request_tlm_marker(bool needed)
1126 {
1127 need_tlm = needed;
1128 }
1129
1131 void codestream::flush()
1132 {
1133 si32 repeat = (si32)num_tiles.area();
1134 for (si32 i = 0; i < repeat; ++i)
1135 tiles[i].prepare_for_flush();
1136 if (need_tlm)
1137 { //write tlm
1138 for (si32 i = 0; i < repeat; ++i)
1139 tiles[i].fill_tlm(&tlm);
1140 tlm.write(outfile);
1141 }
1142 for (si32 i = 0; i < repeat; ++i)
1143 tiles[i].flush(outfile);
1144 ui16 t = swap_byte(JP2K_MARKER::EOC);
1145 if (!outfile->write(&t, 2))
1146 OJPH_ERROR(0x00030071, "Error writing to file");
1147 }
1148
1150 void codestream::close()
1151 {
1152 if (infile)
1153 infile->close();
1154 if (outfile)
1155 outfile->close();
1156 }
1157
1159 line_buf* codestream::exchange(line_buf *line, ui32 &next_component)
1160 {
1161 if (line)
1162 {
1163 bool success = false;
1164 while (!success)
1165 {
1166 success = true;
1167 for (ui32 i = 0; i < num_tiles.w; ++i)
1168 {
1169 ui32 idx = i + cur_tile_row * num_tiles.w;
1170 if ((success &= tiles[idx].push(line, cur_comp)) == false)
1171 break;
1172 }
1173 cur_tile_row += success == false ? 1 : 0;
1174 if (cur_tile_row >= num_tiles.h)
1175 cur_tile_row = 0;
1176 }
1177
1178 if (planar) //process one component at a time
1179 {
1180 if (++cur_line >= comp_size[cur_comp].h)
1181 {
1182 cur_line = 0;
1183 cur_tile_row = 0;
1184 if (++cur_comp >= num_comps)
1185 {
1186 next_component = 0;
1187 return NULL;
1188 }
1189 }
1190 }
1191 else //process all component for a line
1192 {
1193 if (++cur_comp >= num_comps)
1194 {
1195 cur_comp = 0;
1196 if (++cur_line >= comp_size[cur_comp].h)
1197 {
1198 next_component = 0;
1199 return NULL;
1200 }
1201 }
1202 }
1203 }
1204
1205 next_component = cur_comp;
1206 return this->lines + cur_comp;
1207 }
1208
1210 line_buf* codestream::pull(ui32 &comp_num)
1211 {
1212 bool success = false;
1213 while (!success)
1214 {
1215 success = true;
1216 for (ui32 i = 0; i < num_tiles.w; ++i)
1217 {
1218 ui32 idx = i + cur_tile_row * num_tiles.w;
1219 if ((success &= tiles[idx].pull(lines + cur_comp, cur_comp)) == false)
1220 break;
1221 }
1222 cur_tile_row += success == false ? 1 : 0;
1223 if (cur_tile_row >= num_tiles.h)
1224 cur_tile_row = 0;
1225 }
1226 comp_num = cur_comp;
1227
1228 if (planar) //process one component at a time
1229 {
1230 if (++cur_line >= recon_comp_size[cur_comp].h)
1231 {
1232 cur_line = 0;
1233 cur_tile_row = 0;
1234 if (cur_comp++ >= num_comps)
1235 {
1236 comp_num = 0;
1237 return NULL;
1238 }
1239 }
1240 }
1241 else //process all component for a line
1242 {
1243 if (++cur_comp >= num_comps)
1244 {
1245 cur_comp = 0;
1246 if (cur_line++ >= recon_comp_size[cur_comp].h)
1247 {
1248 comp_num = 0;
1249 return NULL;
1250 }
1251 }
1252 }
1253
1254 return lines + comp_num;
1255 }
1256
1257 }
1258}
ojph::comment_exchange
Definition ojph_params.h:291
ojph::comment_exchange::len
ui16 len
Definition ojph_params.h:300
ojph::comment_exchange::data
const char * data
Definition ojph_params.h:299
ojph::infile_base
Definition ojph_file.h:267
ojph::infile_base::eof
virtual bool eof()=0
ojph::infile_base::seek
seek
Definition ojph_file.h:269
ojph::infile_base::OJPH_SEEK_CUR
@ OJPH_SEEK_CUR
Definition ojph_file.h:271
ojph::infile_base::read
virtual size_t read(void *ptr, size_t size)=0
ojph::line_buf
Definition ojph_mem.h:161
ojph::local::codestream::cap
param_cap cap
Definition ojph_codestream_local.h:159
ojph::local::codestream::qcd
param_qcd qcd
Definition ojph_codestream_local.h:160
ojph::local::codestream::outfile
outfile_base * outfile
Definition ojph_codestream_local.h:171
ojph::local::codestream::read
void read()
Definition ojph_codestream_local.cpp:895
ojph::local::codestream::nlt
param_nlt nlt
Definition ojph_codestream_local.h:162
ojph::local::codestream::atk
param_atk atk
Definition ojph_codestream_local.h:166
ojph::local::codestream::infile
infile_base * infile
Definition ojph_codestream_local.h:172
ojph::local::codestream::~codestream
~codestream()
Definition ojph_codestream_local.cpp:69
ojph::local::codestream::tiles
tile * tiles
Definition ojph_codestream_local.h:145
ojph::local::codestream::skipped_res_for_recon
ui32 skipped_res_for_recon
Definition ojph_codestream_local.h:141
ojph::local::codestream::pre_alloc
void pre_alloc()
Definition ojph_codestream_local.cpp:113
ojph::local::codestream::resilient
bool resilient
Definition ojph_codestream_local.h:140
ojph::local::codestream::access_siz
ojph::param_siz access_siz()
Definition ojph_codestream_local.h:81
ojph::local::codestream::tilepart_div
ui32 tilepart_div
Definition ojph_codestream_local.h:153
ojph::local::codestream::tlm
param_tlm tlm
Definition ojph_codestream_local.h:161
ojph::local::codestream::profile
int profile
Definition ojph_codestream_local.h:152
ojph::local::codestream::planar
int planar
Definition ojph_codestream_local.h:151
ojph::local::codestream::close
void close()
Definition ojph_codestream_local.cpp:1150
ojph::local::codestream::request_tlm_marker
void request_tlm_marker(bool needed)
Definition ojph_codestream_local.cpp:1125
ojph::local::codestream::exchange
line_buf * exchange(line_buf *line, ui32 &next_component)
Definition ojph_codestream_local.cpp:1159
ojph::local::codestream::set_planar
void set_planar(int planar)
Definition ojph_codestream_local.cpp:1101
ojph::local::codestream::precinct_scratch
ui8 * precinct_scratch
Definition ojph_codestream_local.h:134
ojph::local::codestream::lines
line_buf * lines
Definition ojph_codestream_local.h:146
ojph::local::codestream::check_imf_validity
void check_imf_validity()
Definition ojph_codestream_local.cpp:283
ojph::local::codestream::restart
void restart()
Definition ojph_codestream_local.cpp:78
ojph::local::codestream::restrict_input_resolution
void restrict_input_resolution(ui32 skipped_res_for_data, ui32 skipped_res_for_recon)
Definition ojph_codestream_local.cpp:866
ojph::local::codestream::need_tlm
bool need_tlm
Definition ojph_codestream_local.h:154
ojph::local::codestream::elastic_alloc
mem_elastic_allocator * elastic_alloc
Definition ojph_codestream_local.h:170
ojph::local::codestream::cur_comp
ui32 cur_comp
Definition ojph_codestream_local.h:138
ojph::local::codestream::siz
param_siz siz
Definition ojph_codestream_local.h:157
ojph::local::codestream::cur_tile_row
ui32 cur_tile_row
Definition ojph_codestream_local.h:139
ojph::local::codestream::allocator
mem_fixed_allocator * allocator
Definition ojph_codestream_local.h:169
ojph::local::codestream::flush
void flush()
Definition ojph_codestream_local.cpp:1131
ojph::local::codestream::write_headers
void write_headers(outfile_base *file, const comment_exchange *comments, ui32 num_comments)
Definition ojph_codestream_local.cpp:546
ojph::local::codestream::recon_comp_size
size * recon_comp_size
Definition ojph_codestream_local.h:149
ojph::local::codestream::precinct_scratch_needed_bytes
ui32 precinct_scratch_needed_bytes
Definition ojph_codestream_local.h:133
ojph::local::codestream::cod
param_cod cod
Definition ojph_codestream_local.h:158
ojph::local::codestream::check_broadcast_validity
void check_broadcast_validity()
Definition ojph_codestream_local.cpp:446
ojph::local::codestream::read_headers
void read_headers(infile_base *file)
Definition ojph_codestream_local.cpp:752
ojph::local::codestream::codestream
codestream()
Definition ojph_codestream_local.cpp:56
ojph::local::codestream::num_comps
ui32 num_comps
Definition ojph_codestream_local.h:147
ojph::local::codestream::set_profile
void set_profile(const char *s)
Definition ojph_codestream_local.cpp:1107
ojph::local::codestream::employ_color_transform
bool employ_color_transform
Definition ojph_codestream_local.h:150
ojph::local::codestream::set_tilepart_divisions
void set_tilepart_divisions(ui32 value)
Definition ojph_codestream_local.cpp:1119
ojph::local::codestream::finalize_alloc
void finalize_alloc()
Definition ojph_codestream_local.cpp:211
ojph::local::codestream::dfs
param_dfs dfs
Definition ojph_codestream_local.h:165
ojph::local::codestream::num_tiles
size num_tiles
Definition ojph_codestream_local.h:144
ojph::local::codestream::cur_line
ui32 cur_line
Definition ojph_codestream_local.h:137
ojph::local::codestream::pull
line_buf * pull(ui32 &comp_num)
Definition ojph_codestream_local.cpp:1210
ojph::local::codestream::enable_resilience
void enable_resilience()
Definition ojph_codestream_local.cpp:886
ojph::local::codestream::skipped_res_for_read
ui32 skipped_res_for_read
Definition ojph_codestream_local.h:141
ojph::local::codestream::comp_size
size * comp_size
Definition ojph_codestream_local.h:148
ojph::local::tile
Definition ojph_tile.h:61
ojph::local::tile::pre_alloc
static void pre_alloc(codestream *codestream, const rect &tile_rect, const rect &recon_tile_rect, ui32 &num_tileparts)
Definition ojph_tile.cpp:56
ojph::mem_elastic_allocator
Definition ojph_mem.h:218
ojph::mem_fixed_allocator
Definition ojph_mem.h:59
ojph::outfile_base
Definition ojph_file.h:75
ojph::outfile_base::write
virtual size_t write(const void *ptr, size_t size)=0
ojph::param_cod
Definition ojph_params.h:104
ojph::param_cod::get_progression_order
int get_progression_order() const
Definition ojph_params.cpp:299
ojph::param_cod::get_num_decompositions
ui32 get_num_decompositions() const
Definition ojph_params.cpp:263
ojph::param_cod::get_log_block_dims
size get_log_block_dims() const
Definition ojph_params.cpp:275
ojph::param_cod::is_reversible
bool is_reversible() const
Definition ojph_params.cpp:281
ojph::param_cod::get_log_precinct_size
size get_log_precinct_size(ui32 level_num) const
Definition ojph_params.cpp:293
ojph::param_cod::get_num_layers
int get_num_layers() const
Definition ojph_params.cpp:323
ojph::param_siz
Definition ojph_params.h:71
ojph::param_siz::get_image_extent
point get_image_extent() const
Definition ojph_params.cpp:96
ojph::param_siz::get_bit_depth
ui32 get_bit_depth(ui32 comp_num) const
Definition ojph_params.cpp:126
ojph::param_siz::get_image_offset
point get_image_offset() const
Definition ojph_params.cpp:102
ojph::param_siz::get_tile_size
size get_tile_size() const
Definition ojph_params.cpp:108
ojph::param_siz::get_downsampling
point get_downsampling(ui32 comp_num) const
Definition ojph_params.cpp:138
ojph::param_siz::get_tile_offset
point get_tile_offset() const
Definition ojph_params.cpp:114
ojph::param_siz::is_signed
bool is_signed(ui32 comp_num) const
Definition ojph_params.cpp:132
ojph::param_siz::get_num_components
ui32 get_num_components() const
Definition ojph_params.cpp:120
ojph::local
Definition ojph_bitbuffer_read.h:52
ojph::local::find_marker
static int find_marker(infile_base *f, const ui16 *char_list, int list_len)
Definition ojph_codestream_local.cpp:691
ojph::local::skip_marker
static int skip_marker(infile_base *file, const char *marker, const char *msg, int msg_level, bool resilient)
Definition ojph_codestream_local.cpp:717
ojph::local::init_wavelet_transform_functions
void init_wavelet_transform_functions()
Definition ojph_transform.cpp:98
ojph::local::init_colour_transform_functions
void init_colour_transform_functions()
Definition ojph_colour.cpp:109
ojph::local::SOD
@ SOD
Definition ojph_params_local.h:146
ojph::local::SIZ
@ SIZ
Definition ojph_params_local.h:123
ojph::local::ATK
@ ATK
Definition ojph_params_local.h:142
ojph::local::PRF
@ PRF
Definition ojph_params_local.h:127
ojph::local::NLT
@ NLT
Definition ojph_params_local.h:141
ojph::local::TLM
@ TLM
Definition ojph_params_local.h:126
ojph::local::PPM
@ PPM
Definition ojph_params_local.h:135
ojph::local::QCC
@ QCC
Definition ojph_params_local.h:132
ojph::local::CRG
@ CRG
Definition ojph_params_local.h:137
ojph::local::DFS
@ DFS
Definition ojph_params_local.h:139
ojph::local::RGN
@ RGN
Definition ojph_params_local.h:133
ojph::local::SOC
@ SOC
Definition ojph_params_local.h:121
ojph::local::QCD
@ QCD
Definition ojph_params_local.h:131
ojph::local::PPT
@ PPT
Definition ojph_params_local.h:136
ojph::local::COC
@ COC
Definition ojph_params_local.h:125
ojph::local::POC
@ POC
Definition ojph_params_local.h:134
ojph::local::PLT
@ PLT
Definition ojph_params_local.h:129
ojph::local::COD
@ COD
Definition ojph_params_local.h:124
ojph::local::CAP
@ CAP
Definition ojph_params_local.h:122
ojph::local::CPF
@ CPF
Definition ojph_params_local.h:130
ojph::local::PLM
@ PLM
Definition ojph_params_local.h:128
ojph::local::SOT
@ SOT
Definition ojph_params_local.h:143
ojph::local::COM
@ COM
Definition ojph_params_local.h:138
ojph::local::EOC
@ EOC
Definition ojph_params_local.h:147
ojph::local::swap_byte
static ui16 swap_byte(ui16 t)
Definition ojph_codestream_local.h:58
ojph
Definition ojph_img_io.h:52
ojph::OJPH_PN_STRING_BROADCAST
const char OJPH_PN_STRING_BROADCAST[]
Definition ojph_params_local.h:94
ojph::OJPH_PO_LRCP
@ OJPH_PO_LRCP
Definition ojph_params_local.h:59
ojph::OJPH_PO_RLCP
@ OJPH_PO_RLCP
Definition ojph_params_local.h:60
ojph::OJPH_PO_CPRL
@ OJPH_PO_CPRL
Definition ojph_params_local.h:63
ojph::OJPH_PO_PCRL
@ OJPH_PO_PCRL
Definition ojph_params_local.h:62
ojph::OJPH_PO_RPCL
@ OJPH_PO_RPCL
Definition ojph_params_local.h:61
ojph::OJPH_PN_STRING_IMF
const char OJPH_PN_STRING_IMF[]
Definition ojph_params_local.h:95
ojph::ui64
uint64_t ui64
Definition ojph_defs.h:56
ojph::OJPH_MSG_INFO
@ OJPH_MSG_INFO
Definition ojph_message.h:55
ojph::OJPH_MSG_ERROR
@ OJPH_MSG_ERROR
Definition ojph_message.h:57
ojph::OJPH_MSG_WARN
@ OJPH_MSG_WARN
Definition ojph_message.h:56
ojph::OJPH_MSG_NO_MSG
@ OJPH_MSG_NO_MSG
Definition ojph_message.h:58
ojph::ui16
uint16_t ui16
Definition ojph_defs.h:52
ojph::OJPH_TILEPART_RESOLUTIONS
@ OJPH_TILEPART_RESOLUTIONS
Definition ojph_params_local.h:100
ojph::OJPH_TILEPART_NO_DIVISIONS
@ OJPH_TILEPART_NO_DIVISIONS
Definition ojph_params_local.h:99
ojph::OJPH_TILEPART_COMPONENTS
@ OJPH_TILEPART_COMPONENTS
Definition ojph_params_local.h:101
ojph::OJPH_PN_BROADCAST
@ OJPH_PN_BROADCAST
Definition ojph_params_local.h:83
ojph::OJPH_PN_UNDEFINED
@ OJPH_PN_UNDEFINED
Definition ojph_params_local.h:76
ojph::OJPH_PN_IMF
@ OJPH_PN_IMF
Definition ojph_params_local.h:84
ojph::si32
int32_t si32
Definition ojph_defs.h:55
ojph::ui32
uint32_t ui32
Definition ojph_defs.h:54
ojph::ui8
uint8_t ui8
Definition ojph_defs.h:50
ojph_codestream_local.h
ojph_colour.h
ojph_max
#define ojph_max(a, b)
Definition ojph_defs.h:73
OJPH_INT_TO_STRING
#define OJPH_INT_TO_STRING(I)
Definition ojph_defs.h:61
ojph_div_ceil
#define ojph_div_ceil(a, b)
Definition ojph_defs.h:70
ojph_min
#define ojph_min(a, b)
Definition ojph_defs.h:76
ojph_unused
#define ojph_unused(x)
Definition ojph_defs.h:78
ojph_mem.h
OJPH_INFO
#define OJPH_INFO(t,...)
MACROs to insert file and line number for info, warning, and error.
Definition ojph_message.h:284
OJPH_ERROR
#define OJPH_ERROR(t,...)
Definition ojph_message.h:288
OJPH_WARN
#define OJPH_WARN(t,...)
Definition ojph_message.h:286
ojph_params.h
ojph_tile.h
ojph_transform.h
OPENJPH_VERSION_PATCH
#define OPENJPH_VERSION_PATCH
Definition ojph_version.h:38
OPENJPH_VERSION_MAJOR
#define OPENJPH_VERSION_MAJOR
Definition ojph_version.h:36
OPENJPH_VERSION_MINOR
#define OPENJPH_VERSION_MINOR
Definition ojph_version.h:37
ojph::local::param_cod
Definition ojph_params_local.h:385
ojph::local::param_cod::get_comp_idx
ui32 get_comp_idx() const
Definition ojph_params_local.h:618
ojph::local::param_cod::OJPH_COD_UNKNOWN
@ OJPH_COD_UNKNOWN
Definition ojph_params_local.h:389
ojph::local::param_cod::read_coc
void read_coc(infile_base *file, ui32 num_comps, param_cod *top_cod)
Definition ojph_params.cpp:1015
ojph::local::param_qcd
Definition ojph_params_local.h:677
ojph::local::param_qcd::get_comp_idx
ui16 get_comp_idx() const
Definition ojph_params_local.h:728
ojph::local::param_qcd::read_qcc
void read_qcc(infile_base *file, ui32 num_comps)
Definition ojph_params.cpp:1739
ojph::local::param_qcd::OJPH_QCD_UNKNOWN
@ OJPH_QCD_UNKNOWN
Definition ojph_params_local.h:681
ojph::local::param_sot
Definition ojph_params_local.h:925
ojph::local::param_sot::get_num_tile_parts
ui8 get_num_tile_parts() const
Definition ojph_params_local.h:944
ojph::local::param_sot::get_tile_index
ui16 get_tile_index() const
Definition ojph_params_local.h:941
ojph::local::param_sot::read
bool read(infile_base *file, bool resilient)
Definition ojph_params.cpp:2141
ojph::local::param_sot::get_tile_part_index
ui8 get_tile_part_index() const
Definition ojph_params_local.h:943
ojph::local::param_tlm::Ttlm_Ptlm_pair
Definition ojph_params_local.h:964
ojph::point
Definition ojph_base.h:58
ojph::point::y
ui32 y
Definition ojph_base.h:60
ojph::point::x
ui32 x
Definition ojph_base.h:60
ojph::rect
Definition ojph_base.h:65
ojph::rect::siz
size siz
Definition ojph_base.h:67
ojph::rect::org
point org
Definition ojph_base.h:66
ojph::size
Definition ojph_base.h:48
ojph::size::w
ui32 w
Definition ojph_base.h:50
ojph::size::h
ui32 h
Definition ojph_base.h:51