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);
272 OJPH_INFO(0x02000010,
"Note: The .pfm implementation is "
273 "experimental. Here, we are assuming that the original data is "
274 "floating-point numbers.");
280 if (num_comps != 3 && num_comps != 1)
282 "The file has %d color components; this cannot be saved to"
283 " a .pfm file", num_comps);
284 bool all_same =
true;
288 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
292 "To save an image to ppm, all the components must have the "
293 "same downsampling ratio");
299 pfm.
open(output_filename);
302#ifdef OJPH_ENABLE_TIFF_SUPPORT
308 bool all_same =
true;
313 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
317 "To save an image to tif(f), all the components must have the "
318 "same downsampling ratio\n");
326 tif.open(output_filename);
337 "The file has %d color components; this cannot be saved to"
342 "The current implementation of yuv file object does not"
343 " support saving file when conversion from yuv to rgb is"
344 " needed; in any case, this is not the normal usage of yuv"
355 yuv.
open(output_filename);
364 "The file has %d color components; this cannot be saved to"
365 " .raw file (only one component is allowed).\n",
370 raw.
configure(is_signed, bit_depth, width);
371 raw.
open(output_filename);
375#ifdef OJPH_ENABLE_TIFF_SUPPORT
377 "unknown output file extension; only pgm, ppm, tif(f) and raw(yuv))"
381 "unknown output file extension; only pgm, ppm, and raw(yuv) are"
387 "Please supply a proper output filename with a proper extension\n");
401 assert(comp_num == c);
402 base->
write(line, comp_num);
416 assert(comp_num == c);
417 base->
write(line, comp_num);
425 catch (
const std::exception& e)
427 const char *p = e.what();
428 if (strncmp(p,
"ojph error", 10) != 0)
433 clock_t end = clock();
434 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
435 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_...
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
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_INFO(t,...)
MACROs to insert file and line number for info, warning, and error.
#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