[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29805] trunk/blender/source/blender: add alpha option for new images (operator and function)

Campbell Barton ideasman42 at gmail.com
Wed Jun 30 00:07:27 CEST 2010


Revision: 29805
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29805
Author:   campbellbarton
Date:     2010-06-30 00:07:27 +0200 (Wed, 30 Jun 2010)

Log Message:
-----------
add alpha option for new images (operator and function)

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/editors/space_image/image_ops.c
    trunk/blender/source/blender/makesrna/intern/rna_main_api.c

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h	2010-06-29 21:23:28 UTC (rev 29804)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h	2010-06-29 22:07:27 UTC (rev 29805)
@@ -115,7 +115,7 @@
 struct Image *BKE_add_image_file(const char *name, int frame);
 
 /* adds image, adds ibuf, generates color or pattern */
-struct Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short uvtestgrid, float color[4]);
+struct Image *BKE_add_image_size(int width, int height, char *name, int depth, int floatbuf, short uvtestgrid, float color[4]);
 /* adds image from imbuf, owns imbuf */
 struct Image *BKE_add_image_imbuf(struct ImBuf *ibuf);
 

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2010-06-29 21:23:28 UTC (rev 29804)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2010-06-29 22:07:27 UTC (rev 29805)
@@ -380,18 +380,18 @@
 	return ima;
 }
 
-static ImBuf *add_ibuf_size(int width, int height, char *name, int floatbuf, short uvtestgrid, float color[4])
+static ImBuf *add_ibuf_size(int width, int height, char *name, int depth, int floatbuf, short uvtestgrid, float color[4])
 {
 	ImBuf *ibuf;
 	unsigned char *rect= NULL;
 	float *rect_float= NULL;
 	
 	if (floatbuf) {
-		ibuf= IMB_allocImBuf(width, height, 24, IB_rectfloat, 0);
+		ibuf= IMB_allocImBuf(width, height, depth, IB_rectfloat, 0);
 		rect_float= (float*)ibuf->rect_float;
 	}
 	else {
-		ibuf= IMB_allocImBuf(width, height, 24, IB_rect, 0);
+		ibuf= IMB_allocImBuf(width, height, depth, IB_rect, 0);
 		rect= (unsigned char*)ibuf->rect;
 	}
 	
@@ -413,7 +413,7 @@
 }
 
 /* adds new image block, creates ImBuf and initializes color */
-Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short uvtestgrid, float color[4])
+Image *BKE_add_image_size(int width, int height, char *name, int depth, int floatbuf, short uvtestgrid, float color[4])
 {
 	/* on save, type is changed to FILE in editsima.c */
 	Image *ima= image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
@@ -426,7 +426,7 @@
 		ima->gen_y= height;
 		ima->gen_type= uvtestgrid;
 		
-		ibuf= add_ibuf_size(width, height, name, floatbuf, uvtestgrid, color);
+		ibuf= add_ibuf_size(width, height, name, depth, floatbuf, uvtestgrid, color);
 		image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
 		
 		ima->ok= IMA_OK_LOADED;
@@ -2075,7 +2075,7 @@
 				/* UV testgrid or black or solid etc */
 				if(ima->gen_x==0) ima->gen_x= 1024;
 				if(ima->gen_y==0) ima->gen_y= 1024;
-				ibuf= add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 0, ima->gen_type, color);
+				ibuf= add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 24, 0, ima->gen_type, color);
 				image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
 				ima->ok= IMA_OK_LOADED;
 			}

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2010-06-29 21:23:28 UTC (rev 29804)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2010-06-29 22:07:27 UTC (rev 29805)
@@ -1182,7 +1182,7 @@
 	PropertyRNA *prop;
 	char name[22];
 	float color[4];
-	int width, height, floatbuf, uvtestgrid;
+	int width, height, floatbuf, uvtestgrid, alpha;
 
 	/* retrieve state */
 	sima= CTX_wm_space_image(C);
