Skip to content
Snippets Groups Projects
main.cpp 5.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • theazgra's avatar
    theazgra committed
    #include "czi_parser.h"
    
    #include "compression/benchmark.h"
    
    theazgra's avatar
    theazgra committed
    #include "utilities/args.hxx"
    
    theazgra's avatar
    theazgra committed
    int main(int argc, char **argv)
    {
    
    theazgra's avatar
    theazgra committed
        args::ArgumentParser argParser("CZI file tools", "Optional arguments are in `[]` necessary in `<>`.");
        // Groups
    
    theazgra's avatar
    theazgra committed
        args::Group cziFileGroup(argParser, "CZI file input - necessary.", args::Group::Validators::All);
    
    theazgra's avatar
    theazgra committed
        args::Group mainMethodGroup(argParser, "Methods:", args::Group::Validators::AtMostOne);
        args::Group optionsGroup(argParser, "Program options:", args::Group::Validators::DontCare);
    
    theazgra's avatar
    theazgra committed
        args::Group compressionGroup(argParser, "Avaible compressions", args::Group::Validators::AtMostOne);
    
    theazgra's avatar
    theazgra committed
    
    
    theazgra's avatar
    theazgra committed
        // Main option, has to be set. Czi file.
    
    theazgra's avatar
    theazgra committed
        args::ValueFlag<std::string> cziFile(cziFileGroup, "czi file", "CZI file to load.", {'i', "input"});
    
    
    theazgra's avatar
    theazgra committed
        // Program methods.
    
    theazgra's avatar
    theazgra committed
        args::HelpFlag helpMethod(mainMethodGroup, "help", "Print help", {'h', "help"});
        args::Flag reportMethod(mainMethodGroup, "report", "Basic information about CZI file. [verbose]", {"report"});
    
    theazgra's avatar
    theazgra committed
        args::Flag compressionTestMethod(mainMethodGroup, "compression-test", "Compress subblocks and output compression ratios <compression method>", {"compression-test"});
    
        args::Flag versionMethod(mainMethodGroup, "Version test", "Check version", {"version", 'V'});
    
        args::Flag benchmarkMethod(mainMethodGroup, "Compression benchmark", "Start compression benchmark for selected CZI file. <report-file> [continuos] [verbose].", {"benchmark"});
    
    theazgra's avatar
    theazgra committed
        args::Flag exportDataMethod(mainMethodGroup, "Export binary dat", "Export raw image data <folder> [continuos]", {"dump-data"});
    
        args::Flag exportImagesMethod(mainMethodGroup, "Export images", "Export images to ppm files <folder>", {"dump-images"});
    
    theazgra's avatar
    theazgra committed
    
    
    theazgra's avatar
    theazgra committed
        // Options
        args::Flag dontParseMetadataOption(optionsGroup, "no metadata", "Dont read metadata byte", {"no-metadata"});
    
    theazgra's avatar
    theazgra committed
        args::Flag verboseOption(optionsGroup, "verbose", "Extend output of method", {'v', "verbose"});
    
        args::ValueFlag<int> compressionLevelOption(optionsGroup, "Compression level", "Compression level", {'l', "level"});
    
        args::ValueFlag<std::string> folderOption(optionsGroup, "Folder", "Folder to which save exported items.", {'f', "folder"});
    
        args::ValueFlag<std::string> reportFileOption(optionsGroup, "Report file", "File where to write report.", {'r', "report"});
    
        args::Flag gzipCompressionOption(compressionGroup, "GZIP", "GZIP (zlib) compression", {"gzip"});
    
    theazgra's avatar
    theazgra committed
        args::Flag lzmaCompressionOption(compressionGroup, "LZMA", "LZMA (2?) compression", {"lzma"});
    
        args::Flag bzip2CompressionOption(compressionGroup, "BZIP2", "BZip2 compression", {"bzip2"});
    
        args::Flag continuousCompressionOption(compressionGroup, "Continuos compression", "Compress continuos array of image data into one buffer.", {'c'});
    
    theazgra's avatar
    theazgra committed
    
        try
        {
    
    theazgra's avatar
    theazgra committed
            argParser.helpParams.width *= 2;
    
    theazgra's avatar
    theazgra committed
            argParser.ParseCLI(argc, argv);
        }
    
    theazgra's avatar
    theazgra committed
        catch (args::Help &)
    
    theazgra's avatar
    theazgra committed
        {
            std::cout << argParser;
            return 0;
        }
    
    theazgra's avatar
    theazgra committed
        catch (args::ValidationError &e)
    
    theazgra's avatar
    theazgra committed
        {
    
            printf(RED "%s Check help with -h or --help.\n" RESET, e.what());
    
    theazgra's avatar
    theazgra committed
            return 1;
        }
    
    theazgra's avatar
    theazgra committed
        catch (args::ParseError &pe)
    
    theazgra's avatar
    theazgra committed
        {
    
            printf(RED "%s Check help with -h or --help.\n" RESET, pe.what());
    
    theazgra's avatar
    theazgra committed
            return 1;
        }
    
        if (versionMethod)
        {
    #if DEBUG
            printf("DEBUG\n");
    #else
            printf("RELEASE\n");
    #endif
            return 0;
        }
    
    
        CziParser parser(dontParseMetadataOption.Get());
        auto parsedFile = parser.parse_czi_file(cziFile.Get());
    
    
            if (!reportFileOption.Matched())
            {
                printf(RED "Report file wasn't specified!\n" RESET);
                return 1;
            }
            int level = -1;
            if (compressionLevelOption.Matched())
                level = compressionLevelOption.Get();
    
            if (continuousCompressionOption.Matched())
            {
                benchmark_continuos_compression(parsedFile, reportFileOption.Get(), verboseOption.Matched(), level);
            }
            else
            {
                benchmark_compression(parsedFile, reportFileOption.Get(), verboseOption.Matched(), level);
            }
    
    
    theazgra's avatar
    theazgra committed
        // Test compression method.
        if (compressionTestMethod)
        {
    
            CompressionMethod cm = CompressionMethod_GZIP;
    
            if (gzipCompressionOption)
    
                cm = CompressionMethod_GZIP;
    
    theazgra's avatar
    theazgra committed
            else if (lzmaCompressionOption)
                cm = CompressionMethod_LZMA;
    
            else if (bzip2CompressionOption)
                cm = CompressionMethod_BZIP2;
    
            int level = 6;
            if (compressionLevelOption.Matched())
                level = compressionLevelOption.Get();
            else
                printf("Using default compression level: %i\n", level);
    
            parsedFile.test_compression(cm, verboseOption.Matched(), level);
    
    theazgra's avatar
    theazgra committed
        if (reportMethod)
        {
            if (verboseOption.Matched())
                parsedFile.report_verbose();
            else
                parsedFile.report();
    
    
        if (exportDataMethod || exportImagesMethod)
    
            if (!folderOption.Matched())
            {
                printf(RED "Folder must be specified!\n" RESET);
                return 1;
    
    theazgra's avatar
    theazgra committed
                fs_wrapper::create_directory_path(folderOption.Get());
    
    theazgra's avatar
    theazgra committed
            if (exportDataMethod && continuousCompressionOption)
    
    theazgra's avatar
    theazgra committed
                parsedFile.dump_continuous_data(folderOption.Get());
                return 0;
    
    theazgra's avatar
    theazgra committed
    
            if (exportDataMethod) // Raw data.
                parsedFile.dump_data(folderOption.Get());
            else // Images.
    
                parsedFile.dump_images(folderOption.Get());
    
    theazgra's avatar
    theazgra committed
    
    
    theazgra's avatar
    theazgra committed
        return 0;