void frame_changed( void )
{
uint32_t new_frame,max,l,f;
double   percent;
GtkWidget *wid;	
GtkAdjustment *adj;
	
	max=incoming->getInfo()->nb_frames;
	wid=WID(gui_scale);
	adj=gtk_range_get_adjustment (GTK_RANGE(wid));
	new_frame=0;
	
	percent=(double)GTK_ADJUSTMENT(adj)->value;
	percent*=max;
	percent/=100.;
	new_frame=(uint32_t)floor(percent);
	
	if(new_frame>=max) new_frame=max-1;
	
	ADM_assert(incoming->getFrameNumberNoAlloc(new_frame, &l, imgsrc,&f));
         memcpy(imgdisplay->data+w*h,imgsrc->data+w*h,(w*h)>>1);
	compute_histogram();
	update();

}
void spinner(void)
{
		read();
		recalc();
		upload();
                compute_histogram();
		update();
}
Пример #3
0
int main ()
{
for(i =0; i<10000000; i++){
  compute_totals ();
  compute_grades ();
  compute_histogram ();
}
  print_results ();
  exit (0);
}
Пример #4
0
int main(void)
{
        float grades[MAX_N_STUDENTS];
        int n = load_grades(grades, MAX_N_STUDENTS);
	

        int bins[N_BINS];
        compute_histogram(bins, n, grades);

        draw_histogram(bins, N_COLUMNS);

        return EXIT_SUCCESS;
}
//
//	Video is in YV12 Colorspace
//
//
uint8_t DIA_getEqualizer(EqualizerParam *param, AVDMGenericVideoStream *in)
{
	int ret;
	uint32_t l,f;
	uint32_t max=in->getInfo()->nb_frames;
        
	incoming=in;
	// Allocate space for green-ised video
	w=in->getInfo()->width;
	h=in->getInfo()->height;
	rgbConv=new ColYuvRgb(w,h);
        rgbConv->reset(w,h);
	
	histogram=new uint32_t [256*128];
        histogramout=new uint32_t [256*128];
	
	imgdst=new ADMImage(w,h);
	imgsrc=new ADMImage(w,h);
        imgdisplay=new ADMImage(w,h);
	
        if(curframe<max) max=curframe;
        
	ADM_assert(in->getFrameNumberNoAlloc(max, &l, imgsrc,&f));
        memcpy(imgdisplay->data+w*h,imgsrc->data+w*h,(w*h)>>1);
	// init local equalizer
		
        memcpy(scaler,param->_scaler,sizeof(scaler));

	dialog=create_dialog1();
	gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog),
										A_RESET,
										GTK_RESPONSE_OK,
										GTK_RESPONSE_CANCEL,
										GTK_RESPONSE_APPLY,
										-1);
	gtk_register_dialog(dialog);
	gtk_widget_set_usize(WID(drawingarea_histin), 256,128);
    gtk_widget_set_usize(WID(drawingarea_histout), 256,128);

	float zoom = UI_calcZoomToFitScreen(GTK_WINDOW(dialog), WID(drawingarea1), w, h);

	zoomW = w * zoom;
	zoomH = h * zoom;
	rgbbuffer=new uint32_t[zoomW*zoomH];

	gtk_widget_set_usize(WID(drawingarea1), zoomW, zoomH);

	if (zoom < 1)
	{
		UI_centreCanvasWindow((GtkWindow*)dialog, WID(drawingarea1), zoomW, zoomH);
		resizer = new ADMImageResizer(w, h, zoomW, zoomH, PIX_FMT_YUV420P, PIX_FMT_RGB32);
	}

	  upload();

	gtk_signal_connect(GTK_OBJECT(WID(drawingarea1)), "expose_event",
		       GTK_SIGNAL_FUNC(draw),
		       NULL);
		       
	
	gtk_signal_connect(GTK_OBJECT(WID(gui_scale)), "value_changed",GTK_SIGNAL_FUNC(frame_changed),   NULL);
  //      gtk_signal_connect(GTK_OBJECT(WID(curve1)), "curve-type-changed",GTK_SIGNAL_FUNC(spinner),   NULL);
	
        /*

        */
        GtkWidget *curve=WID(curve1);
        gtk_curve_set_range (GTK_CURVE(curve),0,255.,0.,255.);
	
        gtk_widget_show(dialog);
        upload();
        compute_histogram();
        spinner();
	ret=0;
	int response;
