Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2012-09-24 15:56:07 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2012-09-24 15:56:07 +0400
commit9e3e12fa4e2b9038314e3f2f690a908042b835fa (patch)
tree4f5178f7e7ff7b8ff6a6ebd74459621f146adaf2 /source/blender/imbuf
parent5a5b37a4fadee5ce2c44b097a50986e0b70ca898 (diff)
Proper fix for #32626: TIFF renders are limited to 8 bit even when we choose 16.
Color management would be applied on both of float and byte buffers on image save in cases if file format doesn't require linear float buffer and if image is saving as render result. This solves both initial report issue and TODO marked in previous fix. Also de-duplicated image buffer color managing code and gave some more meaningful names for few functions. Also wrote documentation around this function, so current assumptions about spaces should be clear enough. Made regression tests by saving EXR/PNG images to all supported format and rendering OpenGL/Normal animation, in all cases seems everything is fine, but more tests for sure would be welcome.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_colormanagement.h9
-rw-r--r--source/blender/imbuf/intern/colormanagement.c144
-rw-r--r--source/blender/imbuf/intern/jp2.c51
-rw-r--r--source/blender/imbuf/intern/tiff.c10
4 files changed, 157 insertions, 57 deletions
diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h
index 5d0ab5e57d4..7126d1bcc8b 100644
--- a/source/blender/imbuf/IMB_colormanagement.h
+++ b/source/blender/imbuf/IMB_colormanagement.h
@@ -45,6 +45,7 @@ struct rcti;
struct PartialBufferUpdateContext;
struct wmWindow;
struct Scene;
+struct ImageFormatData;
struct ColorSpace;
struct ColorManagedDisplay;
@@ -90,15 +91,17 @@ void IMB_colormanagement_imbuf_assign_float_space(struct ImBuf *ibuf, struct Col
void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
const struct ColorManagedDisplaySettings *display_settings);
+struct ImBuf *IMB_colormanagement_imbuf_for_write(struct ImBuf *ibuf, int save_as_render, int allocate_result,
+ const struct ColorManagedViewSettings *view_settings,
+ const struct ColorManagedDisplaySettings *display_settings,
+ struct ImageFormatData *image_format_data);
+
/* ** Public display buffers interfaces ** */
unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
-void IMB_display_buffer_to_imbuf_rect(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
- const struct ColorManagedDisplaySettings *display_settings);
-
void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *linear_buffer, int width, int height,
int channels, const struct ColorManagedViewSettings *view_settings,
const struct ColorManagedDisplaySettings *display_settings, int predivide);
diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c
index 11dce3087c6..18a03c859e9 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -59,6 +59,7 @@
#include "BKE_colortools.h"
#include "BKE_context.h"
+#include "BKE_image.h"
#include "BKE_utildefines.h"
#include "BKE_main.h"
@@ -632,6 +633,37 @@ static void display_transform_get_from_ctx(const bContext *C, ColorManagedViewSe
}
}
+static const char *display_transform_get_colorspace_name(const ColorManagedViewSettings *view_settings,
+ const ColorManagedDisplaySettings *display_settings)
+{
+ ConstConfigRcPtr *config = OCIO_getCurrentConfig();
+
+ if (config) {
+ const char *display = display_settings->display_device;
+ const char *view = view_settings->view_transform;
+ const char *colorspace_name;
+
+ colorspace_name = OCIO_configGetDisplayColorSpaceName(config, display, view);
+
+ OCIO_configRelease(config);
+
+ return colorspace_name;
+ }
+
+ return NULL;
+}
+
+static ColorSpace *display_transform_get_colorspace(const ColorManagedViewSettings *view_settings,
+ const ColorManagedDisplaySettings *display_settings)
+{
+ const char *colorspace_name = display_transform_get_colorspace_name(view_settings, display_settings);
+
+ if (colorspace_name)
+ return colormanage_colorspace_get_named(colorspace_name);
+
+ return NULL;
+}
+
static ConstProcessorRcPtr *create_display_buffer_processor(const char *view_transform, const char *display,
float exposure, float gamma)
{
@@ -1310,19 +1342,11 @@ static void colormanage_display_buffer_process_ex(ImBuf *ibuf, float *display_bu
view_settings->exposure == 0.0f &&
view_settings->gamma == 1.0f)
{
- ConstConfigRcPtr *config = OCIO_getCurrentConfig();
+ const char *from_colorspace = ibuf->rect_colorspace->name;
+ const char *to_colorspace = display_transform_get_colorspace_name(view_settings, display_settings);
- if (config) {
- const char *display = display_settings->display_device;
- const char *view = view_settings->view_transform;
- const char *from_colorspace = ibuf->rect_colorspace->name;
- const char *to_colorspace = OCIO_configGetDisplayColorSpaceName(config, display, view);
-
- if (!strcmp(from_colorspace, to_colorspace))
- skip_transform = TRUE;
-
- OCIO_configRelease(config);
- }
+ if (to_colorspace && !strcmp(from_colorspace, to_colorspace))
+ skip_transform = TRUE;
}
}
@@ -1612,22 +1636,90 @@ void IMB_colormanagement_imbuf_assign_float_space(ImBuf *ibuf, ColorManagedColor
ibuf->float_colorspace = colormanage_colorspace_get_named(colorspace_settings->name);
}
-void IMB_colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
- const ColorManagedDisplaySettings *display_settings)
+static void colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
+ const ColorManagedDisplaySettings *display_settings, int make_byte)
{
- /* OCIO_TODO: byte buffer management is not supported here yet */
- if (!ibuf->rect_float)
- return;
+ if (!ibuf->rect && make_byte)
+ imb_addrectImBuf(ibuf);
if (global_tot_display == 0 || global_tot_view == 0) {
IMB_buffer_float_from_float(ibuf->rect_float, ibuf->rect_float, ibuf->channels, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB,
ibuf->flags & IB_cm_predivide, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
}
else {
- colormanage_display_buffer_process_ex(ibuf, ibuf->rect_float, NULL, view_settings, display_settings);
+ colormanage_display_buffer_process_ex(ibuf, ibuf->rect_float, (unsigned char *)ibuf->rect,
+ view_settings, display_settings);
}
}
+void IMB_colormanagement_imbuf_make_display_space(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
+ const ColorManagedDisplaySettings *display_settings)
+{
+ colormanagement_imbuf_make_display_space(ibuf, view_settings, display_settings, FALSE);
+}
+
+/* prepare image buffer to be saved on disk, applying color management if needed
+ * color management would be applied if image is saving as render result and if
+ * file format is not expecting float buffer to be in linear space (currently
+ * JPEG2000 and TIFF are such formats -- they're storing image as float but
+ * file itself stores applied color space).
+ *
+ * Both byte and float buffers would contain applied color space, and result's
+ * float_colorspace would be set to display color space. This should be checked
+ * in image format write callback and if float_colorspace is not NULL, no color
+ * space transformation should be applied on this buffer.
+ */
+ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, int save_as_render, int allocate_result, const ColorManagedViewSettings *view_settings,
+ const ColorManagedDisplaySettings *display_settings, ImageFormatData *image_format_data)
+{
+ ImBuf *colormanaged_ibuf = ibuf;
+ int do_colormanagement;
+ int is_movie = BKE_imtype_is_movie(image_format_data->imtype);
+ int requires_linear_float = BKE_imtype_requires_linear_float(image_format_data->imtype);
+
+ do_colormanagement = save_as_render && (is_movie || !requires_linear_float);
+
+ if (do_colormanagement) {
+ int make_byte = FALSE;
+ ImFileType *type;
+
+ if (allocate_result)
+ colormanaged_ibuf = IMB_dupImBuf(ibuf);
+
+ /* if file format isn't able to handle float buffer itself,
+ * we need to allocate byte buffer and store color managed
+ * image there
+ */
+ for (type = IMB_FILE_TYPES; type->is_a; type++) {
+ if (type->save && type->ftype(type, ibuf)) {
+ if ((type->flag & IM_FTYPE_FLOAT) == 0)
+ make_byte = TRUE;
+
+ break;
+ }
+ }
+
+ /* perform color space conversions */
+ colormanagement_imbuf_make_display_space(colormanaged_ibuf, view_settings, display_settings, make_byte);
+
+ if (colormanaged_ibuf->rect_float) {
+ if (make_byte && allocate_result) {
+ /* save a bit of memory */
+ imb_freerectfloatImBuf(colormanaged_ibuf);
+ }
+ else {
+ /* float buffer isn't linear anymore,
+ * image format write callback should check for this flag and assume
+ * no space conversion should happen if ibuf->float_colorspace != NULL
+ */
+ colormanaged_ibuf->float_colorspace = display_transform_get_colorspace(view_settings, display_settings);
+ }
+ }
+ }
+
+ return colormanaged_ibuf;
+}
+
static void imbuf_verify_float(ImBuf *ibuf)
{
/* multiple threads could request for display buffer at once and in case
@@ -1737,22 +1829,6 @@ unsigned char *IMB_display_buffer_acquire_ctx(const bContext *C, ImBuf *ibuf, vo
return IMB_display_buffer_acquire(ibuf, view_settings, display_settings, cache_handle);
}
-/* covert float buffer to display space and store it in image buffer's byte array */
-void IMB_display_buffer_to_imbuf_rect(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
- const ColorManagedDisplaySettings *display_settings)
-{
- if (global_tot_display == 0 || global_tot_view == 0) {
- imbuf_verify_float(ibuf);
- }
- else {
- if (!ibuf->rect) {
- imb_addrectImBuf(ibuf);
- }
-
- colormanage_display_buffer_process(ibuf, (unsigned char *) ibuf->rect, view_settings, display_settings);
- }
-}
-
void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *linear_buffer, int width, int height,
int channels, const ColorManagedViewSettings *view_settings,
const ColorManagedDisplaySettings *display_settings, int predivide)
diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c
index dd559c55402..01523463712 100644
--- a/source/blender/imbuf/intern/jp2.c
+++ b/source/blender/imbuf/intern/jp2.c
@@ -544,6 +544,10 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima
parameters->cp_disto_alloc = 1;
}
+static float channel_colormanage_noop(float value)
+{
+ return value;
+}
static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
{
@@ -560,9 +564,20 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
opj_image_cmptparm_t cmptparm[4]; /* maximum of 4 components */
opj_image_t *image = NULL;
+ float (*chanel_colormanage_cb)(float);
+
img_fol_t img_fol; /* only needed for cinema presets */
memset(&img_fol, 0, sizeof(img_fol_t));
+ if (ibuf->float_colorspace) {
+ /* float buffer was managed already, no need in color space conversion */
+ chanel_colormanage_cb = channel_colormanage_noop;
+ }
+ else {
+ /* standard linear-to-srgb conversion if float buffer wasn't managed */
+ chanel_colormanage_cb = linearrgb_to_srgb;
+ }
+
if (ibuf->ftype & JP2_CINE) {
if (ibuf->x == 4096 || ibuf->y == 2160)
@@ -649,9 +664,9 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
if (numcomps == 4) {
PIXEL_LOOPER_BEGIN(rect_float)
{
- r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[0]));
- g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[1]));
- b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[2]));
+ r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(chanel_colormanage_cb(rect_float[0]));
+ g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(chanel_colormanage_cb(rect_float[1]));
+ b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(chanel_colormanage_cb(rect_float[2]));
a[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]);
}
PIXEL_LOOPER_END;
@@ -659,9 +674,9 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
else {
PIXEL_LOOPER_BEGIN(rect_float)
{
- r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[0]));
- g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[1]));
- b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(linearrgb_to_srgb(rect_float[2]));
+ r[i] = DOWNSAMPLE_FLOAT_TO_8BIT(chanel_colormanage_cb(rect_float[0]));
+ g[i] = DOWNSAMPLE_FLOAT_TO_8BIT(chanel_colormanage_cb(rect_float[1]));
+ b[i] = DOWNSAMPLE_FLOAT_TO_8BIT(chanel_colormanage_cb(rect_float[2]));
}
PIXEL_LOOPER_END;
}
@@ -671,9 +686,9 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
if (numcomps == 4) {
PIXEL_LOOPER_BEGIN(rect_float)
{
- r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[0]));
- g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[1]));
- b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[2]));
+ r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(chanel_colormanage_cb(rect_float[0]));
+ g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(chanel_colormanage_cb(rect_float[1]));
+ b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(chanel_colormanage_cb(rect_float[2]));
a[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]);
}
PIXEL_LOOPER_END;
@@ -681,9 +696,9 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
else {
PIXEL_LOOPER_BEGIN(rect_float)
{
- r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[0]));
- g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[1]));
- b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(linearrgb_to_srgb(rect_float[2]));
+ r[i] = DOWNSAMPLE_FLOAT_TO_12BIT(chanel_colormanage_cb(rect_float[0]));
+ g[i] = DOWNSAMPLE_FLOAT_TO_12BIT(chanel_colormanage_cb(rect_float[1]));
+ b[i] = DOWNSAMPLE_FLOAT_TO_12BIT(chanel_colormanage_cb(rect_float[2]));
}
PIXEL_LOOPER_END;
}
@@ -693,9 +708,9 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
if (numcomps == 4) {
PIXEL_LOOPER_BEGIN(rect_float)
{
- r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[0]));
- g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[1]));
- b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[2]));
+ r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(chanel_colormanage_cb(rect_float[0]));
+ g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(chanel_colormanage_cb(rect_float[1]));
+ b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(chanel_colormanage_cb(rect_float[2]));
a[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]);
}
PIXEL_LOOPER_END;
@@ -703,9 +718,9 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
else {
PIXEL_LOOPER_BEGIN(rect_float)
{
- r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[0]));
- g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[1]));
- b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(linearrgb_to_srgb(rect_float[2]));
+ r[i] = DOWNSAMPLE_FLOAT_TO_16BIT(chanel_colormanage_cb(rect_float[0]));
+ g[i] = DOWNSAMPLE_FLOAT_TO_16BIT(chanel_colormanage_cb(rect_float[1]));
+ b[i] = DOWNSAMPLE_FLOAT_TO_16BIT(chanel_colormanage_cb(rect_float[2]));
}
PIXEL_LOOPER_END;
}
diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c
index 2cb30b84a09..e09fdf259c6 100644
--- a/source/blender/imbuf/intern/tiff.c
+++ b/source/blender/imbuf/intern/tiff.c
@@ -790,8 +790,14 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags)
/* convert from float source */
float rgb[4];
- /* TODO - support color management */
- linearrgb_to_srgb_v3_v3(rgb, &fromf[from_i]);
+ if (ibuf->float_colorspace) {
+ /* float buffer was managed already, no need in color space conversion */
+ copy_v3_v3(rgb, &fromf[from_i]);
+ }
+ else {
+ /* standard linear-to-srgb conversion if float buffer wasn't managed */
+ linearrgb_to_srgb_v3_v3(rgb, &fromf[from_i]);
+ }
rgb[3] = fromf[from_i + 3];