Color Management: different fixes for byte buffers
- Color space of byte buffer for generated images haven't been updated properly on change - Byte buffers weren't handling data color spaces on display transform properly
This commit is contained in:
@@ -603,7 +603,8 @@ Image *BKE_image_load_exists(const char *filepath)
|
||||
return BKE_image_load(filepath);
|
||||
}
|
||||
|
||||
static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, float color[4])
|
||||
static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type,
|
||||
float color[4], const char *colorspace)
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
unsigned char *rect = NULL;
|
||||
@@ -616,6 +617,9 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
|
||||
else {
|
||||
ibuf = IMB_allocImBuf(width, height, depth, IB_rect);
|
||||
rect = (unsigned char *)ibuf->rect;
|
||||
|
||||
if (colorspace)
|
||||
IMB_colormanagement_assign_rect_colorspace(ibuf, colorspace);
|
||||
}
|
||||
|
||||
BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
|
||||
@@ -651,7 +655,7 @@ Image *BKE_image_add_generated(unsigned int width, unsigned int height, const ch
|
||||
ima->gen_type = gen_type;
|
||||
ima->gen_flag |= (floatbuf ? IMA_GEN_FLOAT : 0);
|
||||
|
||||
ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, gen_type, color);
|
||||
ibuf = add_ibuf_size(width, height, ima->name, depth, floatbuf, gen_type, color, NULL);
|
||||
image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
|
||||
|
||||
/* assign colorspaces */
|
||||
@@ -2793,7 +2797,8 @@ 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, 24, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type, color);
|
||||
ibuf = add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, 24, (ima->gen_flag & IMA_GEN_FLOAT) != 0, ima->gen_type,
|
||||
color, ima->colorspace_settings.name);
|
||||
image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
|
||||
ima->ok = IMA_OK_LOADED;
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ void IMB_colormanagement_validate_settings(struct ColorManagedDisplaySettings *d
|
||||
struct ColorManagedViewSettings *view_settings);
|
||||
|
||||
const char *IMB_colormanagement_role_colorspace_name_get(int role);
|
||||
void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char *name);
|
||||
|
||||
/* ** Color space transformation functions ** */
|
||||
void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
|
||||
|
||||
@@ -847,16 +847,17 @@ void colormanage_imbuf_set_default_spaces(ImBuf *ibuf)
|
||||
|
||||
void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace)
|
||||
{
|
||||
ColorSpace *colorspace = colormanage_colorspace_get_named(from_colorspace);
|
||||
|
||||
if (colorspace->is_data) {
|
||||
ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ibuf->rect_float) {
|
||||
ColorSpace *colorspace = colormanage_colorspace_get_named(from_colorspace);
|
||||
const char *to_colorspace = global_role_scene_linear;
|
||||
int predivide = ibuf->flags & IB_cm_predivide;
|
||||
|
||||
if (colorspace->is_data) {
|
||||
ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ibuf->rect)
|
||||
imb_freerectImBuf(ibuf);
|
||||
|
||||
@@ -1038,6 +1039,17 @@ const char *IMB_colormanagement_role_colorspace_name_get(int role)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void IMB_colormanagement_assign_rect_colorspace(ImBuf *ibuf, const char *name)
|
||||
{
|
||||
ColorSpace *colorspace = colormanage_colorspace_get_named(name);
|
||||
ibuf->rect_colorspace = colorspace;
|
||||
|
||||
if (colorspace->is_data)
|
||||
ibuf->colormanage_flag |= IMB_COLORMANAGE_IS_DATA;
|
||||
else
|
||||
ibuf->colormanage_flag &= ~IMB_COLORMANAGE_IS_DATA;
|
||||
}
|
||||
|
||||
/*********************** Threaded display buffer transform routines *************************/
|
||||
|
||||
typedef struct DisplayBufferThread {
|
||||
@@ -1132,6 +1144,7 @@ static void *display_buffer_apply_get_linear_buffer(DisplayBufferThread *handle)
|
||||
int buffer_size = channels * width * height;
|
||||
|
||||
int predivide = handle->predivide;
|
||||
int is_data = handle->is_data;
|
||||
|
||||
linear_buffer = MEM_callocN(buffer_size * sizeof(float), "color conversion linear buffer");
|
||||
|
||||
@@ -1153,9 +1166,11 @@ static void *display_buffer_apply_get_linear_buffer(DisplayBufferThread *handle)
|
||||
*fp = (float)(*cp) / 255.0f;
|
||||
}
|
||||
|
||||
/* convert float buffer to scene linear space */
|
||||
IMB_colormanagement_transform(linear_buffer, width, height, channels,
|
||||
from_colorspace, to_colorspace, predivide);
|
||||
if (!is_data) {
|
||||
/* convert float buffer to scene linear space */
|
||||
IMB_colormanagement_transform(linear_buffer, width, height, channels,
|
||||
from_colorspace, to_colorspace, predivide);
|
||||
}
|
||||
}
|
||||
else if (handle->float_colorspace) {
|
||||
/* currently float is non-linear only in sequencer, which is working
|
||||
|
||||
@@ -144,15 +144,15 @@ void WM_init(bContext *C, int argc, const char **argv)
|
||||
|
||||
ED_spacetypes_init(); /* editors/space_api/spacetype.c */
|
||||
|
||||
/* initialize color management stuff */
|
||||
IMB_colormanagement_init();
|
||||
|
||||
ED_file_init(); /* for fsmenu */
|
||||
ED_node_init_butfuncs();
|
||||
|
||||
BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
|
||||
BLF_lang_init();
|
||||
|
||||
/* initialize color management stuff */
|
||||
IMB_colormanagement_init();
|
||||
|
||||
/* get the default database, plus a wm */
|
||||
WM_homefile_read(C, NULL, G.factory_startup);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user