Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    // Avoid performance issues with X11 engine when rendering objects
#ifdef Q_WS_X11
    QApplication::setGraphicsSystem(QLatin1String("raster"));
#endif
    QString help="The arguement to open it: [map.tmx]";

    QApplication a(argc, argv);

    a.setOrganizationDomain(QLatin1String("catchchallenger"));
    a.setApplicationName(QLatin1String("map2png"));
    a.setApplicationVersion(QLatin1String("1.0"));

    CommandLineOptions options;
    parseCommandLineArguments(options);

    if (options.fileToOpen.isEmpty())
    {
        qDebug() << help;
        return 0;
    }

    Map2Png w;
    w.viewMap(options.fileToOpen);

    return a.exec();
}
CommandLineParameters::CommandLineParameters(int &argc, char **argv)
    : desc_("Allowed options")
    , getHelp_(false)
{
    initDesc();
    parseCommandLineArguments(argc, argv);
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    // Avoid performance issues with X11 engine when rendering objects
#ifdef Q_WS_X11
    QApplication::setGraphicsSystem(QLatin1String("raster"));
#endif

    QApplication a(argc, argv);

    a.setOrganizationDomain(QLatin1String("mapeditor.org"));
    a.setApplicationName(QLatin1String("TmxViewer"));
    a.setApplicationVersion(QLatin1String("1.0"));

    CommandLineOptions options;
    parseCommandLineArguments(options);
/*
    if (options.showVersion)
        showVersion();
    if (options.showHelp || (options.fileToOpen.isEmpty()
                             && !options.showVersion))
        showHelp();
    if (options.showVersion
            || options.showHelp
            || options.fileToOpen.isEmpty())
      return 0;
 */ 
    TmxViewer w;
    w.viewMap(options.fileToOpen);
    w.show();

    return a.exec();
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    a.setOrganizationDomain(QLatin1String("mapeditor.org"));
    a.setApplicationName(QLatin1String("TmxRasterizer"));
    a.setApplicationVersion(QLatin1String("1.0"));

    CommandLineOptions options;
    parseCommandLineArguments(options);

    if (options.showVersion) {
        showVersion();
        return 0;
    }
    if (options.showHelp || options.fileToOpen.isEmpty() || options.fileToSave.isEmpty()) {
        showHelp();
        return 0;
    }
    if (options.scale <= 0.0 && options.tileSize <= 0) {
        showHelp();
        return 0;
    }

    TmxRasterizer w;
    w.setAntiAliasing(options.useAntiAliasing);

    if (options.tileSize > 0) {
        w.setTileSize(options.tileSize);
    } else if (options.scale > 0.0) {
        w.setScale(options.scale);
    }

    return w.render(options.fileToOpen, options.fileToSave);
}
CommandLineOptions::CommandLineOptions(int &argc, char **argv)
    : getHelp_(false)
    , streamerType_(PS_UNKNOWN)
    , width_(0)
    , height_(0)
    , desc_("Allowed options")
{
    initDesc();
    parseCommandLineArguments(argc, argv);
}
Exemplo n.º 6
0
/**
 * Given the command line arguments this will read the configuration and return the configuration structure
 * which has the appropriate flags set and contains strings etc
 */
struct interpreterconfiguration* readConfiguration(int argc, char *argv[]) {
	int i;
	struct interpreterconfiguration* configuration=(struct interpreterconfiguration*) malloc(sizeof(struct interpreterconfiguration));
	configuration->intentActive=(char*) malloc(TOTAL_CORES);
	for (i=0;i<TOTAL_CORES;i++) configuration->intentActive[i]=1;
	configuration->displayStats=configuration->displayTiming=configuration->forceCodeOnCore=
			configuration->forceCodeOnShared=configuration->forceDataOnShared=configuration->displayPPCode=0;
	configuration->filename=configuration->compiledByteFilename=configuration->loadByteFilename=NULL;
	parseCommandLineArguments(configuration, argc, argv);
	return configuration;
}
Exemplo n.º 7
0
      App::App(int argc, char** argv)
        : m_mf(nullptr)
        , m_failedTests(0)
      {

        if( !parseCommandLineArguments(argc, argv) )
        {
          return;
        }

        if( !initTests() )
        {
          return;
        }

        test();

      }