_again:
	while( (response=gtk_dialog_run(GTK_DIALOG(dialog)))==GTK_RESPONSE_APPLY)
	{
		spinner();	
	}
        if(response==A_RESET)
        {
                gfloat duo[2]={0,255.};
                gtk_curve_set_curve_type(GTK_CURVE(WID(curve1)),GTK_CURVE_TYPE_SPLINE);
                gtk_curve_reset(GTK_CURVE(WID(curve1)));

                goto _again;
        }
        
	if(response==GTK_RESPONSE_OK)
        {
		printf("Accepting new values\n");
		memcpy(param->_scaler,scaler,sizeof(scaler));
		ret=1;
	}
	gtk_unregister_dialog(dialog);
	gtk_widget_destroy(dialog);
	
	delete imgdst;
	delete imgsrc;
        delete imgdisplay;
	delete [] rgbbuffer;
	
	delete [] histogram;
        delete [] histogramout;
    delete rgbConv;

	if (resizer)
	{
		delete resizer;
		resizer=NULL;
	}

    rgbConv=NULL;    
	histogram=NULL;
        histogramout=NULL;
	
	rgbbuffer=NULL;
	imgdst=NULL;
	imgsrc=NULL;
	dialog=NULL;
        imgdisplay=NULL;
	return ret;

}
Пример #6
0
int ModelBase::load_model(const char* file_name) {
    const char *dot = strrchr(file_name, '.');
	const char supported_ext[2][10] = {".raw", ".pvm"};
	if (!dot || (strcmp(dot, supported_ext[0]) != 0 && strcmp(dot, supported_ext[1]) != 0)) {
		Logger::log("File error: Unsupported file extension (.raw|.pvm allowed)\n");
		return 1;
	}
	unsigned char *loaded_data;
	unsigned int width, height, depth, size, components = 1;
	if (strcmp(dot, supported_ext[1]) == 0) {
		Logger::log("Reading PVM file...\n");
		float scale_x, scale_y, scale_z;
		unsigned char *description, *courtesy, *parameters, *comment;
		loaded_data = readPVMvolume(file_name, &width, &height, &depth, 
			&components, &scale_x, &scale_y, &scale_z, &description, &courtesy, &parameters, &comment);
		if (loaded_data == NULL) { 
			Logger::log("Error: File not found: %s\n", file_name);
			return 1;
		}
		Logger::log("PVM file volume metadata:\nDimensions: width = %d height = %d depth = %d components = %d\n",
			width, height, depth, components);
		if (scale_x!=1.0f || scale_y!=1.0f || scale_z!=1.0f)
			printf("Real dimensions: %g %g %g\n", scale_x, scale_y, scale_z);
		if (description!=NULL)
			printf("Object description:\n%s\n",description);
		if (courtesy!=NULL)
			printf("Courtesy information:\n%s\n",courtesy);
		if (parameters!=NULL)
			printf("Scan parameters:\n%s\n",parameters);
		if (comment!=NULL)
			printf("Additonal comments:\n%s\n",comment);
		printf("\n");
		size = width * height * depth;				
		//float max_scale = MAXIMUM(scale_x, MAXIMUM(scale_y, scale_z));	// scaling - if used indexing in model is: (pos.x*(1/bound.x)) 
		//volume.bound = (-1) * make_float3(scale_x / max_scale, scale_y / max_scale, scale_z / max_scale);
	}
	if (strcmp(dot, supported_ext[0]) == 0) {
		Logger::log("Reading RAW file...\n");
		loaded_data = readRAWfile(file_name, &size);
		if (loaded_data == NULL) { 
			Logger::log("Error: File not found: %s\n", file_name);
			return 1;
		}
		printf("Enter RAW file volume dimensions (width, height, depth): ");   
		scanf("%d %d %d",&width, &height, &depth);
		if (width * height * depth != size) {
			printf("Enter RAW file volume components (bytes per voxel): ");   
			scanf("%d", &components);
			if (width * height * depth * components != size) {
				Logger::log("Error: Incorrect RAW file volume parameters\n");
				free(loaded_data);
				return 1;
			}
		}
	}
	if (components > 2) {
		Logger::log("Error: Unsupported number of components (1|2 allowed)\n");
		free(loaded_data);
		return 1;
	}
	if (components == 2) {
		Logger::log("Quantizing 16 bit volume to 8 bit using a non-linear mapping...\n");
		loaded_data = quantize(loaded_data, width, height, depth);
	}
	if (volume.data != NULL)
		free(volume.data);
	volume.dims = make_ushort3(width, height, depth);
	volume.size = size;
	volume.data = loaded_data;
	strcpy(ModelBase::file_name, file_name);
	Logger::log("File loaded: %s, volume size: %.2f MB\n\n", file_name, volume.size / (float)(1024 * 1024));
	compute_histogram();

	return 0;
}