예제 #1
0
/* Allocates an Image structure and initializes the top level fields to appropriate values. Allocates space for an image of the specified size, unless either rows or cols is 0. Returns a pointer to the allocated Image structure. Returns a NULL pointer if the operation fails. */
Image *image_create(int rows, int cols) {
    Image *image = NULL;
    image = (Image *)malloc( sizeof(Image) );
    
    if (rows > 0 && cols > 0) {
        
        image->data = (FPixel **)malloc( sizeof(FPixel *)*rows );
        
        /* create rows */
        for (int i=0; i<rows;i++) {
            image->data[i] = (FPixel *)malloc(sizeof(FPixel)*cols);
        }

        
    } else {
        printf("Rows and columns must both be greater than 0.\n");
        image->rows = 0;
        image->cols = 0;
        image->data = NULL;
        return(image);
    }
    
    image->rows = rows;
    image->cols = cols;
    image->imagesize = rows * cols;
    image_reset(image);
    
    return(image);
}
예제 #2
0
파일: image.c 프로젝트: dpt/PrivateEye
void image_modified(image_t *i, image_modified_flags flags)
{
  imageobserver_data data;

  i->flags |= image_FLAG_MODIFIED;

  image_reset(i);

  data.modified.flags = flags;

  imageobserver_event(i, imageobserver_CHANGE_MODIFIED, &data);
}
예제 #3
0
파일: image.c 프로젝트: dpt/PrivateEye
void image_destroy(image_t *i)
{
  if (i == NULL)
    return;

  if (--i->refcount <= 0) /* refcount may be zero to start with */
  {
    imageobserver_event(i, imageobserver_CHANGE_ABOUT_TO_DESTROY, NULL);

    list_remove(&list_anchor, &i->list);

    if (i->methods.unload)
      i->methods.unload(i);

    image_reset(i);

    free(i);
  }
}
예제 #4
0
/* Allocates space for the image data given rows and columns and initializes the image data to appropriate values, such as 0.0 for RGBA and 1.0 for Z. Returns 0 if the operation is successful. Returns a non-zero value if the operation fails. This function should probably free existing memory if rows and cols are both non-zero. */
int image_alloc(Image *src, int rows, int cols) {
    
    if (src->data != NULL) {
        
        /* free cols in each row */
        for (int i=0; i<src->rows;i++) {
            free( src->data[i] );
        }
        
        /* free rows */
        free(src->data);
    }
    
    
    
    if (rows > 0 && cols > 0) {
        src->rows = rows;
        src->cols = cols;
        
        src->data = (FPixel **)malloc( sizeof(FPixel *)*rows );
        
        /* create rows */
        for (int i=0; i<rows;i++) {
            src->data[i] = (FPixel *)malloc(sizeof(FPixel)*cols);
        }
        
        src->imagesize = rows*cols;
        
        image_reset(src);
        
        return(0);
    } else {
        printf("Rows and columns must both be greater than 0.\n");
        return(1);
    }
}
예제 #5
0
파일: test7c.c 프로젝트: imtibbet/CS351
int main(int argc, char *argv[]) {
	int frame;
	Color blue, green, purple, red, white;
	Point p[16];
	BezierSurface bc;
	DrawState ds;
	Module *curve;
	View3D view;
	Matrix VTM, GTM;
	int divisions = 4;
	int rows = 300, cols = 400;
	Image *src = image_create(rows, cols);

	// grab the command line argument, if one exists
	if(argc > 1) {
		int tmp = atoi(argv[1]);
		if( tmp >= 0 && tmp < 10 )
			divisions = tmp;
	}
	printf("Creating Bezier surface with %d subdivisions\n", divisions);

	color_set(&white, 1.0, 1.0, 1.0 );
	color_set(&blue, .1, .2, .8);
	color_set(&green, .2, 0.7, 0.3 );
	color_set(&purple, 0.6, 0.1, 0.7 );
	color_set(&red, 0.75, 0.3, 0.3 );

	curve = module_create();

	// create a flat plane
	point_set3D(&p[0], 0.0, -0.2, 0.0); // first row, constant x, even spacing in z
	point_set3D(&p[1], 0.0, -0.2, 0.33);
	point_set3D(&p[2], 0.0, -0.2, 0.66);
	point_set3D(&p[3], 0.0, -0.2, 1.0);
	point_set3D(&p[4], 0.33, -0.2, 0.0); // second row
	point_set3D(&p[5], 0.33, -0.2, 0.33);
	point_set3D(&p[6], 0.33, -0.2, 0.66);
	point_set3D(&p[7], 0.33, -0.2, 1.0);
	point_set3D(&p[8], 0.66, -0.2, 0.0); // third row
	point_set3D(&p[9], 0.66, -0.2, 0.33);
	point_set3D(&p[10], 0.66, -0.2, 0.66);
	point_set3D(&p[11], 0.66, -0.2, 1.0);
	point_set3D(&p[12], 1.0, -0.2, 0.0); // fourth row
	point_set3D(&p[13], 1.0, -0.2, 0.33);
	point_set3D(&p[14], 1.0, -0.2, 0.66);
	point_set3D(&p[15], 1.0, -0.2, 1.0);
	bezierSurface_set(&bc, p);

	// put the curve into a module
	module_color(curve, &red);
	module_bezierSurface(curve, &bc, divisions, 0);

	// create a curved surface sitting above the plane
	point_set3D(&p[0], 0.0, 0.0, 0.0); // first row, constant x, even spacing in z
	point_set3D(&p[1], 0.0, 0.2, 0.33);
	point_set3D(&p[2], 0.0, 0.5, 0.66);
	point_set3D(&p[3], 0.0, 0.1, 1.0);
	point_set3D(&p[4], 0.33, 0.8, 0.0); // second row
	point_set3D(&p[5], 0.33, -0.1, 0.33);
	point_set3D(&p[6], 0.33, 0.0, 0.66);
	point_set3D(&p[7], 0.33, 0.3, 1.0);
	point_set3D(&p[8], 0.66, 0.3, 0.0); // third row
	point_set3D(&p[9], 0.66, 0.8, 0.33);
	point_set3D(&p[10], 0.66, 0.9, 0.66);
	point_set3D(&p[11], 0.66, 0.5, 1.0);
	point_set3D(&p[12], 1.0, 0.4, 0.0); // fourth row
	point_set3D(&p[13], 1.0, 0.2, 0.33);
	point_set3D(&p[14], 1.0, 0.5, 0.66);
	point_set3D(&p[15], 1.0, 1.0, 1.0);
	bezierSurface_set(&bc, p);

	// put the curve into a module
	module_color(curve, &green);
	module_bezierSurface(curve, &bc, divisions, 1);

	// set up the drawstate
	drawstate_setColor(&ds, white);
	ds.shade = ShadeFrame;
	
	// set up the view
	point_set3D(&(view.vrp), 0.0, 1.2, -3.0 );
	vector_set( &(view.vpn), 0.0, -0.8, 2.5 );
	vector_set( &(view.vup), 0.0, 1.0, 0.0 );
	view.d = 1.5;
	view.du = 1.0;
	view.dv = 1.0*rows/cols;
	view.screeny = rows;
	view.screenx = cols;
	view.f = 0.0;
	view.b = 3.0;

	matrix_setView3D( &VTM, &view );
	matrix_identity( &GTM );

	// Create the animation by adjusting the GTM
	for(frame=0;frame<60;frame++) {
		char buffer[256];
		
		matrix_rotateY(&GTM, cos(M_PI/30.0), sin(M_PI/30.0) );
		module_draw( curve, &VTM, &GTM, &ds, NULL, src );

		sprintf(buffer, "bezSurf-frame%03d.ppm", frame);
		image_write(src, buffer);
		image_reset(src);
	}
	
	printf("converting to gif...\n");
	system("convert -delay 1.5 -loop 0 bezSurf-frame*.ppm bezSurf.gif");
	system("rm bezSurf-frame*.ppm");

	// clean up
	image_free( src );

	module_delete( curve );

	return(0);
}
예제 #6
0
파일: test7b.c 프로젝트: imtibbet/CS351
int main(int argc, char *argv[]) {
	int i, frame;
	Color blue, green, purple, red, white;
	Point p[4];
	BezierCurve bc;
	DrawState ds;
	Module *curveA;
	Module *curveB;
	Module *curves;
	View3D view;
	Matrix VTM, GTM;
	int divisions = 4;
	int rows = 300, cols = 400;
	Image *src = image_create(rows, cols);

	// grab the command line argument, if one exists
	if(argc > 1) {
		int tmp = atoi(argv[1]);
		if( tmp >= 0 && tmp < 10 )
			divisions = tmp;
	}
	printf("Creating Bezier curves with %d subdivisions\n", divisions);

	color_set(&white, 1.0, 1.0, 1.0 );
	color_set(&blue, .1, .2, .8);
	color_set(&green, .2, 0.7, 0.3 );
	color_set(&purple, 0.6, 0.1, 0.7 );
	color_set(&red, 0.75, 0.3, 0.3 );

	// set one curve
	point_set3D(&p[0], 0.0, 0.0, 0.0);
	point_set3D(&p[1], 1.0, 0.2, 0.0);
	point_set3D(&p[2], 0.7, 0.5, 0.2);
	point_set3D(&p[3], 1.0, 1.0, 1.0);
	bezierCurve_set(&bc, p);

	// put the curve into a module
	curveA = module_create();
	module_color(curveA, &blue);
	module_bezierCurve(curveA, &bc, divisions);

	// set the second curve
	point_set3D(&p[0], 0.0, 0.0, 0.0);
	point_set3D(&p[1], 0.0, 0.2, 1.0);
	point_set3D(&p[2], 0.2, 0.5, 0.7);
	point_set3D(&p[3], 1.0, 1.0, 1.0);
	bezierCurve_set(&bc, p);

	// put the curve into a module
	curveB = module_create();
	module_color(curveB, &green);
	module_bezierCurve(curveB, &bc, divisions);

	// create a module with six curves
	curves = module_create();
	for(i=0;i<3;i++) {
		module_module( curves, curveA );
		module_module( curves, curveB );
		module_rotateY( curves, cos(2.0*M_PI/3.0), sin(2.0*M_PI/3.0) );
	}

	// set up the drawstate
	drawstate_setColor(&ds, white);

	// set up the view
	point_set3D(&(view.vrp), 0.0, 0.5, -3.0 );
	vector_set( &(view.vpn), 0.0, 0.0, 1.0 );
	vector_set( &(view.vup), 0.0, 1.0, 0.0 );
	view.d = 1.0;
	view.du = 1.0;
	view.dv = 1.0*rows/cols;
	view.screeny = rows;
	view.screenx = cols;
	view.f = 0.0;
	view.b = 3.0;

	matrix_setView3D( &VTM, &view );
	matrix_identity( &GTM );

	// Create the animation by adjusting the GTM
	for(frame=0;frame<60;frame++) {
		char buffer[256];
		
		matrix_rotateY(&GTM, cos(M_PI/30.0), sin(M_PI/30.0) );
		module_draw( curves, &VTM, &GTM, &ds, NULL, src );

		sprintf(buffer, "bez3d-frame%03d.ppm", frame);
		image_write(src, buffer);
		image_reset(src);
	}
	
	printf("converting to gif...\n");
	system("convert -delay 1.5 -loop 0 bez3d-frame*.ppm bez3d.gif");
	system("rm bez3d-frame*.ppm");

	// clean up
	image_free( src );

	module_delete( curveA );
	module_delete( curveB );
	module_delete( curves );

	return(0);
}