add alpha option for new images (operator and function)

This commit is contained in:
Campbell Barton
2010-06-29 22:07:27 +00:00
parent c0bb3303f4
commit 35dd09a9ef
4 changed files with 22 additions and 14 deletions

View File

@@ -115,7 +115,7 @@ void BKE_image_release_ibuf(struct Image *ima, void *lock);
struct Image *BKE_add_image_file(const char *name, int frame); struct Image *BKE_add_image_file(const char *name, int frame);
/* adds image, adds ibuf, generates color or pattern */ /* 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 */ /* adds image from imbuf, owns imbuf */
struct Image *BKE_add_image_imbuf(struct ImBuf *ibuf); struct Image *BKE_add_image_imbuf(struct ImBuf *ibuf);

View File

@@ -380,18 +380,18 @@ Image *BKE_add_image_file(const char *name, int frame)
return ima; 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; ImBuf *ibuf;
unsigned char *rect= NULL; unsigned char *rect= NULL;
float *rect_float= NULL; float *rect_float= NULL;
if (floatbuf) { 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; rect_float= (float*)ibuf->rect_float;
} }
else { else {
ibuf= IMB_allocImBuf(width, height, 24, IB_rect, 0); ibuf= IMB_allocImBuf(width, height, depth, IB_rect, 0);
rect= (unsigned char*)ibuf->rect; rect= (unsigned char*)ibuf->rect;
} }
@@ -413,7 +413,7 @@ static ImBuf *add_ibuf_size(int width, int height, char *name, int floatbuf, sho
} }
/* adds new image block, creates ImBuf and initializes color */ /* 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 */ /* on save, type is changed to FILE in editsima.c */
Image *ima= image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); Image *ima= image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
@@ -426,7 +426,7 @@ Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short
ima->gen_y= height; ima->gen_y= height;
ima->gen_type= uvtestgrid; 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); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
ima->ok= IMA_OK_LOADED; ima->ok= IMA_OK_LOADED;
@@ -2075,7 +2075,7 @@ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r)
/* UV testgrid or black or solid etc */ /* UV testgrid or black or solid etc */
if(ima->gen_x==0) ima->gen_x= 1024; if(ima->gen_x==0) ima->gen_x= 1024;
if(ima->gen_y==0) ima->gen_y= 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); image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
ima->ok= IMA_OK_LOADED; ima->ok= IMA_OK_LOADED;
} }

View File

@@ -1182,7 +1182,7 @@ static int new_exec(bContext *C, wmOperator *op)
PropertyRNA *prop; PropertyRNA *prop;
char name[22]; char name[22];
float color[4]; float color[4];
int width, height, floatbuf, uvtestgrid; int width, height, floatbuf, uvtestgrid, alpha;
/* retrieve state */ /* retrieve state */
sima= CTX_wm_space_image(C); sima= CTX_wm_space_image(C);
@@ -1195,12 +1195,15 @@ static int new_exec(bContext *C, wmOperator *op)
floatbuf= RNA_boolean_get(op->ptr, "float"); floatbuf= RNA_boolean_get(op->ptr, "float");
uvtestgrid= RNA_boolean_get(op->ptr, "uv_test_grid"); uvtestgrid= RNA_boolean_get(op->ptr, "uv_test_grid");
RNA_float_get_array(op->ptr, "color", color); 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) if (!floatbuf && scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
linearrgb_to_srgb_v3_v3(color, color); 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) if(!ima)
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
@@ -1228,6 +1231,9 @@ static int new_exec(bContext *C, wmOperator *op)
void IMAGE_OT_new(wmOperatorType *ot) void IMAGE_OT_new(wmOperatorType *ot)
{ {
PropertyRNA *prop;
float default_color[4]= {0.0f, 0.0f, 0.0f, 1.0f};
/* identifiers */ /* identifiers */
ot->name= "New"; ot->name= "New";
ot->idname= "IMAGE_OT_new"; ot->idname= "IMAGE_OT_new";
@@ -1243,8 +1249,9 @@ void IMAGE_OT_new(wmOperatorType *ot)
RNA_def_string(ot->srna, "name", "Untitled", 21, "Name", "Image datablock name."); 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, "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_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); prop= RNA_def_float_color(ot->srna, "color", 4, 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); 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, "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."); RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth.");
} }

View File

@@ -253,10 +253,10 @@ void rna_Main_lamps_remove(Main *bmain, ReportList *reports, Lamp *lamp)
/* XXX python now has invalid pointer? */ /* 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}; 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--; image->id.us--;
return image; return image;
} }
@@ -685,6 +685,7 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_flag(parm, PROP_REQUIRED); 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, "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_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"); parm= RNA_def_boolean(func, "float_buffer", 0, "Float Buffer", "Create an image with floating point color");
/* return type */ /* return type */
parm= RNA_def_pointer(func, "image", "Image", "", "New image datablock."); parm= RNA_def_pointer(func, "image", "Image", "", "New image datablock.");