Exemplo n.º 8
0
Arquivo: main.cpp Projeto: Y-way/tiled
int main(int argc, char *argv[])
{
#ifdef Q_OS_WIN
    // Make console output work on Windows, if running in a console.
    if (AttachConsole(ATTACH_PARENT_PROCESS)) {
        FILE *dummy = nullptr;
        freopen_s(&dummy, "CONOUT$", "w", stdout);
        freopen_s(&dummy, "CONOUT$", "w", stderr);
    }
#endif

    QApplication a(argc, argv);

    a.setOrganizationDomain(QLatin1String("mapeditor.org"));
    a.setApplicationName(QLatin1String("TmxViewer"));
    a.setApplicationVersion(QLatin1String("1.0"));

    CommandLineOptions options;
    parseCommandLineArguments(options);

    if (options.showVersion)
        showVersion();
    if (options.showHelp || (options.fileToOpen.isEmpty()
                             && !options.showVersion))
        showHelp();
    if (options.showVersion
            || options.showHelp
            || options.fileToOpen.isEmpty())
        return 0;

    TmxViewer w;
    if (!w.viewMap(options.fileToOpen))
        return 1;

    w.show();
    return a.exec();
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setQuitOnLastWindowClosed(false);

    // Check command line arguments.
    if ( argc > 1 )
    {
        parseCommandLineArguments(a.arguments());
    }
    
    // Check whether we can create a system tray icon.
    if ( !QSystemTrayIcon::isSystemTrayAvailable() )
    {
        qFatal("No support for system tray applications.");
        return 1;
    }

    // Create TwitterManager object.
    TwitterManager tw;
    tw.setDebug(DEBUG);

    // Attempt to log in. This should ask for the username and password
    // if they aren't already saved. If it returns false, exit.
    if ( !tw.login() )
    {
        qDebug() << "Login failed.";
        return 1;
    }

    qDebug() << "Login succeeded.";

    tw.refreshMentions();

    return a.exec();
}
int main(int argc, char* argv[])
{
    shrQAStart(argc, argv);

    try
    {
        std::string sFilename;
        char *filePath = findFilePath("Lena.pgm", argv[0]);
        if (filePath) {
            sFilename = filePath;
        } else {
            printf("Error unable to find Lena.pgm\n");
            shrQAFinishExit(argc, (const char **)argv, QA_FAILED);
        }

        // Parse the command line arguments for proper configuration
        parseCommandLineArguments(argc, argv);

        printfNPPinfo(argc, argv);

        if (g_bQATest == false && (g_nDevice == -1) && argc > 1) {
            sFilename = argv[1];
        }

        // if we specify the filename at the command line, then we only test sFilename[0].
        int file_errors = 0;
        std::ifstream infile(sFilename.data(), std::ifstream::in);
        if (infile.good()) {
            std::cout << "boxFilterNPP opened: <" << sFilename.data() << "> successfully!" << std::endl;
            file_errors = 0;
			infile.close();
        } else {
            std::cout << "boxFilterNPP unable to open: <" << sFilename.data() << ">" << std::endl;
            file_errors++;
			infile.close();
        }
        if (file_errors > 0) {
            shrQAFinish(argc, (const char **)argv, QA_FAILED);
            exit(EXIT_FAILURE);
        }

        std::string sResultFilename = sFilename;
        
        std::string::size_type dot = sResultFilename.rfind('.');
        if (dot != std::string::npos) sResultFilename = sResultFilename.substr(0, dot);
        sResultFilename += "_boxFilter.pgm";

        if (argc >= 3 && !g_bQATest)
            sResultFilename = argv[2];

                // declare a host image object for an 8-bit grayscale image
        npp::ImageCPU_8u_C1 oHostSrc;
                // load gray-scale image from disk
        npp::loadImage(sFilename, oHostSrc);
                // declare a device image and copy construct from the host image,
                // i.e. upload host to device
        npp::ImageNPP_8u_C1 oDeviceSrc(oHostSrc);
                
                // create struct with box-filter mask size
        NppiSize oMaskSize = {5, 5};
                // create struct with ROI size given the current mask
        NppiSize oSizeROI = {oDeviceSrc.width() - oMaskSize.width + 1, oDeviceSrc.height() - oMaskSize.height + 1};
                // allocate device image of appropriatedly reduced size
        npp::ImageNPP_8u_C1 oDeviceDst(oSizeROI.width, oSizeROI.height);
                // set anchor point inside the mask to (0, 0)
        NppiPoint oAnchor = {0, 0};
                // run box filter
        NppStatus eStatusNPP;
        eStatusNPP = nppiFilterBox_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(), 
                                          oDeviceDst.data(), oDeviceDst.pitch(), 
                                          oSizeROI, oMaskSize, oAnchor);
        NPP_ASSERT(NPP_NO_ERROR == eStatusNPP);
                // declare a host image for the result
        npp::ImageCPU_8u_C1 oHostDst(oDeviceDst.size());
                // and copy the device result data into it
        oDeviceDst.copyTo(oHostDst.data(), oHostDst.pitch());
        
        saveImage(sResultFilename, oHostDst);
        std::cout << "Saved image: " << sResultFilename << std::endl;
        shrQAFinish(argc, (const char **)argv, QA_PASSED);

        exit(EXIT_SUCCESS);
    }
    catch (npp::Exception & rException)
    {
        std::cerr << "Program error! The following exception occurred: \n";
        std::cerr << rException << std::endl;
        std::cerr << "Aborting." << std::endl;
        shrQAFinish(argc, (const char **)argv, QA_FAILED);
        exit(EXIT_FAILURE);
    }
    catch (...)
    {
        std::cerr << "Program error! An unknow type of exception occurred. \n";
        std::cerr << "Aborting." << std::endl;
        shrQAFinish(argc, (const char **)argv, QA_FAILED);
        exit(EXIT_FAILURE);
        return -1;
    }
    
    return 0;
}
// MAIN FUNCTION -----------------------------------------------------------
int main(int argc, char *argv[])
{
    pthread_t worker;
    pthread_attr_t attr;
    setup(&attr);
    struct logInformation logInfo;
    struct threadArguments taTemp;
    
	parseCommandLineArguments(argc, argv);
    printf("New logging session started on port %i on %s", portNumber, ctime(&timeServerStarted));
    int sockid = makeServerSocket();
    
    // daemonize the process if debuggin mode is not set
    if (commandLineOptions.debuggingMode == FALSE)
    {
        if (daemon_init() != 0)
        {
            printf("Error: unable to daemonize process\n");
            exit(-1);
        }   
    }
    
    while (TRUE)
    {
        // allow an incoming call
        int success = listen(sockid, 1);
        if (success == -1)
        {
            printf("Error: unable to listen on socket\n");
            exit(1);
        }
        
        // wait for an incoming call
        struct sockaddr_in saddr;
        saddr.sin_family = AF_INET;
        socklen_t c_len = sizeof(saddr);
        int fd = accept(sockid, (struct sockaddr *)&saddr, &c_len);
        if (success == -1)
        {
            printf("Error: unable to accept connection on socket\n");
            exit(1);
        }
        //printf("address: %s\n", (char *)inet_ntoa(saddr.sin_addr));
        logInfo.IPaddress = malloc(sizeof((char *)inet_ntoa(saddr.sin_addr)));
        strcpy((logInfo.IPaddress), (char *)inet_ntoa(saddr.sin_addr));
        //printf("We got a call! Yay!\n");
        updateNumberServerRequests(); // update the number of server requests
        
        // get the current time and store it in the log structure
        time_t currentTime = time(0);
        char *timeString = asctime(gmtime(&currentTime)); // get the Greenwich Mean Time
        char *timeStringPointer = timeString;
        // step through the time string until we find the newline character and 
        // change it to a null character to remove it
        while (*timeStringPointer != '\n')
        {
            timeStringPointer++;
        }
        *timeStringPointer = '\0';
        logInfo.timeRequestReceived = timeString;        
        //printf("time request received %s\n", logInfo.timeRequestReceived);

        //int *fdPointer = malloc(sizeof(int));
        //*fdPointer = fd;
        // copy file descriptor for the socket and logInfo structure so we can pass it to a thread
        struct threadArguments *ta = malloc(sizeof(struct threadArguments));
        taTemp.fd = fd;
        taTemp.logInfo = logInfo;
        *ta = taTemp;

        if (commandLineOptions.debuggingMode == TRUE)
        {
            handleCall(ta); // only accept one request at a time
        }
        else
        {
            // create a new thread to handle the request
            pthread_create(&worker, &attr, handleCall, ta);
        }
    }
    
	return 0;
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
    pArgc = &argc;
    pArgv = argv;

    sdkCreateTimer(&frame_timer);
    sdkResetTimer(&frame_timer);

    sdkCreateTimer(&global_timer);
    sdkResetTimer(&global_timer);

    // parse the command line arguments
    parseCommandLineArguments(argc, argv);

    // create window (after we know the size of the input file size)
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      sAppName, NULL
                    };
    RegisterClassEx(&wc);

    // Find out the video size
    g_bIsProgressive = loadVideoSource(sFileName.c_str(),
                                       g_nVideoWidth, g_nVideoHeight,
                                       g_nWindowWidth, g_nWindowHeight);

    // figure out the window size we must create to get a *client* area
    // that is of the size requested by m_dimensions.
    RECT adjustedWindowSize;
    DWORD dwWindowStyle;
    HWND hWnd = NULL;

    {
        dwWindowStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
        SetRect(&adjustedWindowSize, 0, 0, g_nVideoWidth  , g_nVideoHeight);
        AdjustWindowRect(&adjustedWindowSize, dwWindowStyle, false);

        g_nWindowWidth  = adjustedWindowSize.right  - adjustedWindowSize.left;
        g_nWindowHeight = adjustedWindowSize.bottom - adjustedWindowSize.top;

        // Create the application's window
        hWnd = CreateWindow(wc.lpszClassName, sAppName,
                            dwWindowStyle,
                            0, 0,
                            g_nWindowWidth,
                            g_nWindowHeight,
                            NULL, NULL, wc.hInstance, NULL);
    }

    // Initialize CUDA
    cuInit(0);

    int bTCC = 0;

    // If we are using TCC driver, then always turn off interop
    if (bTCC)
    {
        g_bUseInterop = false;
    }

    if (g_bUseInterop)
    {
        // Initialize Direct3D
        if (initD3D9(hWnd, argc, argv, &bTCC) == false)
        {
            g_bAutoQuit = true;
            g_bWaived   = true;
            goto ExitApp;
        }
    }

    // Initialize CUDA/D3D9 context and other video memory resources
    if (initCudaResources(argc, argv, g_bUseInterop, bTCC) == E_FAIL)
    {
        g_bAutoQuit  = true;
        g_bException = true;
        g_bWaived    = true;
        goto ExitApp;
    }

    g_pVideoSource->start();
    g_bRunning = true;

    if (!g_bQAReadback && !bTCC)
    {
        ShowWindow(hWnd, SW_SHOWDEFAULT);
        UpdateWindow(hWnd);
    }

    // the main loop
    sdkStartTimer(&frame_timer);
    sdkStartTimer(&global_timer);
    sdkResetTimer(&global_timer);

    if (!g_bUseInterop)
    {
        // On this case we drive the display with a while loop (no openGL calls)
        while (g_pVideoSource->isStarted() && !g_pFrameQueue->isEndOfDecode())
        {
            renderVideoFrame(hWnd, g_bUseInterop);
        }
    }
    else
    {
        // Standard windows loop
        while (!g_bDone)
        {
            MSG msg;
            ZeroMemory(&msg, sizeof(msg));

            while (msg.message!=WM_QUIT)
            {
                if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
                {
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
                else
                {
                    renderVideoFrame(hWnd, g_bUseInterop);
                }

                if (g_bAutoQuit && g_bDone)
                {
                    break;
                }
            }
        } // while loop
    }

    g_pFrameQueue->endDecode();
    g_pVideoSource->stop();

    printStatistics();

    // clean up CUDA and D3D resources
ExitApp:
    cleanup(g_bWaived ? false : true);

    if (!g_bQAReadback)
    {
        // Unregister windows class
        UnregisterClass(wc.lpszClassName, wc.hInstance);
    }

    if (g_bAutoQuit)
    {
        PostQuitMessage(0);
    }

    if (hWnd)
    {
        DestroyWindow(hWnd);
    }

    if (g_bWaived)
    {
        exit(EXIT_WAIVED);
    }
    else
    {
        exit(g_bException ? EXIT_FAILURE : EXIT_SUCCESS);
    }
}
Exemplo n.º 13
0
int main(int argc, char* argv[])
{
    shrQAStart(argc, argv);

    try
    {
        std::string sFilename;
        char *filePath = findFilePath("Lena.pgm", argv[0]);
        if (filePath) {
            sFilename = filePath;
        } else {
            printf("Error unable to find Lena.pgm\n");
            shrQAFinishExit(argc, (const char **)argv, QA_FAILED);
        }
	// Parse the command line arguments for proper configuration
        parseCommandLineArguments(argc, argv);

        printfNPPinfo(argc, argv);

        if (g_bQATest == false && (g_nDevice == -1) && argc > 1) {
            sFilename = argv[1];
        }

        // if we specify the filename at the command line, then we only test sFilename.
        int file_errors = 0;
        std::ifstream infile(sFilename.data(), std::ifstream::in);
        if (infile.good()) {
            std::cout << "histEqualizationNPP opened: <" << sFilename.data() << "> successfully!" << std::endl;
            file_errors = 0;
			infile.close();
        } else {
            std::cout << "histEqualizationNPP unable to open: <" << sFilename.data() << ">" << std::endl;
            file_errors++;
			infile.close();
        }
        if (file_errors > 0) {
            shrQAFinishExit(argc, (const char **)argv, QA_FAILED);
        }

        std::string dstFileName = sFilename;
        
        std::string::size_type dot = dstFileName.rfind('.');
        if (dot != std::string::npos) dstFileName = dstFileName.substr(0, dot);
        dstFileName += "_histEqualization.pgm";

        if (argc >= 3 && !g_bQATest)
            dstFileName = argv[2];

        npp::ImageCPU_8u_C1 oHostSrc;
        npp::loadImage(sFilename, oHostSrc);
        npp::ImageNPP_8u_C1 oDeviceSrc(oHostSrc);

        //
        // allocate arrays for histogram and levels
        //

        const int binCount = 256;
        const int levelCount = binCount + 1; // levels array has one more element

        Npp32s * histDevice = 0;
        Npp32s * levelsDevice = 0;
            
        NPP_CHECK_CUDA(cudaMalloc((void **)&histDevice,   binCount   * sizeof(Npp32s)));
        NPP_CHECK_CUDA(cudaMalloc((void **)&levelsDevice, levelCount * sizeof(Npp32s)));

        //
        // compute histogram
        //

        NppiSize oSizeROI = {oDeviceSrc.width(), oDeviceSrc.height()}; // full image
                // create device scratch buffer for nppiHistogram
        int nDeviceBufferSize;
        nppiHistogramEvenGetBufferSize_8u_C1R(oSizeROI, levelCount ,&nDeviceBufferSize);
        Npp8u * pDeviceBuffer;
        NPP_CHECK_CUDA(cudaMalloc((void **)&pDeviceBuffer, nDeviceBufferSize));
        
                // compute levels values on host
        Npp32s levelsHost[levelCount];
        NPP_CHECK_NPP(nppiEvenLevelsHost_32s(levelsHost, levelCount, 0, binCount));
                // compute the histogram
        NPP_CHECK_NPP(nppiHistogramEven_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(), oSizeROI, 
                                               histDevice, levelCount, 0, binCount, 
                                               pDeviceBuffer));
                // copy histogram and levels to host memory
        Npp32s histHost[binCount];
        NPP_CHECK_CUDA(cudaMemcpy(histHost, histDevice, binCount * sizeof(Npp32s), cudaMemcpyDeviceToHost));

        Npp32s  lutHost[binCount + 1];

                // fill LUT
        {
            Npp32s * pHostHistogram = histHost;
            Npp32s totalSum = 0;
            for (; pHostHistogram < histHost + binCount; ++pHostHistogram)
                totalSum += *pHostHistogram;

            NPP_ASSERT(totalSum == oSizeROI.width * oSizeROI.height);

            if (totalSum == 0) 
                totalSum = 1;
            float multiplier = 1.0f / float(totalSum) * 0xFF;

            Npp32s runningSum = 0;
            Npp32s * pLookupTable = lutHost;
            for (pHostHistogram = histHost; pHostHistogram < histHost + binCount; ++pHostHistogram)
            {
                *pLookupTable = (Npp32s)(runningSum * multiplier + 0.5f);
                pLookupTable++;
                runningSum += *pHostHistogram;
            }

            lutHost[binCount] = 0xFF; // last element is always 1
        }

        //
        // apply LUT transformation to the image
        //
                // Create a device image for the result.
        npp::ImageNPP_8u_C1 oDeviceDst(oDeviceSrc.size());
        NPP_CHECK_NPP(nppiLUT_Linear_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(), 
                                            oDeviceDst.data(), oDeviceDst.pitch(), 
                                            oSizeROI, 
                                            lutHost, // value and level arrays are in host memory
                                            levelsHost, 
                                            binCount+1));

                // copy the result image back into the storage that contained the 
                // input image
        npp::ImageCPU_8u_C1 oHostDst(oDeviceDst.size());
        oDeviceDst.copyTo(oHostDst.data(), oHostDst.pitch());

                // save the result
        npp::saveImage(dstFileName.c_str(), oHostDst);

        std::cout << "Saved image file " << dstFileName << std::endl;
		shrQAFinishExit(argc, (const char **)argv, QA_PASSED);
    }
    catch (npp::Exception & rException)
    {
        std::cerr << "Program error! The following exception occurred: \n";
        std::cerr << rException << std::endl;
        std::cerr << "Aborting." << std::endl;
		shrQAFinishExit(argc, (const char **)argv, QA_FAILED);
    }
    catch (...)
    {
        std::cerr << "Program error! An unknow type of exception occurred. \n";
        std::cerr << "Aborting." << std::endl;
 		shrQAFinishExit(argc, (const char **)argv, QA_FAILED);
    }
    
    return 0;
}