int main(int argc, char *argv[]) { kdu_customize_warnings(&pretty_cout); kdu_customize_errors(&pretty_cerr); kdu_args args(argc,argv,"-s"); if ((args.get_first() == NULL) || (args.find("-usage") != NULL)) print_usage(args.get_prog_name(),true); if (args.find("-u") != NULL) print_usage(args.get_prog_name(),false); bool quiet = false; if (args.find("-quiet") != NULL) { quiet = true; args.advance(); } kd_message *messages=NULL; while (args.find("-i") != NULL) { const char *string = args.advance(); if (string == NULL) { kdu_error e; e << "The \"-i\" argument requires an input file name."; } FILE *in = fopen(string,"r"); if (in == NULL) { kdu_error e; e << "Cannot open input file, \"" << string << "\"."; } process_input_file(in,messages,string,quiet); fclose(in); args.advance(); } if (args.find("-o") != NULL) { const char *string = args.advance(); if (string == NULL) { kdu_error e; e << "The \"-o\" argument requires an output file name."; } FILE *out = fopen(string,"w"); if (out == NULL) { kdu_error e; e << "Cannot open output file, \"" << string << "\"."; } generate_output_file(out,messages,string,quiet); fclose(out); args.advance(); } if (args.show_unrecognized(pretty_cout) != 0) { kdu_error e; e << "There were unrecognized command line arguments!"; } return 0; }
ossimKakaduJ2kReader::ossimKakaduJ2kReader() : ossimImageHandler(), theCodestream(), theThreadEnv(0), theOpenTileThreadQueue(0), theMinDwtLevels(0), theFileStr(), theSizRecord(), theScalarType(OSSIM_SCALAR_UNKNOWN), theImageRect(), theTile(), theCacheTile(), theTileSizeX(0), theTileSizeY(0), theCacheId(-1) { kdu_customize_warnings(&pretty_cout); // Deliver warnings to stdout. kdu_customize_errors(&pretty_cerr); // Deliver errors to stderr + throw exc }
void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, BOOL keep_codestream, ECodeStreamMode mode) { S32 data_size = base.getDataSize(); S32 max_bytes = (base.getMaxBytes() ? base.getMaxBytes() : data_size); // // Initialization // if (!kdu_message_initialized) { kdu_message_initialized = true; kdu_customize_errors(&LLKDUMessageError::sDefaultMessage); kdu_customize_warnings(&LLKDUMessageWarning::sDefaultMessage); } if (mCodeStreamp) { mCodeStreamp->destroy(); delete mCodeStreamp; mCodeStreamp = NULL; } if (!mInputp && base.getData()) { // The compressed data has been loaded // Setup the source for the codestream mInputp = new LLKDUMemSource(base.getData(), data_size); } if (mInputp) { mInputp->reset(); } mCodeStreamp = new kdu_codestream; mCodeStreamp->create(mInputp); // Set the maximum number of bytes to use from the codestream // *TODO: This seems to be wrong. The base class should have no idea of how j2c compression works so no // good way of computing what's the byte range to be used. mCodeStreamp->set_max_bytes(max_bytes,true); // If you want to flip or rotate the image for some reason, change // the resolution, or identify a restricted region of interest, this is // the place to do it. You may use "kdu_codestream::change_appearance" // and "kdu_codestream::apply_input_restrictions" for this purpose. // If you wish to truncate the code-stream prior to decompression, you // may use "kdu_codestream::set_max_bytes". // If you wish to retain all compressed data so that the material // can be decompressed multiple times, possibly with different appearance // parameters, you should call "kdu_codestream::set_persistent" here. // There are a variety of other features which must be enabled at // this point if you want to take advantage of them. See the // descriptions appearing with the "kdu_codestream" interface functions // in "kdu_compressed.h" for an itemized account of these capabilities. switch (mode) { case MODE_FAST: mCodeStreamp->set_fast(); break; case MODE_RESILIENT: mCodeStreamp->set_resilient(); break; case MODE_FUSSY: mCodeStreamp->set_fussy(); break; default: llassert(0); mCodeStreamp->set_fast(); } kdu_dims dims; mCodeStreamp->get_dims(0,dims); S32 components = mCodeStreamp->get_num_components(); if (components >= 3) { // Check that components have consistent dimensions (for PPM file) kdu_dims dims1; mCodeStreamp->get_dims(1,dims1); kdu_dims dims2; mCodeStreamp->get_dims(2,dims2); if ((dims1 != dims) || (dims2 != dims)) { llerrs << "Components don't have matching dimensions!" << llendl; } } // Get the number of resolution levels in that image mLevels = mCodeStreamp->get_min_dwt_levels(); // Set the base dimensions base.setSize(dims.size.x, dims.size.y, components); base.setLevels(mLevels); if (!keep_codestream) { mCodeStreamp->destroy(); delete mCodeStreamp; mCodeStreamp = NULL; delete mInputp; mInputp = NULL; } }