2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +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
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* allocimbuf.c
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:23:21 +00:00
|
|
|
/** \file blender/imbuf/intern/divers.c
|
|
|
|
* \ingroup imbuf
|
|
|
|
*/
|
|
|
|
|
2006-02-18 14:35:43 +00:00
|
|
|
#include "BLI_rand.h"
|
2009-12-03 21:49:29 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "imbuf.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
#include "IMB_imbuf.h"
|
2006-01-09 19:17:37 +00:00
|
|
|
#include "IMB_allocimbuf.h"
|
2012-12-31 13:52:13 +00:00
|
|
|
#include "IMB_filter.h"
|
2011-01-07 19:18:31 +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
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
#include "IMB_colormanagement_intern.h"
|
|
|
|
|
2012-10-04 20:31:08 +00:00
|
|
|
#include "BLI_threads.h"
|
|
|
|
|
2010-12-01 02:54:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/**************************** Interlace/Deinterlace **************************/
|
|
|
|
|
2012-01-08 13:55:53 +00:00
|
|
|
void IMB_de_interlace(ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
ImBuf *tbuf1, *tbuf2;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-03-03 17:58:06 +00:00
|
|
|
if (ibuf == NULL) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (ibuf->flags & IB_fields) return;
|
|
|
|
ibuf->flags |= IB_fields;
|
|
|
|
|
|
|
|
if (ibuf->rect) {
|
2003-04-27 09:59:36 +00:00
|
|
|
/* make copies */
|
2010-10-16 14:32:17 +00:00
|
|
|
tbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect);
|
|
|
|
tbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-10-21 05:46:41 +00:00
|
|
|
ibuf->x *= 2;
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
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);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
ibuf->x /= 2;
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
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);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
IMB_freeImBuf(tbuf1);
|
|
|
|
IMB_freeImBuf(tbuf2);
|
|
|
|
}
|
|
|
|
ibuf->y /= 2;
|
|
|
|
}
|
|
|
|
|
2012-01-08 13:55:53 +00:00
|
|
|
void IMB_interlace(ImBuf *ibuf)
|
2003-04-30 18:38:50 +00:00
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
ImBuf *tbuf1, *tbuf2;
|
2003-04-30 18:38:50 +00:00
|
|
|
|
2011-03-03 17:58:06 +00:00
|
|
|
if (ibuf == NULL) return;
|
2005-01-03 19:53:04 +00:00
|
|
|
ibuf->flags &= ~IB_fields;
|
2003-04-30 18:38:50 +00:00
|
|
|
|
2005-01-03 19:53:04 +00:00
|
|
|
ibuf->y *= 2;
|
2003-04-30 18:38:50 +00:00
|
|
|
|
2005-01-03 19:53:04 +00:00
|
|
|
if (ibuf->rect) {
|
|
|
|
/* make copies */
|
2010-10-16 14:32:17 +00:00
|
|
|
tbuf1 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect);
|
|
|
|
tbuf2 = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 32, IB_rect);
|
2003-04-30 18:38:50 +00:00
|
|
|
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
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);
|
2003-04-30 18:38:50 +00:00
|
|
|
|
2005-01-03 19:53:04 +00:00
|
|
|
ibuf->x *= 2;
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
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);
|
2005-01-03 19:53:04 +00:00
|
|
|
ibuf->x /= 2;
|
2003-04-30 18:38:50 +00:00
|
|
|
|
2005-01-03 19:53:04 +00:00
|
|
|
IMB_freeImBuf(tbuf1);
|
|
|
|
IMB_freeImBuf(tbuf2);
|
|
|
|
}
|
2003-04-30 18:38:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 13:55:53 +00:00
|
|
|
/************************* Floyd-Steinberg dithering *************************/
|
|
|
|
|
|
|
|
typedef struct DitherContext {
|
|
|
|
int *error_buf, *e;
|
|
|
|
int v[4], v0[4], v1[4];
|
|
|
|
float f;
|
|
|
|
} DitherContext;
|
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
static DitherContext *create_dither_context(int w, float factor)
|
2012-01-08 13:55:53 +00:00
|
|
|
{
|
|
|
|
DitherContext *di;
|
|
|
|
int i;
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
di = MEM_callocN(sizeof(DitherContext), "dithering context");
|
|
|
|
di->f = factor / 16.0f;
|
|
|
|
di->error_buf = MEM_callocN(4 * (w + 1) * sizeof(int), "dithering error");
|
|
|
|
di->e = di->error_buf;
|
2012-01-08 13:55:53 +00:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
di->v[i] = di->v0[i] = di->v1[i] = 1024.0f * (BLI_frand() - 0.5f);
|
2012-01-08 13:55:53 +00:00
|
|
|
|
|
|
|
return di;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_dither_context(DitherContext *di)
|
|
|
|
{
|
|
|
|
MEM_freeN(di->error_buf);
|
|
|
|
MEM_freeN(di);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dither_finish_row(DitherContext *di)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
di->v[i] = di->v0[i] = di->v1[i] = 0;
|
2012-01-08 13:55:53 +00:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
di->e = di->error_buf;
|
2012-01-08 13:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MINLINE unsigned char dither_value(unsigned short v_in, DitherContext *di, int i)
|
|
|
|
{
|
|
|
|
int dv, d2;
|
|
|
|
unsigned char v_out;
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
di->v[i] = v_in + (2 * di->v[i] + di->e[4]) * di->f;
|
2012-01-08 13:55:53 +00:00
|
|
|
CLAMP(di->v[i], 0, 0xFF00);
|
|
|
|
v_out = USHORTTOUCHAR(di->v[i]);
|
2012-05-13 22:05:51 +00:00
|
|
|
di->v[i] -= v_out << 8;
|
2012-01-08 13:55:53 +00:00
|
|
|
dv = di->v[i];
|
2012-05-13 22:05:51 +00:00
|
|
|
d2 = di->v[i] << 1;
|
2012-01-08 13:55:53 +00:00
|
|
|
di->v[i] += d2;
|
|
|
|
*(di->e++) = di->v[i] + di->v0[i];
|
|
|
|
di->v[i] += d2;
|
|
|
|
|
|
|
|
di->v0[i] = di->v[i] + di->v1[i];
|
|
|
|
di->v1[i] = dv;
|
|
|
|
di->v[i] += d2;
|
|
|
|
|
|
|
|
return v_out;
|
|
|
|
}
|
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/************************* Generic Buffer Conversion *************************/
|
2003-04-30 18:38:50 +00:00
|
|
|
|
2012-01-08 13:55:53 +00:00
|
|
|
MINLINE void ushort_to_byte_v4(uchar b[4], const unsigned short us[4])
|
2011-12-28 13:29:33 +00:00
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
b[0] = USHORTTOUCHAR(us[0]);
|
|
|
|
b[1] = USHORTTOUCHAR(us[1]);
|
|
|
|
b[2] = USHORTTOUCHAR(us[2]);
|
|
|
|
b[3] = USHORTTOUCHAR(us[3]);
|
2012-01-08 13:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MINLINE void ushort_to_byte_dither_v4(uchar b[4], const unsigned short us[4], DitherContext *di)
|
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
b[0] = dither_value(us[0], di, 0);
|
|
|
|
b[1] = dither_value(us[1], di, 1);
|
|
|
|
b[2] = dither_value(us[2], di, 2);
|
|
|
|
b[3] = dither_value(us[3], di, 3);
|
2012-01-08 13:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MINLINE void float_to_byte_dither_v4(uchar b[4], const float f[4], DitherContext *di)
|
|
|
|
{
|
|
|
|
unsigned short us[4] = {FTOUSHORT(f[0]), FTOUSHORT(f[1]), FTOUSHORT(f[2]), FTOUSHORT(f[3])};
|
|
|
|
ushort_to_byte_dither_v4(b, us, di);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* float to byte pixels, output 4-channel RGBA */
|
|
|
|
void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
|
2012-05-13 22:05:51 +00:00
|
|
|
int channels_from, float dither, int profile_to, int profile_from, int predivide,
|
|
|
|
int width, int height, int stride_to, int stride_from)
|
2011-12-28 13:29:33 +00:00
|
|
|
{
|
|
|
|
float tmp[4];
|
|
|
|
int x, y;
|
2012-12-02 16:01:06 +00:00
|
|
|
DitherContext *di = NULL;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
|
|
|
/* we need valid profiles */
|
|
|
|
BLI_assert(profile_to != IB_PROFILE_NONE);
|
|
|
|
BLI_assert(profile_from != IB_PROFILE_NONE);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (dither)
|
2012-05-13 22:05:51 +00:00
|
|
|
di = create_dither_context(width, dither);
|
2012-01-08 13:55:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
if (channels_from == 1) {
|
2012-05-13 22:05:51 +00:00
|
|
|
/* single channel input */
|
|
|
|
const float *from = rect_from + stride_from * y;
|
|
|
|
uchar *to = rect_to + stride_to * y * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from++, to += 4)
|
2011-12-28 13:29:33 +00:00
|
|
|
to[0] = to[1] = to[2] = to[3] = FTOCHAR(from[0]);
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (channels_from == 3) {
|
2012-05-13 22:05:51 +00:00
|
|
|
/* RGB input */
|
|
|
|
const float *from = rect_from + stride_from * y * 3;
|
|
|
|
uchar *to = rect_to + stride_to * y * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (profile_to == profile_from) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* no color space conversion */
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 3, to += 4) {
|
2012-01-19 10:04:51 +00:00
|
|
|
rgb_float_to_uchar(to, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
to[3] = 255;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_SRGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert from linear to sRGB */
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 3, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
linearrgb_to_srgb_v3_v3(tmp, from);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgb_float_to_uchar(to, tmp);
|
2011-12-28 13:29:33 +00:00
|
|
|
to[3] = 255;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert from sRGB to linear */
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 3, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_v3_v3(tmp, from);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgb_float_to_uchar(to, tmp);
|
2011-12-28 13:29:33 +00:00
|
|
|
to[3] = 255;
|
|
|
|
}
|
2009-07-17 02:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (channels_from == 4) {
|
2012-05-13 22:05:51 +00:00
|
|
|
/* RGBA input */
|
|
|
|
const float *from = rect_from + stride_from * y * 4;
|
|
|
|
uchar *to = rect_to + stride_to * y * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (profile_to == profile_from) {
|
2012-12-31 13:52:13 +00:00
|
|
|
float straight[4];
|
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/* no color space conversion */
|
2012-12-31 13:52:13 +00:00
|
|
|
if (dither && predivide) {
|
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2013-01-15 08:37:17 +00:00
|
|
|
premul_to_straight_v4_v4(straight, from);
|
2012-12-31 13:52:13 +00:00
|
|
|
float_to_byte_dither_v4(to, straight, di);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dither) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4)
|
2012-01-08 13:55:53 +00:00
|
|
|
float_to_byte_dither_v4(to, from, di);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
2012-12-31 13:52:13 +00:00
|
|
|
else if (predivide) {
|
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2013-01-15 08:37:17 +00:00
|
|
|
premul_to_straight_v4_v4(straight, from);
|
2012-12-31 13:52:13 +00:00
|
|
|
rgba_float_to_uchar(to, straight);
|
|
|
|
}
|
|
|
|
}
|
2011-12-28 13:29:33 +00:00
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4)
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(to, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_SRGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert from linear to sRGB */
|
2012-01-08 13:55:53 +00:00
|
|
|
unsigned short us[4];
|
2012-12-31 13:52:13 +00:00
|
|
|
float straight[4];
|
2012-01-08 13:55:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (dither && predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2013-01-15 08:37:17 +00:00
|
|
|
premul_to_straight_v4_v4(straight, from);
|
2012-12-31 13:52:13 +00:00
|
|
|
linearrgb_to_srgb_ushort4(us, from);
|
2012-01-08 13:55:53 +00:00
|
|
|
ushort_to_byte_dither_v4(to, us, di);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (dither) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-08 13:55:53 +00:00
|
|
|
linearrgb_to_srgb_ushort4(us, from);
|
|
|
|
ushort_to_byte_dither_v4(to, us, di);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2013-01-15 08:37:17 +00:00
|
|
|
premul_to_straight_v4_v4(straight, from);
|
2012-12-31 13:52:13 +00:00
|
|
|
linearrgb_to_srgb_ushort4(us, from);
|
2012-01-08 13:55:53 +00:00
|
|
|
ushort_to_byte_v4(to, us);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-08 13:55:53 +00:00
|
|
|
linearrgb_to_srgb_ushort4(us, from);
|
|
|
|
ushort_to_byte_v4(to, us);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert from sRGB to linear */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (dither && predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_predivide_v4(tmp, from);
|
2012-01-08 13:55:53 +00:00
|
|
|
float_to_byte_dither_v4(to, tmp, di);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (dither) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_v4(tmp, from);
|
2012-01-08 13:55:53 +00:00
|
|
|
float_to_byte_dither_v4(to, tmp, di);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_predivide_v4(tmp, from);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(to, tmp);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_v4(tmp, from);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(to, tmp);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
2010-01-09 00:16:35 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-17 02:43:15 +00:00
|
|
|
}
|
2012-01-08 13:55:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (dither)
|
2012-01-08 13:55:53 +00:00
|
|
|
dither_finish_row(di);
|
2009-07-17 02:43:15 +00:00
|
|
|
}
|
2012-01-08 13:55:53 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (dither)
|
2012-01-08 13:55:53 +00:00
|
|
|
clear_dither_context(di);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* byte to float pixels, input and output 4-channel RGBA */
|
|
|
|
void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from,
|
2012-05-13 22:05:51 +00:00
|
|
|
int profile_to, int profile_from, int predivide,
|
|
|
|
int width, int height, int stride_to, int stride_from)
|
2011-12-28 13:29:33 +00:00
|
|
|
{
|
|
|
|
float tmp[4];
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* we need valid profiles */
|
|
|
|
BLI_assert(profile_to != IB_PROFILE_NONE);
|
|
|
|
BLI_assert(profile_from != IB_PROFILE_NONE);
|
|
|
|
|
|
|
|
/* RGBA input */
|
2012-03-24 06:38:07 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
2012-05-13 22:05:51 +00:00
|
|
|
const uchar *from = rect_from + stride_from * y * 4;
|
|
|
|
float *to = rect_to + stride_to * y * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (profile_to == profile_from) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* no color space conversion */
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4)
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_uchar_to_float(to, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert sRGB to linear */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-08 13:55:53 +00:00
|
|
|
srgb_to_linearrgb_uchar4_predivide(to, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-08 13:55:53 +00:00
|
|
|
srgb_to_linearrgb_uchar4(to, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
2006-12-20 17:57:56 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_SRGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert linear to sRGB */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_uchar_to_float(tmp, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
linearrgb_to_srgb_predivide_v4(to, tmp);
|
2010-01-09 00:16:35 +00:00
|
|
|
}
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_uchar_to_float(tmp, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
linearrgb_to_srgb_v4(to, tmp);
|
2010-01-09 00:16:35 +00:00
|
|
|
}
|
2006-12-20 17:57:56 +00:00
|
|
|
}
|
2006-02-18 14:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-09 19:17:37 +00:00
|
|
|
}
|
2006-01-11 10:41:04 +00:00
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/* float to float pixels, output 4-channel RGBA */
|
|
|
|
void IMB_buffer_float_from_float(float *rect_to, const float *rect_from,
|
2012-05-13 22:05:51 +00:00
|
|
|
int channels_from, int profile_to, int profile_from, int predivide,
|
|
|
|
int width, int height, int stride_to, int stride_from)
|
2011-06-06 22:10:05 +00:00
|
|
|
{
|
2011-12-28 13:29:33 +00:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* we need valid profiles */
|
|
|
|
BLI_assert(profile_to != IB_PROFILE_NONE);
|
|
|
|
BLI_assert(profile_from != IB_PROFILE_NONE);
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
if (channels_from == 1) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* single channel input */
|
2012-03-24 06:38:07 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
2012-05-13 22:05:51 +00:00
|
|
|
const float *from = rect_from + stride_from * y;
|
|
|
|
float *to = rect_to + stride_to * y * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from++, to += 4)
|
2011-12-28 13:29:33 +00:00
|
|
|
to[0] = to[1] = to[2] = to[3] = from[0];
|
|
|
|
}
|
2011-06-06 22:10:05 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (channels_from == 3) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* RGB input */
|
2012-03-24 06:38:07 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
2012-05-13 22:05:51 +00:00
|
|
|
const float *from = rect_from + stride_from * y * 3;
|
|
|
|
float *to = rect_to + stride_to * y * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (profile_to == profile_from) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* no color space conversion */
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 3, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
copy_v3_v3(to, from);
|
|
|
|
to[3] = 1.0f;
|
2011-06-06 22:10:05 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert from sRGB to linear */
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 3, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_v3_v3(to, from);
|
|
|
|
to[3] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_SRGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert from linear to sRGB */
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 3, to += 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
linearrgb_to_srgb_v3_v3(to, from);
|
|
|
|
to[3] = 1.0f;
|
2011-06-06 22:10:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (channels_from == 4) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* RGBA input */
|
2012-03-24 06:38:07 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
2012-05-13 22:05:51 +00:00
|
|
|
const float *from = rect_from + stride_from * y * 4;
|
|
|
|
float *to = rect_to + stride_to * y * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (profile_to == profile_from) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* same profile, copy */
|
2012-05-13 22:05:51 +00:00
|
|
|
memcpy(to, from, sizeof(float) * 4 * width);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert to sRGB to linear */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4)
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_predivide_v4(to, from);
|
2011-06-06 22:10:05 +00:00
|
|
|
}
|
2011-12-28 13:29:33 +00:00
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4)
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_v4(to, from);
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_SRGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert from linear to sRGB */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4)
|
2011-12-28 13:29:33 +00:00
|
|
|
linearrgb_to_srgb_predivide_v4(to, from);
|
|
|
|
}
|
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4)
|
2011-12-28 13:29:33 +00:00
|
|
|
linearrgb_to_srgb_v4(to, from);
|
2011-06-06 22:10:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* byte to byte pixels, input and output 4-channel RGBA */
|
|
|
|
void IMB_buffer_byte_from_byte(uchar *rect_to, const uchar *rect_from,
|
2012-05-13 22:05:51 +00:00
|
|
|
int profile_to, int profile_from, int predivide,
|
|
|
|
int width, int height, int stride_to, int stride_from)
|
2011-12-28 13:29:33 +00:00
|
|
|
{
|
|
|
|
float tmp[4];
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* we need valid profiles */
|
|
|
|
BLI_assert(profile_to != IB_PROFILE_NONE);
|
|
|
|
BLI_assert(profile_from != IB_PROFILE_NONE);
|
|
|
|
|
|
|
|
/* always RGBA input */
|
2012-03-24 06:38:07 +00:00
|
|
|
for (y = 0; y < height; y++) {
|
2012-05-13 22:05:51 +00:00
|
|
|
const uchar *from = rect_from + stride_from * y * 4;
|
|
|
|
uchar *to = rect_to + stride_to * y * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (profile_to == profile_from) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* same profile, copy */
|
2012-05-13 22:05:51 +00:00
|
|
|
memcpy(to, from, sizeof(uchar) * 4 * width);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert to sRGB to linear */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_uchar_to_float(tmp, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_predivide_v4(tmp, tmp);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(to, tmp);
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_uchar_to_float(tmp, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
srgb_to_linearrgb_v4(tmp, tmp);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(to, tmp);
|
2011-06-06 22:10:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (profile_to == IB_PROFILE_SRGB) {
|
2011-12-28 13:29:33 +00:00
|
|
|
/* convert from linear to sRGB */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (predivide) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_uchar_to_float(tmp, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
linearrgb_to_srgb_predivide_v4(tmp, tmp);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(to, tmp);
|
2011-06-06 22:10:05 +00:00
|
|
|
}
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (x = 0; x < width; x++, from += 4, to += 4) {
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_uchar_to_float(tmp, from);
|
2011-12-28 13:29:33 +00:00
|
|
|
linearrgb_to_srgb_v4(tmp, tmp);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(to, tmp);
|
2011-06-06 22:10:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-28 13:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************** ImBuf Conversion *****************************/
|
|
|
|
|
2012-01-08 13:55:53 +00:00
|
|
|
void IMB_rect_from_float(ImBuf *ibuf)
|
2011-12-28 13:29:33 +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
|
|
|
float *buffer;
|
|
|
|
const char *from_colorspace;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
|
|
|
/* verify we have a float buffer */
|
2012-05-13 22:05:51 +00:00
|
|
|
if (ibuf->rect_float == NULL)
|
2011-12-28 13:29:33 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* create byte rect if it didn't exist yet */
|
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
|
|
|
if (ibuf->rect == NULL) {
|
|
|
|
if (imb_addrectImBuf(ibuf) == 0)
|
|
|
|
return;
|
2012-06-11 12:13:41 +00:00
|
|
|
}
|
2011-12-28 13:29:33 +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
|
|
|
if (ibuf->float_colorspace == NULL)
|
|
|
|
from_colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR);
|
|
|
|
else
|
|
|
|
from_colorspace = ibuf->float_colorspace->name;
|
|
|
|
|
|
|
|
buffer = MEM_dupallocN(ibuf->rect_float);
|
|
|
|
|
|
|
|
/* first make float buffer in byte space */
|
2012-12-31 13:52:13 +00:00
|
|
|
IMB_colormanagement_transform(buffer, ibuf->x, ibuf->y, ibuf->channels, from_colorspace, ibuf->rect_colorspace->name, TRUE);
|
|
|
|
|
|
|
|
/* convert from float's premul alpha to byte's straight alpha */
|
|
|
|
IMB_unpremultiply_rect_float(buffer, ibuf->planes, ibuf->x, ibuf->y);
|
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
|
|
|
|
|
|
|
/* convert float to byte */
|
|
|
|
IMB_buffer_byte_from_float((unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
|
|
|
|
FALSE, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
|
|
|
|
|
|
|
|
MEM_freeN(buffer);
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2011-06-06 22:10:05 +00:00
|
|
|
/* ensure user flag is reset */
|
|
|
|
ibuf->userflags &= ~IB_RECT_INVALID;
|
|
|
|
}
|
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/* converts from linear float to sRGB byte for part of the texture, buffer will hold the changed part */
|
2012-10-25 15:25:28 +00:00
|
|
|
void IMB_partial_rect_from_float(ImBuf *ibuf, float *buffer, int x, int y, int w, int h, int is_data)
|
2010-12-01 02:54:10 +00:00
|
|
|
{
|
2011-12-28 13:29:33 +00:00
|
|
|
float *rect_float;
|
|
|
|
uchar *rect_byte;
|
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
|
|
|
int profile_from = IB_PROFILE_LINEAR_RGB;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
|
|
|
/* verify we have a float buffer */
|
2012-05-13 22:05:51 +00:00
|
|
|
if (ibuf->rect_float == NULL || buffer == NULL)
|
2011-12-28 13:29:33 +00:00
|
|
|
return;
|
2010-12-01 02:54:10 +00:00
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/* create byte rect if it didn't exist yet */
|
2012-05-13 22:05:51 +00:00
|
|
|
if (ibuf->rect == NULL)
|
2011-12-28 13:29:33 +00:00
|
|
|
imb_addrectImBuf(ibuf);
|
2010-12-01 02:54:10 +00:00
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/* do conversion */
|
2012-05-13 22:05:51 +00:00
|
|
|
rect_float = ibuf->rect_float + (x + y * ibuf->x) * ibuf->channels;
|
|
|
|
rect_byte = (uchar *)ibuf->rect + (x + y * ibuf->x) * 4;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-10-25 15:25:28 +00:00
|
|
|
if (is_data) {
|
|
|
|
/* exception for non-color data, just copy float */
|
|
|
|
IMB_buffer_float_from_float(buffer, rect_float,
|
2012-11-09 09:33:28 +00:00
|
|
|
ibuf->channels, IB_PROFILE_LINEAR_RGB, IB_PROFILE_LINEAR_RGB, 0,
|
|
|
|
w, h, w, ibuf->x);
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-10-25 15:25:28 +00:00
|
|
|
/* and do color space conversion to byte */
|
|
|
|
IMB_buffer_byte_from_float(rect_byte, rect_float,
|
2012-12-31 13:52:13 +00:00
|
|
|
4, ibuf->dither, IB_PROFILE_SRGB, profile_from, TRUE,
|
2012-11-09 09:33:28 +00:00
|
|
|
w, h, ibuf->x, w);
|
2012-10-25 15:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
IMB_buffer_float_from_float(buffer, rect_float,
|
2012-12-31 13:52:13 +00:00
|
|
|
ibuf->channels, IB_PROFILE_SRGB, profile_from, TRUE,
|
2012-11-09 09:33:28 +00:00
|
|
|
w, h, w, ibuf->x);
|
2012-10-25 15:25:28 +00:00
|
|
|
|
|
|
|
/* XXX: need to convert to image buffer's rect space */
|
|
|
|
IMB_buffer_byte_from_float(rect_byte, buffer,
|
2012-11-09 09:33:28 +00:00
|
|
|
4, ibuf->dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB, 0,
|
|
|
|
w, h, ibuf->x, w);
|
2012-10-25 15:25:28 +00:00
|
|
|
}
|
2011-12-28 13:29:33 +00:00
|
|
|
|
|
|
|
/* ensure user flag is reset */
|
|
|
|
ibuf->userflags &= ~IB_RECT_INVALID;
|
2010-12-01 02:54:10 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 13:55:53 +00:00
|
|
|
void IMB_float_from_rect(ImBuf *ibuf)
|
2006-01-12 15:46:29 +00:00
|
|
|
{
|
2013-04-11 14:15:52 +00:00
|
|
|
float *rect_float;
|
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/* verify if we byte and float buffers */
|
2012-05-13 22:05:51 +00:00
|
|
|
if (ibuf->rect == NULL)
|
2011-12-28 13:29:33 +00:00
|
|
|
return;
|
|
|
|
|
2013-04-11 14:15:52 +00:00
|
|
|
/* allocate float buffer outside of image buffer,
|
|
|
|
* so work-in-progress color space conversion doesn't
|
|
|
|
* interfere with other parts of blender
|
2012-10-04 20:31:08 +00:00
|
|
|
*/
|
2013-04-11 14:15:52 +00:00
|
|
|
rect_float = ibuf->rect_float;
|
|
|
|
if (rect_float == NULL) {
|
|
|
|
int size;
|
2012-10-04 20:31:08 +00:00
|
|
|
|
2013-04-11 14:15:52 +00:00
|
|
|
size = ibuf->x * ibuf->y;
|
|
|
|
size = size * 4 * sizeof(float);
|
|
|
|
ibuf->channels = 4;
|
|
|
|
|
|
|
|
rect_float = MEM_mapallocN(size, "IMB_float_from_rect");
|
2012-10-04 20:31:08 +00:00
|
|
|
|
2013-04-11 14:15:52 +00:00
|
|
|
if (rect_float == NULL)
|
2011-12-28 13:29:33 +00:00
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* first, create float buffer in non-linear space */
|
2013-04-11 14:15:52 +00:00
|
|
|
IMB_buffer_float_from_byte(rect_float, (unsigned char *) ibuf->rect, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
|
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
|
|
|
FALSE, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
|
|
|
|
|
|
|
|
/* then make float be in linear space */
|
2013-04-11 14:15:52 +00:00
|
|
|
IMB_colormanagement_colorspace_to_scene_linear(rect_float, ibuf->x, ibuf->y, ibuf->channels,
|
2012-12-31 13:52:13 +00:00
|
|
|
ibuf->rect_colorspace, FALSE);
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2012-12-31 13:52:13 +00:00
|
|
|
/* byte buffer is straight alpha, float should always be premul */
|
2013-04-11 14:15:52 +00:00
|
|
|
IMB_premultiply_rect_float(rect_float, ibuf->channels, ibuf->x, ibuf->y);
|
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2013-04-11 14:15:52 +00:00
|
|
|
if (ibuf->rect_float == NULL) {
|
|
|
|
ibuf->rect_float = rect_float;
|
|
|
|
ibuf->mall |= IB_rectfloat;
|
|
|
|
ibuf->flags |= IB_rectfloat;
|
|
|
|
}
|
2010-07-12 14:57:24 +00:00
|
|
|
}
|
|
|
|
|
2011-12-28 13:29:33 +00:00
|
|
|
/**************************** Color to Grayscale *****************************/
|
2011-06-24 03:49:56 +00:00
|
|
|
|
|
|
|
/* no profile conversion */
|
2012-01-08 13:55:53 +00:00
|
|
|
void IMB_color_to_bw(ImBuf *ibuf)
|
2011-06-24 03:49:56 +00:00
|
|
|
{
|
2013-04-04 02:05:11 +00:00
|
|
|
float *rct_fl = ibuf->rect_float;
|
2012-05-13 22:05:51 +00:00
|
|
|
uchar *rct = (uchar *)ibuf->rect;
|
2011-06-24 03:49:56 +00:00
|
|
|
int i;
|
2011-12-28 13:29:33 +00:00
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
if (rct_fl) {
|
|
|
|
for (i = ibuf->x * ibuf->y; i > 0; i--, rct_fl += 4)
|
|
|
|
rct_fl[0] = rct_fl[1] = rct_fl[2] = rgb_to_grayscale(rct_fl);
|
2011-06-24 03:49:56 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (rct) {
|
2012-05-13 22:05:51 +00:00
|
|
|
for (i = ibuf->x * ibuf->y; i > 0; i--, rct += 4)
|
|
|
|
rct[0] = rct[1] = rct[2] = rgb_to_grayscale_byte(rct);
|
2011-06-24 03:49:56 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-14 13:25:23 +00:00
|
|
|
|
2012-02-25 16:49:59 +00:00
|
|
|
void IMB_buffer_float_clamp(float *buf, int width, int height)
|
|
|
|
{
|
2012-05-13 22:05:51 +00:00
|
|
|
int i, total = width * height * 4;
|
2012-03-24 06:38:07 +00:00
|
|
|
for (i = 0; i < total; i++) {
|
2012-10-23 13:28:22 +00:00
|
|
|
buf[i] = min_ff(1.0, buf[i]);
|
2012-02-14 13:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 19:31:28 +00:00
|
|
|
|
2012-12-31 13:52:13 +00:00
|
|
|
void IMB_buffer_float_unpremultiply(float *buf, int width, int height)
|
|
|
|
{
|
|
|
|
int total = width * height;
|
2013-01-15 08:37:17 +00:00
|
|
|
float *fp = buf;
|
2012-12-31 13:52:13 +00:00
|
|
|
while (total--) {
|
2013-01-15 08:37:17 +00:00
|
|
|
premul_to_straight_v4(fp);
|
|
|
|
fp += 4;
|
2012-12-31 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IMB_buffer_float_premultiply(float *buf, int width, int height)
|
|
|
|
{
|
|
|
|
int total = width * height;
|
2013-01-15 08:37:17 +00:00
|
|
|
float *fp = buf;
|
2012-12-31 13:52:13 +00:00
|
|
|
while (total--) {
|
2013-01-15 08:37:17 +00:00
|
|
|
straight_to_premul_v4(fp);
|
|
|
|
fp += 4;
|
2012-12-31 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 19:31:28 +00:00
|
|
|
/**************************** alter saturation *****************************/
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
void IMB_saturation(ImBuf *ibuf, float sat)
|
2012-03-17 19:31:28 +00:00
|
|
|
{
|
|
|
|
int i;
|
2012-05-13 22:05:51 +00:00
|
|
|
unsigned char *rct = (unsigned char *)ibuf->rect;
|
2013-04-04 02:05:11 +00:00
|
|
|
float *rct_fl = ibuf->rect_float;
|
2012-03-17 19:31:28 +00:00
|
|
|
float hsv[3];
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (rct) {
|
2012-03-17 19:31:28 +00:00
|
|
|
float rgb[3];
|
2012-05-13 22:05:51 +00:00
|
|
|
for (i = ibuf->x * ibuf->y; i > 0; i--, rct += 4) {
|
2012-03-17 19:31:28 +00:00
|
|
|
rgb_uchar_to_float(rgb, rct);
|
2012-05-26 11:01:01 +00:00
|
|
|
rgb_to_hsv_v(rgb, hsv);
|
2012-05-13 22:05:51 +00:00
|
|
|
hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rgb, rgb + 1, rgb + 2);
|
2012-03-17 19:31:28 +00:00
|
|
|
rgb_float_to_uchar(rct, rgb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
if (rct_fl) {
|
|
|
|
for (i = ibuf->x * ibuf->y; i > 0; i--, rct_fl += 4) {
|
|
|
|
rgb_to_hsv_v(rct_fl, hsv);
|
|
|
|
hsv_to_rgb(hsv[0], hsv[1] * sat, hsv[2], rct_fl, rct_fl + 1, rct_fl + 2);
|
2012-03-17 19:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|