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
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);
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;
105};
106
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);
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
163};
164
167{
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 }
194};
195
198{
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 }
225};
226
227
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);
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
269};
270
274{
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);
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
317
321};
322
326{
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
357};
358
360static
361bool 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, int &qfactor, 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("-qfactor", qfactor);
387 interpreter.reinterpret("-reversible", reversible);
388 interpreter.reinterpret_to_bool("-colour_trans", employ_color_transform);
389 interpreter.reinterpret("-num_comps", num_comps);
390 interpreter.reinterpret("-tlm_marker", tlm_marker);
391 interpreter.reinterpret("-com", com_string);
392
393 size_interpreter block_interpreter(block_size);
394 size_interpreter dims_interpreter(dims);
395 size_list_interpreter sizelist(max_num_precincts, num_precincts,
396 precinct_size);
397
398 if (num_comps > 16384) {
399 printf("More than 16384 components is not supported in JPEG2000."
400 "You specified %d\n", num_comps);
401 return false;
402 }
403
404 if (num_comps > max_num_comps)
405 {
406 max_num_comps = num_comps;
407 comp_downsamp = new ojph::point[num_comps];
408 bit_depth = new ojph::ui32[num_comps];
409 is_signed = new ojph::si32[num_comps];
410 for (ojph::ui32 i = 0; i < num_comps; ++i)
411 {
412 comp_downsamp[i] = ojph::point(0, 0);
413 bit_depth[i] = 0;
414 is_signed[i] = -1;
415 }
416 }
417
418 point_list_interpreter pointlist(max_num_comps, num_comp_downsamps,
419 comp_downsamp);
420 ui32_list_interpreter ilist(max_num_comps, num_bit_depths, bit_depth);
421 si32_to_bool_list_interpreter blist(max_num_comps, num_is_signed, is_signed);
422 point_interpreter img_off_interpreter(image_offset);
423 size_interpreter tile_size_interpreter(tile_size);
424 point_interpreter tile_off_interpreter(tile_offset);
425 tileparts_division_interpreter tp_div_interpreter(tileparts_at_resolutions,
426 tileparts_at_components);
427 try
428 {
429 interpreter.reinterpret("-block_size", &block_interpreter);
430 interpreter.reinterpret("-dims", &dims_interpreter);
431 interpreter.reinterpret("-image_offset", &img_off_interpreter);
432 interpreter.reinterpret("-tile_size", &tile_size_interpreter);
433 interpreter.reinterpret("-tile_offset", &tile_off_interpreter);
434 interpreter.reinterpret("-precincts", &sizelist);
435 interpreter.reinterpret("-downsamp", &pointlist);
436 interpreter.reinterpret("-bit_depth", &ilist);
437 interpreter.reinterpret("-signed", &blist);
438 interpreter.reinterpret("-tileparts", &tp_div_interpreter);
439 }
440 catch (const char *s)
441 {
442 printf("%s\n",s);
443 return false;
444 }
445
446 if (interpreter.is_exhausted() == false) {
447 printf("The following arguments were not interpreted:\n");
448 ojph::argument t = interpreter.get_argument_zero();
449 t = interpreter.get_next_avail_argument(t);
450 while (t.is_valid()) {
451 printf("%s\n", t.arg);
452 t = interpreter.get_next_avail_argument(t);
453 }
454 return false;
455 }
456 return true;
457}
458
460static
461const char* get_file_extension(const char* filename)
462{
463 size_t len = strlen(filename);
464 const char* p = strrchr(filename, '.');
465 if (p == NULL || p == filename + len - 1)
466 OJPH_ERROR(0x01000071,
467 "no file extension is found, or there are no characters "
468 "after the dot \'.\' for filename \"%s\" \n", filename);
469 return p;
470}
471
473static
474bool is_matching(const char *ref, const char *other)
475{
476 size_t num_ele = strlen(ref);
477
478 if (num_ele != strlen(other))
479 return false;
480
481 for (ojph::ui32 i = 0; i < num_ele; ++i)
482 if (ref[i] != other[i] && ref[i] != tolower(other[i]))
483 return false;
484
485 return true;
486}
487
489// main
491
492int main(int argc, char * argv[]) {
493 char *input_filename = NULL;
494 char *output_filename = NULL;
495 char prog_order_store[] = "RPCL";
496 char *prog_order = prog_order_store;
497 char profile_string_store[] = "";
498 char *profile_string = profile_string_store;
499 char *com_string = NULL;
500 ojph::ui32 num_decompositions = 5;
501 float quantization_step = -1.0f;
502 int qfactor = -1;
503 bool reversible = false;
504 int employ_color_transform = -1;
505
506 const int max_precinct_sizes = 33; //maximum number of decompositions is 32
507 ojph::size precinct_size[max_precinct_sizes];
508 int num_precincts = -1;
509
510 ojph::size block_size(64,64);
511 ojph::size dims(0, 0);
512 ojph::size tile_size(0, 0);
513 ojph::point tile_offset(0, 0);
514 ojph::point image_offset(0, 0);
515 const ojph::ui32 initial_num_comps = 4;
516 ojph::ui32 max_num_comps = initial_num_comps;
517 ojph::ui32 num_components = 0;
518 ojph::ui32 num_is_signed = 0;
519 ojph::si32 is_signed_store[initial_num_comps] = {-1, -1, -1, -1};
520 ojph::si32 *is_signed = is_signed_store;
521 ojph::ui32 num_bit_depths = 0;
522 ojph::ui32 bit_depth_store[initial_num_comps] = {0, 0, 0, 0};
523 ojph::ui32 *bit_depth = bit_depth_store;
524 ojph::ui32 num_comp_downsamps = 0;
525 ojph::point downsampling_store[initial_num_comps];
526 ojph::point *comp_downsampling = downsampling_store;
527 bool tlm_marker = false;
528 bool tileparts_at_resolutions = false;
529 bool tileparts_at_components = false;
530
531 if (argc <= 1) {
532 std::cout <<
533 "\nThe following arguments are necessary:\n"
534#ifdef OJPH_ENABLE_TIFF_SUPPORT
535 " -i input file name (either pgm, ppm, pfm, tif(f), or raw(yuv))\n"
536#else
537 " -i input file name (either pgm, ppm, pfm, or raw(yuv))\n"
538#endif // !OJPH_ENABLE_TIFF_SUPPORT
539 " -o output file name\n\n"
540
541 "The following option has a default value (optional):\n"
542 " -num_decomps (5) number of decompositions\n"
543 " -qstep (0.00001...0.5) quantization step size for lossy\n"
544 " compression; quantization steps size for all subbands are\n"
545 " derived from this value. {The default value for 8bit\n"
546 " images is 0.0039}\n"
547 " -qfactor (1...100) compression quality factor; 1 is worst\n"
548 " quality and 100 is best quality. Only valid for\n"
549 " images with 1 or 3 components. Cannot be used\n"
550 " together with -qstep.\n"
551 " -reversible <true | false> If this is 'false', an irreversible or\n"
552 " lossy compression is employed, using the 9/7 wavelet\n"
553 " transform; if 'true', a reversible compression is\n"
554 " performed, where the 5/3 wavelet is used.\n"
555 " Default value is 'false'.\n"
556 " -colour_trans <true | false> This option employs a color transform,\n"
557 " to transform RGB color images into the YUV domain.\n"
558 " This option should NOT be used with YUV images, because\n"
559 " they have already been transformed.\n"
560 " If there are three color components that are\n"
561 " downsampled by the same amount then this option can be\n"
562 " 'true' or 'false'. This option is also available when\n"
563 " there are more than three colour components, where it is\n"
564 " applied to the first three colour components.\n"
565 " -prog_order (RPCL) is the progression order, and can be one of:\n"
566 " LRCP, RLCP, RPCL, PCRL, CPRL.\n"
567 " -block_size {x,y} (64,64) where x and y are the height and width of\n"
568 " a codeblock. In unix-like environment, { and } must be\n"
569 " preceded by a ""\\"".\n"
570 " -precincts {x,y},{x,y},...,{x,y} where {x,y} is the precinct size\n"
571 " starting from the coarsest resolution; the last precinct\n"
572 " is repeated for all finer resolutions\n"
573 " -tile_offset {x,y} tile offset. \n"
574 " -tile_size {x,y} tile width and height. \n"
575 " -image_offset {x,y} image offset from origin. \n"
576 " -tileparts (None) employ tilepart divisions at each resolution, \n"
577 " indicated by the letter R, and/or component, indicated \n"
578 " by the letter C. For both, use \"-tileparts RC\".\n"
579 " -tlm_marker <true | false> if 'true', a TLM marker is inserted.\n"
580 " Default value is false.\n"
581 " -profile (None) is the profile, the code will check if the \n"
582 " selected options meet the profile. Currently only \n"
583 " BROADCAST and IMF are supported. This automatically \n"
584 " sets tlm_marker to true and tileparts to C.\n"
585 " -com (None) if set, inserts a COM marker with the specified\n"
586 " string. If the string has spaces, please use\n"
587 " double quotes, as in -com \"This is a comment\".\n"
588 "\n"
589
590 "When the input file is a YUV file, these arguments need to be \n"
591 " supplied: \n"
592 " -dims {x,y} x is image width, y is height\n"
593 " -num_comps number of components\n"
594 " -signed a comma-separated list of true or false parameters, one\n"
595 " for each component; for example: true,false,false\n"
596 " -bit_depth a comma-separated list of bit depth values, one per \n"
597 " component; for example: 12,10,10\n"
598 " -downsamp {x,y},{x,y},...,{x,y} a list of x,y points, one for each\n"
599 " component; for example {1,1},{2,2},{2,2}\n\n"
600 "\n"
601
602 ".pfm files receive special treatment. Currently, lossy compression\n"
603 "with these files is not supported, only lossless. When these files are\n"
604 "used, the NLT segment marker is automatically inserted into the\n"
605 "codestream when needed, as explained shortly. The following arguments\n"
606 "can be useful for this file type.\n"
607 " -signed a comma-separated list of true or false parameters, one\n"
608 " for each component; for example: true,false,false.\n"
609 " If you are sure that all sample values are positive or 0,\n"
610 " set the corresponding entry to false; otherwise set it to\n"
611 " true.\n"
612 " When a component entry is set to true, an NLT segment\n"
613 " marker segment is inserted into the codestream.\n"
614 " The NLT segment specifies a non-linear transform that\n"
615 " changes only negative values, producing better coding\n"
616 " efficiency.\n"
617 " The NLT segment marker might be less supported in other\n"
618 " encoders.\n"
619 " -bit_depth a comma-separated list of bit depth values, one per \n"
620 " component; for example: 12,10,10.\n"
621 " Floating value numbers are treated as integers, and they\n"
622 " are shifted to the right, keeping only the specified\n"
623 " number of bits. Up to 32 bits (which is the default) are\n"
624 " supported.\n"
625
626 "\n";
627 return -1;
628 }
629 if (!get_arguments(argc, argv, input_filename, output_filename,
630 prog_order, profile_string, num_decompositions,
631 quantization_step, qfactor, reversible,
632 employ_color_transform,
633 max_precinct_sizes, num_precincts, precinct_size,
634 block_size, dims, image_offset, tile_size, tile_offset,
635 max_num_comps, num_components,
636 num_comp_downsamps, comp_downsampling,
637 num_bit_depths, bit_depth, num_is_signed, is_signed,
638 tlm_marker, tileparts_at_resolutions,
639 tileparts_at_components, com_string))
640 {
641 return -1;
642 }
643
644 if (qfactor != -1 && quantization_step != -1.0f)
645 OJPH_ERROR(0x010000A1,
646 "-qfactor and -qstep cannot be used together\n");
647 if (qfactor != -1 && (qfactor < 1 || qfactor > 100))
648 OJPH_ERROR(0x010000A2,
649 "-qfactor must be between 1 and 100\n");
650
651 clock_t begin = clock();
652
653 try
654 {
655 ojph::codestream codestream;
656
657 ojph::ppm_in ppm;
658 ojph::pfm_in pfm;
659 ojph::yuv_in yuv;
660 ojph::raw_in raw;
661 ojph::dpx_in dpx;
662#ifdef OJPH_ENABLE_TIFF_SUPPORT
663 ojph::tif_in tif;
664#endif // !OJPH_ENABLE_TIFF_SUPPORT
665
666 ojph::image_in_base *base = NULL;
667 if (input_filename == NULL)
668 OJPH_ERROR(0x01000007, "please specify an input file name using"
669 " the -i command line option");
670 if (output_filename == NULL)
671 OJPH_ERROR(0x01000008, "please specify an output file name using"
672 " the -o command line option");
673 const char *v = get_file_extension(input_filename);
674
675 if (v)
676 {
677 if (is_matching(".pgm", v))
678 {
679 ppm.open(input_filename);
680 ojph::param_siz siz = codestream.access_siz();
681 siz.set_image_extent(ojph::point(image_offset.x + ppm.get_width(),
682 image_offset.y + ppm.get_height()));
683 ojph::ui32 num_comps = ppm.get_num_components();
684 assert(num_comps == 1);
685 siz.set_num_components(num_comps);
686 for (ojph::ui32 c = 0; c < num_comps; ++c)
688 ppm.get_bit_depth(c), ppm.get_is_signed(c));
689 siz.set_image_offset(image_offset);
690 siz.set_tile_size(tile_size);
691 siz.set_tile_offset(tile_offset);
692
693 ojph::param_cod cod = codestream.access_cod();
694 cod.set_num_decomposition(num_decompositions);
695 cod.set_block_dims(block_size.w, block_size.h);
696 if (num_precincts != -1)
697 cod.set_precinct_size(num_precincts, precinct_size);
698 cod.set_progression_order(prog_order);
699 cod.set_color_transform(false);
700 cod.set_reversible(reversible);
701 if (!reversible && quantization_step != -1.0f)
702 codestream.access_qcd().set_irrev_quant(quantization_step);
703 if (!reversible && qfactor != -1)
704 codestream.access_qcd().set_qfactor((ojph::ui8)qfactor);
705 if (profile_string[0] != '\0')
706 codestream.set_profile(profile_string);
707 codestream.set_tilepart_divisions(tileparts_at_resolutions,
708 tileparts_at_components);
709 codestream.request_tlm_marker(tlm_marker);
710
711 if (employ_color_transform != -1)
712 OJPH_WARN(0x01000001,
713 "-colour_trans option is not needed and was not used\n");
714 if (dims.w != 0 || dims.h != 0)
715 OJPH_WARN(0x01000002,
716 "-dims option is not needed and was not used\n");
717 if (num_components != 0)
718 OJPH_WARN(0x01000003,
719 "-num_comps is not needed and was not used\n");
720 if (is_signed[0] != -1)
721 OJPH_WARN(0x01000004,
722 "-signed is not needed and was not used\n");
723 if (bit_depth[0] != 0)
724 OJPH_WARN(0x01000005,
725 "-bit_depth is not needed and was not used\n");
726 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
727 OJPH_WARN(0x01000006,
728 "-downsamp is not needed and was not used\n");
729
730 base = &ppm;
731 }
732 else if (is_matching(".ppm", v))
733 {
734 ppm.open(input_filename);
735 ojph::param_siz siz = codestream.access_siz();
736 siz.set_image_extent(ojph::point(image_offset.x + ppm.get_width(),
737 image_offset.y + ppm.get_height()));
738 ojph::ui32 num_comps = ppm.get_num_components();
739 assert(num_comps == 3);
740 siz.set_num_components(num_comps);
741 for (ojph::ui32 c = 0; c < num_comps; ++c)
743 ppm.get_bit_depth(c), ppm.get_is_signed(c));
744 siz.set_image_offset(image_offset);
745 siz.set_tile_size(tile_size);
746 siz.set_tile_offset(tile_offset);
747
748 ojph::param_cod cod = codestream.access_cod();
749 cod.set_num_decomposition(num_decompositions);
750 cod.set_block_dims(block_size.w, block_size.h);
751 if (num_precincts != -1)
752 cod.set_precinct_size(num_precincts, precinct_size);
753 cod.set_progression_order(prog_order);
754 if (employ_color_transform == -1)
755 cod.set_color_transform(true);
756 else
757 cod.set_color_transform(employ_color_transform == 1);
758 cod.set_reversible(reversible);
759 if (!reversible && quantization_step != -1.0f)
760 codestream.access_qcd().set_irrev_quant(quantization_step);
761 if (!reversible && qfactor != -1)
762 codestream.access_qcd().set_qfactor((ojph::ui8)qfactor);
763 codestream.set_planar(false);
764 if (profile_string[0] != '\0')
765 codestream.set_profile(profile_string);
766 codestream.set_tilepart_divisions(tileparts_at_resolutions,
767 tileparts_at_components);
768 codestream.request_tlm_marker(tlm_marker);
769
770 if (dims.w != 0 || dims.h != 0)
771 OJPH_WARN(0x01000011,
772 "-dims option is not needed and was not used\n");
773 if (num_components != 0)
774 OJPH_WARN(0x01000012,
775 "-num_comps is not needed and was not used\n");
776 if (is_signed[0] != -1)
777 OJPH_WARN(0x01000013,
778 "-signed is not needed and was not used\n");
779 if (bit_depth[0] != 0)
780 OJPH_WARN(0x01000014,
781 "-bit_depth is not needed and was not used\n");
782 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
783 OJPH_WARN(0x01000015,
784 "-downsamp is not needed and was not used\n");
785
786 base = &ppm;
787 }
788 else if (is_matching(".pfm", v))
789 {
790 pfm.open(input_filename);
791 ojph::param_siz siz = codestream.access_siz();
792 siz.set_image_extent(ojph::point(image_offset.x + pfm.get_width(),
793 image_offset.y + pfm.get_height()));
794 ojph::ui32 num_comps = pfm.get_num_components();
795 assert(num_comps == 1 || num_comps == 3);
796 siz.set_num_components(num_comps);
797
798 if (bit_depth[0] != 0) // one was set
799 if (num_bit_depths < num_comps) // but if not enough, repeat
800 for (ojph::ui32 c = num_bit_depths; c < num_comps; ++c)
801 bit_depth[c] = bit_depth[num_bit_depths - 1];
802
803 bool all_the_same = true;
804 if (num_comps == 3)
805 all_the_same = all_the_same
806 && bit_depth[0] == bit_depth[1]
807 && bit_depth[1] == bit_depth[2];
808
809 for (ojph::ui32 c = 0; c < num_comps; ++c) {
810 if (bit_depth[c] == 0)
811 bit_depth[c] = 32;
812 siz.set_component(c, ojph::point(1,1), bit_depth[c], true);
813 }
814 pfm.configure(bit_depth);
815
816 siz.set_image_offset(image_offset);
817 siz.set_tile_size(tile_size);
818 siz.set_tile_offset(tile_offset);
819
820 ojph::param_cod cod = codestream.access_cod();
821 cod.set_num_decomposition(num_decompositions);
822 cod.set_block_dims(block_size.w, block_size.h);
823 if (num_precincts != -1)
824 cod.set_precinct_size(num_precincts, precinct_size);
825 cod.set_progression_order(prog_order);
826 if (num_comps == 1)
827 {
828 if (employ_color_transform != -1)
829 OJPH_WARN(0x01000091,
830 "-colour_trans option is not needed and was not used; "
831 "this is because the image has one component only\n");
832 }
833 else
834 {
835 if (employ_color_transform == -1)
836 cod.set_color_transform(true);
837 else
838 cod.set_color_transform(employ_color_transform == 1);
839 }
840 cod.set_reversible(reversible);
841 if (!reversible && qfactor != -1)
842 codestream.access_qcd().set_qfactor((ojph::ui8)qfactor);
843 else if (!reversible) {
844 const float min_step = 1.0f / 16384.0f;
845 if (quantization_step == -1.0f)
846 quantization_step = min_step;
847 else
848 quantization_step = ojph_max(quantization_step, min_step);
849 codestream.access_qcd().set_irrev_quant(quantization_step);
850 }
851
852 // Note: Even if only ALL_COMPS is set to
853 // OJPH_NLT_BINARY_COMPLEMENT_NLT, the library can decide if
854 // one ALL_COMPS NLT marker segment is needed, or multiple
855 // per component NLT marker segments are needed (when the components
856 // have different bit depths or signedness).
857 // Of course for .pfm images all components should have the same
858 // bit depth and signedness.
859 ojph::param_nlt nlt = codestream.access_nlt();
860 if (all_the_same)
863 else
864 for (ojph::ui32 c = 0; c < num_comps; ++c)
867
868 codestream.set_planar(false);
869 if (profile_string[0] != '\0')
870 codestream.set_profile(profile_string);
871 codestream.set_tilepart_divisions(tileparts_at_resolutions,
872 tileparts_at_components);
873 codestream.request_tlm_marker(tlm_marker);
874
875 if (dims.w != 0 || dims.h != 0)
876 OJPH_WARN(0x01000092,
877 "-dims option is not needed and was not used\n");
878 if (num_components != 0)
879 OJPH_WARN(0x01000093,
880 "-num_comps is not needed and was not used\n");
881 if (is_signed[0] != -1)
882 OJPH_WARN(0x01000094,
883 "-signed is not needed and was not used\n");
884 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
885 OJPH_WARN(0x01000095,
886 "-downsamp is not needed and was not used\n");
887
888 base = &pfm;
889 }
890#ifdef OJPH_ENABLE_TIFF_SUPPORT
891 else if (is_matching(".tif", v) || is_matching(".tiff", v))
892 {
893 tif.open(input_filename);
894 ojph::param_siz siz = codestream.access_siz();
895 siz.set_image_extent(ojph::point(image_offset.x + tif.get_size().w,
896 image_offset.y + tif.get_size().h));
897 ojph::ui32 num_comps = tif.get_num_components();
898 siz.set_num_components(num_comps);
899 if(num_bit_depths > 0 )
900 tif.set_bit_depth(num_bit_depths, bit_depth);
901 for (ojph::ui32 c = 0; c < num_comps; ++c)
902 siz.set_component(c, tif.get_comp_subsampling(c),
903 tif.get_bit_depth(c), tif.get_is_signed(c));
904 siz.set_image_offset(image_offset);
905 siz.set_tile_size(tile_size);
906 siz.set_tile_offset(tile_offset);
907
908 ojph::param_cod cod = codestream.access_cod();
909 cod.set_num_decomposition(num_decompositions);
910 cod.set_block_dims(block_size.w, block_size.h);
911 if (num_precincts != -1)
912 cod.set_precinct_size(num_precincts, precinct_size);
913 cod.set_progression_order(prog_order);
914 if (employ_color_transform == -1 && num_comps >= 3)
915 cod.set_color_transform(true);
916 else
917 cod.set_color_transform(employ_color_transform == 1);
918 cod.set_reversible(reversible);
919 if (!reversible && quantization_step != -1)
920 codestream.access_qcd().set_irrev_quant(quantization_step);
921 if (!reversible && qfactor != -1) {
922 if (num_comps != 1 && num_comps != 3)
923 OJPH_ERROR(0x010000A3,
924 "-qfactor is only supported for images with 1 or 3 "
925 "components\n");
926 codestream.access_qcd().set_qfactor((ojph::ui8)qfactor);
927
928 }
929 codestream.set_planar(false);
930 if (profile_string[0] != '\0')
931 codestream.set_profile(profile_string);
932 codestream.set_tilepart_divisions(tileparts_at_resolutions,
933 tileparts_at_components);
934 codestream.request_tlm_marker(tlm_marker);
935
936 if (dims.w != 0 || dims.h != 0)
937 OJPH_WARN(0x01000061,
938 "-dims option is not needed and was not used\n");
939 if (num_components != 0)
940 OJPH_WARN(0x01000062,
941 "-num_comps is not needed and was not used\n");
942 if (is_signed[0] != -1)
943 OJPH_WARN(0x01000063,
944 "-signed is not needed and was not used\n");
945 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
946 OJPH_WARN(0x01000065,
947 "-downsamp is not needed and was not used\n");
948
949 base = &tif;
950 }
951#endif // !OJPH_ENABLE_TIFF_SUPPORT
952 else if (is_matching(".yuv", v))
953 {
954 ojph::param_siz siz = codestream.access_siz();
955 if (dims.w == 0 || dims.h == 0)
956 OJPH_ERROR(0x01000021,
957 "-dims option must have positive dimensions\n");
958 siz.set_image_extent(ojph::point(image_offset.x + dims.w,
959 image_offset.y + dims.h));
960 if (num_components <= 0)
961 OJPH_ERROR(0x01000022,
962 "-num_comps option is missing and must be provided\n");
963 if (num_is_signed <= 0)
964 OJPH_ERROR(0x01000023,
965 "-signed option is missing and must be provided\n");
966 if (num_bit_depths <= 0)
967 OJPH_ERROR(0x01000024,
968 "-bit_depth option is missing and must be provided\n");
969 if (num_comp_downsamps <= 0)
970 OJPH_ERROR(0x01000025,
971 "-downsamp option is missing and must be provided\n");
972
973 yuv.set_img_props(dims, num_components, num_comp_downsamps,
974 comp_downsampling);
975 yuv.set_bit_depth(num_bit_depths, bit_depth);
976
977 ojph::ui32 last_signed_idx = 0, last_bit_depth_idx = 0;
978 ojph::ui32 last_downsamp_idx = 0;
979 siz.set_num_components(num_components);
980 for (ojph::ui32 c = 0; c < num_components; ++c)
981 {
982 ojph::point cp_ds = comp_downsampling
983 [c < num_comp_downsamps ? c : last_downsamp_idx];
984 last_downsamp_idx += last_downsamp_idx+1 < num_comp_downsamps ? 1:0;
985 ojph::ui32 bd = bit_depth[c<num_bit_depths ? c : last_bit_depth_idx];
986 last_bit_depth_idx += last_bit_depth_idx + 1 < num_bit_depths ? 1:0;
987 int is = is_signed[c < num_is_signed ? c : last_signed_idx];
988 last_signed_idx += last_signed_idx + 1 < num_is_signed ? 1 : 0;
989 siz.set_component(c, cp_ds, bd, is == 1);
990 }
991 siz.set_image_offset(image_offset);
992 siz.set_tile_size(tile_size);
993 siz.set_tile_offset(tile_offset);
994
995 ojph::param_cod cod = codestream.access_cod();
996 cod.set_num_decomposition(num_decompositions);
997 cod.set_block_dims(block_size.w, block_size.h);
998 if (num_precincts != -1)
999 cod.set_precinct_size(num_precincts, precinct_size);
1000 cod.set_progression_order(prog_order);
1001 if (employ_color_transform == -1)
1002 cod.set_color_transform(false);
1003 else
1004 OJPH_ERROR(0x01000031,
1005 "We currently do not support color transform on raw(yuv) files."
1006 " In any case, this not a normal usage scenario. The OpenJPH "
1007 "library however does support that, but ojph_compress.cpp must be "
1008 "modified to send all lines from one component before moving to "
1009 "the next component; this requires buffering components outside"
1010 " of the OpenJPH library");
1011 cod.set_reversible(reversible);
1012 if (!reversible && quantization_step != -1.0f)
1013 codestream.access_qcd().set_irrev_quant(quantization_step);
1014 if (!reversible && qfactor != -1) {
1015 if (num_components != 1 && num_components != 3)
1016 OJPH_ERROR(0x010000A4,
1017 "-qfactor is only supported for images with 1 or 3 "
1018 "components\n");
1019 codestream.access_qcd().set_qfactor((ojph::ui8)qfactor);
1020 }
1021 codestream.set_planar(true);
1022 if (profile_string[0] != '\0')
1023 codestream.set_profile(profile_string);
1024 codestream.set_tilepart_divisions(tileparts_at_resolutions,
1025 tileparts_at_components);
1026 codestream.request_tlm_marker(tlm_marker);
1027
1028 yuv.open(input_filename);
1029 base = &yuv;
1030 }
1031 else if (is_matching(".raw", v))
1032 {
1033 ojph::param_siz siz = codestream.access_siz();
1034 if (dims.w == 0 || dims.h == 0)
1035 OJPH_ERROR(0x01000081,
1036 "-dims option must have positive dimensions\n");
1037 siz.set_image_extent(ojph::point(image_offset.x + dims.w,
1038 image_offset.y + dims.h));
1039 if (num_components != 1)
1040 OJPH_ERROR(0x01000082,
1041 "-num_comps must be 1\n");
1042 if (num_is_signed <= 0)
1043 OJPH_ERROR(0x01000083,
1044 "-signed option is missing and must be provided\n");
1045 if (num_bit_depths <= 0)
1046 OJPH_ERROR(0x01000084,
1047 "-bit_depth option is missing and must be provided\n");
1048 if (num_comp_downsamps <= 0)
1049 OJPH_ERROR(0x01000085,
1050 "-downsamp option is missing and must be provided\n");
1051
1052 raw.set_img_props(dims, bit_depth[0], is_signed);
1053
1054 siz.set_num_components(num_components);
1055 siz.set_component(0, comp_downsampling[0], bit_depth[0], is_signed[0]);
1056 siz.set_image_offset(image_offset);
1057 siz.set_tile_size(tile_size);
1058 siz.set_tile_offset(tile_offset);
1059
1060 ojph::param_cod cod = codestream.access_cod();
1061 cod.set_num_decomposition(num_decompositions);
1062 cod.set_block_dims(block_size.w, block_size.h);
1063 if (num_precincts != -1)
1064 cod.set_precinct_size(num_precincts, precinct_size);
1065 cod.set_progression_order(prog_order);
1066 if (employ_color_transform != -1)
1067 OJPH_ERROR(0x01000086,
1068 "color transform is meaningless since .raw files are single "
1069 "component files");
1070 cod.set_reversible(reversible);
1071 if (!reversible && quantization_step != -1.0f)
1072 codestream.access_qcd().set_irrev_quant(quantization_step);
1073 if (!reversible && qfactor != -1)
1074 codestream.access_qcd().set_qfactor((ojph::ui8)qfactor);
1075 codestream.set_planar(true);
1076 if (profile_string[0] != '\0')
1077 codestream.set_profile(profile_string);
1078 codestream.set_tilepart_divisions(tileparts_at_resolutions,
1079 tileparts_at_components);
1080 codestream.request_tlm_marker(tlm_marker);
1081
1082 raw.open(input_filename);
1083 base = &raw;
1084 }
1085 else if (is_matching(".dpx", v))
1086 {
1087 dpx.open(input_filename);
1088 ojph::param_siz siz = codestream.access_siz();
1089 siz.set_image_extent(ojph::point(image_offset.x + dpx.get_size().w,
1090 image_offset.y + dpx.get_size().h));
1091 ojph::ui32 num_comps = dpx.get_num_components();
1092 siz.set_num_components(num_comps);
1093 //if (num_bit_depths > 0)
1094 // dpx.set_bit_depth(num_bit_depths, bit_depth);
1095 for (ojph::ui32 c = 0; c < num_comps; ++c)
1096 siz.set_component(c, dpx.get_comp_subsampling(c),
1097 dpx.get_bit_depth(c), dpx.get_is_signed(c));
1098 siz.set_image_offset(image_offset);
1099 siz.set_tile_size(tile_size);
1100 siz.set_tile_offset(tile_offset);
1101
1102 ojph::param_cod cod = codestream.access_cod();
1103 cod.set_num_decomposition(num_decompositions);
1104 cod.set_block_dims(block_size.w, block_size.h);
1105 if (num_precincts != -1)
1106 cod.set_precinct_size(num_precincts, precinct_size);
1107 cod.set_progression_order(prog_order);
1108 if (employ_color_transform == -1 && num_comps >= 3)
1109 cod.set_color_transform(true);
1110 else
1111 cod.set_color_transform(employ_color_transform == 1);
1112 cod.set_reversible(reversible);
1113 if (!reversible && quantization_step != -1)
1114 codestream.access_qcd().set_irrev_quant(quantization_step);
1115 if (!reversible && qfactor != -1) {
1116 if (num_comps != 1 && num_comps != 3)
1117 OJPH_ERROR(0x010000A5,
1118 "-qfactor is only supported for images with 1 or 3 "
1119 "components\n");
1120 codestream.access_qcd().set_qfactor((ojph::ui8)qfactor);
1121 }
1122 codestream.set_planar(false);
1123 if (profile_string[0] != '\0')
1124 codestream.set_profile(profile_string);
1125 codestream.set_tilepart_divisions(tileparts_at_resolutions,
1126 tileparts_at_components);
1127 codestream.request_tlm_marker(tlm_marker);
1128
1129 if (dims.w != 0 || dims.h != 0)
1130 OJPH_WARN(0x01000071,
1131 "-dims option is not needed and was not used\n");
1132 if (num_components != 0)
1133 OJPH_WARN(0x01000072,
1134 "-num_comps is not needed and was not used\n");
1135 if (is_signed[0] != -1)
1136 OJPH_WARN(0x01000073,
1137 "-signed is not needed and was not used\n");
1138 if (comp_downsampling[0].x != 0 || comp_downsampling[0].y != 0)
1139 OJPH_WARN(0x01000075,
1140 "-downsamp is not needed and was not used\n");
1141
1142 base = &dpx;
1143 }
1144 else
1145#if defined( OJPH_ENABLE_TIFF_SUPPORT)
1146 OJPH_ERROR(0x01000041,
1147 "unknown input file extension; only pgm, ppm, dpx, tif(f),"
1148 " or raw(yuv) are supported\n");
1149#else
1150 OJPH_ERROR(0x01000041,
1151 "unknown input file extension; only pgm, ppm, dpx,"
1152 " or raw(yuv) are supported\n");
1153#endif // !OJPH_ENABLE_TIFF_SUPPORT
1154 }
1155 else
1156 OJPH_ERROR(0x01000051,
1157 "Please supply a proper input filename with a proper three-letter "
1158 "extension\n");
1159
1161 if (com_string)
1162 com_ex.set_string(com_string);
1163 ojph::j2c_outfile j2c_file;
1164 j2c_file.open(output_filename);
1165 codestream.write_headers(&j2c_file, &com_ex, com_string ? 1 : 0);
1166
1167 ojph::ui32 next_comp;
1168 ojph::line_buf* cur_line = codestream.exchange(NULL, next_comp);
1169 if (codestream.is_planar())
1170 {
1171 ojph::param_siz siz = codestream.access_siz();
1172 for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c)
1173 {
1174 ojph::point p = siz.get_downsampling(c);
1175 ojph::ui32 height = ojph_div_ceil(siz.get_image_extent().y, p.y);
1176 height -= ojph_div_ceil(siz.get_image_offset().y, p.y);
1177 for (ojph::ui32 i = height; i > 0; --i)
1178 {
1179 assert(c == next_comp);
1180 base->read(cur_line, next_comp);
1181 cur_line = codestream.exchange(cur_line, next_comp);
1182 }
1183 }
1184 }
1185 else
1186 {
1187 ojph::param_siz siz = codestream.access_siz();
1188 ojph::ui32 height = siz.get_image_extent().y;
1189 height -= siz.get_image_offset().y;
1190 for (ojph::ui32 i = 0; i < height; ++i)
1191 {
1192 for (ojph::ui32 c = 0; c < siz.get_num_components(); ++c)
1193 {
1194 assert(c == next_comp);
1195 base->read(cur_line, next_comp);
1196 cur_line = codestream.exchange(cur_line, next_comp);
1197 }
1198 }
1199 }
1200
1201 codestream.flush();
1202 codestream.close();
1203 base->close();
1204
1205 if (max_num_comps != initial_num_comps)
1206 {
1207 delete[] comp_downsampling;
1208 delete[] bit_depth;
1209 delete[] is_signed;
1210 }
1211 }
1212 catch (const std::exception& e)
1213 {
1214 const char *p = e.what();
1215 if (strncmp(p, "ojph error", 10) != 0)
1216 printf("%s\n", p);
1217 exit(-1);
1218 }
1219
1220 clock_t end = clock();
1221 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
1222 printf("Elapsed time = %f\n", elapsed_secs);
1223
1224 return 0;
1225
1226}
bool is_valid()
Definition ojph_arg.h:58
void init(int argc, char *argv[])
Definition ojph_arg.h:73
void reinterpret_to_bool(const char *str, int &val)
Definition ojph_arg.h:216
void reinterpret(const char *str, int &val)
Definition ojph_arg.h:146
argument get_argument_zero()
Definition ojph_arg.h:126
argument get_next_avail_argument(const argument &arg)
Definition ojph_arg.h:133
The object represent a codestream.
param_siz access_siz()
Returns the underlying SIZ marker segment object.
param_cod access_cod()
Returns the underlying COD marker segment object.
void close()
Call this function to close the underlying file; works for both encoding and decoding codestreams.
void set_planar(bool planar)
Sets the sequence of pushing or pull rows from the machinery.
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...
void request_tlm_marker(bool needed)
Request the addition of the optional TLM marker segment. This request should occur before writing cod...
void set_profile(const char *s)
Sets the codestream profile.
param_qcd access_qcd()
Returns the underlying QCD marker segment object.
void set_tilepart_divisions(bool at_resolutions, bool at_components)
Sets the locations where a tile is partitioned into tile parts.
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...
param_nlt access_nlt()
Returns the underlying NLT marker segment object.
bool is_planar() const
Query if the codestream extraction is planar or not. See the documentation for ojph::codestream::set_...
void flush()
This is the last call to a writing (encoding) codestream. This will write encoded bitstream data to t...
void set_string(const char *str)
ui32 get_num_components()
bool get_is_signed(ui32 comp_num)
void open(const char *filename)
ui32 get_bit_depth(ui32 comp_num)
size get_size()
point get_comp_subsampling(ui32 comp_num)
virtual void close()
Definition ojph_img_io.h:71
virtual ui32 read(const line_buf *line, ui32 comp_num)=0
void open(const char *filename)
Definition ojph_file.cpp:62
void set_num_decomposition(ui32 num_decompositions)
void set_precinct_size(int num_levels, size *precinct_size)
void set_progression_order(const char *name)
void set_block_dims(ui32 width, ui32 height)
void set_color_transform(bool color_transform)
void set_reversible(bool reversible)
non-linearity point transformation object (implements NLT marker segment)
@ OJPH_NLT_BINARY_COMPLEMENT_NLT
void set_nonlinear_transform(ui32 comp_num, ui8 nl_type)
enables or disables type 3 nonlinearity for a component or the default setting
void set_irrev_quant(float delta)
Set the irreversible quantization base delta.
void set_qfactor(ui8 qfactor)
Sets Qfactor.
void set_tile_size(size s)
point get_image_extent() const
void set_component(ui32 comp_num, const point &downsampling, ui32 bit_depth, bool is_signed)
void set_num_components(ui32 num_comps)
void set_tile_offset(point offset)
point get_image_offset() const
void set_image_offset(point offset)
point get_downsampling(ui32 comp_num) const
void set_image_extent(point extent)
ui32 get_num_components() const
ui32 get_width()
ui32 get_height()
void open(const char *filename)
ui32 get_num_components()
void configure(ui32 *bit_depth)
ui32 get_height()
void open(const char *filename)
ui32 get_num_components()
ui32 get_width()
ui32 get_bit_depth(ui32 comp_num)
point get_comp_subsampling(ui32 comp_num)
bool get_is_signed(ui32 comp_num)
void set_img_props(const size &s, ui32 bit_depth, bool is_signed)
void open(const char *filename)
void open(const char *filename)
void set_img_props(const size &s, ui32 num_components, ui32 num_downsampling, const point *downsampling)
void set_bit_depth(ui32 num_bit_depths, ui32 *bit_depth)
int32_t si32
Definition ojph_defs.h:55
uint32_t ui32
Definition ojph_defs.h:54
uint8_t ui8
Definition ojph_defs.h:50
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, int &qfactor, 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)
int main(int argc, char *argv[])
static const char * get_file_extension(const char *filename)
static bool is_matching(const char *ref, const char *other)
#define ojph_max(a, b)
Definition ojph_defs.h:73
#define ojph_div_ceil(a, b)
Definition ojph_defs.h:70
#define OJPH_ERROR(t,...)
#define OJPH_WARN(t,...)
point_interpreter(ojph::point &val)
virtual void operate(const char *str)
const ojph::ui32 max_num_eles
virtual void operate(const char *str)
point_list_interpreter(const ojph::ui32 max_num_elements, ojph::ui32 &num_elements, ojph::point *list)
si32_to_bool_list_interpreter(const ojph::ui32 max_num_elements, ojph::ui32 &num_elements, ojph::si32 *list)
virtual void operate(const char *str)
virtual void operate(const char *str)
size_interpreter(ojph::size &val)
virtual void operate(const char *str)
size_list_interpreter(const int max_num_elements, int &num_elements, ojph::size *list)
tileparts_division_interpreter(bool &at_resolutions, bool &at_components)
virtual void operate(const char *str)
virtual void operate(const char *str)
ui32_list_interpreter(const ojph::ui32 max_num_elements, ojph::ui32 &num_elements, ojph::ui32 *list)
const ojph::ui32 max_num_eles