Skip to content
Snippets Groups Projects
main.cpp 4.32 KiB
Newer Older
  • Learn to ignore specific revisions
  • theazgra's avatar
    theazgra committed
    #include "czi_parser.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);
        args::Group compressionGroup(argParser, "Avaible compressions", args::Group::Validators::Xor);
    
    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"});
    
    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"});
    
    theazgra's avatar
    theazgra committed
        args::Flag rleCompressionOption(compressionGroup, "RLE", "RLE compression", {"rle"});
        args::Flag lzCompressionOption(compressionGroup, "LZ", "LZ compression", {"lz"});
    
        args::Flag gzipCompressionOption(compressionGroup, "GZIP", "GZIP (zlib) compression", {"gzip"});
    
    theazgra's avatar
    theazgra committed
        args::Flag lzmaCompressionOption(compressionGroup, "LZMA", "LZMA (2?) compression", {"lzma"});
    
    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;
        }
    
    theazgra's avatar
    theazgra committed
    
        CziParser parser(dontParseMetadataOption.Get());
        auto parsedFile = parser.parse_czi_file(cziFile.Get());
    
        // Test compression method.
        if (compressionTestMethod)
        {
            CompressionMethod cm = CompressionMethod_RLE;
    
            if (lzCompressionOption)
                cm = CompressionMethod_LZ;
    
            else if (gzipCompressionOption)
                cm = CompressionMethod_GZIP;
    
    theazgra's avatar
    theazgra committed
            else if (lzmaCompressionOption)
                cm = CompressionMethod_LZMA;
    
    theazgra's avatar
    theazgra committed
    
            parsedFile.test_compression(cm, verboseOption.Matched());
        }
    
    
    theazgra's avatar
    theazgra committed
        /*
    
        std::string cziFile = (argc > 1) ? argv[1] : "/home/mor0146/gitlab/data_project/czi-format/data/CZT-Stack-Anno.czi"; //"/home/mor0146/gitlab/data_project/czi-format/data/m2/exampleSingleChannel.czi";
        if (cziFile == "-v" || cziFile == "--version")
        {
    #if DEBUG
            printf("Running `Debug` version\n.");
    #else
            printf("Running `Release` version\n.");
    #endif
            return 0;
        }
    
        always_assert(is_file(cziFile));
    
    
    theazgra's avatar
    theazgra committed
        std::string method = argc > 2 ? argv[2] : "";
        std::string dumpName = argc > 3 ? argv[3] : "";
    
    theazgra's avatar
    theazgra committed
        bool report = method == "--report";
        bool reportAll = method == "--report-verbose";
    
    theazgra's avatar
    theazgra committed
        bool dumpRawImageData = method == "--dump-raw-image-data";
    
        bool dumpImageData = method == "--dump-images";
    
        bool nextImageDiff = method == "--diff-next";
    
    theazgra's avatar
    theazgra committed
        bool testRle = method == "--rle-report";
    
        auto name = get_filename_without_extension(cziFile);
        auto x = get_files_in_parent_directory(cziFile, true);
        auto y = get_files_with_same_prefix(x, name);
    
    
        CziParser parser;
        auto parseResult = parser.parse_czi_file(cziFile);
    
    theazgra's avatar
    theazgra committed
            parseResult.report_verbose();
        else if (report)
            parseResult.report();
    
    theazgra's avatar
    theazgra committed
        else if (dumpRawImageData)
    
    theazgra's avatar
    theazgra committed
            parseResult.dump_image_data(dumpName);
    
    theazgra's avatar
    theazgra committed
        else if (dumpImageData)
    
    theazgra's avatar
    theazgra committed
        {
    
            parseResult.extract_images(dumpName);
    
    theazgra's avatar
    theazgra committed
        }
    
        else if (nextImageDiff)
        {
            always_assert(dumpName != "");
            parseResult.differences_between_next(dumpName);
        }
    
    theazgra's avatar
    theazgra committed
        else if (testRle)
        {
            parseResult.test_rle_encode();
        }
    
    theazgra's avatar
    theazgra committed
    */
    
    theazgra's avatar
    theazgra committed
        return 0;