60 const char *next_char = str;
66 if (*next_char !=
',')
67 throw "resolutions in a list must be separated by a comma";
72 if (endptr == next_char)
73 throw "resolution number is improperly formatted";
81 throw "list elements must separated by a "",""";
84 throw "there are too many elements in the resolution list";
95 char *&input_filename,
char *&output_filename,
101 interpreter.
init(argc, argv);
104 int num_skipped_res = 0;
113 if (num_skipped_res > 0)
115 skipped_res_for_read = skipped_res[0];
116 if (num_skipped_res > 1)
117 skipped_res_for_recon = skipped_res[1];
119 skipped_res_for_recon = skipped_res_for_read;
123 printf(
"The following arguments were not interpreted:\n");
127 printf(
"%s\n", t.
arg);
139 size_t len = strlen(filename);
140 const char* p = strrchr(filename,
'.');
141 if (p == NULL || p == filename + len - 1)
143 "no file extension is found, or there are no characters "
144 "after the dot \'.\' for filename \"%s\" \n", filename);
152 size_t num_ele = strlen(ref);
154 if (num_ele != strlen(other))
158 if (ref[i] != other[i] && ref[i] != tolower(other[i]))
165int main(
int argc,
char *argv[]) {
167 char *input_filename = NULL;
168 char *output_filename = NULL;
171 bool resilient =
false;
175 "\nThe following arguments are necessary:\n"
176 " -i <input file name>\n"
177#ifdef OJPH_ENABLE_TIFF_SUPPORT
178 " -o <output file name> (either pgm, ppm, tif(f), or raw(yuv))\n\n"
180 " -o <output file name> (either pgm, ppm, or raw(yuv))\n\n"
182 "The following arguments are optional:\n"
183 " -skip_res x,y a comma-separated list of two elements containing the\n"
184 " number of resolutions to skip. You can specify 1 or 2\n"
185 " parameters; the first specifies the number of resolution\n"
186 " for which data reading is skipped. The second is the\n"
187 " number of skipped resolution for reconstruction, which is\n"
188 " either equal to the first or smaller. If the second is not\n"
189 " specified, it is made to equal to the first.\n"
190 " -resilient <true | false> if 'true', the decoder will not exit when\n"
191 " running into recoverable errors in the codestream.\n"
192 " Default: 'false'.\n"
197 if (!
get_arguments(argc, argv, input_filename, output_filename,
198 skipped_res_for_read, skipped_res_for_recon,
204 clock_t begin = clock();
207 if (output_filename == NULL)
209 "Please provide an output file using the -o option\n");
212 j2c_file.
open(input_filename);
217 #ifdef OJPH_ENABLE_TIFF_SUPPORT
230 skipped_res_for_recon);
238 "The file has more than one color component, but .pgm can "
239 "contain only one color component\n");
242 ppm.
open(output_filename);
252 "The file has %d color components; this cannot be saved to"
254 bool all_same =
true;
259 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
263 "To save an image to ppm, all the components must have the "
264 "same downsampling ratio\n");
267 ppm.
open(output_filename);
278 if (num_comps != 3 && num_comps != 1)
280 "The file has %d color components; this cannot be saved to"
281 " a .pfm file\n", num_comps);
282 bool all_same =
true;
287 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
291 "To save an image to ppm, all the components must have the "
292 "same downsampling ratio\n");
300 "This codestream is not supported; it does not have an "
301 "NLT segment marker for this component (or no default NLT "
305 "There is discrepancy in component %d configuration between "
306 "SIZ marker segment, which specifies bit_depth = %d and "
307 "signedness = %s, and NLT marker segment, which specifies "
308 "bit_depth = %d and signedness = %s.\n", c,
310 bd, is ?
"True" :
"False");
315 "This codestream is lossy (not reversible), and we currently "
316 "only support reversible codestreams for .pfm target files. "
317 "This is only temporary and will be changed at some point.\n");
320 pfm.
open(output_filename);
323#ifdef OJPH_ENABLE_TIFF_SUPPORT
329 bool all_same =
true;
334 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
338 "To save an image to tif(f), all the components must have the "
339 "same downsampling ratio\n");
347 tif.open(output_filename);
358 "The file has %d color components; this cannot be saved to"
363 "The current implementation of yuv file object does not"
364 " support saving file when conversion from yuv to rgb is"
365 " needed; in any case, this is not the normal usage of yuv"
376 yuv.
open(output_filename);
385 "The file has %d color components; this cannot be saved to"
386 " .raw file (only one component is allowed).\n",
391 raw.
configure(is_signed, bit_depth, width);
392 raw.
open(output_filename);
396#ifdef OJPH_ENABLE_TIFF_SUPPORT
398 "unknown output file extension; only pgm, ppm, tif(f) and raw(yuv))"
402 "unknown output file extension; only pgm, ppm, and raw(yuv) are"
408 "Please supply a proper output filename with a proper extension\n");
422 assert(comp_num == c);
423 base->
write(line, comp_num);
437 assert(comp_num == c);
438 base->
write(line, comp_num);
446 catch (
const std::exception& e)
448 const char *p = e.what();
449 if (strncmp(p,
"ojph error", 10) != 0)
454 clock_t end = clock();
455 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
456 printf(
"Elapsed time = %f\n", elapsed_secs);
void init(int argc, char *argv[])
void reinterpret(const char *str, int &val)
argument get_argument_zero()
argument get_next_avail_argument(const argument &arg)
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 restrict_input_resolution(ui32 skipped_res_for_data, ui32 skipped_res_for_recon)
This function restricts resolution decoding for a codestream. It is for a reading (decoding) codestre...
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.
void enable_resilience()
This enables codestream resilience; that is, the library tries its best to decode the codestream,...
void read_headers(infile_base *file)
This call reads the headers of a codestream. It is for a reading (or decoding) codestream,...
void create()
This call is for a decoding (or reading) codestream. Call this function after calling restrict_input_...
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_...
line_buf * pull(ui32 &comp_num)
This call is to pull one row from the codestream, being decoded. The returned line_buf object holds o...
virtual ui32 write(const line_buf *line, ui32 comp_num)=0
void open(const char *filename)
bool is_using_color_transform() const
bool is_reversible() const
non-linearity point transformation object (implements NLT marker segment)
bool get_type3_transformation(ui32 comp_num, ui8 &bit_depth, bool &is_signed)
get the state (enabled or disabled) of type 3 nonlinearity for a component or the default setting
ui32 get_bit_depth(ui32 comp_num) const
ui32 get_recon_height(ui32 comp_num) const
point get_downsampling(ui32 comp_num) const
ui32 get_recon_width(ui32 comp_num) const
bool is_signed(ui32 comp_num) const
ui32 get_num_components() const
void open(char *filename)
void configure(ui32 width, ui32 height, ui32 num_components, float scale, ui32 *bit_depth)
void open(char *filename)
void configure(ui32 width, ui32 height, ui32 num_components, ui32 bit_depth)
void open(char *filename)
void configure(bool is_signed, ui32 bit_depth, ui32 width)
void open(char *filename)
void configure(ui32 bit_depth, ui32 num_components, ui32 *comp_width)
int main(int argc, char *argv[])
static const char * get_file_extension(const char *filename)
static bool get_arguments(int argc, char *argv[], char *&input_filename, char *&output_filename, ojph::ui32 &skipped_res_for_read, ojph::ui32 &skipped_res_for_recon, bool &resilient)
static bool is_matching(const char *ref, const char *other)
#define OJPH_ERROR(t,...)
virtual void operate(const char *str)
ui32_list_interpreter(const int max_num_elements, int &num_elements, ojph::ui32 *list)
const ojph::ui32 max_num_eles