bool
CheckRender::PGMvsPGM( const char *src_file, const char *ref_file, const float epsilon, const float threshold )
{
    unsigned char *src_data = NULL, *ref_data = NULL;
    unsigned long error_count = 0;
    unsigned int width, height;

    char *ref_file_path = shrFindFilePath(ref_file, m_ExecPath);
    if (ref_file_path == NULL) {
        printf("CheckRender::PGMvsPGM unable to find <%s> in <%s> Aborting comparison!\n", ref_file, m_ExecPath);
        printf(">>> Check info.xml and [project//data] folder <%s> <<<\n", ref_file);
        printf("Aborting comparison!\n");
        printf("  FAILED!\n");
        error_count++;
    } else {

        if (src_file == NULL || ref_file_path == NULL) {
            printf("PGMvsPGM: Aborting comparison\n");
            return false;
        }
		printf("   src_file <%s>\n", src_file);
		printf("   ref_file <%s>\n", ref_file_path);

        if (shrLoadPGMub(ref_file_path, &ref_data, &width, &height) != shrTRUE) {
            printf("PGMvsPGM: unable to load ref image file: %s\n", ref_file_path);
            return false;
        }

        if (shrLoadPGMub(src_file, &src_data, &width, &height) != shrTRUE) {
            printf("PGMvsPGM: unable to load src image file: %s\n", src_file);
            return false;
        }

        printf("PGMvsPGM: comparing images size (%d,%d) epsilon(%2.4f), threshold(%4.2f%%)\n",
                m_Height, m_Width, epsilon, threshold*100);
        if (shrCompareubt( ref_data, src_data, m_Height*m_Width, epsilon, threshold ) == shrFALSE) {
            error_count = 1;
        }
    }

    if (error_count == 0) {
        printf("  PASSED!\n");
    } else {
        printf("  FAILED! %d errors...\n", (unsigned int)error_count);
    }
    return (error_count == 0);  // returns true if all pixels pass
}
int main( int argc, char** argv )
{
    bool setQuit = false;
    int capWidth = gw;
    int capHeight = gh;

    state.use_IPP = false;
	state.bqatest = false;
	unsigned int devN = 0;
	if( shrGetCmdLineArgumentu(argc, (const char **)argv, "device", &devN ) ) {
		printf("Using device %d\n", devN);
	}
	if( shrCheckCmdLineFlag( argc,  (const char **)argv, "qatest") ) {
		printf("QA test mode.\n");
		capture = NULL;
		state.bqatest = true;
	} else {

		printf("Attempting to initialize camera\n");
		if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
			capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
		else if( argc == 2 )
			capture = cvCaptureFromAVI( argv[1] );
	}

	if( !capture )
	{
		fprintf(stderr,"Could not initialize capturing...\n");
		fprintf(stderr,"Attempting to use PGM files..\n");
	} else { 
		printf("Camera Initialized\n");
		printf("Setting Size\n");
#ifdef _MSC_VER
		Sleep(5000);
#else
		sleep(5); // pause 5 seconds before setting size on Mac , otherwise unstable
#endif
		cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, gw);
		cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, gh);

	}

    initGlut(argc,argv, gw, gh);
	initGLData(gw, gh, NULL);
	// Initialize openCL
	// loads the CL functions from the .cl files
	// also loads reference images../data/minicooper/frame10.pgm
	
    clCtx = initOCLFlow(vbo,devN);
	if( !capture ) {
		if( images[0].w != gw || images[0].h != gh || images[1].w != gw || images[1].h != gh ) {
			fprintf(stderr, "Bad image sizes supplied. Please use %d x %d images\n", gw, gh );
		}

		// load the file into the texture (actually initOCLFLow loaded them into GPU but discarded them
		// so this is justa quick way to load them into the texture as well)
		unsigned int w, h;
		unsigned char *image_ub = NULL;
		shrLoadPGMub( "data/minicooper/frame10.pgm", (unsigned char **)&image_ub, &w, &h );
		glBindTexture(GL_TEXTURE_RECTANGLE_NV, tex);
		glTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, gw, gh, GL_LUMINANCE, GL_UNSIGNED_BYTE, image_ub );
	}
    glutMainLoop();

    return 0;
}