@@ -1195,13 +1195,16 @@
 	floatbuf= RNA_boolean_get(op->ptr, "float");
 	uvtestgrid= RNA_boolean_get(op->ptr, "uv_test_grid");
 	RNA_float_get_array(op->ptr, "color", color);
-	color[3]= RNA_float_get(op->ptr, "alpha");
+	alpha= RNA_boolean_get(op->ptr, "alpha");
 	
 	if (!floatbuf && scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
 		linearrgb_to_srgb_v3_v3(color, color);
 
-	ima = BKE_add_image_size(width, height, name, floatbuf, uvtestgrid, color);
+	if(!alpha)
+		color[3]= 1.0f;
 
+	ima = BKE_add_image_size(width, height, name, alpha ? 32 : 24, floatbuf, uvtestgrid, color);
+
 	if(!ima)
 		return OPERATOR_CANCELLED;
 
@@ -1228,6 +1231,9 @@
 
 void IMAGE_OT_new(wmOperatorType *ot)
 {
+	PropertyRNA *prop;
+	float default_color[4]= {0.0f, 0.0f, 0.0f, 1.0f};
+	
 	/* identifiers */
 	ot->name= "New";
 	ot->idname= "IMAGE_OT_new";
@@ -1243,8 +1249,9 @@
 	RNA_def_string(ot->srna, "name", "Untitled", 21, "Name", "Image datablock name.");
 	RNA_def_int(ot->srna, "width", 1024, 1, INT_MAX, "Width", "Image width.", 1, 16384);
 	RNA_def_int(ot->srna, "height", 1024, 1, INT_MAX, "Height", "Image height.", 1, 16384);
-	RNA_def_float_color(ot->srna, "color", 3, NULL, 0.0f, FLT_MAX, "Color", "Default fill color.", 0.0f, 1.0f);
-	RNA_def_float(ot->srna, "alpha", 1.0f, 0.0f, 1.0f, "Alpha", "Default fill alpha.", 0.0f, 1.0f);
+	prop= RNA_def_float_color(ot->srna, "color", 4, NULL, 0.0f, FLT_MAX, "Color", "Default fill color.", 0.0f, 1.0f);
+	RNA_def_property_float_array_default(prop, default_color);
+	RNA_def_boolean(ot->srna, "alpha", 1, "Alpha", "Create an image with an alpha channel.");
 	RNA_def_boolean(ot->srna, "uv_test_grid", 0, "UV Test Grid", "Fill the image with a grid for UV map testing.");
 	RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth.");
 }

Modified: trunk/blender/source/blender/makesrna/intern/rna_main_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2010-06-29 21:23:28 UTC (rev 29804)
+++ trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2010-06-29 22:07:27 UTC (rev 29805)
@@ -253,10 +253,10 @@
 	/* XXX python now has invalid pointer? */
 }
 
-Image *rna_Main_images_new(Main *bmain, char* name, int width, int height, int float_buffer)
+Image *rna_Main_images_new(Main *bmain, char* name, int width, int height, int alpha, int float_buffer)
 {
 	float color[4]= {0.0, 0.0, 0.0, 1.0};
-	Image *image= BKE_add_image_size(width, height, name, float_buffer, 0, color);
+	Image *image= BKE_add_image_size(width, height, name, alpha ? 32:24, float_buffer, 0, color);
 	image->id.us--;
 	return image;
 }
@@ -685,6 +685,7 @@
 	RNA_def_property_flag(parm, PROP_REQUIRED);
 	parm= RNA_def_int(func, "width", 1024, 1, INT_MAX, "", "Width of the image.", 0, INT_MAX);
 	parm= RNA_def_int(func, "height", 1024, 1, INT_MAX, "", "Height of the image.", 0, INT_MAX);
+	parm= RNA_def_boolean(func, "alpha", 0, "Alpha", "Use alpha channel");
 	parm= RNA_def_boolean(func, "float_buffer", 0, "Float Buffer", "Create an image with floating point color");
 	/* return type */
 	parm= RNA_def_pointer(func, "image", "Image", "", "New image datablock.");





More information about the Bf-blender-cvs mailing list