OpenJPH: /build/openjph/src/OpenJPH/src/apps/ojph_compress/ojph_compress.cpp Source File

OpenJPH Open-source implementation of JPEG2000 Part-15

Loading...
Searching...
No Matches
ojph_compress.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_compress.cpp
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38
39#include <ctime>
40#include <iostream>
41
42#include "ojph_arg.h"
43#include "ojph_mem.h"
44#include "ojph_img_io.h"
45#include "ojph_file.h"
46#include "ojph_codestream.h"
47#include "ojph_params.h"
48#include "ojph_message.h"
49
51 struct size_list_interpreter : public ojph::cli_interpreter::arg_inter_base
52{
53 size_list_interpreter(const int max_num_elements, int& num_elements,
54 ojph::size* list)
55 : max_num_eles(max_num_elements), sizelist(list), num_eles(num_elements)
56 {}
57
58 virtual void operate(const char *str)
59 {
60 const char *next_char = str;
61 num_eles = 0;
62 do
63 {
64 if (num_eles)
65 {
66 if (*next_char != ',') //separate sizes by a comma
67 throw "sizes in a sizes list must be separated by a comma";
68 next_char++;
69 }
70
71 if (*next_char != '{')
72 throw "size must start with {";
73 next_char++;
74 char *endptr;
75 sizelist[num_eles].w = (ojph::ui32)strtoul(next_char, &endptr, 10);
76 if (endptr == next_char)
77 throw "size number is improperly formatted";
78 next_char = endptr;
79 if (*next_char != ',')
80 throw "size must have a "","" between the two numbers";
81 next_char++;
82 sizelist[num_eles].h = (ojph::ui32)strtoul(next_char, &endptr, 10);
83 if (endptr == next_char)
84 throw "number is improperly formatted";
85 next_char = endptr;
86 if (*next_char != '}')
87 throw "size must end with }";
88 next_char++;
89
90 ++num_eles;
91 }
92 while (*next_char == ',' && num_eles < max_num_eles);
93 if (num_eles < max_num_eles)
94 {
95 if (*next_char)
96 throw "size elements must separated by a "",""";
97 }
98 else if (*next_char)
99 throw "there are too many elements in the size list";
100 }
101
102 const int max_num_eles;
103 ojph::size* sizelist;
104 int& num_eles;
105};
106
108 struct point_list_interpreter : public ojph::cli_interpreter::arg_inter_base
109{
110 point_list_interpreter(const ojph::ui32 max_num_elements,
111 ojph::ui32& num_elements,
112 ojph::point* list)
113 : max_num_eles(max_num_elements), pointlist(list), num_eles(num_elements)
114 { }
115
116 virtual void operate(const char *str)
117 {
118 const char *next_char = str;
119 num_eles = 0;
120 do
121 {
122 if (num_eles)
123 {
124 if (*next_char != ',') //separate sizes by a comma
125 throw "sizes in a sizes list must be separated by a comma";
126 next_char++;
127 }
128
129 if (*next_char != '{')
130 throw "size must start with {";
131 next_char++;
132 char *endptr;
133 pointlist[num_eles].x = (ojph::ui32)strtoul(next_char, &endptr, 10);
134 if (endptr == next_char)
135 throw "point number is improperly formatted";
136 next_char = endptr;
137 if (*next_char != ',')
138 throw "point must have a "","" between the two numbers";
139 next_char++;
140 pointlist[num_eles].y = (ojph::ui32)strtoul(next_char, &endptr, 10);
141 if (endptr == next_char)
142 throw "number is improperly formatted";
143 next_char = endptr;
144 if (*next_char != '}')
145 throw "point must end with }";
146 next_char++;
147
148 ++num_eles;
149 }
150 while (*next_char == ',' && num_eles < max_num_eles);
151 if (num_eles < max_num_eles)
152 {
153 if (*next_char)
154 throw "size elements must separated by a "",""";
155 }
156 else if (*next_char)
157 throw "there are too many elements in the size list";
158 }
159
160 const ojph::ui32 max_num_eles;
161 ojph::point* pointlist;
162 ojph::ui32& num_eles;
163};
164
166 struct size_interpreter : public ojph::cli_interpreter::arg_inter_base
167{
168 size_interpreter(ojph::size& val) : val(val) {}
169 virtual void operate(const char *str)
170 {
171 const char *next_char = str;
172 if (*next_char != '{')
173 throw "size must start with {";
174 next_char++;
175 char *endptr;
176 val.w = (ojph::ui32)strtoul(next_char, &endptr, 10);
177 if (endptr == next_char)
178 throw "size number is improperly formatted";
179 next_char = endptr;
180 if (*next_char != ',')
181 throw "size must have a "","" between the two numbers";
182 next_char++;
183 val.h = (ojph::ui32)strtoul(next_char, &endptr, 10);
184 if (endptr == next_char)
185 throw "number is improperly formatted";
186 next_char = endptr;
187 if (*next_char != '}')
188 throw "size must end with }";
189 next_char++;
190 if (*next_char != '\0') //must be end of string
191 throw "size has extra characters";
192 }
193 ojph::size& val;
194};
195
197 struct point_interpreter : public ojph::cli_interpreter::arg_inter_base
198{
199 point_interpreter(ojph::point& val) : val(val) {}
200 virtual void operate(const char *str)
201 {
202 const char *next_char = str;
203 if (*next_char != '{')
204 throw "size must start with {";
205 next_char++;
206 char *endptr;
207 val.x = (ojph::ui32)strtoul(next_char, &endptr, 10);
208 if (endptr == next_char)
209 throw "size number is improperly formatted";
210 next_char = endptr;
211 if (*next_char != ',')
212 throw "size must have a "","" between the two numbers";
213 next_char++;
214 val.y = (ojph::ui32)strtoul(next_char, &endptr, 10);
215 if (endptr == next_char)
216 throw "number is improperly formatted";
217 next_char = endptr;
218 if (*next_char != '}')
219 throw "size must end with }";
220 next_char++;
221 if (*next_char != '\0') //must be end of string
222 throw "size has extra characters";
223 }
224 ojph::point& val;
225};
226
227
229 struct ui32_list_interpreter : public ojph::cli_interpreter::arg_inter_base
230{
231 ui32_list_interpreter(const ojph::ui32 max_num_elements,
232 ojph::ui32& num_elements,
233 ojph::ui32* list)
234 : max_num_eles(max_num_elements), ui32list(list), num_eles(num_elements)
235 {}
236
237 virtual void operate(const char *str)
238 {
239 const char *next_char = str;
240 num_eles = 0;
241 do
242 {
243 if (num_eles)
244 {
245 if (*next_char != ',') //separate sizes by a comma
246 throw "sizes in a sizes list must be separated by a comma";
247 next_char++;
248 }
249 char *endptr;
250 ui32list[num_eles] = (ojph::ui32)strtoul(next_char, &endptr, 10);
251 if (endptr == next_char)
252 throw "size number is improperly formatted";
253 next_char = endptr;
254 ++num_eles;
255 }
256 while (*next_char == ',' && num_eles < max_num_eles);
257 if (num_eles < max_num_eles)
258 {
259 if (*next_char)
260 throw "list elements must separated by a "",""";
261 }
262 else if (*next_char)
263 throw "there are too many elements in the size list";
264 }
265
266 const ojph::ui32 max_num_eles;
267 ojph::ui32* ui32list;
268 ojph::ui32& num_eles;
269};
270
272 struct si32_to_bool_list_interpreter
273: public ojph::cli_interpreter::arg_inter_base
274{
275 si32_to_bool_list_interpreter(const ojph::ui32 max_num_elements,
276 ojph::ui32& num_elements,
277 ojph::si32* list)
278 : max_num_eles(max_num_elements), boollist(list), num_eles(num_elements) {}
279
280 virtual void operate(const char *str)
281 {
282 const char *next_char = str;
283 num_eles = 0;
284 do
285 {
286 if (num_eles)
287 {
288 if (*next_char != ',') //separate sizes by a comma
289 throw "sizes in a sizes list must be separated by a comma";
290 next_char++;
291 }
292 if (strncmp(next_char, "true", 4) == 0)
293 {
294 boollist[num_eles] = 1;
295 next_char += 4;
296 }
297 else if (strncmp(next_char, "false", 5) == 0)
298 {
299 boollist[num_eles] = 0;
300 next_char += 5;
301 }
302 else
303 throw "unknown bool value";
304 ++num_eles;
305 }
306 while (*next_char == ',' && num_eles < max_num_eles);
307 if (num_eles < max_num_eles)
308 {
309 if (*next_char)
310 throw "size elements must separated by a "",""";
311 }
312 else if (*next_char)
313 throw "there are too many elements in the size list";
314 }
315
316 ojph::ui32 get_num_elements() { return num_eles; }
317
318 const ojph::ui32 max_num_eles;
319 ojph::si32* boollist;
320 ojph::ui32& num_eles;
321};
322
324 struct tileparts_division_interpreter
325: public ojph::cli_interpreter::arg_inter_base
326{
327 tileparts_division_interpreter(bool& at_resolutions,
328 bool& at_components)
329 : at_resolutions(at_resolutions), at_components(at_components) {}
330
331 virtual void operate(const char *str)
332 {
333 size_t len = strlen(str);
334 if (len == 1 && strncmp(str, "C", 2) == 0)
335 {
336 at_resolutions = false;
337 at_components = true;
338 }
339 else if (len == 1 && strncmp(str, "R", 2) == 0)
340 {
341 at_resolutions = true;
342 at_components = false;
343 }
344 else if (len == 2 &&
345 (strncmp(str, "RC", 3) == 0 || strncmp(str, "CR", 3) == 0))
346 {
347 at_resolutions = true;
348 at_components = true;
349 }
350 else
351 throw "could not interpret -tileparts fields; allowed values are "
352 "\"R\" \"C\" and \"RC\"";
353 }
354
355 bool& at_resolutions;
356 bool& at_components;
357};
358
360static
361 bool get_arguments(int argc, char *argv[], char *&input_filename,
362 char *&output_filename, char *&progression_order,
363 char *&profile_string, ojph::ui32 &num_decompositions,
364 float &quantization_step, bool &reversible,
365 int &employ_color_transform,
366 const int max_num_precincts, int &num_precincts,
367 ojph::size *precinct_size, ojph::size& block_size,
368 ojph::size& dims, ojph::point& image_offset,
369 ojph::size& tile_size, ojph::point& tile_offset,
370 ojph::ui32& max_num_comps, ojph::ui32& num_comps,
371 ojph::ui32& num_comp_downsamps, ojph::point*& comp_downsamp,
372 ojph::ui32& num_bit_depths, ojph::ui32*& bit_depth,
373 ojph::ui32& num_is_signed, ojph::si32*& is_signed,
374 bool& tlm_marker, bool& tileparts_at_resolutions,
375 bool& tileparts_at_components, char *&com_string)
376{
377 ojph::cli_interpreter interpreter;
378 interpreter.init(argc, argv);
379
380 interpreter.reinterpret("-i", input_filename);
381 interpreter.reinterpret("-o", output_filename);
382 interpreter.reinterpret("-prog_order", progression_order);
383 interpreter.reinterpret("-profile", profile_string);
384 interpreter.reinterpret("-num_decomps", num_decompositions);
385 interpreter.reinterpret("-qstep", quantization_step);
386 interpreter.reinterpret("-reversible", reversible);
387 interpreter.reinterpret_to_bool("-colour_trans", employ_color_transform);
388 interpreter.reinterpret("-num_comps", num_comps);
389 interpreter.reinterpret("-tlm_marker", tlm_marker);
390 interpreter.reinterpret("-com", com_string);
391
392 size_interpreter block_interpreter(block_size);
393 size_interpreter dims_interpreter(dims);
394 size_list_interpreter sizelist(max_num_precincts, num_precincts,
395 precinct_size);
396
397 if (num_comps > 255)
398 throw "more than 255 components is not supported";
399 if (num_comps > max_num_comps)
400 {
401 max_num_comps = num_comps;
402 comp_downsamp = new ojph::point[num_comps];
403 bit_depth = new ojph::ui32[num_comps];
404 is_signed = new ojph::si32[num_comps];
405 for (ojph::ui32 i = 0; i < num_comps; ++i)
406 {
407 comp_downsamp[i] = ojph::point(0, 0);
408 bit_depth[i] = 0;
409 is_signed[i] = -1;
410 }
411 }
412
413 point_list_interpreter pointlist(max_num_comps, num_comp_downsamps,
414 comp_downsamp);
415 ui32_list_interpreter ilist(max_num_comps, num_bit_depths, bit_depth);
416 si32_to_bool_list_interpreter blist(max_num_comps, num_is_signed, is_signed);
417 point_interpreter img_off_interpreter(image_offset);
418 size_interpreter tile_size_interpreter(tile_size);
419 point_interpreter tile_off_interpreter(tile_offset);
420 tileparts_division_interpreter tp_div_interpreter(tileparts_at_resolutions,
421 tileparts_at_components);
422 try
423 {
424 interpreter.reinterpret("-block_size", &block_interpreter);
425 interpreter.reinterpret("-dims", &dims_interpreter);
426 interpreter.reinterpret("-image_offset", &img_off_interpreter);
427 interpreter.reinterpret("-tile_size", &tile_size_interpreter);
428 interpreter.reinterpret("-tile_offset", &tile_off_interpreter);
429 interpreter.reinterpret("-precincts", &sizelist);
430 interpreter.reinterpret("-downsamp", &pointlist);
431 interpreter.reinterpret("-bit_depth", &ilist);
432 interpreter.reinterpret("-signed", &blist);
433 interpreter.reinterpret("-tileparts", &tp_div_interpreter);
434 }
435 catch (const char *s)
436 {
437 printf("%s\n",s);
438 return false;
439 }
440
441 if (interpreter.is_exhausted() == false) {
442 printf("The following arguments were not interpreted:\n");
443 ojph::argument t = interpreter.get_argument_zero();
444 t = interpreter.get_next_avail_argument(t);
445 while (t.is_valid()) {
446 printf("%s\n", t.arg);
447 t = interpreter.get_next_avail_argument(t);
448 }
449 return false;
450 }
451 return true;
452}
453
455static
456 const char* get_file_extension(const char* filename)
457{
458 size_t len = strlen(filename);
459 const char* p = strrchr(filename, '.');
460 if (p == NULL || p == filename + len - 1)
461 OJPH_ERROR(0x01000071,
462 "no file extension is found, or there are no characters "
463 "after the dot \'.\' for filename \"%s\" \n", filename);
464 return p;
465}
466
468static
469 bool is_matching(const char *ref, const char *other)
470{
471 size_t num_ele = strlen(ref);
472
473 if (num_ele != strlen(other))
474 return false;
475
476 for (ojph::ui32 i = 0; i < num_ele; ++i)
477 if (ref[i] != other[i] && ref[i] != tolower(other[i]))
478 return false;
479
480 return true;
481}
482
484// main
486
487 int main(int argc, char * argv[]) {
488 char *input_filename = NULL;
489 char *output_filename = NULL;
490 char prog_order_store[] = "RPCL";
491 char *prog_order = prog_order_store;
492 char profile_string_store[] = "";
493 char *profile_string = profile_string_store;
494 char *com_string = NULL;
495 ojph::ui32 num_decompositions = 5;
496 float quantization_step = -1.0f;
497 bool reversible = false;
498 int employ_color_transform = -1;
499
500 const int max_precinct_sizes = 33; //maximum number of decompositions is 32
501 ojph::size precinct_size[max_precinct_sizes];
502 int num_precincts = -1;
503
504 ojph::size block_size(64,64);
505 ojph::size dims(0, 0);
506 ojph::size tile_size(0, 0);
507 ojph::point tile_offset(0, 0);
508 ojph::point image_offset(0, 0);
509 const ojph::ui32 initial_num_comps = 4;
510 ojph::ui32 max_num_comps = initial_num_comps;
511 ojph::ui32 num_components = 0;
512 ojph::ui32 num_is_signed = 0;
513 ojph::si32 is_signed_store[initial_num_comps] = {-1, -1, -1, -1};
514 ojph::si32 *is_signed = is_signed_store;
515 ojph::ui32 num_bit_depths = 0;
516 ojph::ui32 bit_depth_store[initial_num_comps] = {0, 0, 0, 0};
517 ojph::ui32 *bit_depth = bit_depth_store;
518 ojph::ui32 num_comp_downsamps = 0;
519 ojph::point downsampling_store[initial_num_comps];
520 ojph::point *comp_downsampling = downsampling_store;
521 bool tlm_marker = false;
522 bool tileparts_at_resolutions = false;
523 bool tileparts_at_components = false;
524
525 if (argc <= 1) {
526 std::cout <<
527 "\nThe following arguments are necessary:\n"
528#ifdef OJPH_ENABLE_TIFF_SUPPORT
529 " -i input file name (either pgm, ppm, pfm, tif(f), or raw(yuv))\n"
530#else
531 " -i input file name (either pgm, ppm, pfm, or raw(yuv))\n"
532#endif // !OJPH_ENABLE_TIFF_SUPPORT
533 " -o output file name\n\n"
534
535 "The following option has a default value (optional):\n"
536 " -num_decomps (5) number of decompositions\n"
537 " -qstep (0.00001...0.5) quantization step size for lossy\n"
538 " compression; quantization steps size for all subbands are\n"
539 " derived from this value. {The default value for 8bit\n"
540 " images is 0.0039}\n"
541 " -reversible <true | false> If this is 'false', an irreversible or\n"
542 " lossy compression is employed, using the 9/7 wavelet\n"
543 " transform; if 'true', a reversible compression is\n"
544 " performed, where the 5/3 wavelet is used.\n"
545 " Default value is 'false'.\n"
546 " -colour_trans <true | false> This option employs a color transform,\n"
547 " to transform RGB color images into the YUV domain.\n"
548 " This option should NOT be used with YUV images, because\n"
549 " they have already been transformed.\n"
550 " If there are three color components that are\n"
551 " downsampled by the same amount then this option can be\n"
552 " 'true' or 'false'. This option is also available when\n"
553 " there are more than three colour components, where it is\n"
554 " applied to the first three colour components.\n"
555 " -prog_order (RPCL) is the progression order, and can be one of:\n"
556 " LRCP, RLCP, RPCL, PCRL, CPRL.\n"
557 " -block_size {x,y} (64,64) where x and y are the height and width of\n"
558 " a codeblock. In unix-like environment, { and } must be\n"
559 " preceded by a ""\\"".\n"
560 " -precincts {x,y},{x,y},...,{x,y} where {x,y} is the precinct size\n"
561 " starting from the coarsest resolution; the last precinct\n"
562 " is repeated for all finer resolutions\n"
563 " -tile_offset {x,y} tile offset. \n"
564 " -tile_size {x,y} tile width and height. \n"
565 " -image_offset {x,y} image offset from origin. \n"
566 " -tileparts (None) employ tilepart divisions at each resolution, \n"
567 " indicated by the letter R, and/or component, indicated \n"
568 " by the letter C. For both, use \"-tileparts RC\".\n"
569 " -tlm_marker <true | false> if 'true', a TLM marker is inserted.\n"
570 " Default value is false.\n"
571 " -profile (None) is the profile, the code will check if the \n"
572 " selected options meet the profile. Currently only \n"
573 " BROADCAST and IMF are supported. This automatically \n"
574 " sets tlm_marker to true and tileparts to C.\n"
575 " -com (None) if set, inserts a COM marker with the specified\n"
576 " string. If the string has spaces, please use\n"
577 " double quotes, as in -com \"This is a comment\".\n"
578 "\n"
579
580 "When the input file is a YUV file, these arguments need to be \n"
581 " supplied: \n"
582 " -dims {x,y} x is image width, y is height\n"
583 " -num_comps number of components\n"
584 " -signed a comma-separated list of true or false parameters, one\n"
585 " for each component; for example: true,false,false\n"
586 " -bit_depth a comma-separated list of bit depth values, one per \n"
587 " component; for example: 12,10,10\n"
588 " -downsamp {x,y},{x,y},...,{x,y} a list of x,y points, one for each\n"
589 " component; for example {1,1},{2,2},{2,2}\n\n"
590 "\n"
591
592 ".pfm files receive special treatment. Currently, lossy compression\n"
593 "with these files is not supported, only lossless. When these files are\n"
594 "used, the NLT segment marker is automatically inserted into the\n"
595 "codestream when needed, as explained shortly. The following arguments\n"
596 "can be useful for this file type.\n"
597 " -signed a comma-separated list of true or false parameters, one\n"
598 " for each component; for example: true,false,false.\n"
599 " If you are sure that all sample values are positive or 0,\n"
600 " set the corresponding entry to false; otherwise set it to\n"
601 " true.\n"
602 " When a component entry is set to true, an NLT segment\n"
603 " marker segment is inserted into the codestream.\n"
604 " The NLT segment specifies a non-linear transform that\n"
605 " changes only negative values, producing better coding\n"
606 " efficiency.\n"
607 " The NLT segment marker might be less supported in other\n"
608 " encoders.\n"
609 " -bit_depth a comma-separated list of bit depth values, one per \n"
610 " component; for example: 12,10,10.\n"
611 " Floating value numbers are treated as integers, and they\n"
612 " are shifted to the right, keeping only the specified\n"
613 " number of bits. Up to 32 bits (which is the default) are\n"
614 " supported.\n"
615
616 "\n";
617 return -1;
618 }
619 if (!get_arguments(argc, argv, input_filename, output_filename,
620 prog_order, profile_string, num_decompositions,
621 quantization_step, reversible, employ_color_transform,
622 max_precinct_sizes, num_precincts, precinct_size,
623 block_size, dims, image_offset, tile_size, tile_offset,
624 max_num_comps, num_components,
625 num_comp_downsamps, comp_downsampling,
626 num_bit_depths, bit_depth, num_is_signed, is_signed,
627 tlm_marker, tileparts_at_resolutions,
628 tileparts_at_components, com_string))
629 {
630 return -1;
631 }
632
633 clock_t begin = clock();
634
635 try
636 {
637 ojph::codestream codestream;
638
639 ojph::ppm_in ppm;
640 ojph::pfm_in pfm;
641 ojph::yuv_in yuv;
642 ojph::raw_in raw;
643 ojph::dpx_in dpx;
644#ifdef OJPH_ENABLE_TIFF_SUPPORT
645 ojph::tif_in tif;
646#endif // !OJPH_ENABLE_TIFF_SUPPORT
647
648 ojph::image_in_base *base = NULL;
649 if (input_filename == NULL)
650 OJPH_ERROR(0x01000007, "please specify an input file name using"
651 " the -i command line option");
652 if (output_filename == NULL)
653 OJPH_ERROR(0x01000008, "please specify an output file name using"
654 " the -o command line option");
655 const char *v = get_file_extension(input_filename);
656
657 if (v)
658 {
659 if (is_matching(".pgm", v))
660 {
661 ppm.open(input_filename);
662 ojph::param_siz siz = codestream.access_siz();
663 siz.set_image_extent(ojph::point(image_offset.x + ppm.get_width(),
664 image_offset.y + ppm.get_height()));
665 ojph::ui32 num_comps = ppm.get_num_components();
666 assert(num_comps == 1);
667 siz.set_num_components(num_comps);
668 for (ojph::ui32 c = 0; c < num_comps; ++c)
669 siz.set_component(c, ppm.get_comp_subsampling(c),
670 ppm.get_bit_depth(c), ppm.get_is_signed(c));
671 siz.set_image_offset(image_offset);
672 siz.set_tile_size(tile_size);
673 siz.set_tile_offset(tile_offset);
674
675 ojph::param_cod cod = codestream.access_cod();
676 cod.set_num_decomposition(num_decompositions);
677 cod.set_block_dims(block_size.w, block_size.h);
678 if (num_precincts != -1)
679 cod.set_precinct_size(num_precincts, precinct_size);
680 cod.set_progression_order(prog_order);
681 cod.set_color_transform(false);
682 cod.set_reversible(reversible);
683 if (!reversible && quantization_step != -1.0f)
684 codestream.access_qcd().set_irrev_quant(quantization_step);
685 if (profile_string[0] != '\0')
686 codestream.set_profile(profile_string);
687 codestream.set_tilepart_divisions(tileparts_at_resolutions,
688 tileparts_at_components);
689 codestream.request_tlm_marker(tlm_marker);
690
691 if (employ_color_transform != -1)
692 OJPH_WARN(0x01000001,
693 "-colour_trans option is not needed and was not used\n");
694 if (dims.w != 0 || dims.h != 0)
695 OJPH_WARN(0x01000002,
696 "-dims option is not needed and was not used\n");
697 if (num_components != 0)
698 OJPH_WARN(0x01000003,
699 "-num_comps is not needed and was not used\n");
700 if (is_signed[0] != -1)
701 OJPH_WARN(0x01000004,
702 "-signed is not needed and was not used\n");
703 if (bit_depth[0] != 0)
704 OJPH_WARN(0x01000005,
705 "-bit_depth is not needed and was not used\n");
706 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
707 OJPH_WARN(0x01000006,
708 "-downsamp is not needed and was not used\n");
709
710 base = &ppm;
711 }
712 else if (is_matching(".ppm", v))
713 {
714 ppm.open(input_filename);
715 ojph::param_siz siz = codestream.access_siz();
716 siz.set_image_extent(ojph::point(image_offset.x + ppm.get_width(),
717 image_offset.y + ppm.get_height()));
718 ojph::ui32 num_comps = ppm.get_num_components();
719 assert(num_comps == 3);
720 siz.set_num_components(num_comps);
721 for (ojph::ui32 c = 0; c < num_comps; ++c)
722 siz.set_component(c, ppm.get_comp_subsampling(c),
723 ppm.get_bit_depth(c), ppm.get_is_signed(c));
724 siz.set_image_offset(image_offset);
725 siz.set_tile_size(tile_size);
726 siz.set_tile_offset(tile_offset);
727
728 ojph::param_cod cod = codestream.access_cod();
729 cod.set_num_decomposition(num_decompositions);
730 cod.set_block_dims(block_size.w, block_size.h);
731 if (num_precincts != -1)
732 cod.set_precinct_size(num_precincts, precinct_size);
733 cod.set_progression_order(prog_order);
734 if (employ_color_transform == -1)
735 cod.set_color_transform(true);
736 else
737 cod.set_color_transform(employ_color_transform == 1);
738 cod.set_reversible(reversible);
739 if (!reversible && quantization_step != -1.0f)
740 codestream.access_qcd().set_irrev_quant(quantization_step);
741 codestream.set_planar(false);
742 if (profile_string[0] != '\0')
743 codestream.set_profile(profile_string);
744 codestream.set_tilepart_divisions(tileparts_at_resolutions,
745 tileparts_at_components);
746 codestream.request_tlm_marker(tlm_marker);
747
748 if (dims.w != 0 || dims.h != 0)
749 OJPH_WARN(0x01000011,
750 "-dims option is not needed and was not used\n");
751 if (num_components != 0)
752 OJPH_WARN(0x01000012,
753 "-num_comps is not needed and was not used\n");
754 if (is_signed[0] != -1)
755 OJPH_WARN(0x01000013,
756 "-signed is not needed and was not used\n");
757 if (bit_depth[0] != 0)
758 OJPH_WARN(0x01000014,
759 "-bit_depth is not needed and was not used\n");
760 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
761 OJPH_WARN(0x01000015,
762 "-downsamp is not needed and was not used\n");
763
764 base = &ppm;
765 }
766 else if (is_matching(".pfm", v))
767 {
768 pfm.open(input_filename);
769 ojph::param_siz siz = codestream.access_siz();
770 siz.set_image_extent(ojph::point(image_offset.x + pfm.get_width(),
771 image_offset.y + pfm.get_height()));
772 ojph::ui32 num_comps = pfm.get_num_components();
773 assert(num_comps == 1 || num_comps == 3);
774 siz.set_num_components(num_comps);
775
776 if (bit_depth[0] != 0) // one was set
777 if (num_bit_depths < num_comps) // but if not enough, repeat
778 for (ojph::ui32 c = num_bit_depths; c < num_comps; ++c)
779 bit_depth[c] = bit_depth[num_bit_depths - 1];
780
781 bool all_the_same = true;
782 if (num_comps == 3)
783 all_the_same = all_the_same
784 && bit_depth[0] == bit_depth[1]
785 && bit_depth[1] == bit_depth[2];
786
787 for (ojph::ui32 c = 0; c < num_comps; ++c) {
788 if (bit_depth[c] == 0)
789 bit_depth[c] = 32;
790 siz.set_component(c, ojph::point(1,1), bit_depth[c], true);
791 }
792 pfm.configure(bit_depth);
793
794 siz.set_image_offset(image_offset);
795 siz.set_tile_size(tile_size);
796 siz.set_tile_offset(tile_offset);
797
798 ojph::param_cod cod = codestream.access_cod();
799 cod.set_num_decomposition(num_decompositions);
800 cod.set_block_dims(block_size.w, block_size.h);
801 if (num_precincts != -1)
802 cod.set_precinct_size(num_precincts, precinct_size);
803 cod.set_progression_order(prog_order);
804 if (num_comps == 1)
805 {
806 if (employ_color_transform != -1)
807 OJPH_WARN(0x01000091,
808 "-colour_trans option is not needed and was not used; "
809 "this is because the image has one component only\n");
810 }
811 else
812 {
813 if (employ_color_transform == -1)
814 cod.set_color_transform(true);
815 else
816 cod.set_color_transform(employ_color_transform == 1);
817 }
818 cod.set_reversible(reversible);
819 if (!reversible) {
820 const float min_step = 1.0f / 16384.0f;
821 if (quantization_step == -1.0f)
822 quantization_step = min_step;
823 else
824 quantization_step = ojph_max(quantization_step, min_step);
825 codestream.access_qcd().set_irrev_quant(quantization_step);
826 }
827
828 // Note: Even if only ALL_COMPS is set to
829 // OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
830 // one ALL_COMPS NLT marker segment is needed, or multiple
831 // per component NLT marker segments are needed (when the components
832 // have different bit depths or signedness).
833 // Of course for .pfm images all components should have the same
834 // bit depth and signedness.
835 ojph::param_nlt nlt = codestream.access_nlt();
836 if (all_the_same)
837 nlt.set_nonlinear_transform(ojph::param_nlt::ALL_COMPS,
838 ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
839 else
840 for (ojph::ui32 c = 0; c < num_comps; ++c)
841 nlt.set_nonlinear_transform(c,
842 ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT);
843
844 codestream.set_planar(false);
845 if (profile_string[0] != '\0')
846 codestream.set_profile(profile_string);
847 codestream.set_tilepart_divisions(tileparts_at_resolutions,
848 tileparts_at_components);
849 codestream.request_tlm_marker(tlm_marker);
850
851 if (dims.w != 0 || dims.h != 0)
852 OJPH_WARN(0x01000092,
853 "-dims option is not needed and was not used\n");
854 if (num_components != 0)
855 OJPH_WARN(0x01000093,
856 "-num_comps is not needed and was not used\n");
857 if (is_signed[0] != -1)
858 OJPH_WARN(0x01000094,
859 "-signed is not needed and was not used\n");
860 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
861 OJPH_WARN(0x01000095,
862 "-downsamp is not needed and was not used\n");
863
864 base = &pfm;
865 }
866#ifdef OJPH_ENABLE_TIFF_SUPPORT
867 else if (is_matching(".tif", v) || is_matching(".tiff", v))
868 {
869 tif.open(input_filename);
870 ojph::param_siz siz = codestream.access_siz();
871 siz.set_image_extent(ojph::point(image_offset.x + tif.get_size().w,
872 image_offset.y + tif.get_size().h));
873 ojph::ui32 num_comps = tif.get_num_components();
874 siz.set_num_components(num_comps);
875 if(num_bit_depths > 0 )
876 tif.set_bit_depth(num_bit_depths, bit_depth);
877 for (ojph::ui32 c = 0; c < num_comps; ++c)
878 siz.set_component(c, tif.get_comp_subsampling(c),
879 tif.get_bit_depth(c), tif.get_is_signed(c));
880 siz.set_image_offset(image_offset);
881 siz.set_tile_size(tile_size);
882 siz.set_tile_offset(tile_offset);
883
884 ojph::param_cod cod = codestream.access_cod();
885 cod.set_num_decomposition(num_decompositions);
886 cod.set_block_dims(block_size.w, block_size.h);
887 if (num_precincts != -1)
888 cod.set_precinct_size(num_precincts, precinct_size);
889 cod.set_progression_order(prog_order);
890 if (employ_color_transform == -1 && num_comps >= 3)
891 cod.set_color_transform(true);
892 else
893 cod.set_color_transform(employ_color_transform == 1);
894 cod.set_reversible(reversible);
895 if (!reversible && quantization_step != -1)
896 codestream.access_qcd().set_irrev_quant(quantization_step);
897 codestream.set_planar(false);
898 if (profile_string[0] != '\0')
899 codestream.set_profile(profile_string);
900 codestream.set_tilepart_divisions(tileparts_at_resolutions,
901 tileparts_at_components);
902 codestream.request_tlm_marker(tlm_marker);
903
904 if (dims.w != 0 || dims.h != 0)
905 OJPH_WARN(0x01000061,
906 "-dims option is not needed and was not used\n");
907 if (num_components != 0)
908 OJPH_WARN(0x01000062,
909 "-num_comps is not needed and was not used\n");
910 if (is_signed[0] != -1)
911 OJPH_WARN(0x01000063,
912 "-signed is not needed and was not used\n");
913 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
914 OJPH_WARN(0x01000065,
915 "-downsamp is not needed and was not used\n");
916
917 base = &tif;
918 }
919#endif // !OJPH_ENABLE_TIFF_SUPPORT
920 else if (is_matching(".yuv", v))
921 {
922 ojph::param_siz siz = codestream.access_siz();
923 if (dims.w == 0 || dims.h == 0)
924 OJPH_ERROR(0x01000021,
925 "-dims option must have positive dimensions\n");
926 siz.set_image_extent(ojph::point(image_offset.x + dims.w,
927 image_offset.y + dims.h));
928 if (num_components <= 0)
929 OJPH_ERROR(0x01000022,
930 "-num_comps option is missing and must be provided\n");
931 if (num_is_signed <= 0)
932 OJPH_ERROR(0x01000023,
933 "-signed option is missing and must be provided\n");
934 if (num_bit_depths <= 0)
935 OJPH_ERROR(0x01000024,
936 "-bit_depth option is missing and must be provided\n");
937 if (num_comp_downsamps <= 0)
938 OJPH_ERROR(0x01000025,
939 "-downsamp option is missing and must be provided\n");
940
941 yuv.set_img_props(dims, num_components, num_comp_downsamps,
942 comp_downsampling);
943 yuv.set_bit_depth(num_bit_depths, bit_depth);
944
945 ojph::ui32 last_signed_idx = 0, last_bit_depth_idx = 0;
946 ojph::ui32 last_downsamp_idx = 0;
947 siz.set_num_components(num_components);
948 for (ojph::ui32 c = 0; c < num_components; ++c)
949 {
950 ojph::point cp_ds = comp_downsampling
951 [c < num_comp_downsamps ? c : last_downsamp_idx];
952 last_downsamp_idx += last_downsamp_idx+1 < num_comp_downsamps ? 1:0;
953 ojph::ui32 bd = bit_depth[c<num_bit_depths ? c : last_bit_depth_idx];
954 last_bit_depth_idx += last_bit_depth_idx + 1 < num_bit_depths ? 1:0;
955 int is = is_signed[c < num_is_signed ? c : last_signed_idx];
956 last_signed_idx += last_signed_idx + 1 < num_is_signed ? 1 : 0;
957 siz.set_component(c, cp_ds, bd, is == 1);
958 }
959 siz.set_image_offset(image_offset);
960 siz.set_tile_size(tile_size);
961 siz.set_tile_offset(tile_offset);
962
963 ojph::param_cod cod = codestream.access_cod();
964 cod.set_num_decomposition(num_decompositions);
965 cod.set_block_dims(block_size.w, block_size.h);
966 if (num_precincts != -1)
967 cod.set_precinct_size(num_precincts, precinct_size);
968 cod.set_progression_order(prog_order);
969 if (employ_color_transform == -1)
970 cod.set_color_transform(false);
971 else
972 OJPH_ERROR(0x01000031,
973 "We currently do not support color transform on raw(yuv) files."
974 " In any case, this not a normal usage scenario. The OpenJPH "
975 "library however does support that, but ojph_compress.cpp must be "
976 "modified to send all lines from one component before moving to "
977 "the next component; this requires buffering components outside"
978 " of the OpenJPH library");
979 cod.set_reversible(reversible);
980 if (!reversible && quantization_step != -1.0f)
981 codestream.access_qcd().set_irrev_quant(quantization_step);
982 codestream.set_planar(true);
983 if (profile_string[0] != '\0')
984 codestream.set_profile(profile_string);
985 codestream.set_tilepart_divisions(tileparts_at_resolutions,
986 tileparts_at_components);
987 codestream.request_tlm_marker(tlm_marker);
988
989 yuv.open(input_filename);
990 base = &yuv;
991 }
992 else if (is_matching(".raw", v))
993 {
994 ojph::param_siz siz = codestream.access_siz();
995 if (dims.w == 0 || dims.h == 0)
996 OJPH_ERROR(0x01000081,
997 "-dims option must have positive dimensions\n");
998 siz.set_image_extent(ojph::point(image_offset.x + dims.w,
999 image_offset.y + dims.h));
1000 if (num_components != 1)
1001 OJPH_ERROR(0x01000082,
1002 "-num_comps must be 1\n");
1003 if (num_is_signed <= 0)
1004 OJPH_ERROR(0x01000083,
1005 "-signed option is missing and must be provided\n");
1006 if (num_bit_depths <= 0)
1007 OJPH_ERROR(0x01000084,
1008 "-bit_depth option is missing and must be provided\n");
1009 if (num_comp_downsamps <= 0)
1010 OJPH_ERROR(0x01000085,
1011 "-downsamp option is missing and must be provided\n");
1012
1013 raw.set_img_props(dims, bit_depth[0], is_signed);
1014
1015 siz.set_num_components(num_components);
1016 siz.set_component(0, comp_downsampling[0], bit_depth[0], is_signed[0]);
1017 siz.set_image_offset(image_offset);
1018 siz.set_tile_size(tile_size);
1019 siz.set_tile_offset(tile_offset);
1020
1021 ojph::param_cod cod = codestream.access_cod();
1022 cod.set_num_decomposition(num_decompositions);
1023 cod.set_block_dims(block_size.w, block_size.h);
1024 if (num_precincts != -1)
1025 cod.set_precinct_size(num_precincts, precinct_size);
1026 cod.set_progression_order(prog_order);
1027 if (employ_color_transform != -1)
1028 OJPH_ERROR(0x01000086,
1029 "color transform is meaningless since .raw files are single "
1030 "component files");
1031 cod.set_reversible(reversible);
1032 if (!reversible && quantization_step != -1.0f)
1033 codestream.access_qcd().set_irrev_quant(quantization_step);
1034 codestream.set_planar(true);
1035 if (profile_string[0] != '\0')
1036 codestream.set_profile(profile_string);
1037 codestream.set_tilepart_divisions(tileparts_at_resolutions,
1038 tileparts_at_components);
1039 codestream.request_tlm_marker(tlm_marker);
1040
1041 raw.open(input_filename);
1042 base = &raw;
1043 }
1044 else if (is_matching(".dpx", v))
1045 {
1046 dpx.open(input_filename);
1047 ojph::param_siz siz = codestream.access_siz();
1048 siz.set_image_extent(ojph::point(image_offset.x + dpx.get_size().w,
1049 image_offset.y + dpx.get_size().h));
1050 ojph::ui32 num_comps = dpx.get_num_components();
1051 siz.set_num_components(num_comps);
1052 //if (num_bit_depths > 0)
1053 // dpx.set_bit_depth(num_bit_depths, bit_depth);
1054 for (ojph::ui32 c = 0; c < num_comps; ++c)
1055 siz.set_component(c, dpx.get_comp_subsampling(c),
1056 dpx.get_bit_depth(c), dpx.get_is_signed(c));
1057 siz.set_image_offset(image_offset);
1058 siz.set_tile_size(tile_size);
1059 siz.set_tile_offset(tile_offset);
1060
1061 ojph::param_cod cod = codestream.access_cod();
1062 cod.set_num_decomposition(num_decompositions);
1063 cod.set_block_dims(block_size.w, block_size.h);
1064 if (num_precincts != -1)
1065 cod.set_precinct_size(num_precincts, precinct_size);
1066 cod.set_progression_order(prog_order);
1067 if (employ_color_transform == -1 && num_comps >= 3)
1068 cod.set_color_transform(true);
1069 else
1070 cod.set_color_transform(employ_color_transform == 1);
1071 cod.set_reversible(reversible);
1072 if (!reversible && quantization_step != -1)
1073 codestream.access_qcd().set_irrev_quant(quantization_step);
1074 codestream.set_planar(false);
1075 if (profile_string[0] != '\0')
1076 codestream.set_profile(profile_string);
1077 codestream.set_tilepart_divisions(tileparts_at_resolutions,
1078 tileparts_at_components);
1079 codestream.request_tlm_marker(tlm_marker);
1080
1081 if (dims.w != 0 || dims.h != 0)
1082 OJPH_WARN(0x01000071,
1083 "-dims option is not needed and was not used\n");
1084 if (num_components != 0)
1085 OJPH_WARN(0x01000072,
1086 "-num_comps is not needed and was not used\n");
1087 if (is_signed[0] != -1)
1088 OJPH_WARN(0x01000073,
1089 "-signed is not needed and was not used\n");
1090 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
1091 OJPH_WARN(0x01000075,
1092 "-downsamp is not needed and was not used\n");
1093
1094 base = &dpx;
1095 }
1096 else
1097#if defined( OJPH_ENABLE_TIFF_SUPPORT)
1098 OJPH_ERROR(0x01000041,
1099 "unknown input file extension; only pgm, ppm, dpx, tif(f),"
1100 " or raw(yuv) are supported\n");
1101#else
1102 OJPH_ERROR(0x01000041,
1103 "unknown input file extension; only pgm, ppm, dpx,"
1104 " or raw(yuv) are supported\n");
1105#endif // !OJPH_ENABLE_TIFF_SUPPORT
1106 }
1107 else
1108 OJPH_ERROR(0x01000051,
1109 "Please supply a proper input filename with a proper three-letter "
1110 "extension\n");
1111
1112 ojph::comment_exchange com_ex;
1113 if (com_string)
1114 com_ex.set_string(com_string);
1115 ojph::j2c_outfile j2c_file;
1116 j2c_file.open(output_filename);
1117 codestream.write_headers(&j2c_file, &com_ex, com_string ? 1 : 0);
1118
1119 ojph::ui32 next_comp;
1120 ojph::line_buf* cur_line = codestream.exchange(NULL, next_comp);
1121 if (codestream.is_planar())
1122 {
1123 ojph::param_siz siz = codestream.access_siz();
1124 for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c)
1125 {
1126 ojph::point p = siz.get_downsampling(c);
1127 ojph::ui32 height = ojph_div_ceil(siz.get_image_extent().y, p.y);
1128 height -= ojph_div_ceil(siz.get_image_offset().y, p.y);
1129 for (ojph::ui32 i = height; i > 0; --i)
1130 {
1131 assert(c == next_comp);
1132 base->read(cur_line, next_comp);
1133 cur_line = codestream.exchange(cur_line, next_comp);
1134 }
1135 }
1136 }
1137 else
1138 {
1139 ojph::param_siz siz = codestream.access_siz();
1140 ojph::ui32 height = siz.get_image_extent().y;
1141 height -= siz.get_image_offset().y;
1142 for (ojph::ui32 i = 0; i < height; ++i)
1143 {
1144 for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c)
1145 {
1146 assert(c == next_comp);
1147 base->read(cur_line, next_comp);
1148 cur_line = codestream.exchange(cur_line, next_comp);
1149 }
1150 }
1151 }
1152
1153 codestream.flush();
1154 codestream.close();
1155 base->close();
1156
1157 if (max_num_comps != initial_num_comps)
1158 {
1159 delete[] comp_downsampling;
1160 delete[] bit_depth;
1161 delete[] is_signed;
1162 }
1163 }
1164 catch (const std::exception& e)
1165 {
1166 const char *p = e.what();
1167 if (strncmp(p, "ojph error", 10) != 0)
1168 printf("%s\n", p);
1169 exit(-1);
1170 }
1171
1172 clock_t end = clock();
1173 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
1174 printf("Elapsed time = %f\n", elapsed_secs);
1175
1176 return 0;
1177
1178}
ojph::argument
Definition ojph_arg.h:53
ojph::argument::is_valid
bool is_valid()
Definition ojph_arg.h:58
ojph::argument::arg
char * arg
Definition ojph_arg.h:57
ojph::cli_interpreter
Definition ojph_arg.h:66
ojph::cli_interpreter::init
void init(int argc, char *argv[])
Definition ojph_arg.h:73
ojph::cli_interpreter::reinterpret_to_bool
void reinterpret_to_bool(const char *str, int &val)
Definition ojph_arg.h:216
ojph::cli_interpreter::reinterpret
void reinterpret(const char *str, int &val)
Definition ojph_arg.h:146
ojph::cli_interpreter::is_exhausted
bool is_exhausted()
Definition ojph_arg.h:118
ojph::cli_interpreter::get_argument_zero
argument get_argument_zero()
Definition ojph_arg.h:126
ojph::cli_interpreter::get_next_avail_argument
argument get_next_avail_argument(const argument &arg)
Definition ojph_arg.h:133
ojph::codestream
The object represent a codestream.
Definition ojph_codestream.h:89
ojph::codestream::access_siz
param_siz access_siz()
Returns the underlying SIZ marker segment object.
Definition ojph_codestream.cpp:79
ojph::codestream::access_cod
param_cod access_cod()
Returns the underlying COD marker segment object.
Definition ojph_codestream.cpp:85
ojph::codestream::close
void close()
Call this function to close the underlying file; works for both encoding and decoding codestreams.
Definition ojph_codestream.cpp:206
ojph::codestream::set_planar
void set_planar(bool planar)
Sets the sequence of pushing or pull rows from the machinery.
Definition ojph_codestream.cpp:103
ojph::codestream::exchange
line_buf * exchange(line_buf *line, ui32 &next_component)
This call is used to send image data rows to the library. We expect to send one row from a single com...
Definition ojph_codestream.cpp:212
ojph::codestream::request_tlm_marker
void request_tlm_marker(bool needed)
Request the addition of the optional TLM marker segment. This request should occur before writing cod...
Definition ojph_codestream.cpp:141
ojph::codestream::set_profile
void set_profile(const char *s)
Sets the codestream profile.
Definition ojph_codestream.cpp:109
ojph::codestream::access_qcd
param_qcd access_qcd()
Returns the underlying QCD marker segment object.
Definition ojph_codestream.cpp:91
ojph::codestream::set_tilepart_divisions
void set_tilepart_divisions(bool at_resolutions, bool at_components)
Sets the locations where a tile is partitioned into tile parts.
Definition ojph_codestream.cpp:115
ojph::codestream::write_headers
void write_headers(outfile_base *file, const comment_exchange *comments=NULL, ui32 num_comments=0)
Writes codestream headers when the codestream is used for writing. This function should be called aft...
Definition ojph_codestream.cpp:159
ojph::codestream::access_nlt
param_nlt access_nlt()
Returns the underlying NLT marker segment object.
Definition ojph_codestream.cpp:97
ojph::codestream::is_planar
bool is_planar() const
Query if the codestream extraction is planar or not. See the documentation for ojph::codestream::set_...
Definition ojph_codestream.cpp:153
ojph::codestream::flush
void flush()
This is the last call to a writing (encoding) codestream. This will write encoded bitstream data to t...
Definition ojph_codestream.cpp:200
ojph::comment_exchange
Definition ojph_params.h:291
ojph::comment_exchange::set_string
void set_string(const char *str)
Definition ojph_params.cpp:456
ojph::dpx_in
Definition ojph_img_io.h:240
ojph::dpx_in::get_num_components
ui32 get_num_components()
Definition ojph_img_io.h:284
ojph::dpx_in::get_is_signed
bool get_is_signed(ui32 comp_num)
Definition ojph_img_io.h:289
ojph::dpx_in::open
void open(const char *filename)
Definition ojph_img_io.cpp:1796
ojph::dpx_in::get_bit_depth
ui32 get_bit_depth(ui32 comp_num)
Definition ojph_img_io.h:285
ojph::dpx_in::get_size
size get_size()
Definition ojph_img_io.h:283
ojph::dpx_in::get_comp_subsampling
point get_comp_subsampling(ui32 comp_num)
Definition ojph_img_io.h:293
ojph::image_in_base
Definition ojph_img_io.h:67
ojph::image_in_base::close
virtual void close()
Definition ojph_img_io.h:71
ojph::image_in_base::read
virtual ui32 read(const line_buf *line, ui32 comp_num)=0
ojph::j2c_outfile
Definition ojph_file.h:98
ojph::j2c_outfile::open
void open(const char *filename)
Definition ojph_file.cpp:62
ojph::line_buf
Definition ojph_mem.h:161
ojph::param_cod
Definition ojph_params.h:104
ojph::param_cod::set_num_decomposition
void set_num_decomposition(ui32 num_decompositions)
Definition ojph_params.cpp:164
ojph::param_cod::set_precinct_size
void set_precinct_size(int num_levels, size *precinct_size)
Definition ojph_params.cpp:187
ojph::param_cod::set_progression_order
void set_progression_order(const char *name)
Definition ojph_params.cpp:215
ojph::param_cod::set_block_dims
void set_block_dims(ui32 width, ui32 height)
Definition ojph_params.cpp:173
ojph::param_cod::set_color_transform
void set_color_transform(bool color_transform)
Definition ojph_params.cpp:242
ojph::param_cod::set_reversible
void set_reversible(bool reversible)
Definition ojph_params.cpp:248
ojph::param_nlt
non-linearity point transformation object (implements NLT marker segment)
Definition ojph_params.h:245
ojph::param_nlt::OJPH_NLT_BINARY_COMPLEMENT_NLT
@ OJPH_NLT_BINARY_COMPLEMENT_NLT
Definition ojph_params.h:252
ojph::param_nlt::ALL_COMPS
@ ALL_COMPS
Definition ojph_params.h:247
ojph::param_nlt::set_nonlinear_transform
void set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
enables or disables type 3 nonlinearity for a component or the default setting
Definition ojph_params.cpp:434
ojph::param_qcd::set_irrev_quant
void set_irrev_quant(float delta)
Set the irreversible quantization base delta.
Definition ojph_params.cpp:414
ojph::param_siz
Definition ojph_params.h:71
ojph::param_siz::set_tile_size
void set_tile_size(size s)
Definition ojph_params.cpp:65
ojph::param_siz::get_image_extent
point get_image_extent() const
Definition ojph_params.cpp:96
ojph::param_siz::set_component
void set_component(ui32 comp_num, const point &downsampling, ui32 bit_depth, bool is_signed)
Definition ojph_params.cpp:89
ojph::param_siz::set_num_components
void set_num_components(ui32 num_comps)
Definition ojph_params.cpp:83
ojph::param_siz::set_tile_offset
void set_tile_offset(point offset)
Definition ojph_params.cpp:77
ojph::param_siz::get_image_offset
point get_image_offset() const
Definition ojph_params.cpp:102
ojph::param_siz::set_image_offset
void set_image_offset(point offset)
Definition ojph_params.cpp:71
ojph::param_siz::get_downsampling
point get_downsampling(ui32 comp_num) const
Definition ojph_params.cpp:138
ojph::param_siz::set_image_extent
void set_image_extent(point extent)
Definition ojph_params.cpp:59
ojph::param_siz::get_num_components
ui32 get_num_components() const
Definition ojph_params.cpp:120
ojph::pfm_in
Definition ojph_img_io.h:457
ojph::pfm_in::get_width
ui32 get_width()
Definition ojph_img_io.h:492
ojph::pfm_in::get_height
ui32 get_height()
Definition ojph_img_io.h:493
ojph::pfm_in::open
void open(const char *filename)
Definition ojph_img_io.cpp:566
ojph::pfm_in::get_num_components
ui32 get_num_components()
Definition ojph_img_io.h:494
ojph::pfm_in::configure
void configure(ui32 *bit_depth)
Definition ojph_img_io.h:483
ojph::ppm_in
Definition ojph_img_io.h:82
ojph::ppm_in::get_height
ui32 get_height()
Definition ojph_img_io.h:117
ojph::ppm_in::open
void open(const char *filename)
Definition ojph_img_io.cpp:245
ojph::ppm_in::get_num_components
ui32 get_num_components()
Definition ojph_img_io.h:119
ojph::ppm_in::get_width
ui32 get_width()
Definition ojph_img_io.h:116
ojph::ppm_in::get_bit_depth
ui32 get_bit_depth(ui32 comp_num)
Definition ojph_img_io.h:120
ojph::ppm_in::get_comp_subsampling
point get_comp_subsampling(ui32 comp_num)
Definition ojph_img_io.h:124
ojph::ppm_in::get_is_signed
bool get_is_signed(ui32 comp_num)
Definition ojph_img_io.h:122
ojph::raw_in
Definition ojph_img_io.h:409
ojph::raw_in::set_img_props
void set_img_props(const size &s, ui32 bit_depth, bool is_signed)
Definition ojph_img_io.cpp:1591
ojph::raw_in::open
void open(const char *filename)
Definition ojph_img_io.cpp:1495
ojph::yuv_in
Definition ojph_img_io.h:348
ojph::yuv_in::open
void open(const char *filename)
Definition ojph_img_io.cpp:1296
ojph::yuv_in::set_img_props
void set_img_props(const size &s, ui32 num_components, ui32 num_downsampling, const point *downsampling)
Definition ojph_img_io.cpp:1351
ojph::yuv_in::set_bit_depth
void set_bit_depth(ui32 num_bit_depths, ui32 *bit_depth)
Definition ojph_img_io.cpp:1378
ojph::si32
int32_t si32
Definition ojph_defs.h:55
ojph::ui32
uint32_t ui32
Definition ojph_defs.h:54
ojph_arg.h
ojph_codestream.h
main
int main(int argc, char *argv[])
Definition ojph_compress.cpp:487
get_file_extension
static const char * get_file_extension(const char *filename)
Definition ojph_compress.cpp:456
get_arguments
static bool get_arguments(int argc, char *argv[], char *&input_filename, char *&output_filename, char *&progression_order, char *&profile_string, ojph::ui32 &num_decompositions, float &quantization_step, bool &reversible, int &employ_color_transform, const int max_num_precincts, int &num_precincts, ojph::size *precinct_size, ojph::size &block_size, ojph::size &dims, ojph::point &image_offset, ojph::size &tile_size, ojph::point &tile_offset, ojph::ui32 &max_num_comps, ojph::ui32 &num_comps, ojph::ui32 &num_comp_downsamps, ojph::point *&comp_downsamp, ojph::ui32 &num_bit_depths, ojph::ui32 *&bit_depth, ojph::ui32 &num_is_signed, ojph::si32 *&is_signed, bool &tlm_marker, bool &tileparts_at_resolutions, bool &tileparts_at_components, char *&com_string)
Definition ojph_compress.cpp:361
is_matching
static bool is_matching(const char *ref, const char *other)
Definition ojph_compress.cpp:469
ojph_max
#define ojph_max(a, b)
Definition ojph_defs.h:73
ojph_div_ceil
#define ojph_div_ceil(a, b)
Definition ojph_defs.h:70
ojph_file.h
ojph_img_io.h
ojph_mem.h
ojph_message.h
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::cli_interpreter::arg_inter_base
Definition ojph_arg.h:249
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::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
point_interpreter
Definition ojph_compress.cpp:198
point_interpreter::point_interpreter
point_interpreter(ojph::point &val)
Definition ojph_compress.cpp:199
point_interpreter::operate
virtual void operate(const char *str)
Definition ojph_compress.cpp:200
point_interpreter::val
ojph::point & val
Definition ojph_compress.cpp:224
point_list_interpreter
Definition ojph_compress.cpp:109
point_list_interpreter::num_eles
ojph::ui32 & num_eles
Definition ojph_compress.cpp:162
point_list_interpreter::max_num_eles
const ojph::ui32 max_num_eles
Definition ojph_compress.cpp:160
point_list_interpreter::operate
virtual void operate(const char *str)
Definition ojph_compress.cpp:116
point_list_interpreter::pointlist
ojph::point * pointlist
Definition ojph_compress.cpp:161
point_list_interpreter::point_list_interpreter
point_list_interpreter(const ojph::ui32 max_num_elements, ojph::ui32 &num_elements, ojph::point *list)
Definition ojph_compress.cpp:110
si32_to_bool_list_interpreter
Definition ojph_compress.cpp:274
si32_to_bool_list_interpreter::si32_to_bool_list_interpreter
si32_to_bool_list_interpreter(const ojph::ui32 max_num_elements, ojph::ui32 &num_elements, ojph::si32 *list)
Definition ojph_compress.cpp:275
si32_to_bool_list_interpreter::num_eles
ojph::ui32 & num_eles
Definition ojph_compress.cpp:320
si32_to_bool_list_interpreter::max_num_eles
const ojph::ui32 max_num_eles
Definition ojph_compress.cpp:318
si32_to_bool_list_interpreter::get_num_elements
ojph::ui32 get_num_elements()
Definition ojph_compress.cpp:316
si32_to_bool_list_interpreter::operate
virtual void operate(const char *str)
Definition ojph_compress.cpp:280
si32_to_bool_list_interpreter::boollist
ojph::si32 * boollist
Definition ojph_compress.cpp:319
size_interpreter
Definition ojph_compress.cpp:167
size_interpreter::operate
virtual void operate(const char *str)
Definition ojph_compress.cpp:169
size_interpreter::size_interpreter
size_interpreter(ojph::size &val)
Definition ojph_compress.cpp:168
size_interpreter::val
ojph::size & val
Definition ojph_compress.cpp:193
size_list_interpreter
Definition ojph_compress.cpp:52
size_list_interpreter::num_eles
int & num_eles
Definition ojph_compress.cpp:104
size_list_interpreter::max_num_eles
const int max_num_eles
Definition ojph_compress.cpp:102
size_list_interpreter::sizelist
ojph::size * sizelist
Definition ojph_compress.cpp:103
size_list_interpreter::operate
virtual void operate(const char *str)
Definition ojph_compress.cpp:58
size_list_interpreter::size_list_interpreter
size_list_interpreter(const int max_num_elements, int &num_elements, ojph::size *list)
Definition ojph_compress.cpp:53
tileparts_division_interpreter
Definition ojph_compress.cpp:326
tileparts_division_interpreter::tileparts_division_interpreter
tileparts_division_interpreter(bool &at_resolutions, bool &at_components)
Definition ojph_compress.cpp:327
tileparts_division_interpreter::operate
virtual void operate(const char *str)
Definition ojph_compress.cpp:331
tileparts_division_interpreter::at_components
bool & at_components
Definition ojph_compress.cpp:356
tileparts_division_interpreter::at_resolutions
bool & at_resolutions
Definition ojph_compress.cpp:355
ui32_list_interpreter
Definition ojph_compress.cpp:230
ui32_list_interpreter::operate
virtual void operate(const char *str)
Definition ojph_compress.cpp:237
ui32_list_interpreter::ui32_list_interpreter
ui32_list_interpreter(const ojph::ui32 max_num_elements, ojph::ui32 &num_elements, ojph::ui32 *list)
Definition ojph_compress.cpp:231
ui32_list_interpreter::max_num_eles
const ojph::ui32 max_num_eles
Definition ojph_compress.cpp:266
ui32_list_interpreter::num_eles
ojph::ui32 & num_eles
Definition ojph_compress.cpp:268
ui32_list_interpreter::ui32list
ojph::ui32 * ui32list
Definition ojph_compress.cpp:267