Color Management: port image stamp to new color management system
Use the same approach as interface does by using default view which is supposed to be invertible to convert color from display space to scene linear.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#define __BLF_API_H__
|
||||
|
||||
struct rctf;
|
||||
struct ColorManagedDisplay;
|
||||
|
||||
int BLF_init(int points, int dpi);
|
||||
void BLF_exit(void);
|
||||
@@ -151,7 +152,7 @@ void BLF_shadow_offset(int fontid, int x, int y);
|
||||
*
|
||||
* BLF_buffer(NULL, NULL, 0, 0, 0, FALSE);
|
||||
*/
|
||||
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, int do_color_management);
|
||||
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, struct ColorManagedDisplay *display);
|
||||
|
||||
/* Set the color to be used for text. */
|
||||
void BLF_buffer_col(int fontid, float r, float g, float b, float a);
|
||||
|
||||
@@ -27,6 +27,7 @@ set(INC
|
||||
../blenlib
|
||||
../editors/include
|
||||
../makesdna
|
||||
../imbuf
|
||||
../../../intern/guardedalloc
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ Import ('env')
|
||||
|
||||
sources = env.Glob('intern/*.c')
|
||||
|
||||
incs = '. intern #/intern/guardedalloc ../blenkernel ../blenlib ../makesdna ../editors/include'
|
||||
incs = '. intern #/intern/guardedalloc ../blenkernel ../blenlib ../makesdna ,,/imbuf ../editors/include'
|
||||
incs += ' #/extern/glew/include'
|
||||
incs += ' ' + env['BF_FREETYPE_INC']
|
||||
incs += ' ' + env['BF_GETTEXT_INC']
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
#include "blf_internal_types.h"
|
||||
#include "blf_internal.h"
|
||||
|
||||
|
||||
/* Max number of font in memory.
|
||||
* Take care that now every font have a glyph cache per size/dpi,
|
||||
* so we don't need load the same font with different size, just
|
||||
@@ -746,7 +745,7 @@ void BLF_shadow_offset(int fontid, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, int do_color_management)
|
||||
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, struct ColorManagedDisplay *display)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
|
||||
@@ -756,7 +755,7 @@ void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int
|
||||
font->buf_info.w = w;
|
||||
font->buf_info.h = h;
|
||||
font->buf_info.ch = nch;
|
||||
font->buf_info.do_color_management = do_color_management;
|
||||
font->buf_info.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
#include "BIF_gl.h"
|
||||
#include "BLF_api.h"
|
||||
|
||||
#include "IMB_colormanagement.h"
|
||||
|
||||
#include "blf_internal_types.h"
|
||||
#include "blf_internal.h"
|
||||
|
||||
@@ -245,11 +247,12 @@ void blf_font_buffer(FontBLF *font, const char *str)
|
||||
blf_font_ensure_ascii_table(font);
|
||||
|
||||
/* another buffer specific call for color conversion */
|
||||
if (buf_info->do_color_management) {
|
||||
srgb_to_linearrgb_v4(b_col_float, buf_info->col);
|
||||
if (buf_info->display) {
|
||||
copy_v4_v4(b_col_float, buf_info->col);
|
||||
IMB_colormanagement_display_to_scene_linear_v3(b_col_float, buf_info->display);
|
||||
}
|
||||
else {
|
||||
copy_v4_v4(b_col_float, buf_info->col);
|
||||
srgb_to_linearrgb_v4(b_col_float, buf_info->col);
|
||||
}
|
||||
|
||||
while (str[i]) {
|
||||
|
||||
@@ -145,8 +145,8 @@ typedef struct FontBufInfoBLF {
|
||||
/* number of channels. */
|
||||
int ch;
|
||||
|
||||
/* is the float buffer linear */
|
||||
int do_color_management;
|
||||
/* display device used for color management */
|
||||
struct ColorManagedDisplay *display;
|
||||
|
||||
/* and the color, the alphas is get from the glyph!
|
||||
* color is srgb space */
|
||||
|
||||
@@ -1505,19 +1505,21 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
int x, y, y_ofs;
|
||||
float h_fixed;
|
||||
const int mono = blf_mono_font_render; // XXX
|
||||
struct ColorManagedDisplay *display;
|
||||
const char *display_device;
|
||||
|
||||
/* this could be an argument if we want to operate on non linear float imbuf's
|
||||
* for now though this is only used for renders which use scene settings */
|
||||
|
||||
/* OCIO_TODO: for now harcode sRGB to linearrgb conversion, need to be fixed ASAP */
|
||||
const int do_color_management = TRUE;
|
||||
|
||||
#define BUFF_MARGIN_X 2
|
||||
#define BUFF_MARGIN_Y 1
|
||||
|
||||
if (!rect && !rectf)
|
||||
return;
|
||||
|
||||
display_device = scene->display_settings.display_device;
|
||||
display = IMB_colormanagement_display_get_named(display_device);
|
||||
|
||||
stampdata(scene, camera, &stamp_data, 1);
|
||||
|
||||
/* TODO, do_versions */
|
||||
@@ -1527,7 +1529,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
/* set before return */
|
||||
BLF_size(mono, scene->r.stamp_font_id, 72);
|
||||
|
||||
BLF_buffer(mono, rectf, rect, width, height, channels, do_color_management);
|
||||
BLF_buffer(mono, rectf, rect, width, height, channels, display);
|
||||
BLF_buffer_col(mono, scene->r.fg_stamp[0], scene->r.fg_stamp[1], scene->r.fg_stamp[2], 1.0);
|
||||
pad = BLF_width_max(mono);
|
||||
|
||||
@@ -1544,7 +1546,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
y -= h;
|
||||
|
||||
/* also a little of space to the background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and draw the text. */
|
||||
@@ -1561,7 +1563,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
y -= h;
|
||||
|
||||
/* and space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
@@ -1577,7 +1579,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
y -= h;
|
||||
|
||||
/* and space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
@@ -1593,7 +1595,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
y -= h;
|
||||
|
||||
/* and space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
@@ -1608,7 +1610,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
BLF_width_and_height(mono, stamp_data.marker, &w, &h); h = h_fixed;
|
||||
|
||||
/* extra space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and pad the text. */
|
||||
@@ -1624,7 +1626,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
BLF_width_and_height(mono, stamp_data.time, &w, &h); h = h_fixed;
|
||||
|
||||
/* extra space for background */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
x - BUFF_MARGIN_X, y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and pad the text. */
|
||||
@@ -1639,7 +1641,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
BLF_width_and_height(mono, stamp_data.frame, &w, &h); h = h_fixed;
|
||||
|
||||
/* extra space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and pad the text. */
|
||||
@@ -1654,7 +1656,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
BLF_width_and_height(mono, stamp_data.camera, &w, &h); h = h_fixed;
|
||||
|
||||
/* extra space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
BLF_draw_buffer(mono, stamp_data.camera);
|
||||
@@ -1667,7 +1669,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h = h_fixed;
|
||||
|
||||
/* extra space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
BLF_draw_buffer(mono, stamp_data.cameralens);
|
||||
@@ -1680,7 +1682,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
x = width - w - 2;
|
||||
|
||||
/* extra space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and pad the text. */
|
||||
@@ -1696,7 +1698,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
y = height - h;
|
||||
|
||||
/* extra space for background. */
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
|
||||
@@ -289,7 +289,11 @@ static void checker_board_text(unsigned char *rect, float *rect_float, int width
|
||||
|
||||
BLF_size(mono, 54, 72); /* hard coded size! */
|
||||
|
||||
BLF_buffer(mono, rect_float, rect, width, height, 4, TRUE);
|
||||
/* OCIO_TODO: using NULL as display will assume using sRGB display
|
||||
* this is correct since currently generated images are assumed to be in sRGB space,
|
||||
* but this would probably needed to be fixed in some way
|
||||
*/
|
||||
BLF_buffer(mono, rect_float, rect, width, height, 4, NULL);
|
||||
|
||||
for (y = 0; y < height; y += step) {
|
||||
text[1] = '1';
|
||||
|
||||
@@ -82,6 +82,8 @@ struct ImBuf;
|
||||
*/
|
||||
struct anim;
|
||||
|
||||
struct ColorManagedDisplay;
|
||||
|
||||
/**
|
||||
*
|
||||
* \attention Defined in allocimbuf.c
|
||||
@@ -478,12 +480,12 @@ void IMB_freezbuffloatImBuf(struct ImBuf *ibuf);
|
||||
* \attention Defined in rectop.c
|
||||
*/
|
||||
void IMB_rectfill(struct ImBuf *drect, const float col[4]);
|
||||
void IMB_rectfill_area(struct ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2);
|
||||
void IMB_rectfill_area(struct ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2, struct ColorManagedDisplay *display);
|
||||
void IMB_rectfill_alpha(struct ImBuf *ibuf, const float value);
|
||||
|
||||
/* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */
|
||||
void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
|
||||
const float col[4], const int do_color_management,
|
||||
const float col[4], struct ColorManagedDisplay *display,
|
||||
int x1, int y1, int x2, int y2);
|
||||
|
||||
/* defined in metadata.c */
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "IMB_imbuf.h"
|
||||
|
||||
#include "IMB_allocimbuf.h"
|
||||
#include "IMB_colormanagement.h"
|
||||
|
||||
|
||||
/* blend modes */
|
||||
@@ -486,7 +487,7 @@ void IMB_rectfill(struct ImBuf *drect, const float col[4])
|
||||
|
||||
|
||||
void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
|
||||
const float col[4], const int do_color_management,
|
||||
const float col[4], struct ColorManagedDisplay *display,
|
||||
int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int i, j;
|
||||
@@ -553,11 +554,12 @@ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
|
||||
float col_conv[4];
|
||||
float *pixel;
|
||||
|
||||
if (do_color_management) {
|
||||
srgb_to_linearrgb_v4(col_conv, col);
|
||||
if (display) {
|
||||
copy_v4_v4(col_conv, col);
|
||||
IMB_colormanagement_display_to_scene_linear_v3(col_conv, display);
|
||||
}
|
||||
else {
|
||||
copy_v4_v4(col_conv, col);
|
||||
srgb_to_linearrgb_v4(col_conv, col);
|
||||
}
|
||||
|
||||
for (j = 0; j < y2 - y1; j++) {
|
||||
@@ -581,12 +583,10 @@ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
|
||||
}
|
||||
}
|
||||
|
||||
void IMB_rectfill_area(struct ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2)
|
||||
void IMB_rectfill_area(struct ImBuf *ibuf, const float col[4], int x1, int y1, int x2, int y2, struct ColorManagedDisplay *display)
|
||||
{
|
||||
int do_color_management;
|
||||
if (!ibuf) return;
|
||||
do_color_management = (ibuf->profile == IB_PROFILE_LINEAR_RGB);
|
||||
buf_rectfill_area((unsigned char *) ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, col, do_color_management,
|
||||
buf_rectfill_area((unsigned char *) ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, col, display,
|
||||
x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user