Fix T42008: Dragging and packing issue about new blank image

The issue was caused by the fact that we never used to store the
generated image color in DNA, so image reload will loose this
information.

Now we store the color in DNA, making ti so re-loading the image
will preserve it's generated color.

It is now also possible to change generated image color using the
color swatch in image properties after the image was created.
This commit is contained in:
Sergey Sharybin 2014-10-02 19:04:38 +06:00
parent 9ac0b4ff05
commit 617131410c
Notes: blender-bot 2023-02-14 10:01:19 +01:00
Referenced by issue #42008, Dragging and packing issue about new blank image
5 changed files with 23 additions and 2 deletions

View File

@ -62,6 +62,7 @@
#include "DNA_meshdata_types.h"
#include "BLI_blenlib.h"
#include "BLI_math_vector.h"
#include "BLI_threads.h"
#include "BLI_timecode.h" /* for stamp timecode format */
#include "BLI_utildefines.h"
@ -365,6 +366,7 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
nima->gen_x = ima->gen_x;
nima->gen_y = ima->gen_y;
nima->gen_type = ima->gen_type;
copy_v4_v4(nima->gen_color, ima->gen_color);
nima->animspeed = ima->animspeed;
@ -769,6 +771,7 @@ Image *BKE_image_add_generated(Main *bmain, unsigned int width, unsigned int hei
ima->gen_type = gen_type;
ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0);
ima->gen_depth = depth;
copy_v4_v4(ima->gen_color, color);
ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, gen_type, color, &ima->colorspace_settings);
image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
@ -2996,7 +2999,6 @@ BLI_INLINE bool image_quick_test(Image *ima, ImageUser *iuser)
static ImBuf *image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r)
{
ImBuf *ibuf = NULL;
float color[] = {0, 0, 0, 1};
int frame = 0, index = 0;
if (lock_r)
@ -3041,7 +3043,7 @@ static ImBuf *image_acquire_ibuf(Image *ima, ImageUser *iuser, void **lock_r)
if (ima->gen_y == 0) ima->gen_y = 1024;
if (ima->gen_depth == 0) ima->gen_depth = 24;
ibuf = add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, ima->gen_depth, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type,
color, &ima->colorspace_settings);
ima->gen_color, &ima->colorspace_settings);
image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
ima->ok = IMA_OK_LOADED;
}

View File

@ -390,4 +390,11 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
Image *image;
for (image = main->image.first; image != NULL; image = image->id.next) {
image->gen_color[3] - 1.0f;
}
}
}

View File

@ -809,6 +809,10 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char
uiItemR(col, &imaptr, "use_generated_float", 0, NULL, ICON_NONE);
uiItemR(split, &imaptr, "generated_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
if (ima->gen_type == IMA_GENTYPE_BLANK) {
uiItemR(layout, &imaptr, "generated_color", 0, NULL, ICON_NONE);
}
}
}

View File

@ -109,6 +109,7 @@ typedef struct Image {
int gen_x, gen_y;
char gen_type, gen_flag;
short gen_depth;
float gen_color[4];
/* display aspect - for UV editing images resized for faster openGL display */
float aspx, aspy;

View File

@ -589,6 +589,13 @@ static void rna_def_image(BlenderRNA *brna)
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
prop = RNA_def_property(srna, "generated_color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_float_sdna(prop, NULL, "gen_color");
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Color", "Fill color for the generated image");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
/* realtime properties */
prop = RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");