diff options
Diffstat (limited to 'source/blender/imbuf')
20 files changed, 327 insertions, 204 deletions
diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h index ff1784c54dd..437a699208b 100644 --- a/source/blender/imbuf/IMB_colormanagement.h +++ b/source/blender/imbuf/IMB_colormanagement.h @@ -71,6 +71,8 @@ const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf); BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3]); BLI_INLINE unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char[3]); +BLI_INLINE void IMB_colormangement_xyz_to_rgb(float rgb[3], const float xyz[3]); +BLI_INLINE void IMB_colormangement_rgb_to_xyz(float xyz[3], const float rgb[3]); /* ** Color space transformation functions ** */ void IMB_colormanagement_transform(float *buffer, int width, int height, int channels, @@ -96,6 +98,12 @@ void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct Co void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, bool predivide); +void IMB_colormanagement_scene_linear_to_color_picking_v3(float pixel[3]); +void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[3]); + +void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3]); +void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[3]); + void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], struct ColorManagedDisplay *display); void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display); @@ -137,18 +145,20 @@ void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *li void IMB_display_buffer_release(void *cache_handle); -/* ** Display funcrions ** */ +/* ** Display functions ** */ int IMB_colormanagement_display_get_named_index(const char *name); const char *IMB_colormanagement_display_get_indexed_name(int index); const char *IMB_colormanagement_display_get_default_name(void); struct ColorManagedDisplay *IMB_colormanagement_display_get_named(const char *name); const char *IMB_colormanagement_display_get_none_name(void); +const char *IMB_colormanagement_display_get_default_view_transform_name( + struct ColorManagedDisplay *display); -/* ** View funcrions ** */ +/* ** View functions ** */ int IMB_colormanagement_view_get_named_index(const char *name); const char *IMB_colormanagement_view_get_indexed_name(int index); -/* ** Look funcrions ** */ +/* ** Look functions ** */ int IMB_colormanagement_look_get_named_index(const char *name); const char *IMB_colormanagement_look_get_indexed_name(int index); @@ -157,7 +167,7 @@ int IMB_colormanagement_colorspace_get_named_index(const char *name); const char *IMB_colormanagement_colorspace_get_indexed_name(int index); const char *IMB_colormanagement_view_get_default_name(const char *display_name); -void IMB_colormanagment_colorspace_from_ibuf_ftype(struct ColorManagedColorspaceSettings *colorspace_settings, struct ImBuf *ibuf); +void IMB_colormanagement_colorspace_from_ibuf_ftype(struct ColorManagedColorspaceSettings *colorspace_settings, struct ImBuf *ibuf); /* ** RNA helper functions ** */ void IMB_colormanagement_display_items_add(struct EnumPropertyItem **items, int *totitem); @@ -220,6 +230,11 @@ bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C /* Finish GLSL-based display space conversion */ void IMB_colormanagement_finish_glsl_draw(void); +/* ** View transform ** */ +void IMB_colormanagement_init_default_view_settings( + struct ColorManagedViewSettings *view_settings, + const struct ColorManagedDisplaySettings *display_settings); + /* Roles */ enum { COLOR_ROLE_SCENE_LINEAR = 0, diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index b145a86ba4b..4c531c40d16 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -426,13 +426,6 @@ int imb_get_anim_type(const char *name); */ bool IMB_isfloat(struct ImBuf *ibuf); -/** - * - * \attention Defined in divers.c - */ -void IMB_de_interlace(struct ImBuf *ibuf); -void IMB_interlace(struct ImBuf *ibuf); - /* create char buffer, color corrected if necessary, for ImBufs that lack one */ void IMB_rect_from_float(struct ImBuf *ibuf); /* Create char buffer for part of the image, color corrected if necessary, diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h index 15a684d31a4..948358467de 100644 --- a/source/blender/imbuf/IMB_imbuf_types.h +++ b/source/blender/imbuf/IMB_imbuf_types.h @@ -51,10 +51,14 @@ #define IMB_FILENAME_SIZE 1024 typedef struct DDSData { - unsigned int fourcc; /* DDS fourcc info */ - unsigned int nummipmaps; /* The number of mipmaps in the dds file */ - unsigned char *data; /* The compressed image data */ - unsigned int size; /* The size of the compressed data */ + /** DDS fourcc info */ + unsigned int fourcc; + /** The number of mipmaps in the dds file */ + unsigned int nummipmaps; + /** The compressed image data */ + unsigned char *data; + /** The size of the compressed data */ + unsigned int size; } DDSData; /** @@ -66,9 +70,13 @@ typedef struct DDSData { * */ -/* ibuf->ftype flag, main image types */ -/* Warning: Keep explicit value assignments here, this file is included in areas where not all format defines - * are set (e.g. intern/dds only get WITH_DDS, even if TIFF, HDR etc are also defined). See T46524. */ + +/* Warning: Keep explicit value assignments here, + * this file is included in areas where not all format defines are set + * (e.g. intern/dds only get WITH_DDS, even if TIFF, HDR etc are also defined). + * See T46524. */ + +/** #ImBuf.ftype flag, main image types. */ enum eImbTypes { IMB_FTYPE_PNG = 1, IMB_FTYPE_TGA = 2, @@ -136,24 +144,30 @@ enum eImbTypes { typedef struct ImbFormatOptions { short flag; - char quality; /* quality serves dual purpose as quality number for jpeg or compression amount for png */ + /** quality serves dual purpose as quality number for jpeg or compression amount for png */ + char quality; } ImbFormatOptions; typedef struct ImBuf { struct ImBuf *next, *prev; /**< allow lists of ImBufs, for caches or flipbooks */ /* dimensions */ - int x, y; /* width and Height of our image buffer. - * Should be 'unsigned int' since most formats use this. - * but this is problematic with texture math in imagetexture.c - * avoid problems and use int. - campbell */ + /** Width and Height of our image buffer. + * Should be 'unsigned int' since most formats use this. + * but this is problematic with texture math in imagetexture.c + * avoid problems and use int. - campbell */ + int x, y; - unsigned char planes; /* Active amount of bits/bitplanes */ - int channels; /* amount of channels in rect_float (0 = 4 channel default) */ + /** Active amount of bits/bitplanes */ + unsigned char planes; + /** Number of channels in `rect_float` (0 = 4 channel default) */ + int channels; /* flags */ - int flags; /* Controls which components should exist. */ - int mall; /* what is malloced internal, and can be freed */ + /** Controls which components should exist. */ + int flags; + /** what is malloced internal, and can be freed */ + int mall; /* pixels */ @@ -179,42 +193,63 @@ typedef struct ImBuf { unsigned int **tiles; /* zbuffer */ - int *zbuf; /* z buffer data, original zbuffer */ - float *zbuf_float; /* z buffer data, camera coordinates */ + /** z buffer data, original zbuffer */ + int *zbuf; + /** z buffer data, camera coordinates */ + float *zbuf_float; /* parameters used by conversion between byte and float */ - float dither; /* random dither value, for conversion from float -> byte rect */ + /** random dither value, for conversion from float -> byte rect */ + float dither; /* mipmapping */ - struct ImBuf *mipmap[IMB_MIPMAP_LEVELS]; /* MipMap levels, a series of halved images */ + /** MipMap levels, a series of halved images */ + struct ImBuf *mipmap[IMB_MIPMAP_LEVELS]; int miptot, miplevel; /* externally used data */ - int index; /* reference index for ImBuf lists */ - int userflags; /* used to set imbuf to dirty and other stuff */ - struct IDProperty *metadata; /* image metadata */ - void *userdata; /* temporary storage */ + /** reference index for ImBuf lists */ + int index; + /** used to set imbuf to dirty and other stuff */ + int userflags; + /** image metadata */ + struct IDProperty *metadata; + /** temporary storage */ + void *userdata; /* file information */ - enum eImbTypes ftype; /* file type we are going to save as */ - ImbFormatOptions foptions; /* file format specific flags */ - char name[IMB_FILENAME_SIZE]; /* filename associated with this image */ - char cachename[IMB_FILENAME_SIZE]; /* full filename used for reading from cache */ + /** file type we are going to save as */ + enum eImbTypes ftype; + /** file format specific flags */ + ImbFormatOptions foptions; + /** filename associated with this image */ + char name[IMB_FILENAME_SIZE]; + /** full filename used for reading from cache */ + char cachename[IMB_FILENAME_SIZE]; /* memory cache limiter */ - struct MEM_CacheLimiterHandle_s *c_handle; /* handle for cache limiter */ - int refcounter; /* reference counter for multiple users */ + /** handle for cache limiter */ + struct MEM_CacheLimiterHandle_s *c_handle; + /** reference counter for multiple users */ + int refcounter; /* some parameters to pass along for packing images */ - unsigned char *encodedbuffer; /* Compressed image only used with png currently */ - unsigned int encodedsize; /* Size of data written to encodedbuffer */ - unsigned int encodedbuffersize; /* Size of encodedbuffer */ + /** Compressed image only used with png currently */ + unsigned char *encodedbuffer; + /** Size of data written to encodedbuffer */ + unsigned int encodedsize; + /** Size of encodedbuffer */ + unsigned int encodedbuffersize; /* color management */ - struct ColorSpace *rect_colorspace; /* color space of byte buffer */ - struct ColorSpace *float_colorspace; /* color space of float buffer, used by sequencer only */ - unsigned int *display_buffer_flags; /* array of per-display display buffers dirty flags */ - struct ColormanageCache *colormanage_cache; /* cache used by color management */ + /** color space of byte buffer */ + struct ColorSpace *rect_colorspace; + /** color space of float buffer, used by sequencer only */ + struct ColorSpace *float_colorspace; + /** array of per-display display buffers dirty flags */ + unsigned int *display_buffer_flags; + /** cache used by color management */ + struct ColormanageCache *colormanage_cache; int colormanage_flag; rcti invalid_rect; @@ -222,17 +257,22 @@ typedef struct ImBuf { struct DDSData dds_data; } ImBuf; -/* Moved from BKE_bmfont_types.h because it is a userflag bit mask. */ /** * \brief userflags: Flags used internally by blender for imagebuffers */ -#define IB_BITMAPFONT (1 << 0) /* this image is a font */ -#define IB_BITMAPDIRTY (1 << 1) /* image needs to be saved is not the same as filename */ -#define IB_MIPMAP_INVALID (1 << 2) /* image mipmaps are invalid, need recreate */ -#define IB_RECT_INVALID (1 << 3) /* float buffer changed, needs recreation of byte rect */ -#define IB_DISPLAY_BUFFER_INVALID (1 << 4) /* either float or byte buffer changed, need to re-calculate display buffers */ -#define IB_PERSISTENT (1 << 5) /* image buffer is persistent in the memory and should never be removed from the cache */ +enum { + /** image needs to be saved is not the same as filename */ + IB_BITMAPDIRTY = (1 << 1), + /** image mipmaps are invalid, need recreate */ + IB_MIPMAP_INVALID = (1 << 2), + /** float buffer changed, needs recreation of byte rect */ + IB_RECT_INVALID = (1 << 3), + /** either float or byte buffer changed, need to re-calculate display buffers */ + IB_DISPLAY_BUFFER_INVALID = (1 << 4), + /** image buffer is persistent in the memory and should never be removed from the cache */ + IB_PERSISTENT = (1 << 5), +}; /** * \name Imbuf Component flags @@ -240,23 +280,27 @@ typedef struct ImBuf { * * \{ */ -#define IB_rect (1 << 0) -#define IB_test (1 << 1) -#define IB_fields (1 << 2) -#define IB_zbuf (1 << 3) -#define IB_mem (1 << 4) -#define IB_rectfloat (1 << 5) -#define IB_zbuffloat (1 << 6) -#define IB_multilayer (1 << 7) -#define IB_metadata (1 << 8) -#define IB_animdeinterlace (1 << 9) -#define IB_tiles (1 << 10) -#define IB_tilecache (1 << 11) -#define IB_alphamode_premul (1 << 12) /* indicates whether image on disk have premul alpha */ -#define IB_alphamode_detect (1 << 13) /* if this flag is set, alpha mode would be guessed from file */ -#define IB_ignore_alpha (1 << 14) /* ignore alpha on load and substitute it with 1.0f */ -#define IB_thumbnail (1 << 15) -#define IB_multiview (1 << 16) +enum { + IB_rect = 1 << 0, + IB_test = 1 << 1, + IB_zbuf = 1 << 3, + IB_mem = 1 << 4, + IB_rectfloat = 1 << 5, + IB_zbuffloat = 1 << 6, + IB_multilayer = 1 << 7, + IB_metadata = 1 << 8, + IB_animdeinterlace = 1 << 9, + IB_tiles = 1 << 10, + IB_tilecache = 1 << 11, + /** indicates whether image on disk have premul alpha */ + IB_alphamode_premul = 1 << 12, + /** if this flag is set, alpha mode would be guessed from file */ + IB_alphamode_detect = 1 << 13, + /** ignore alpha on load and substitute it with 1.0f */ + IB_ignore_alpha = 1 << 14, + IB_thumbnail = 1 << 15, + IB_multiview = 1 << 16, +}; /** \} */ diff --git a/source/blender/imbuf/intern/IMB_anim.h b/source/blender/imbuf/intern/IMB_anim.h index 804095a0727..0328bbe6609 100644 --- a/source/blender/imbuf/intern/IMB_anim.h +++ b/source/blender/imbuf/intern/IMB_anim.h @@ -86,7 +86,6 @@ #define ANIM_SEQUENCE (1 << 0) #define ANIM_MOVIE (1 << 4) #define ANIM_AVI (1 << 6) -#define ANIM_QTIME (1 << 7) #define ANIM_FFMPEG (1 << 8) #define MAXNUMSTREAMS 50 diff --git a/source/blender/imbuf/intern/IMB_colormanagement_intern.h b/source/blender/imbuf/intern/IMB_colormanagement_intern.h index 0b4557e7bef..ee3d207a8db 100644 --- a/source/blender/imbuf/intern/IMB_colormanagement_intern.h +++ b/source/blender/imbuf/intern/IMB_colormanagement_intern.h @@ -42,6 +42,8 @@ struct OCIO_ConstProcessorRcPtr; struct ImBuf; extern float imbuf_luma_coefficients[3]; +extern float imbuf_xyz_to_rgb[3][3]; +extern float imbuf_rgb_to_xyz[3][3]; #define MAX_COLORSPACE_NAME 64 #define MAX_COLORSPACE_DESCRIPTION 512 @@ -103,6 +105,8 @@ struct ColorManagedView *colormanage_view_get_default(const ColorManagedDisplay struct ColorManagedView *colormanage_view_add(const char *name); struct ColorManagedView *colormanage_view_get_indexed(int index); struct ColorManagedView *colormanage_view_get_named(const char *name); +struct ColorManagedView *colormanage_view_get_named_for_display( + const char *display_name, const char *name); struct ColorSpace *colormanage_colorspace_add(const char *name, const char *description, bool is_invertible, bool is_data); struct ColorSpace *colormanage_colorspace_get_named(const char *name); diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index 589955d2ab3..f7005d7ee89 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -155,13 +155,6 @@ void imb_freetilesImBuf(ImBuf *ibuf) ibuf->mall &= ~IB_tiles; } -static void imb_free_bitmap_font(ImBuf *ibuf) -{ - if (ibuf->userdata && (ibuf->userflags & IB_BITMAPFONT)) { - MEM_freeN(ibuf->userdata); - } -} - static void freeencodedbufferImBuf(ImBuf *ibuf) { if (ibuf == NULL) return; @@ -215,7 +208,6 @@ void IMB_freeImBuf(ImBuf *ibuf) imb_freerectImBuf(ibuf); imb_freerectfloatImBuf(ibuf); imb_freetilesImBuf(ibuf); - imb_free_bitmap_font(ibuf); IMB_freezbufImBuf(ibuf); IMB_freezbuffloatImBuf(ibuf); freeencodedbufferImBuf(ibuf); @@ -521,7 +513,6 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1) x = ibuf1->x; y = ibuf1->y; - if (ibuf1->flags & IB_fields) y *= 2; ibuf2 = IMB_allocImBuf(x, y, ibuf1->planes, flags); if (ibuf2 == NULL) return NULL; diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 89ae32ee2b3..7f33a95953b 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -114,9 +114,9 @@ static void free_anim_movie(struct anim *UNUSED(anim)) #if defined(_WIN32) -# define PATHSEPARATOR '\\' +# define PATHSEPARATOR '\\' #else -# define PATHSEPARATOR '/' +# define PATHSEPARATOR '/' #endif static int an_stringdec(const char *string, char *head, char *tail, unsigned short *numlen) diff --git a/source/blender/imbuf/intern/cineon/logImageCore.h b/source/blender/imbuf/intern/cineon/logImageCore.h index b6f4fff73f6..f696d1b44d8 100644 --- a/source/blender/imbuf/intern/cineon/logImageCore.h +++ b/source/blender/imbuf/intern/cineon/logImageCore.h @@ -49,7 +49,7 @@ extern "C" { /* There are some differences between DPX and Cineon so we need to know from what type of file the datas come from */ enum format { format_DPX, - format_Cineon + format_Cineon, }; typedef struct LogImageElement { @@ -125,7 +125,7 @@ enum transfer { transfer_NTSC, transfer_PAL, transfer_ZLinear, - transfer_Homogeneous + transfer_Homogeneous, }; /* The SMPTE defines this code: @@ -179,7 +179,7 @@ enum descriptor { descriptor_UserDefined7Elt, descriptor_UserDefined8Elt, /* following descriptors are for internal use only */ - descriptor_YA + descriptor_YA, }; /* int functions return 0 for OK */ diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 86c4156ad8b..887e2390718 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -93,10 +93,12 @@ static int global_tot_display = 0; static int global_tot_view = 0; static int global_tot_looks = 0; -/* Set to ITU-BT.709 / sRGB primaries weight. Brute force stupid, but only - * option with no colormanagement in place. - */ -float imbuf_luma_coefficients[3] = { 0.2126f, 0.7152f, 0.0722f }; +/* Luma coefficients and XYZ to RGB to be initialized by OCIO. */ +float imbuf_luma_coefficients[3] = {0.0f}; +float imbuf_xyz_to_rgb[3][3] = {{0.0f}}; +float imbuf_rgb_to_xyz[3][3] = {{0.0f}}; +static float imbuf_xyz_to_linear_srgb[3][3] = {{0.0f}}; +static float imbuf_linear_srgb_to_xyz[3][3] = {{0.0f}}; /* lock used by pre-cached processors getters, so processor wouldn't * be created several times @@ -130,7 +132,14 @@ static struct global_glsl_state { /* Container for GLSL state needed for OCIO module. */ struct OCIO_GLSLDrawState *ocio_glsl_state; struct OCIO_GLSLDrawState *transform_ocio_glsl_state; -} global_glsl_state; +} global_glsl_state = {NULL}; + +static struct global_color_picking_state { + /* Cached processor for color picking conversion. */ + OCIO_ConstProcessorRcPtr *processor_to; + OCIO_ConstProcessorRcPtr *processor_from; + bool failed; +} global_color_picking_state = {NULL}; /*********************** Color managed cache *************************/ @@ -556,6 +565,10 @@ static void colormanage_load_config(OCIO_ConstConfigRcPtr *config) /* Load luminance coefficients. */ OCIO_configGetDefaultLumaCoefs(config, imbuf_luma_coefficients); + OCIO_configGetXYZtoRGB(config, imbuf_xyz_to_rgb); + invert_m3_m3(imbuf_rgb_to_xyz, imbuf_xyz_to_rgb); + copy_m3_m3(imbuf_xyz_to_linear_srgb, OCIO_XYZ_TO_LINEAR_SRGB); + invert_m3_m3(imbuf_linear_srgb_to_xyz, imbuf_xyz_to_linear_srgb); } static void colormanage_free_config(void) @@ -699,6 +712,15 @@ void colormanagement_exit(void) if (global_glsl_state.transform_ocio_glsl_state) OCIO_freeOGLState(global_glsl_state.transform_ocio_glsl_state); + if (global_color_picking_state.processor_to) + OCIO_processorRelease(global_color_picking_state.processor_to); + + if (global_color_picking_state.processor_from) + OCIO_processorRelease(global_color_picking_state.processor_from); + + memset(&global_glsl_state, 0, sizeof(global_glsl_state)); + memset(&global_color_picking_state, 0, sizeof(global_color_picking_state)); + colormanage_free_config(); } @@ -930,23 +952,33 @@ static OCIO_ConstProcessorRcPtr *display_to_scene_linear_processor(ColorManagedD return (OCIO_ConstProcessorRcPtr *) display->to_scene_linear; } -static void init_default_view_settings(const ColorManagedDisplaySettings *display_settings, - ColorManagedViewSettings *view_settings) +void IMB_colormanagement_init_default_view_settings( + ColorManagedViewSettings *view_settings, + const ColorManagedDisplaySettings *display_settings) { - ColorManagedDisplay *display; - ColorManagedView *default_view = NULL; - - display = colormanage_display_get_named(display_settings->display_device); - - if (display) - default_view = colormanage_view_get_default(display); - - if (default_view) - BLI_strncpy(view_settings->view_transform, default_view->name, sizeof(view_settings->view_transform)); - else + /* First, try use "Default" view transform of the requested device. */ + ColorManagedView *default_view = colormanage_view_get_named_for_display( + display_settings->display_device, "Default"); + /* If that fails, we fall back to the default view transform of the display + * as per OCIO configuration. */ + if (default_view == NULL) { + ColorManagedDisplay *display = colormanage_display_get_named( + display_settings->display_device); + if (display != NULL) { + default_view = colormanage_view_get_default(display); + } + } + if (default_view != NULL) { + BLI_strncpy(view_settings->view_transform, + default_view->name, + sizeof(view_settings->view_transform)); + } + else { view_settings->view_transform[0] = '\0'; - + } + /* TODO(sergey): Find a way to safely/reliable un-hardcode this. */ BLI_strncpy(view_settings->look, "None", sizeof(view_settings->look)); + /* Initialize rest of the settings. */ view_settings->flag = 0; view_settings->gamma = 1.0f; view_settings->exposure = 0.0f; @@ -1901,6 +1933,78 @@ void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, in } } +/* Conversion between color picking role. Typically we would expect such a + * requirements: + * - It is approximately perceptually linear, so that the HSV numbers and + * the HSV cube/circle have an intuitive distribution. + * - It has the same gamut as the scene linear color space. + * - Color picking values 0..1 map to scene linear values in the 0..1 range, + * so that picked albedo values are energy conserving. + */ +void IMB_colormanagement_scene_linear_to_color_picking_v3(float pixel[3]) +{ + if (!global_color_picking_state.processor_to && !global_color_picking_state.failed) { + /* Create processor if none exists. */ + BLI_mutex_lock(&processor_lock); + + if (!global_color_picking_state.processor_to && !global_color_picking_state.failed) { + global_color_picking_state.processor_to = + create_colorspace_transform_processor(global_role_scene_linear, + global_role_color_picking); + + if (!global_color_picking_state.processor_to) { + global_color_picking_state.failed = true; + } + } + + BLI_mutex_unlock(&processor_lock); + } + + if (global_color_picking_state.processor_to) { + OCIO_processorApplyRGB(global_color_picking_state.processor_to, pixel); + } +} + +void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[3]) +{ + if (!global_color_picking_state.processor_from && !global_color_picking_state.failed) { + /* Create processor if none exists. */ + BLI_mutex_lock(&processor_lock); + + if (!global_color_picking_state.processor_from && !global_color_picking_state.failed) { + global_color_picking_state.processor_from = + create_colorspace_transform_processor(global_role_color_picking, + global_role_scene_linear); + + if (!global_color_picking_state.processor_from) { + global_color_picking_state.failed = true; + } + } + + BLI_mutex_unlock(&processor_lock); + } + + if (global_color_picking_state.processor_from) { + OCIO_processorApplyRGB(global_color_picking_state.processor_from, pixel); + } +} + +/* Conversion between sRGB, for rare cases like hex color or copy/pasting + * between UI theme and scene linear colors. */ +void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3]) +{ + mul_m3_v3(imbuf_rgb_to_xyz, pixel); + mul_m3_v3(imbuf_xyz_to_linear_srgb, pixel); + linearrgb_to_srgb_v3_v3(pixel, pixel); +} + +void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[3]) +{ + srgb_to_linearrgb_v3_v3(pixel, pixel); + mul_m3_v3(imbuf_linear_srgb_to_xyz, pixel); + mul_m3_v3(imbuf_xyz_to_rgb, pixel); +} + /* convert pixel from scene linear to display space using default view * used by performance-critical areas such as color-related widgets where we want to reduce * amount of per-widget allocations @@ -2138,11 +2242,10 @@ unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf, const ColorManagedViewSet applied_view_settings = view_settings; } else { - /* if no view settings were specified, use default display transformation - * this happens for images which don't want to be displayed with render settings - */ - - init_default_view_settings(display_settings, &default_view_settings); + /* If no view settings were specified, use default ones, which will + * attempt not to do any extra color correction. */ + IMB_colormanagement_init_default_view_settings( + &default_view_settings, display_settings); applied_view_settings = &default_view_settings; } @@ -2363,6 +2466,12 @@ const char *IMB_colormanagement_display_get_none_name(void) return colormanage_display_get_default_name(); } +const char *IMB_colormanagement_display_get_default_view_transform_name( + struct ColorManagedDisplay *display) +{ + return colormanage_view_get_default_name(display); +} + /*********************** View functions *************************/ const char *colormanage_view_get_default_name(const ColorManagedDisplay *display) @@ -2421,6 +2530,22 @@ ColorManagedView *colormanage_view_get_indexed(int index) return BLI_findlink(&global_views, index - 1); } +ColorManagedView *colormanage_view_get_named_for_display( + const char *display_name, const char *name) +{ + ColorManagedDisplay *display = colormanage_display_get_named(display_name); + if (display == NULL) { + return NULL; + } + LISTBASE_FOREACH(LinkData *, view_link, &display->views) { + ColorManagedView *view = view_link->data; + if (STRCASEEQ(name, view->name)) { + return view; + } + } + return NULL; +} + int IMB_colormanagement_view_get_named_index(const char *name) { ColorManagedView *view = colormanage_view_get_named(name); @@ -2570,7 +2695,7 @@ const char *IMB_colormanagement_colorspace_get_indexed_name(int index) return ""; } -void IMB_colormanagment_colorspace_from_ibuf_ftype(ColorManagedColorspaceSettings *colorspace_settings, ImBuf *ibuf) +void IMB_colormanagement_colorspace_from_ibuf_ftype(ColorManagedColorspaceSettings *colorspace_settings, ImBuf *ibuf) { /* Don't modify non-color data space, it does not change with file type. */ ColorSpace *colorspace = colormanage_colorspace_get_named(colorspace_settings->name); @@ -3138,7 +3263,8 @@ ColormanageProcessor *IMB_colormanagement_display_processor_new(const ColorManag applied_view_settings = view_settings; } else { - init_default_view_settings(display_settings, &default_view_settings); + IMB_colormanagement_init_default_view_settings( + &default_view_settings, display_settings); applied_view_settings = &default_view_settings; } @@ -3435,11 +3561,10 @@ bool IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettin applied_view_settings = view_settings; } else { - /* if no view settings were specified, use default display transformation - * this happens for images which don't want to be displayed with render settings - */ - - init_default_view_settings(display_settings, &default_view_settings); + /* If no view settings were specified, use default ones, which will + * attempt not to do any extra color correction. */ + IMB_colormanagement_init_default_view_settings( + &default_view_settings, display_settings); applied_view_settings = &default_view_settings; } diff --git a/source/blender/imbuf/intern/colormanagement_inline.c b/source/blender/imbuf/intern/colormanagement_inline.c index 4a55f8f86ae..37ef8779f58 100644 --- a/source/blender/imbuf/intern/colormanagement_inline.c +++ b/source/blender/imbuf/intern/colormanagement_inline.c @@ -62,4 +62,14 @@ unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3]) return unit_float_to_uchar_clamp(val); } +void IMB_colormangement_xyz_to_rgb(float rgb[3], const float xyz[3]) +{ + mul_v3_m3v3(rgb, imbuf_xyz_to_rgb, xyz); +} + +void IMB_colormangement_rgb_to_xyz(float xyz[3], const float rgb[3]) +{ + mul_v3_m3v3(xyz, imbuf_rgb_to_xyz, rgb); +} + #endif /* __IMB_COLORMANAGEMENT_INLINE_H__ */ diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index 2b6fa573e63..e6635080163 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -45,62 +45,6 @@ #include "MEM_guardedalloc.h" -/**************************** Interlace/Deinterlace **************************/ - -void IMB_de_interlace(ImBuf *ibuf) -{ - ImBuf *tbuf1, *tbuf2; - - if (ibuf == NULL) return; - if (ibuf->flags & IB_fields) return; - ibuf->flags |= IB_fields; - - if (ibuf->rect) { - /* make copies */ - tbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect); - tbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect); - - ibuf->x *= 2; - IMB_rectcpy(tbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); - IMB_rectcpy(tbuf2, ibuf, 0, 0, tbuf2->x, 0, ibuf->x, ibuf->y); - - ibuf->x /= 2; - IMB_rectcpy(ibuf, tbuf1, 0, 0, 0, 0, tbuf1->x, tbuf1->y); - IMB_rectcpy(ibuf, tbuf2, 0, tbuf2->y, 0, 0, tbuf2->x, tbuf2->y); - - IMB_freeImBuf(tbuf1); - IMB_freeImBuf(tbuf2); - } - ibuf->y /= 2; -} - -void IMB_interlace(ImBuf *ibuf) -{ - ImBuf *tbuf1, *tbuf2; - - if (ibuf == NULL) return; - ibuf->flags &= ~IB_fields; - - ibuf->y *= 2; - - if (ibuf->rect) { - /* make copies */ - tbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect); - tbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect); - - IMB_rectcpy(tbuf1, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); - IMB_rectcpy(tbuf2, ibuf, 0, 0, 0, tbuf2->y, ibuf->x, ibuf->y); - - ibuf->x *= 2; - IMB_rectcpy(ibuf, tbuf1, 0, 0, 0, 0, tbuf1->x, tbuf1->y); - IMB_rectcpy(ibuf, tbuf2, tbuf2->x, 0, 0, 0, tbuf2->x, tbuf2->y); - ibuf->x /= 2; - - IMB_freeImBuf(tbuf1); - IMB_freeImBuf(tbuf2); - } -} - /************************* Floyd-Steinberg dithering *************************/ typedef struct DitherContext { diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index 167f2e4f8e0..56f90d39850 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -1041,7 +1041,7 @@ static IndexBuildContext *index_fallback_create_context(struct anim *anim, IMB_T /* since timecode indices only work with ffmpeg right now, * don't know a sensible fallback here... * - * so no proxies, no game to play... + * so no proxies... */ if (proxy_sizes_in_use == IMB_PROXY_NONE) { return NULL; diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index caf2634bac7..de74a321504 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -119,21 +119,21 @@ static void info_callback(const char *msg, void *client_data) } #endif -# define PIXEL_LOOPER_BEGIN(_rect) \ +#define PIXEL_LOOPER_BEGIN(_rect) \ for (y = h - 1; y != (unsigned int)(-1); y--) { \ for (i = y * w, i_next = (y + 1) * w; \ i < i_next; \ i++, _rect += 4) \ { \ -# define PIXEL_LOOPER_BEGIN_CHANNELS(_rect, _channels) \ +#define PIXEL_LOOPER_BEGIN_CHANNELS(_rect, _channels) \ for (y = h - 1; y != (unsigned int)(-1); y--) { \ for (i = y * w, i_next = (y + 1) * w; \ i < i_next; \ i++, _rect += _channels) \ { \ -# define PIXEL_LOOPER_END \ +#define PIXEL_LOOPER_END \ } \ } (void)0 \ diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 99b3bdb9015..c57281ceb48 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -1,5 +1,5 @@ /* - * ***** BEGIN GPLLICENSE BLOCK ***** + * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/source/blender/imbuf/intern/openexr/openexr_stub.cpp b/source/blender/imbuf/intern/openexr/openexr_stub.cpp index b7138ee464a..2b38cf44e8c 100644 --- a/source/blender/imbuf/intern/openexr/openexr_stub.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_stub.cpp @@ -1,5 +1,5 @@ /* - * ***** BEGIN GPLLICENSE BLOCK ***** + * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c index 0b4490a3beb..0cb1ab4b2c5 100644 --- a/source/blender/imbuf/intern/readimage.c +++ b/source/blender/imbuf/intern/readimage.c @@ -230,7 +230,6 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_S BLI_strncpy(ibuf->cachename, filepath_tx, sizeof(ibuf->cachename)); for (a = 1; a < ibuf->miptot; a++) BLI_strncpy(ibuf->mipmap[a - 1]->cachename, filepath_tx, sizeof(ibuf->cachename)); - if (flags & IB_fields) IMB_de_interlace(ibuf); } close(file); diff --git a/source/blender/imbuf/intern/stereoimbuf.c b/source/blender/imbuf/intern/stereoimbuf.c index a4418443790..61bb8da4f50 100644 --- a/source/blender/imbuf/intern/stereoimbuf.c +++ b/source/blender/imbuf/intern/stereoimbuf.c @@ -43,7 +43,6 @@ #include "MEM_guardedalloc.h" -#include "BLI_threads.h" #include "BLI_utildefines.h" #include "BLI_math.h" @@ -722,7 +721,6 @@ ImBuf *IMB_stereo3d_ImBuf(ImageFormatData *im_format, ImBuf *ibuf_left, ImBuf *i ibuf_stereo->rect_colorspace = ibuf_left->rect_colorspace; ibuf_stereo->float_colorspace = ibuf_left->float_colorspace; - /* copy flags for IB_fields and other settings */ ibuf_stereo->flags = ibuf_left->flags; imb_stereo3d_data_initialize( @@ -1233,7 +1231,6 @@ void IMB_ImBufFromStereo3d( ibuf_left = IMB_allocImBuf(width, height, ibuf_stereo3d->planes, (is_float ? IB_rectfloat : IB_rect)); ibuf_right = IMB_allocImBuf(width, height, ibuf_stereo3d->planes, (is_float ? IB_rectfloat : IB_rect)); - /* copy flags for IB_fields and other settings */ ibuf_left->flags = ibuf_stereo3d->flags; ibuf_right->flags = ibuf_stereo3d->flags; diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 9d2b635bd7b..ed7a9763322 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -44,10 +44,10 @@ #include "BLI_threads.h" #include BLI_SYSTEM_PID_H -#include "BLO_readfile.h" - #include "DNA_space_types.h" /* For FILE_MAX_LIBEXTRA */ +#include "BLO_readfile.h" + #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" #include "IMB_thumbs.h" @@ -61,12 +61,15 @@ #include <stdio.h> #ifdef WIN32 -# include <windows.h> /* need to include windows.h so _WIN32_IE is defined */ + /* Need to include windows.h so _WIN32_IE is defined. */ +# include <windows.h> # ifndef _WIN32_IE -# define _WIN32_IE 0x0400 /* minimal requirements for SHGetSpecialFolderPath on MINGW MSVC has this defined already */ + /* Minimal requirements for SHGetSpecialFolderPath on MINGW MSVC has this defined already. */ +# define _WIN32_IE 0x0400 # endif -# include <shlobj.h> /* for SHGetSpecialFolderPath, has to be done before BLI_winstuff - * because 'near' is disabled through BLI_windstuff */ + /* For SHGetSpecialFolderPath, has to be done before BLI_winstuff + * because 'near' is disabled through BLI_windstuff */ +# include <shlobj.h> # include <direct.h> /* chdir */ # include "BLI_winstuff.h" # include "utfconv.h" diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c index a2363f96bfa..7ffdc0ac388 100644 --- a/source/blender/imbuf/intern/thumbs_blend.c +++ b/source/blender/imbuf/intern/thumbs_blend.c @@ -29,16 +29,14 @@ #include <string.h> #include "BLI_utildefines.h" -#include "BLI_endian_switch.h" -#include "BLI_fileops.h" #include "BLI_linklist.h" +#include "BLI_listbase.h" /* Needed due to import of BLO_readfile.h */ #include "BLO_blend_defs.h" #include "BLO_readfile.h" #include "BKE_idcode.h" #include "BKE_icons.h" -#include "BKE_library.h" #include "BKE_main.h" #include "DNA_ID.h" /* For preview images... */ diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index 6a095b2da1f..3c08955e2b3 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -41,7 +41,6 @@ #include "BLI_utildefines.h" #include "BLI_path_util.h" #include "BLI_fileops.h" -#include "BLI_string.h" #include "imbuf.h" #include "IMB_imbuf_types.h" @@ -51,14 +50,16 @@ #include "IMB_anim.h" #ifdef WITH_FFMPEG -#include "BKE_global.h" /* G.debug */ -#include <libavcodec/avcodec.h> -#include <libavformat/avformat.h> -#include <libavdevice/avdevice.h> -#include <libavutil/log.h> +# include "BLI_string.h" /* BLI_vsnprintf */ -#include "ffmpeg_compat.h" +# include "BKE_global.h" /* G.debug */ +# include <libavcodec/avcodec.h> +# include <libavformat/avformat.h> +# include <libavdevice/avdevice.h> +# include <libavutil/log.h> + +# include "ffmpeg_compat.h" #endif #define UTIL_DEBUG 0 @@ -92,14 +93,14 @@ const char *imb_ext_image[] = { #ifdef WITH_OPENIMAGEIO ".psd", ".pdd", ".psb", #endif - NULL + NULL, }; const char *imb_ext_image_filepath_only[] = { #ifdef WITH_OPENIMAGEIO ".psd", ".pdd", ".psb", #endif - NULL + NULL, }; const char *imb_ext_movie[] = { @@ -131,7 +132,7 @@ const char *imb_ext_movie[] = { ".xvid", ".mxf", ".webm", - NULL + NULL, }; /* sort of wrong being here... */ @@ -150,7 +151,7 @@ const char *imb_ext_audio[] = { ".aiff", ".m4a", ".mka", - NULL + NULL, }; int IMB_ispic_type(const char *name) |