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";
94 char *&input_filename,
char *&output_filename,
100 interpreter.
init(argc, argv);
103 int num_skipped_res = 0;
112 if (num_skipped_res > 0)
114 skipped_res_for_read = skipped_res[0];
115 if (num_skipped_res > 1)
116 skipped_res_for_recon = skipped_res[1];
118 skipped_res_for_recon = skipped_res_for_read;
122 printf(
"The following arguments were not interpreted:\n");
126 printf(
"%s\n", t.
arg);
137 size_t len = strlen(filename);
138 const char* p = strrchr(filename,
'.');
139 if (p == NULL || p == filename + len - 1)
141 "no file extension is found, or there are no characters "
142 "after the dot \'.\' for filename \"%s\" \n", filename);
147 int main(
int argc,
char *argv[]) {
149 char *input_filename = NULL;
150 char *output_filename = NULL;
153 bool resilient =
false;
157 "\nThe following arguments are necessary:\n"
158 " -i input file name\n"
159 #ifdef OJPH_ENABLE_TIFF_SUPPORT
160 " -o output file name (either pgm, ppm, tif(f), or raw(yuv))\n\n"
162 " -o output file name (either pgm, ppm, or raw(yuv))\n\n"
164 "The following arguments are options:\n"
165 " -skip_res x,y a comma-separated list of two elements containing the\n"
166 " number of resolutions to skip. You can specify 1 or 2\n"
167 " parameters; the first specifies the number of resolution\n"
168 " for which data reading is skipped. The second is the\n"
169 " number of skipped resolution for reconstruction, which is\n"
170 " either equal to the first or smaller. If the second is not\n"
171 " specified, it is made to equal to the first.\n"
172 " -resilient true if you want the decoder to be more tolerant of errors\n"
173 " in the codestream\n\n"
177 if (!
get_arguments(argc, argv, input_filename, output_filename,
178 skipped_res_for_read, skipped_res_for_recon,
184 clock_t begin = clock();
187 if (output_filename == NULL)
189 "Please provide and output file using the -o option\n");
192 j2c_file.
open(input_filename);
196 #ifdef OJPH_ENABLE_TIFF_SUPPORT
208 skipped_res_for_recon);
211 if (strncmp(
".pgm", v, 4) == 0)
216 "The file has more than one color component, but .pgm can "
217 "contain only on color component\n");
220 ppm.
open(output_filename);
223 else if (strncmp(
".ppm", v, 4) == 0)
230 "The file has %d color components; this cannot be saved to"
232 bool all_same =
true;
237 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
241 "To save an image to ppm, all the components must have the "
242 "downsampling ratio\n");
245 ppm.
open(output_filename);
248 #ifdef OJPH_ENABLE_TIFF_SUPPORT
249 else if (strncmp(
".tif", v, 4) == 0 || strncmp(
".tiff", v, 5) == 0)
254 bool all_same =
true;
259 all_same = all_same && (p1.
x == p.
x) && (p1.
y == p.
y);
263 "To save an image to tif(f), all the components must have the "
264 "downsampling ratio\n");
272 tif.open(output_filename);
276 else if (strncmp(
".yuv", v, 4) == 0 || strncmp(
".raw", v, 4) == 0)
283 "The file has %d color components; this cannot be saved to"
288 "The current implementation of raw(yuv) file object does not"
289 " support saving file when conversion from raw(yuv) to rgb is"
290 " needed; in any case, this is not the normal usage of raw(yuv)"
301 yuv.
open(output_filename);
305 #ifdef OJPH_ENABLE_TIFF_SUPPORT
307 "unknown output file extension; only pgm, ppm, tif(f) and raw(yuv))"
311 "unknown output file extension; only pgm, ppm, and raw(yuv) are"
317 "Please supply a proper output filename with a proper extension\n");
331 assert(comp_num == c);
332 base->
write(line, comp_num);
346 assert(comp_num == c);
347 base->
write(line, comp_num);
355 catch (
const std::exception& e)
357 const char *p = e.what();
358 if (strncmp(p,
"ojph error", 10) != 0)
363 clock_t end = clock();
364 double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
365 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
OJPH_EXPORT 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 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(ui32 bit_depth, ui32 num_components, ui32 *comp_width)
int main(int argc, char *argv[])
const char * get_file_extension(const char *filename)
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)
#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