diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-25 07:47:34 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-25 07:47:34 +0400 |
commit | a044f532aba515efb09cf5773e112fa5e938b008 (patch) | |
tree | f4fe7a5013f567ea8ff1f4925422a68dc152a479 /source/blender | |
parent | ddf934dedf6fa40d2ef1e3d4c6dc0d33ee6dfaea (diff) |
Image save as operator 'BW' option wasnt working on some formats, now only show when its supported.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 51 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 49 |
5 files changed, 70 insertions, 40 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 9ff42bc706b..c829fc69b05 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -60,10 +60,10 @@ char BKE_ftype_to_imtype(const int ftype); int BKE_imtype_to_ftype(char imtype); int BKE_imtype_is_movie(const char imtype); -int BKE_imtype_supports_alpha(const char imtype); int BKE_imtype_supports_zbuf(const char imtype); int BKE_imtype_supports_compress(const char imtype); int BKE_imtype_supports_quality(const char imtype); +char BKE_imtype_valid_channels(const char imtype); char BKE_imtype_valid_depths(const char imtype); char BKE_imtype_from_arg(const char *arg); @@ -115,6 +115,10 @@ struct RenderResult; /* image-user gets a new image, check settings */ #define IMA_SIGNAL_USER_NEW_IMAGE 6 +#define IMA_CHAN_FLAG_BW 1 +#define IMA_CHAN_FLAG_RGB 2 +#define IMA_CHAN_FLAG_ALPHA 4 + /* depending Image type, and (optional) ImageUser setting it returns ibuf */ /* always call to make signals work */ struct ImBuf *BKE_image_get_ibuf(struct Image *ima, struct ImageUser *iuser); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 034177e2b5d..c7f74f37a2d 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -900,24 +900,6 @@ int BKE_imtype_is_movie(const char imtype) return 0; } -int BKE_imtype_supports_alpha(const char imtype) -{ - switch(imtype) { - case R_IMF_IMTYPE_TARGA: - case R_IMF_IMTYPE_IRIS: - case R_IMF_IMTYPE_PNG: - /* case R_IMF_IMTYPE_BMP: */ /* read but not write */ - case R_IMF_IMTYPE_RADHDR: - case R_IMF_IMTYPE_TIFF: - case R_IMF_IMTYPE_OPENEXR: - case R_IMF_IMTYPE_MULTILAYER: - case R_IMF_IMTYPE_DDS: - case R_IMF_IMTYPE_JP2: - return 1; - } - return 0; -} - int BKE_imtype_supports_zbuf(const char imtype) { switch(imtype) { @@ -948,6 +930,39 @@ int BKE_imtype_supports_quality(const char imtype) return 0; } +char BKE_imtype_valid_channels(const char imtype) +{ + char chan_flag= IMA_CHAN_FLAG_RGB; /* assume all support rgb */ + + /* alpha */ + switch(imtype) { + case R_IMF_IMTYPE_TARGA: + case R_IMF_IMTYPE_IRIS: + case R_IMF_IMTYPE_PNG: + /* case R_IMF_IMTYPE_BMP: */ /* read but not write */ + case R_IMF_IMTYPE_RADHDR: + case R_IMF_IMTYPE_TIFF: + case R_IMF_IMTYPE_OPENEXR: + case R_IMF_IMTYPE_MULTILAYER: + case R_IMF_IMTYPE_DDS: + case R_IMF_IMTYPE_JP2: + chan_flag |= IMA_CHAN_FLAG_ALPHA; + } + + /* bw */ + switch(imtype) { + case R_IMF_IMTYPE_PNG: + case R_IMF_IMTYPE_JPEG90: + case R_IMF_IMTYPE_TARGA: + case R_IMF_IMTYPE_RAWTGA: + case R_IMF_IMTYPE_TIFF: + case R_IMF_IMTYPE_IRIS: + chan_flag |= IMA_CHAN_FLAG_BW; + } + + return chan_flag; +} + char BKE_imtype_valid_depths(const char imtype) { switch (imtype) { diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index b7ac5f394b0..8e8dd559fb1 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -187,7 +187,7 @@ void RNA_def_function_ui_description(FunctionRNA *func, const char *description) /* Dynamic Enums * strings are not freed, assumed pointing to static location. */ -void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item); +void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item); void RNA_enum_item_add_separator(EnumPropertyItem **items, int *totitem); void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item); void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item, int value); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index abaeb202ffa..e911c936df8 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -2696,7 +2696,7 @@ int rna_parameter_size_alloc(PropertyRNA *parm) /* Dynamic Enums */ -void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item) +void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item) { EnumPropertyItem *newitems; int tot= *totitem; diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 8661c0f1ae9..72b07b8da2c 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -217,6 +217,10 @@ EnumPropertyItem image_color_mode_items[] ={ {R_IMF_PLANES_RGBA, "RGBA", 0, "RGBA", "Images are saved with RGB and Alpha data (if supported)"}, {0, NULL, 0, NULL, NULL}}; +#define IMAGE_COLOR_MODE_BW image_color_mode_items[0] +#define IMAGE_COLOR_MODE_RGB image_color_mode_items[1] +#define IMAGE_COLOR_MODE_RGBA image_color_mode_items[2] + EnumPropertyItem image_color_depth_items[] = { /* 1 (monochrome) not used */ {R_IMF_CHAN_DEPTH_8, "8", 0, "8", "8 bit color channels"}, @@ -615,11 +619,16 @@ static void rna_ImageFormatSettings_file_format_set(PointerRNA *ptr, int value) { ImageFormatData *imf= (ImageFormatData *)ptr->data; ID *id= ptr->id.data; + const char is_render= (id && GS(id->name) == ID_SCE); + /* see note below on why this is */ + const char chan_flag= BKE_imtype_valid_channels(imf->imtype) | (is_render ? IMA_CHAN_FLAG_BW : 0); imf->imtype= value; /* ensure depth and color settings match */ - if (!BKE_imtype_supports_alpha(imf->imtype)) { + if ( ((imf->planes == R_IMF_PLANES_BW) && !(chan_flag & IMA_CHAN_FLAG_BW)) || + ((imf->planes == R_IMF_PLANES_RGBA) && !(chan_flag & IMA_CHAN_FLAG_ALPHA))) + { imf->planes= R_IMF_PLANES_RGB; } @@ -675,16 +684,30 @@ static EnumPropertyItem *rna_ImageFormatSettings_color_mode_itemf(bContext *C, P PropertyRNA *UNUSED(prop), int *free) { ImageFormatData *imf= (ImageFormatData *)ptr->data; + ID *id= ptr->id.data; + const char is_render= (id && GS(id->name) == ID_SCE); - if ((imf == NULL) || BKE_imtype_supports_alpha(imf->imtype)) { + /* note, we need to act differently for render + * where 'BW' will force greyscale even if the output format writes + * as RGBA, this is age old blender convention and not sure how useful + * it really is but keep it for now - campbell */ + const char chan_flag= BKE_imtype_valid_channels(imf->imtype) | (is_render ? IMA_CHAN_FLAG_BW : 0); + + if (chan_flag == (IMA_CHAN_FLAG_BW|IMA_CHAN_FLAG_RGB|IMA_CHAN_FLAG_ALPHA)) { return image_color_mode_items; } else { - static EnumPropertyItem color_mode_items[] ={ - {R_IMF_PLANES_BW, "BW", 0, "BW", "Images get saved in 8 bits grayscale (only PNG, JPEG, TGA, TIF)"}, - {R_IMF_PLANES_RGB, "RGB", 0, "RGB", "Images are saved with RGB (color) data"}, - {0, NULL, 0, NULL, NULL}}; - return color_mode_items; + int totitem= 0; + EnumPropertyItem *item= NULL; + + if (chan_flag & IMA_CHAN_FLAG_BW) RNA_enum_item_add(&item, &totitem, &IMAGE_COLOR_MODE_BW); + if (chan_flag & IMA_CHAN_FLAG_RGB) RNA_enum_item_add(&item, &totitem, &IMAGE_COLOR_MODE_RGB); + if (chan_flag & IMA_CHAN_FLAG_ALPHA) RNA_enum_item_add(&item, &totitem, &IMAGE_COLOR_MODE_RGBA); + + RNA_enum_item_end(&item, &totitem); + *free= 1; + + return item; } } @@ -2727,18 +2750,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna) RNA_def_struct_path_func(srna, "rna_RenderSettings_path"); RNA_def_struct_ui_text(srna, "Render Data", "Rendering settings for a Scene datablock"); -#if 0 /* moved */ - - prop= RNA_def_property(srna, "color_mode", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_bitflag_sdna(prop, NULL, "planes"); - RNA_def_property_enum_items(prop, image_color_mode_items); - RNA_def_property_ui_text(prop, "Color Mode", - "Choose BW for saving greyscale images, RGB for saving red, green and blue channels, " - "and RGBA for saving red, green, blue and alpha channels"); - RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL); - -#endif - /* Render Data */ prop= RNA_def_property(srna, "image_settings", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_NEVER_NULL); |