// Apply button handler void pyuvFormatDialog::formatApplyClick(wxCommandEvent& e) { // Apply data format changes framerateText->GetValue().ToDouble(&frame->GetRate()); customwidthText->GetValue().ToULong(&frame->GetWidth()); frame->GetWidthScreen() = frame->GetWidth() / frame->GetScale(); customheightText->GetValue().ToULong(&frame->GetHeight()); frame->GetHeightScreen() = frame->GetHeight() / frame->GetScale(); headersizeText->GetValue().ToULong(&frame->GetHeaderSize()); frame->GetColorSpaceNumber() = componentChoice->GetSelection(); frame->GetSubsamplingNumber() = samplingChoice->GetSelection(); frame->GetYUVOrder() = orderChoice->GetSelection(); frame->GetInterleavedFlag() = interleaveCheck->GetValue(); frame->GetInterlacedFlag() = interlaceCheck->GetValue(); frame->GetAnamorphicFlag() = anamorphCheck->GetValue(); frame->GetSampleBits() = bitpersampleText->GetValue(); frame->GetSignedFlag() = signedCheck->GetValue(); frame->GetEndiannessFlag() = endianCheck->GetValue(); gammaText->GetValue().ToDouble(&frame->GetGamma()); // When size is not well defined if (!(frame->GetWidth() * frame->GetHeight())) { wxMessageBox(wxT("You have to select a valid size"), wxT("Wait, wait..."), wxOK | wxICON_WARNING, this); return; } // When colorspace is not defined if (frame->GetColorSpaceNumber() == CS_UNDEF) { wxMessageBox(wxT("You have to select a valid colorspace"), wxT("Wait, wait..."), wxOK | wxICON_WARNING, this); return; } // When subsampling is not defined if (frame->GetSubsamplingNumber() == SS_UNDEF) { wxMessageBox(wxT("You have to select a valid subsampling"), wxT("Wait, wait..."), wxOK | wxICON_WARNING, this); return; } if (frame->GetFile() && frame->GetFile()->IsOpened()) { // File and frame size frame->GetFileSize() = frame->GetFile()->Length(); frame->GetFrameSize() = (unsigned long) ((double) (frame->GetWidth() * frame->GetHeight()) * (*frame->GetFrameDensity())[frame->GetSubsamplingNumber()]); frame->GetFrameBytes() = frame->GetFrameSize() * ((frame->GetSampleBits() > 8) ? 2 : 1); frame->GetNumFrame() = (unsigned long)floor((double)(frame->GetFileSize() - frame->GetHeaderSize()) / (double)frame->GetFrameBytes()); frame->GetFrameNumber() = 0; // Set up wxString info; info.Printf(wxT("%d frames, %.0f'%.0f\", %.3f MB"), frame->GetNumFrame(), floorf(((float)frame->GetNumFrame() / (float)frame->GetRate()) / 60.0F), ((float)frame->GetNumFrame() / (float)frame->GetRate()) - 60.0F * floorf(((float)frame->GetNumFrame() / (float)frame->GetRate()) / 60.0F), (float)frame->GetFileSize() / 1048576.0F); frame->SetStatusText(info, 1); frame->pyuvDispose(); frame->pyuvPrepare(); // Do a one-shot timer tick wxCommandEvent ev; frame->OnStop(ev); // Associate the drawing image frame->GetImage() = &(frame->drawCanvas->img); } // create header file wxFileName headername(frame->GetFileName()); headername.SetExt(wxT("hdr")); wxTextFile headerfile; if (headername.FileExists()) { // Open the file headerfile.Open(headername.GetFullPath()); } else { // Create the file headerfile.Create(headername.GetFullPath()); } // write settings in it // width = XXXX // height = XXXX // rate = XXXX // format = XXXX // depth = XXXX // space = XXXX // gamma = XXXX headerfile.AddLine(wxString::Format(wxT("width = %d"), (uint32_t)frame->GetWidth())); headerfile.AddLine(wxString::Format(wxT("height = %d"), (uint32_t)frame->GetHeight())); headerfile.AddLine(wxString::Format(wxT("rate = %f"), frame->GetRate())); headerfile.AddLine(wxString::Format(wxT("format = %s"), (*frame->GetFormatShort())[frame->GetFormat()])); headerfile.AddLine(wxString::Format(wxT("depth = %d"), frame->GetSampleBits())); headerfile.AddLine(wxString::Format(wxT("space = %s"), (*frame->GetComponents())[frame->GetColorSpaceNumber()])); headerfile.AddLine(wxString::Format(wxT("gamma = %f"), frame->GetGamma())); // close file headerfile.Write(); headerfile.Close(); // Check if OK is pushed if (e.GetId() == wxID_OK) Destroy(); }
int _tmain(int argc, _TCHAR* argv[]) { try { po::options_description desc( "Options" ); desc.add_options() ( "help,h", "Show detailed help." ) ( "options,p", "Show parameter information." ) ( "version,p", "Show version information." ) ( "input-file,i", po::value<std::vector<std::string>>(), "Define file(s) for the convertion input." ) ( "input-type,I", po::value<std::vector<std::string>>(), "Define file type(s) for automatic conversion of files in the working directory." ) ( "output-file,o", po::value<std::string>(), "Define file for the convertion output." ) ( "noheader,h", "Disable adding of header support defines." ) ( "const,C", "Define array as const." ) ( "respectcase,r", "Disable converting file types into lower case." ) ( "wxnone,w", "Disable adding of wxWidgets support macro's." ) ( "wxheader,W", po::value<std::string>()->default_value( "wx/wx.h" ), "Select the header that includes wxWidgets (precompiled header?)." ) ( "appendtype,t", "Add the file type at the end of the identifier (myimage_png)." ) ( "text,T", "Disable binary output and use text output, converts feed codes to systems defaults." ) ; po::positional_options_description posdesc; posdesc.add( "input-file", -1 ); po::variables_map opt; po::store( po::command_line_parser( argc, argv ).options( desc ).positional( posdesc ).run(), opt ); po::store( po::parse_config_file( fs::ifstream( fs::path( "default.cfg" ) ), desc ), opt ); po::notify( opt ); std::cout << WXINCLUDE_INFO << std::endl; /* Show options when requested */ if ( opt.count( "options" ) ) { std::cout << desc << std::endl << std::endl; exit( 0 ); } /* Show help when requested */ if ( opt.count( "help" ) ) { std::cout << WXINCLUDE_HELP; std::cout << std::endl << desc << std::endl << std::endl; exit( 0 ); } /* Show version when requested */ if ( opt.count( "version" ) ) { std::cout << WXINCLUDE_VERSION << std::endl; exit( 0 ); } /* Process */ if ( opt.count( "input-file" ) || opt.count( "input-type" ) ) { if ( opt.count( "output-file" ) ) { /* Create timer */ boost::timer timer; /* Create output file */ std::string headername( opt[ "output-file" ].as<std::string>() ); fs::path outputpath( headername ); fs::ofstream output( outputpath, std::ios::out | std::ios::trunc ); /* Use buffer */ char outbuffer[BUFFER_SIZE]; output.rdbuf()->pubsetbuf( outbuffer, BUFFER_SIZE ); if ( !opt.count( "text" ) ) output.setf( std::ios::binary ); if ( !output ) throw std::runtime_error( "Failed to create output file!" ); /* Show status */ std::cout << "Build : file '" << outputpath.leaf() << "'..." << std::endl; /* Get base name of file */ headername = fs::basename( outputpath ); /* Data string stream */ std::ostringstream data; /* Write header start when wanted */ if ( !opt.count( "noheader" ) ) defineheader_start( data, headername, opt.count( "wxnone" ) ? false : true, opt.count( "const" ) ? true : false ); /* Get defined or else default wx header */ std::string includename( opt[ "wxheader" ].as<std::string>() ); /* Write macros when wanted */ if ( !opt.count( "wxnone" ) ) definemacros( data, includename, opt[ "wxheader" ].defaulted() ); /* Common input buffer */ char inbuffer[BUFFER_SIZE]; /* Process input files based on provided list */ if ( opt.count( "input-file" ) ) { std::vector<std::string> files( opt[ "input-file" ].as<std::vector<std::string>>() ); BOOST_FOREACH( std::string& file, files ) { fs::path inputpath( file ); std::string fileext( fs::extension( inputpath ) ); fs::ifstream input( inputpath, std::ios::in | std::ios::binary | std::ios::ate ); input.rdbuf()->pubsetbuf( inbuffer, BUFFER_SIZE ); if ( input.is_open() ) { /* Show status */ std::cout << "Process: file '" << file << "'..." << std::endl; /* Remove extension */ boost::erase_last( file, fileext ); if ( !opt.count( "respectcase" ) ) boost::to_lower( fileext ); /* Append type */ if ( opt.count( "appendtype" ) ) { boost::erase_first( fileext, "." ); /* Static and NO copy constructor for speed */ static boost::format fmt( "%1%_%2%" ); file = boost::str( fmt % file % fileext ); } /* Lower case names when wanted */ if ( !opt.count( "respectcase" ) ) boost::to_lower( file ); /* Process file */ definefile( data, input, file, opt.count( "const" ) ? true : false ); } else { /* Only show warning, other files need to be processed */ std::cout << "Warning: input file '" << file << "' failed to open." << std::endl; } } } /* Process input files based on provided type */ if ( opt.count( "input-type" ) ) { std::vector<std::string> types( opt[ "input-type" ].as<std::vector<std::string>>() ); for ( fs::directory_iterator dir_itr( fs::initial_path() ); dir_itr != fs::directory_iterator(); ++dir_itr ) { BOOST_FOREACH( std::string& type, types ) { /* Normal file? */ if ( fs::is_regular( dir_itr->status() ) ) { /* Wanted type? */ std::string fileext( fs::extension( dir_itr->path() )); bool equals = false; if ( opt.count( "respectcase" ) ) equals = boost::equals( fileext, type ); else equals = boost::iequals( fileext, type ); if ( equals ) { fs::ifstream input( dir_itr->path(), std::ios::in | std::ios::binary | std::ios::ate ); input.rdbuf()->pubsetbuf( inbuffer, BUFFER_SIZE ); std::string file( dir_itr->path().leaf() ); if ( input.is_open() ) { /* Show status */ std::cout << "Process: file '" << file << "'..." << std::endl; /* Remove extension */ boost::erase_last( file, fileext ); /* Append type */ if ( opt.count( "appendtype" ) ) { boost::erase_first( fileext, "." ); /* Static and NO copy constructor for speed */ static boost::format fmt( "%1%_%2%" ); file = boost::str( fmt % file % fileext ); } /* Lower case names when wanted */ if ( !opt.count( "respectcase" ) ) boost::to_lower( file ); /* Process file */ definefile( data, input, file, opt.count( "const" ) ? true : false ); } else { /* Only show warning, other files need to be processed */ std::cout << "Warning: input file '" << file << "' failed to open." << std::endl; } } } } } }
int main ( int argc, const char* argv[] ) { if(argc <= 2) { std::cerr << "You need to specify at least the output file and one input file." << std::endl << "Example: " << argv[0] << " output_file input_file" << std::endl; return 1; } try { std::string headername (argv[1]); std::vector<std::string> input_files; for(int i = 2; i < argc; i++) { input_files.push_back(std::string(argv[i])); } /* Process */ std::ofstream output ( headername, std::ios::out | std::ios::trunc| std::ios::binary ); /* Use buffer */ char outbuffer[BUFFER_SIZE]; output.rdbuf()->pubsetbuf ( outbuffer, BUFFER_SIZE ); if ( !output ) throw std::runtime_error ( "Failed to create output file!" ); /* Show status */ std::cout << "Build : file '" << headername << "'..." << std::endl; /* Get base name of file */ headername = GetFileBasename ( headername ); /* Data string stream */ std::ostringstream data; /* Write header start when wanted */ defineheader_start ( data, headername, /*use macro*/ true, /* const */ true ); /* Write macros */ definemacros ( data ); /* Common input buffer */ char inbuffer[BUFFER_SIZE]; for ( auto iter = input_files.begin(); iter != input_files.end(); iter++ ) { std::string &file = *iter; //std::string fileext = GetFileExtension ( file ); std::ifstream input ( file, std::ios::in | std::ios::binary | std::ios::ate ); input.rdbuf()->pubsetbuf ( inbuffer, BUFFER_SIZE ); if ( input.is_open() ) { /* Show status */ std::cout << "Process: file '" << file << "'..." << std::endl; /* Remove extension */ file = removeExtension(file); std::transform(file.begin(), file.end(), file.begin(), ::tolower); std::transform(file.begin(), file.end(), file.begin(), toUnderscores); /* Process file */ definefile ( data, input, file, true ); } else { /* Only show warning, other files need to be processed */ std::cout << "Warning: input file '" << file << "' failed to open." << std::endl; } } /* Write header end when wanted */ defineheader_end ( data, headername ); /* Write data to output file */ output.seekp ( 0, std::ios::beg ); output << data.str(); } catch ( std::exception& e ) { std::cerr << "Error: " << e.what() << std::endl; } catch ( ... ) { std::cerr << "Error: Exception of unknown type!" << std::endl; } return 0; }