60 const char *next_char = str;
66 if (*next_char !=
',')
67 throw "sizes in a sizes list must be separated by a comma";
72 if (endptr == next_char)
73 throw "size number is improperly formatted";
81 throw "list elements must separated by a "",""";
84 throw "there are too many elements in the size 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 options:\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 if you want the decoder to be more tolerant of errors\n"
191 " in the codestream\n\n"
195 if (!
get_arguments(argc, argv, input_filename, output_filename,
196 skipped_res_for_read, skipped_res_for_recon,
202 clock_t begin = clock();
205 if (output_filename == NULL)
207 "Please provide and output file using the -o option\n");
210 j2c_file.
open(input_filename);
214 #ifdef OJPH_ENABLE_TIFF_SUPPORT
227 skipped_res_for_recon);
235 "The file has more than one color component, but .pgm can "
236 "contain only on color component\n");
239 ppm.
open(output_filename);
249 "The file has %d color components; this cannot be saved to"
251 bool all_same =
true;
256 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
260 "To save an image to ppm, all the components must have the "
261 "downsampling ratio\n");
264 ppm.
open(output_filename);
267#ifdef OJPH_ENABLE_TIFF_SUPPORT
273 bool all_same =
true;
278 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
282 "To save an image to tif(f), all the components must have the "
283 "downsampling ratio\n");
291 tif.open(output_filename);
302 "The file has %d color components; this cannot be saved to"
307 "The current implementation of yuv file object does not"
308 " support saving file when conversion from yuv to rgb is"
309 " needed; in any case, this is not the normal usage of yuv"
320 yuv.
open(output_filename);
329 "The file has %d color components; this cannot be saved to"
330 " .raw file (only one component is allowed).\n",
335 raw.
configure(is_signed, bit_depth, width);
336 raw.
open(output_filename);
340#ifdef OJPH_ENABLE_TIFF_SUPPORT
342 "unknown output file extension; only pgm, ppm, tif(f) and raw(yuv))"
346 "unknown output file extension; only pgm, ppm, and raw(yuv) are"
352 "Please supply a proper output filename with a proper extension\n");
366 assert(comp_num == c);
367 base->
write(line, comp_num);
381 assert(comp_num == c);
382 base->
write(line, comp_num);
390 catch (
const std::exception& e)
392 const char *p = e.what();
393 if (strncmp(p,
"ojph error", 10) != 0)
398 clock_t end = clock();
399 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
400 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)
OJPH_EXPORT param_siz access_siz()
OJPH_EXPORT param_cod access_cod()
OJPH_EXPORT void restrict_input_resolution(ui32 skipped_res_for_data, ui32 skipped_res_for_recon)
OJPH_EXPORT void set_planar(bool planar)
OJPH_EXPORT void enable_resilience()
OJPH_EXPORT void read_headers(infile_base *file)
OJPH_EXPORT void create()
OJPH_EXPORT bool is_planar() const
OJPH_EXPORT line_buf * pull(ui32 &comp_num)
virtual ui32 write(const line_buf *line, ui32 comp_num)=0
void open(const char *filename)
OJPH_EXPORT bool is_using_color_transform() const
OJPH_EXPORT ui32 get_bit_depth(ui32 comp_num) const
OJPH_EXPORT ui32 get_recon_height(ui32 comp_num) const
OJPH_EXPORT point get_downsampling(ui32 comp_num) const
OJPH_EXPORT ui32 get_recon_width(ui32 comp_num) const
OJPH_EXPORT bool is_signed(ui32 comp_num) const
OJPH_EXPORT ui32 get_num_components() const
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