forked from bartvdbraak/blender
fix [#32126] STAMP: Setting a background color causes color flicker
when rendering the sequencer can output float or char buffers which stamp wasn't accounting for.
This commit is contained in:
parent
866f986898
commit
10f631094c
@ -145,13 +145,13 @@ void BLF_shadow_offset(int fontid, int x, int y);
|
||||
/* Set the buffer, size and number of channels to draw, one thing to take care is call
|
||||
* this function with NULL pointer when we finish, for example:
|
||||
*
|
||||
* BLF_buffer(my_fbuf, my_cbuf, 100, 100, 4);
|
||||
* BLF_buffer(my_fbuf, my_cbuf, 100, 100, 4, TRUE);
|
||||
*
|
||||
* ... set color, position and draw ...
|
||||
*
|
||||
* BLF_buffer(NULL, NULL, 0, 0, 0);
|
||||
* 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 is_linear);
|
||||
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, int do_color_management);
|
||||
|
||||
/* Set the color to be used for text. */
|
||||
void BLF_buffer_col(int fontid, float r, float g, float b, float a);
|
||||
|
@ -746,7 +746,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 is_linear)
|
||||
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, int do_color_management)
|
||||
{
|
||||
FontBLF *font = BLF_get(fontid);
|
||||
|
||||
@ -756,7 +756,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.is_linear = is_linear;
|
||||
font->buf_info.do_color_management = do_color_management;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ void blf_font_buffer(FontBLF *font, const char *str)
|
||||
blf_font_ensure_ascii_table(font);
|
||||
|
||||
/* another buffer spesific call for color conversion */
|
||||
if (buf_info->is_linear) {
|
||||
if (buf_info->do_color_management) {
|
||||
srgb_to_linearrgb_v4(b_col_float, buf_info->col);
|
||||
}
|
||||
else {
|
||||
@ -304,9 +304,9 @@ void blf_font_buffer(FontBLF *font, const char *str)
|
||||
fbuf[3] = (alphatest = (fbuf[3] + (b_col_float[3]))) < 1.0f ? alphatest : 1.0f;
|
||||
}
|
||||
else {
|
||||
fbuf[0] = (b_col_float[0] * a) + (fbuf[0] * (1 - a));
|
||||
fbuf[1] = (b_col_float[1] * a) + (fbuf[1] * (1 - a));
|
||||
fbuf[2] = (b_col_float[2] * a) + (fbuf[2] * (1 - a));
|
||||
fbuf[0] = (b_col_float[0] * a) + (fbuf[0] * (1.0f - a));
|
||||
fbuf[1] = (b_col_float[1] * a) + (fbuf[1] * (1.0f - a));
|
||||
fbuf[2] = (b_col_float[2] * a) + (fbuf[2] * (1.0f - a));
|
||||
fbuf[3] = (alphatest = (fbuf[3] + (b_col_float[3] * a))) < 1.0f ? alphatest : 1.0f;
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ typedef struct FontBufInfoBLF {
|
||||
int ch;
|
||||
|
||||
/* is the float buffer linear */
|
||||
int is_linear;
|
||||
int do_color_management;
|
||||
|
||||
/* and the color, the alphas is get from the glyph!
|
||||
* color is srgb space */
|
||||
|
@ -1476,6 +1476,10 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
|
||||
float h_fixed;
|
||||
const int mono = blf_mono_font_render; // XXX
|
||||
|
||||
/* 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 */
|
||||
const int do_color_management = (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) != 0;
|
||||
|
||||
#define BUFF_MARGIN_X 2
|
||||
#define BUFF_MARGIN_Y 1
|
||||
|
||||
@ -1491,7 +1495,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, (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) != 0);
|
||||
BLF_buffer(mono, rectf, rect, width, height, channels, do_color_management);
|
||||
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);
|
||||
|
||||
@ -1508,7 +1512,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and draw the text. */
|
||||
@ -1525,7 +1529,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
@ -1541,7 +1545,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
@ -1557,7 +1561,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
0, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
BLF_position(mono, x, y + y_ofs, 0.0);
|
||||
@ -1572,7 +1576,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and pad the text. */
|
||||
@ -1588,7 +1592,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
x - BUFF_MARGIN_X, y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and pad the text. */
|
||||
@ -1603,7 +1607,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and pad the text. */
|
||||
@ -1618,7 +1622,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
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);
|
||||
@ -1631,7 +1635,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
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);
|
||||
@ -1644,7 +1648,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
x - BUFF_MARGIN_X, y - BUFF_MARGIN_Y, x + w + BUFF_MARGIN_X, y + h + BUFF_MARGIN_Y);
|
||||
|
||||
/* and pad the text. */
|
||||
@ -1660,7 +1664,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,
|
||||
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, do_color_management,
|
||||
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);
|
||||
|
@ -482,7 +482,9 @@ void IMB_rectfill_area(struct ImBuf *ibuf, const float col[4], int x1, int y1, i
|
||||
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], int x1, int y1, int x2, int y2);
|
||||
void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
|
||||
const float col[4], const int do_color_management,
|
||||
int x1, int y1, int x2, int y2);
|
||||
|
||||
/* defined in metadata.c */
|
||||
int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *field);
|
||||
|
@ -31,9 +31,11 @@
|
||||
* \ingroup imbuf
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_math_color.h"
|
||||
#include "BLI_math_vector.h"
|
||||
|
||||
#include "imbuf.h"
|
||||
#include "IMB_imbuf_types.h"
|
||||
@ -481,7 +483,8 @@ 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],
|
||||
void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
|
||||
const float col[4], const int do_color_management,
|
||||
int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int i, j;
|
||||
@ -545,21 +548,30 @@ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height,
|
||||
}
|
||||
|
||||
if (rectf) {
|
||||
float col_conv[4];
|
||||
float *pixel;
|
||||
|
||||
if (do_color_management) {
|
||||
srgb_to_linearrgb_v4(col_conv, col);
|
||||
}
|
||||
else {
|
||||
copy_v4_v4(col_conv, col);
|
||||
}
|
||||
|
||||
for (j = 0; j < y2 - y1; j++) {
|
||||
for (i = 0; i < x2 - x1; i++) {
|
||||
pixel = rectf + 4 * (((y1 + j) * width) + (x1 + i));
|
||||
if (a == 1.0f) {
|
||||
pixel[0] = col[0];
|
||||
pixel[1] = col[1];
|
||||
pixel[2] = col[2];
|
||||
pixel[0] = col_conv[0];
|
||||
pixel[1] = col_conv[1];
|
||||
pixel[2] = col_conv[2];
|
||||
pixel[3] = 1.0f;
|
||||
}
|
||||
else {
|
||||
float alphatest;
|
||||
pixel[0] = (col[0] * a) + (pixel[0] * ai);
|
||||
pixel[1] = (col[1] * a) + (pixel[1] * ai);
|
||||
pixel[2] = (col[2] * a) + (pixel[2] * ai);
|
||||
pixel[0] = (col_conv[0] * a) + (pixel[0] * ai);
|
||||
pixel[1] = (col_conv[1] * a) + (pixel[1] * ai);
|
||||
pixel[2] = (col_conv[2] * a) + (pixel[2] * ai);
|
||||
pixel[3] = (alphatest = (pixel[3] + a)) < 1.0f ? alphatest : 1.0f;
|
||||
}
|
||||
}
|
||||
@ -569,8 +581,11 @@ 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)
|
||||
{
|
||||
int do_color_management;
|
||||
if (!ibuf) return;
|
||||
buf_rectfill_area((unsigned char *) ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, col, x1, y1, x2, y2);
|
||||
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,
|
||||
x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user