2011-10-10 09:38:02 +00:00
|
|
|
/*
|
2010-03-21 00:25:52 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
#include <math.h>
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
#include <stdlib.h>
|
2011-02-13 10:52:18 +00:00
|
|
|
|
2011-12-16 09:25:07 +00:00
|
|
|
#include "BLI_math_base.h"
|
2013-04-27 12:51:23 +00:00
|
|
|
#include "BLI_math_color.h"
|
|
|
|
#include "BLI_math_vector.h"
|
2013-03-09 05:35:49 +00:00
|
|
|
|
|
|
|
#include "BKE_image.h"
|
|
|
|
|
2016-05-05 12:02:40 +02:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
#include "BLF_api.h"
|
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
typedef struct FillColorThreadData {
|
|
|
|
unsigned char *rect;
|
|
|
|
float *rect_float;
|
|
|
|
int width;
|
|
|
|
float color[4];
|
|
|
|
} FillColorThreadData;
|
|
|
|
|
|
|
|
static void image_buf_fill_color_slice(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width, int height,
|
|
|
|
const float color[4])
|
2010-03-21 00:25:52 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* blank image */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (rect_float) {
|
2016-05-05 12:02:40 +02:00
|
|
|
float linear_color[4];
|
|
|
|
srgb_to_linearrgb_v4(linear_color, color);
|
2012-05-06 17:22:54 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++) {
|
2016-05-05 12:02:40 +02:00
|
|
|
copy_v4_v4(rect_float, linear_color);
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float += 4;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (rect) {
|
2012-01-19 10:04:51 +00:00
|
|
|
unsigned char ccol[4];
|
|
|
|
rgba_float_to_uchar(ccol, color);
|
2012-05-06 17:22:54 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
rect[0] = ccol[0];
|
|
|
|
rect[1] = ccol[1];
|
|
|
|
rect[2] = ccol[2];
|
|
|
|
rect[3] = ccol[3];
|
|
|
|
rect += 4;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
static void image_buf_fill_color_thread_do(void *data_v,
|
|
|
|
int start_scanline,
|
|
|
|
int num_scanlines)
|
|
|
|
{
|
|
|
|
FillColorThreadData *data = (FillColorThreadData *)data_v;
|
|
|
|
size_t offset = ((size_t)start_scanline) * data->width * 4;
|
|
|
|
unsigned char *rect = (data->rect != NULL) ? (data->rect + offset) : NULL;
|
|
|
|
float *rect_float = (data->rect_float != NULL) ? (data->rect_float + offset) : NULL;
|
|
|
|
image_buf_fill_color_slice(rect,
|
|
|
|
rect_float,
|
|
|
|
data->width,
|
|
|
|
num_scanlines,
|
|
|
|
data->color);
|
|
|
|
}
|
2010-03-21 00:25:52 +00:00
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
void BKE_image_buf_fill_color(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width, int height,
|
|
|
|
const float color[4])
|
2010-03-21 00:25:52 +00:00
|
|
|
{
|
2016-05-05 23:33:40 +02:00
|
|
|
if (((size_t)width) * height < 64 * 64) {
|
|
|
|
image_buf_fill_color_slice(rect, rect_float, width, height, color);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
FillColorThreadData data;
|
|
|
|
data.rect = rect;
|
|
|
|
data.rect_float = rect_float;
|
|
|
|
data.width = width;
|
|
|
|
copy_v4_v4(data.color, color);
|
|
|
|
IMB_processor_apply_threaded_scanlines(
|
|
|
|
height, image_buf_fill_color_thread_do, &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void image_buf_fill_checker_slice(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width, int height,
|
|
|
|
int offset)
|
|
|
|
{
|
|
|
|
/* these two passes could be combined into one, but it's more readable and
|
2012-03-03 20:19:11 +00:00
|
|
|
* easy to tweak like this, speed isn't really that much of an issue in this situation... */
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
int checkerwidth = 32, dark = 1;
|
2010-03-21 00:25:52 +00:00
|
|
|
int x, y;
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
unsigned char *rect_orig = rect;
|
|
|
|
float *rect_float_orig = rect_float;
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2012-05-26 11:01:01 +00:00
|
|
|
float h = 0.0, hoffs = 0.0;
|
|
|
|
float hsv[3] = {0.0f, 0.9f, 0.9f};
|
|
|
|
float rgb[3];
|
2010-03-21 00:25:52 +00:00
|
|
|
|
2017-07-20 23:51:15 +02:00
|
|
|
float dark_linear_color = 0.0f, bright_linear_color = 0.0f;
|
2016-05-05 12:02:40 +02:00
|
|
|
if (rect_float != NULL) {
|
|
|
|
dark_linear_color = srgb_to_linearrgb(0.25f);
|
|
|
|
bright_linear_color = srgb_to_linearrgb(0.58f);
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
/* checkers */
|
2016-05-05 23:33:40 +02:00
|
|
|
for (y = offset; y < height + offset; y++) {
|
2012-05-06 17:22:54 +00:00
|
|
|
dark = powf(-1.0f, floorf(y / checkerwidth));
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
if (x % checkerwidth == 0) dark = -dark;
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
if (rect_float) {
|
|
|
|
if (dark > 0) {
|
2016-05-05 12:02:40 +02:00
|
|
|
rect_float[0] = rect_float[1] = rect_float[2] = dark_linear_color;
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float[3] = 1.0f;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-05-05 12:02:40 +02:00
|
|
|
rect_float[0] = rect_float[1] = rect_float[2] = bright_linear_color;
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float[3] = 1.0f;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float += 4;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (dark > 0) {
|
2012-05-06 17:22:54 +00:00
|
|
|
rect[0] = rect[1] = rect[2] = 64;
|
|
|
|
rect[3] = 255;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:22:54 +00:00
|
|
|
rect[0] = rect[1] = rect[2] = 150;
|
|
|
|
rect[3] = 255;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
2012-05-06 17:22:54 +00:00
|
|
|
rect += 4;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-21 10:25:21 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
rect = rect_orig;
|
|
|
|
rect_float = rect_float_orig;
|
2010-03-21 10:25:21 +00:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
/* 2nd pass, colored + */
|
2016-05-05 23:33:40 +02:00
|
|
|
for (y = offset; y < height + offset; y++) {
|
2012-05-06 17:22:54 +00:00
|
|
|
hoffs = 0.125f * floorf(y / checkerwidth);
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
h = 0.125f * floorf(x / checkerwidth);
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2014-02-24 22:25:06 +11:00
|
|
|
if ((abs((x % checkerwidth) - (checkerwidth / 2)) < 4) &&
|
|
|
|
(abs((y % checkerwidth) - (checkerwidth / 2)) < 4))
|
2012-05-20 19:49:27 +00:00
|
|
|
{
|
2014-02-24 22:25:06 +11:00
|
|
|
if ((abs((x % checkerwidth) - (checkerwidth / 2)) < 1) ||
|
|
|
|
(abs((y % checkerwidth) - (checkerwidth / 2)) < 1))
|
2012-05-20 19:49:27 +00:00
|
|
|
{
|
2014-02-24 22:25:06 +11:00
|
|
|
hsv[0] = fmodf(fabsf(h - hoffs), 1.0f);
|
2012-05-26 11:01:01 +00:00
|
|
|
hsv_to_rgb_v(hsv, rgb);
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
if (rect) {
|
2012-05-26 11:01:01 +00:00
|
|
|
rect[0] = (char)(rgb[0] * 255.0f);
|
|
|
|
rect[1] = (char)(rgb[1] * 255.0f);
|
|
|
|
rect[2] = (char)(rgb[2] * 255.0f);
|
2012-05-06 17:22:54 +00:00
|
|
|
rect[3] = 255;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
if (rect_float) {
|
2016-05-05 12:02:40 +02:00
|
|
|
srgb_to_linearrgb_v3_v3(rect_float, rgb);
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float[3] = 1.0f;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
if (rect_float) rect_float += 4;
|
|
|
|
if (rect) rect += 4;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
typedef struct FillCheckerThreadData {
|
|
|
|
unsigned char *rect;
|
|
|
|
float *rect_float;
|
|
|
|
int width;
|
|
|
|
} FillCheckerThreadData;
|
|
|
|
|
|
|
|
static void image_buf_fill_checker_thread_do(void *data_v,
|
|
|
|
int start_scanline,
|
|
|
|
int num_scanlines)
|
|
|
|
{
|
|
|
|
FillCheckerThreadData *data = (FillCheckerThreadData *)data_v;
|
|
|
|
size_t offset = ((size_t)start_scanline) * data->width * 4;
|
|
|
|
unsigned char *rect = (data->rect != NULL) ? (data->rect + offset) : NULL;
|
|
|
|
float *rect_float = (data->rect_float != NULL) ? (data->rect_float + offset) : NULL;
|
|
|
|
image_buf_fill_checker_slice(rect,
|
|
|
|
rect_float,
|
|
|
|
data->width,
|
|
|
|
num_scanlines,
|
|
|
|
start_scanline);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_image_buf_fill_checker(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width, int height)
|
|
|
|
{
|
|
|
|
if (((size_t)width) * height < 64 * 64) {
|
|
|
|
image_buf_fill_checker_slice(rect, rect_float, width, height, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
FillCheckerThreadData data;
|
|
|
|
data.rect = rect;
|
|
|
|
data.rect_float = rect_float;
|
|
|
|
data.width = width;
|
|
|
|
IMB_processor_apply_threaded_scanlines(
|
|
|
|
height, image_buf_fill_checker_thread_do, &data);
|
|
|
|
}
|
|
|
|
}
|
2010-03-21 00:25:52 +00:00
|
|
|
|
|
|
|
/* Utility functions for BKE_image_buf_fill_checker_color */
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
#define BLEND_FLOAT(real, add) (real + add <= 1.0f) ? (real + add) : 1.0f
|
2011-03-28 04:22:50 +00:00
|
|
|
#define BLEND_CHAR(real, add) ((real + (char)(add * 255.0f)) <= 255) ? (real + (char)(add * 255.0f)) : 255
|
2010-03-21 00:25:52 +00:00
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
static void checker_board_color_fill(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int offset,
|
|
|
|
int total_height)
|
2010-03-21 00:25:52 +00:00
|
|
|
{
|
|
|
|
int hue_step, y, x;
|
2012-05-26 11:01:01 +00:00
|
|
|
float hsv[3], rgb[3];
|
2010-03-21 00:25:52 +00:00
|
|
|
|
2012-05-26 11:01:01 +00:00
|
|
|
hsv[1] = 1.0;
|
2010-03-21 00:25:52 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
hue_step = power_of_2_max_i(width / 8);
|
|
|
|
if (hue_step < 8) hue_step = 8;
|
2010-03-21 00:25:52 +00:00
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
for (y = offset; y < height + offset; y++) {
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
hsv[2] = 0.1 + (y * (0.4 / total_height)); /* use a number lower then 1.0 else its too bright */
|
2012-05-06 17:22:54 +00:00
|
|
|
for (x = 0; x < width; x++) {
|
2012-05-26 11:01:01 +00:00
|
|
|
hsv[0] = (float)((double)(x / hue_step) * 1.0 / width * hue_step);
|
|
|
|
hsv_to_rgb_v(hsv, rgb);
|
2010-03-21 00:25:52 +00:00
|
|
|
|
|
|
|
if (rect) {
|
2012-05-26 11:01:01 +00:00
|
|
|
rect[0] = (char)(rgb[0] * 255.0f);
|
|
|
|
rect[1] = (char)(rgb[1] * 255.0f);
|
|
|
|
rect[2] = (char)(rgb[2] * 255.0f);
|
2012-05-06 17:22:54 +00:00
|
|
|
rect[3] = 255;
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
rect += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rect_float) {
|
2012-05-26 11:01:01 +00:00
|
|
|
rect_float[0] = rgb[0];
|
|
|
|
rect_float[1] = rgb[1];
|
|
|
|
rect_float[2] = rgb[2];
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float[3] = 1.0f;
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
rect_float += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
static void checker_board_color_tint(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int size,
|
|
|
|
float blend,
|
|
|
|
int offset)
|
2010-03-21 00:25:52 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
2012-05-06 17:22:54 +00:00
|
|
|
float blend_half = blend * 0.5f;
|
2010-03-21 00:25:52 +00:00
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
for (y = offset; y < height + offset; y++) {
|
2012-05-06 17:22:54 +00:00
|
|
|
for (x = 0; x < width; x++) {
|
2016-05-05 23:33:40 +02:00
|
|
|
if (((y / size) % 2 == 1 && (x / size) % 2 == 1) ||
|
|
|
|
((y / size) % 2 == 0 && (x / size) % 2 == 0))
|
|
|
|
{
|
2010-03-21 00:25:52 +00:00
|
|
|
if (rect) {
|
2012-05-06 17:22:54 +00:00
|
|
|
rect[0] = (char)BLEND_CHAR(rect[0], blend);
|
|
|
|
rect[1] = (char)BLEND_CHAR(rect[1], blend);
|
|
|
|
rect[2] = (char)BLEND_CHAR(rect[2], blend);
|
|
|
|
rect[3] = 255;
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
rect += 4;
|
|
|
|
}
|
|
|
|
if (rect_float) {
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float[0] = BLEND_FLOAT(rect_float[0], blend);
|
|
|
|
rect_float[1] = BLEND_FLOAT(rect_float[1], blend);
|
|
|
|
rect_float[2] = BLEND_FLOAT(rect_float[2], blend);
|
|
|
|
rect_float[3] = 1.0f;
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
rect_float += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (rect) {
|
2012-05-06 17:22:54 +00:00
|
|
|
rect[0] = (char)BLEND_CHAR(rect[0], blend_half);
|
|
|
|
rect[1] = (char)BLEND_CHAR(rect[1], blend_half);
|
|
|
|
rect[2] = (char)BLEND_CHAR(rect[2], blend_half);
|
|
|
|
rect[3] = 255;
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
rect += 4;
|
|
|
|
}
|
|
|
|
if (rect_float) {
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float[0] = BLEND_FLOAT(rect_float[0], blend_half);
|
|
|
|
rect_float[1] = BLEND_FLOAT(rect_float[1], blend_half);
|
|
|
|
rect_float[2] = BLEND_FLOAT(rect_float[2], blend_half);
|
|
|
|
rect_float[3] = 1.0f;
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
rect_float += 4;
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
static void checker_board_grid_fill(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
float blend,
|
|
|
|
int offset)
|
2010-03-21 00:25:52 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
2016-05-05 23:33:40 +02:00
|
|
|
for (y = offset; y < height + offset; y++) {
|
2012-05-06 17:22:54 +00:00
|
|
|
for (x = 0; x < width; x++) {
|
2012-05-20 19:49:27 +00:00
|
|
|
if (((y % 32) == 0) || ((x % 32) == 0) || x == 0) {
|
2010-03-21 00:25:52 +00:00
|
|
|
if (rect) {
|
2012-05-06 17:22:54 +00:00
|
|
|
rect[0] = BLEND_CHAR(rect[0], blend);
|
|
|
|
rect[1] = BLEND_CHAR(rect[1], blend);
|
|
|
|
rect[2] = BLEND_CHAR(rect[2], blend);
|
|
|
|
rect[3] = 255;
|
2010-03-21 00:25:52 +00:00
|
|
|
|
|
|
|
rect += 4;
|
|
|
|
}
|
|
|
|
if (rect_float) {
|
2012-05-06 17:22:54 +00:00
|
|
|
rect_float[0] = BLEND_FLOAT(rect_float[0], blend);
|
|
|
|
rect_float[1] = BLEND_FLOAT(rect_float[1], blend);
|
|
|
|
rect_float[2] = BLEND_FLOAT(rect_float[2], blend);
|
|
|
|
rect_float[3] = 1.0f;
|
2016-05-05 23:33:40 +02:00
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
rect_float += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (rect_float) rect_float += 4;
|
|
|
|
if (rect) rect += 4;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* defined in image.c */
|
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
static void checker_board_text(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int step,
|
|
|
|
int outline)
|
2010-03-21 00:25:52 +00:00
|
|
|
{
|
2010-11-26 16:33:42 +00:00
|
|
|
int x, y;
|
2010-03-22 09:30:00 +00:00
|
|
|
int pen_x, pen_y;
|
2012-05-06 17:22:54 +00:00
|
|
|
char text[3] = {'A', '1', '\0'};
|
2013-06-28 13:05:15 +00:00
|
|
|
const int mono = blf_mono_font_render;
|
2010-11-26 16:33:42 +00:00
|
|
|
|
|
|
|
BLF_size(mono, 54, 72); /* hard coded size! */
|
2010-03-21 00:25:52 +00:00
|
|
|
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
/* 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);
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2016-04-22 20:02:03 +10:00
|
|
|
const float text_color[4] = {0.0, 0.0, 0.0, 1.0};
|
|
|
|
const float text_outline[4] = {1.0, 1.0, 1.0, 1.0};
|
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
for (y = 0; y < height; y += step) {
|
|
|
|
text[1] = '1';
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
for (x = 0; x < width; x += step) {
|
2010-03-22 09:30:00 +00:00
|
|
|
/* hard coded offset */
|
|
|
|
pen_x = x + 33;
|
|
|
|
pen_y = y + 44;
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
/* terribly crappy outline font! */
|
2016-04-22 20:02:03 +10:00
|
|
|
BLF_buffer_col(mono, text_outline);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
BLF_position(mono, pen_x - outline, pen_y, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
2012-05-06 17:22:54 +00:00
|
|
|
BLF_position(mono, pen_x + outline, pen_y, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
2012-05-06 17:22:54 +00:00
|
|
|
BLF_position(mono, pen_x, pen_y - outline, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
2012-05-06 17:22:54 +00:00
|
|
|
BLF_position(mono, pen_x, pen_y + outline, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2012-05-06 17:22:54 +00:00
|
|
|
BLF_position(mono, pen_x - outline, pen_y - outline, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
2012-05-06 17:22:54 +00:00
|
|
|
BLF_position(mono, pen_x + outline, pen_y + outline, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
2012-05-06 17:22:54 +00:00
|
|
|
BLF_position(mono, pen_x - outline, pen_y + outline, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
2012-05-06 17:22:54 +00:00
|
|
|
BLF_position(mono, pen_x + outline, pen_y - outline, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
|
2016-04-22 20:02:03 +10:00
|
|
|
BLF_buffer_col(mono, text_color);
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
BLF_position(mono, pen_x, pen_y, 0.0);
|
2015-09-18 20:10:26 +10:00
|
|
|
BLF_draw_buffer(mono, text, 2);
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
text[1]++;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
2010-03-22 09:30:00 +00:00
|
|
|
text[0]++;
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
/* cleanup the buffer. */
|
2013-08-07 03:36:05 +00:00
|
|
|
BLF_buffer(mono, NULL, NULL, 0, 0, 0, NULL);
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 23:33:40 +02:00
|
|
|
static void checker_board_color_prepare_slice(unsigned char *rect,
|
|
|
|
float *rect_float,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int offset,
|
|
|
|
int total_height)
|
|
|
|
{
|
|
|
|
checker_board_color_fill(rect, rect_float, width, height, offset, total_height);
|
|
|
|
checker_board_color_tint(rect, rect_float, width, height, 1, 0.03f, offset);
|
|
|
|
checker_board_color_tint(rect, rect_float, width, height, 4, 0.05f, offset);
|
|
|
|
checker_board_color_tint(rect, rect_float, width, height, 32, 0.07f, offset);
|
|
|
|
checker_board_color_tint(rect, rect_float, width, height, 128, 0.15f, offset);
|
|
|
|
checker_board_grid_fill(rect, rect_float, width, height, 1.0f / 4.0f, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct FillCheckerColorThreadData {
|
|
|
|
unsigned char *rect;
|
|
|
|
float *rect_float;
|
|
|
|
int width, height;
|
|
|
|
} FillCheckerColorThreadData;
|
|
|
|
|
|
|
|
static void checker_board_color_prepare_thread_do(void *data_v,
|
|
|
|
int start_scanline,
|
|
|
|
int num_scanlines)
|
|
|
|
{
|
|
|
|
FillCheckerColorThreadData *data = (FillCheckerColorThreadData *)data_v;
|
|
|
|
size_t offset = ((size_t)data->width) * start_scanline * 4;
|
|
|
|
unsigned char *rect = (data->rect != NULL) ? (data->rect + offset) : NULL;
|
|
|
|
float *rect_float = (data->rect_float != NULL) ? (data->rect_float + offset) : NULL;
|
|
|
|
checker_board_color_prepare_slice(rect,
|
|
|
|
rect_float,
|
|
|
|
data->width,
|
|
|
|
num_scanlines,
|
|
|
|
start_scanline,
|
|
|
|
data->height);
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:25:52 +00:00
|
|
|
void BKE_image_buf_fill_checker_color(unsigned char *rect, float *rect_float, int width, int height)
|
|
|
|
{
|
2016-05-05 23:33:40 +02:00
|
|
|
if (((size_t)width) * height < 64 * 64) {
|
|
|
|
checker_board_color_prepare_slice(rect, rect_float, width, height, 0, height);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
FillCheckerColorThreadData data;
|
|
|
|
data.rect = rect;
|
|
|
|
data.rect_float = rect_float;
|
|
|
|
data.width = width;
|
|
|
|
data.height = height;
|
|
|
|
IMB_processor_apply_threaded_scanlines(
|
|
|
|
height, checker_board_color_prepare_thread_do, &data);
|
|
|
|
}
|
2010-03-21 00:25:52 +00:00
|
|
|
|
|
|
|
checker_board_text(rect, rect_float, width, height, 128, 2);
|
2016-05-05 12:02:40 +02:00
|
|
|
|
2016-05-05 22:04:31 +02:00
|
|
|
if (rect_float != NULL) {
|
|
|
|
/* TODO(sergey): Currently it's easier to fill in form buffer and
|
|
|
|
* linearize it afterwards. This could be optimized with some smart
|
|
|
|
* trickery around blending factors and such.
|
|
|
|
*/
|
2016-05-05 23:33:40 +02:00
|
|
|
IMB_buffer_float_from_float_threaded(rect_float, rect_float,
|
|
|
|
4,
|
|
|
|
IB_PROFILE_LINEAR_RGB,
|
|
|
|
IB_PROFILE_SRGB,
|
|
|
|
true,
|
|
|
|
width, height,
|
|
|
|
width, width);
|
2016-05-05 22:04:31 +02:00
|
|
|
}
|
2010-03-21 00:25:52 +00:00
|
|
|
}
|