diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-06-30 02:07:27 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-06-30 02:07:27 +0400 |
commit | 35dd09a9efc7840a79e7ef345f5e8850c41f77b1 (patch) | |
tree | e1ec68044a36cfe4eaf9dba89449dfbb649e57f2 | |
parent | c0bb3303f48986fc4e1853af6c766023fbe61dfd (diff) |
add alpha option for new images (operator and function)
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 17 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_main_api.c | 5 |
4 files changed, 22 insertions, 14 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 7bdb9aaf709..d7eb5fe8246 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -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); /* 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); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index f06e9302a60..a584e91fc0f 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -380,18 +380,18 @@ Image *BKE_add_image_file(const char *name, int frame) 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 @@ static ImBuf *add_ibuf_size(int width, int height, char *name, int floatbuf, sho } /* 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 @@ Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short 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 @@ ImBuf *BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r) /* 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; } diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index f84fd6fc430..1787faff327 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1182,7 +1182,7 @@ static int new_exec(bContext *C, wmOperator *op) 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,12 +1195,15 @@ static int new_exec(bContext *C, wmOperator *op) 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 @@ static int new_exec(bContext *C, wmOperator *op) 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 @@ void IMAGE_OT_new(wmOperatorType *ot) 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."); } diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 0dbaaa87a99..4564ecd586b 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -253,10 +253,10 @@ void rna_Main_lamps_remove(Main *bmain, ReportList *reports, Lamp *lamp) /* 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 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop) 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."); |