2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-04-30 14:24:11 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup imbuf
|
2012-04-30 14:24:11 +00:00
|
|
|
*
|
2021-10-12 17:52:35 +11:00
|
|
|
* This file was moved here from the `src/` directory.
|
|
|
|
|
* It is meant to deal with endianness. It resided in a general blending lib.
|
|
|
|
|
* The other functions were only used during rendering. This single function remained.
|
2023-07-31 11:50:54 +10:00
|
|
|
* It should probably move to `imbuf/intern/util.cc`, but we'll keep it here for the time being.
|
2011-02-27 20:23:21 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstdlib>
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
|
2012-08-07 16:47:46 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_interp.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_task.h"
|
|
|
|
|
#include "BLI_utildefines.h"
|
2012-03-08 14:23:34 +00:00
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
#include "IMB_colormanagement.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
2007-07-10 19:13:03 +00:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void IMB_convert_rgba_to_abgr(ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2015-05-29 13:38:20 +02:00
|
|
|
size_t size;
|
2023-05-18 10:19:01 +02:00
|
|
|
uchar rt, *cp = ibuf->byte_buffer.data;
|
|
|
|
|
float rtf, *cpf = ibuf->float_buffer.data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->byte_buffer.data) {
|
2008-01-20 18:55:56 +00:00
|
|
|
size = ibuf->x * ibuf->y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size-- > 0) {
|
2012-05-13 22:05:51 +00:00
|
|
|
rt = cp[0];
|
|
|
|
|
cp[0] = cp[3];
|
|
|
|
|
cp[3] = rt;
|
|
|
|
|
rt = cp[1];
|
|
|
|
|
cp[1] = cp[2];
|
|
|
|
|
cp[2] = rt;
|
|
|
|
|
cp += 4;
|
2008-01-20 18:55:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->float_buffer.data) {
|
2008-01-20 18:55:56 +00:00
|
|
|
size = ibuf->x * ibuf->y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
while (size-- > 0) {
|
2012-05-13 22:05:51 +00:00
|
|
|
rtf = cpf[0];
|
|
|
|
|
cpf[0] = cpf[3];
|
|
|
|
|
cpf[3] = rtf;
|
|
|
|
|
rtf = cpf[1];
|
|
|
|
|
cpf[1] = cpf[2];
|
|
|
|
|
cpf[2] = rtf;
|
|
|
|
|
cpf += 4;
|
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
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-14 16:11:13 +10:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
static void pixel_from_buffer(const ImBuf *ibuf, uchar **outI, float **outF, int x, int y)
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
|
|
|
|
{
|
2023-05-02 20:09:09 +10:00
|
|
|
size_t offset = size_t(ibuf->x) * y * 4 + 4 * x;
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->byte_buffer.data) {
|
|
|
|
|
*outI = ibuf->byte_buffer.data + offset;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->float_buffer.data) {
|
|
|
|
|
*outF = ibuf->float_buffer.data + offset;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +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
|
|
|
|
2012-11-11 08:48:35 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Bi-Cubic Interpolation
|
2020-09-14 16:11:13 +10:00
|
|
|
* \{ */
|
2008-11-19 02:07:23 +00:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void bicubic_interpolation_color(const ImBuf *in, uchar outI[4], float outF[4], float u, float v)
|
2007-07-10 19:13:03 +00:00
|
|
|
{
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outF) {
|
2023-05-18 10:19:01 +02:00
|
|
|
BLI_bicubic_interpolation_fl(in->float_buffer.data, outF, in->x, in->y, 4, u, v);
|
2012-11-11 08:48:35 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-18 10:19:01 +02:00
|
|
|
BLI_bicubic_interpolation_char(in->byte_buffer.data, outI, in->x, in->y, 4, u, v);
|
2007-07-10 19:13:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 13:47:42 +01:00
|
|
|
void bicubic_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int xout, int yout)
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
uchar *outI = nullptr;
|
|
|
|
|
float *outF = nullptr;
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (in == nullptr || (in->byte_buffer.data == nullptr && in->float_buffer.data == nullptr)) {
|
2012-10-01 06:18:45 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* GCC warns these could be uninitialized, but its ok. */
|
2019-08-14 23:29:46 +10:00
|
|
|
pixel_from_buffer(out, &outI, &outF, xout, yout);
|
2018-06-17 17:04:54 +02:00
|
|
|
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
bicubic_interpolation_color(in, outI, outF, u, v);
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-10 19:13:03 +00:00
|
|
|
/** \} */
|
2020-09-14 16:11:13 +10:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2007-07-10 19:13:03 +00:00
|
|
|
/** \name Bi-Linear Interpolation
|
2020-09-14 16:11:13 +10:00
|
|
|
* \{ */
|
|
|
|
|
|
2021-12-08 09:54:52 +01:00
|
|
|
void bilinear_interpolation_color_fl(
|
2023-06-03 08:36:28 +10:00
|
|
|
const ImBuf *in, uchar /*outI*/[4], float outF[4], float u, float v)
|
2021-06-11 10:53:52 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(outF);
|
2023-05-18 10:19:01 +02:00
|
|
|
BLI_assert(in->float_buffer.data);
|
|
|
|
|
BLI_bilinear_interpolation_fl(in->float_buffer.data, outF, in->x, in->y, 4, u, v);
|
2021-06-11 10:53:52 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-08 09:54:52 +01:00
|
|
|
void bilinear_interpolation_color_char(
|
2023-06-03 08:36:28 +10:00
|
|
|
const ImBuf *in, uchar outI[4], float /*outF*/[4], float u, float v)
|
2021-06-11 10:53:52 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(outI);
|
2023-05-18 10:19:01 +02:00
|
|
|
BLI_assert(in->byte_buffer.data);
|
|
|
|
|
BLI_bilinear_interpolation_char(in->byte_buffer.data, outI, in->x, in->y, 4, u, v);
|
2021-06-11 10:53:52 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void bilinear_interpolation_color(const ImBuf *in, uchar outI[4], float outF[4], float u, float v)
|
2007-07-10 19:13:03 +00:00
|
|
|
{
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
if (outF) {
|
2023-05-18 10:19:01 +02:00
|
|
|
BLI_bilinear_interpolation_fl(in->float_buffer.data, outF, in->x, in->y, 4, u, v);
|
2007-07-10 19:13:03 +00:00
|
|
|
}
|
2012-11-11 08:48:35 +00:00
|
|
|
else {
|
2023-05-18 10:19:01 +02:00
|
|
|
BLI_bilinear_interpolation_char(in->byte_buffer.data, outI, in->x, in->y, 4, u, v);
|
2009-05-28 06:13:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* function assumes out to be zero'ed, only does RGBA */
|
|
|
|
|
/* BILINEAR INTERPOLATION */
|
|
|
|
|
|
2012-10-01 06:18:45 +00:00
|
|
|
void bilinear_interpolation_color_wrap(
|
2023-06-03 08:36:28 +10:00
|
|
|
const ImBuf *in, uchar outI[4], float outF[4], float u, float v)
|
2009-05-28 06:13:56 +00:00
|
|
|
{
|
|
|
|
|
float *row1, *row2, *row3, *row4, a, b;
|
2022-09-13 16:29:06 +10:00
|
|
|
uchar *row1I, *row2I, *row3I, *row4I;
|
2009-05-28 06:13:56 +00:00
|
|
|
float a_b, ma_b, a_mb, ma_mb;
|
|
|
|
|
int y1, y2, x1, x2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-17 18:08:14 +00:00
|
|
|
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-02 20:09:09 +10:00
|
|
|
x1 = int(floor(u));
|
|
|
|
|
x2 = int(ceil(u));
|
|
|
|
|
y1 = int(floor(v));
|
|
|
|
|
y2 = int(ceil(v));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* sample area entirely outside image? */
|
2012-10-01 06:18:45 +00:00
|
|
|
if (x2 < 0 || x1 > in->x - 1 || y2 < 0 || y1 > in->y - 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:56:58 +10:00
|
|
|
/* Wrap interpolation pixels - main difference from #bilinear_interpolation_color. */
|
2019-04-23 11:01:30 +10:00
|
|
|
if (x1 < 0) {
|
2012-05-13 22:05:51 +00:00
|
|
|
x1 = in->x + x1;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
|
|
|
|
if (y1 < 0) {
|
2012-05-13 22:05:51 +00:00
|
|
|
y1 = in->y + y1;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (x2 >= in->x) {
|
2012-05-13 22:05:51 +00:00
|
|
|
x2 = x2 - in->x;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
|
|
|
|
if (y2 >= in->y) {
|
2012-05-13 22:05:51 +00:00
|
|
|
y2 = y2 - in->y;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-17 14:11:13 +02:00
|
|
|
a = u - floorf(u);
|
|
|
|
|
b = v - floorf(v);
|
|
|
|
|
a_b = a * b;
|
|
|
|
|
ma_b = (1.0f - a) * b;
|
|
|
|
|
a_mb = a * (1.0f - b);
|
|
|
|
|
ma_mb = (1.0f - a) * (1.0f - b);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-05-28 06:13:56 +00:00
|
|
|
if (outF) {
|
2023-05-18 10:19:01 +02:00
|
|
|
float *in_rect_float = in->float_buffer.data;
|
2012-07-07 22:51:57 +00:00
|
|
|
/* sample including outside of edges of image */
|
2023-05-18 10:19:01 +02:00
|
|
|
row1 = in_rect_float + size_t(in->x) * y1 * 4 + 4 * x1;
|
|
|
|
|
row2 = in_rect_float + size_t(in->x) * y2 * 4 + 4 * x1;
|
|
|
|
|
row3 = in_rect_float + size_t(in->x) * y1 * 4 + 4 * x2;
|
|
|
|
|
row4 = in_rect_float + size_t(in->x) * y2 * 4 + 4 * x2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
outF[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
|
|
|
|
|
outF[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
|
|
|
|
|
outF[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
|
|
|
|
|
outF[3] = ma_mb * row1[3] + a_mb * row3[3] + ma_b * row2[3] + a_b * row4[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-17 14:11:13 +02:00
|
|
|
/* clamp here or else we can easily get off-range */
|
2020-03-04 11:31:51 +11:00
|
|
|
clamp_v4(outF, 0.0f, 1.0f);
|
2009-05-28 06:13:56 +00:00
|
|
|
}
|
|
|
|
|
if (outI) {
|
2023-05-18 10:19:01 +02:00
|
|
|
uchar *in_rect = in->byte_buffer.data;
|
2012-07-07 22:51:57 +00:00
|
|
|
/* sample including outside of edges of image */
|
2023-05-18 10:19:01 +02:00
|
|
|
row1I = in_rect + size_t(in->x) * y1 * 4 + 4 * x1;
|
|
|
|
|
row2I = in_rect + size_t(in->x) * y2 * 4 + 4 * x1;
|
|
|
|
|
row3I = in_rect + size_t(in->x) * y1 * 4 + 4 * x2;
|
|
|
|
|
row4I = in_rect + size_t(in->x) * y2 * 4 + 4 * x2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-07 10:12:12 +02:00
|
|
|
/* Tested with white images and this should not wrap back to zero. */
|
2020-09-04 16:23:00 +02:00
|
|
|
outI[0] = roundf(ma_mb * row1I[0] + a_mb * row3I[0] + ma_b * row2I[0] + a_b * row4I[0]);
|
|
|
|
|
outI[1] = roundf(ma_mb * row1I[1] + a_mb * row3I[1] + ma_b * row2I[1] + a_b * row4I[1]);
|
|
|
|
|
outI[2] = roundf(ma_mb * row1I[2] + a_mb * row3I[2] + ma_b * row2I[2] + a_b * row4I[2]);
|
|
|
|
|
outI[3] = roundf(ma_mb * row1I[3] + a_mb * row3I[3] + ma_b * row2I[3] + a_b * row4I[3]);
|
2007-07-10 19:13:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 13:47:42 +01:00
|
|
|
void bilinear_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int xout, int yout)
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
uchar *outI = nullptr;
|
|
|
|
|
float *outF = nullptr;
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (in == nullptr || (in->byte_buffer.data == nullptr && in->float_buffer.data == nullptr)) {
|
2012-10-01 06:18:45 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2022-09-19 14:47:27 +10:00
|
|
|
/* GCC warns these could be uninitialized, but its ok. */
|
2019-08-14 23:29:46 +10:00
|
|
|
pixel_from_buffer(out, &outI, &outF, xout, yout);
|
2018-06-17 17:04:54 +02:00
|
|
|
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
bilinear_interpolation_color(in, outI, outF, u, v);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 16:11:13 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2007-07-10 19:13:03 +00:00
|
|
|
/** \name Nearest Interpolation
|
2020-09-14 16:11:13 +10:00
|
|
|
* \{ */
|
|
|
|
|
|
2021-12-08 09:54:52 +01:00
|
|
|
void nearest_interpolation_color_char(
|
2023-06-03 08:36:28 +10:00
|
|
|
const ImBuf *in, uchar outI[4], float /*outF*/[4], float u, float v)
|
2007-07-10 19:13:03 +00:00
|
|
|
{
|
2021-06-11 10:53:52 +02:00
|
|
|
BLI_assert(outI);
|
2023-05-18 10:19:01 +02:00
|
|
|
BLI_assert(in->byte_buffer.data);
|
2010-07-17 18:08:14 +00:00
|
|
|
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
|
2023-05-02 20:09:09 +10:00
|
|
|
int x1 = int(u);
|
|
|
|
|
int y1 = int(v);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-11 10:53:52 +02:00
|
|
|
/* sample area entirely outside image? */
|
|
|
|
|
if (x1 < 0 || x1 >= in->x || y1 < 0 || y1 >= in->y) {
|
|
|
|
|
outI[0] = outI[1] = outI[2] = outI[3] = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-02 20:09:09 +10:00
|
|
|
const size_t offset = (size_t(in->x) * y1 + x1) * 4;
|
2023-05-18 10:19:01 +02:00
|
|
|
const uchar *dataI = in->byte_buffer.data + offset;
|
2021-06-11 10:53:52 +02:00
|
|
|
outI[0] = dataI[0];
|
|
|
|
|
outI[1] = dataI[1];
|
|
|
|
|
outI[2] = dataI[2];
|
|
|
|
|
outI[3] = dataI[3];
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 09:54:52 +01:00
|
|
|
void nearest_interpolation_color_fl(
|
2023-06-03 08:36:28 +10:00
|
|
|
const ImBuf *in, uchar /*outI*/[4], float outF[4], float u, float v)
|
2021-06-11 10:53:52 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(outF);
|
2023-05-18 10:19:01 +02:00
|
|
|
BLI_assert(in->float_buffer.data);
|
2021-06-11 10:53:52 +02:00
|
|
|
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
|
2023-05-02 20:09:09 +10:00
|
|
|
int x1 = int(u);
|
|
|
|
|
int y1 = int(v);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* sample area entirely outside image? */
|
2021-06-11 10:53:52 +02:00
|
|
|
if (x1 < 0 || x1 >= in->x || y1 < 0 || y1 >= in->y) {
|
|
|
|
|
zero_v4(outF);
|
2012-10-01 06:18:45 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-02 20:09:09 +10:00
|
|
|
const size_t offset = (size_t(in->x) * y1 + x1) * 4;
|
2023-05-18 10:19:01 +02:00
|
|
|
const float *dataF = in->float_buffer.data + offset;
|
2021-06-11 10:53:52 +02:00
|
|
|
copy_v4_v4(outF, dataF);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void nearest_interpolation_color(const ImBuf *in, uchar outI[4], float outF[4], float u, float v)
|
2021-06-11 10:53:52 +02:00
|
|
|
{
|
|
|
|
|
if (outF) {
|
|
|
|
|
nearest_interpolation_color_fl(in, outI, outF, u, v);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2021-06-11 10:53:52 +02:00
|
|
|
nearest_interpolation_color_char(in, outI, outF, u, v);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2007-07-10 19:13:03 +00:00
|
|
|
}
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
2015-05-29 13:38:20 +02:00
|
|
|
void nearest_interpolation_color_wrap(
|
2023-06-03 08:36:28 +10:00
|
|
|
const ImBuf *in, uchar outI[4], float outF[4], float u, float v)
|
2015-05-29 13:38:20 +02:00
|
|
|
{
|
|
|
|
|
const float *dataF;
|
2022-09-13 16:29:06 +10:00
|
|
|
uchar *dataI;
|
2015-05-29 13:38:20 +02:00
|
|
|
int y, x;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-29 13:38:20 +02:00
|
|
|
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-02 20:09:09 +10:00
|
|
|
x = int(floor(u));
|
|
|
|
|
y = int(floor(v));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-29 13:38:20 +02:00
|
|
|
x = x % in->x;
|
|
|
|
|
y = y % in->y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:56:58 +10:00
|
|
|
/* Wrap interpolation pixels - main difference from #nearest_interpolation_color. */
|
2019-04-23 11:01:30 +10:00
|
|
|
if (x < 0) {
|
2015-05-29 13:38:20 +02:00
|
|
|
x += in->x;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
|
|
|
|
if (y < 0) {
|
2015-05-29 13:38:20 +02:00
|
|
|
y += in->y;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
dataI = in->byte_buffer.data + size_t(in->x) * y * 4 + 4 * x;
|
2015-05-29 13:38:20 +02:00
|
|
|
if (outI) {
|
|
|
|
|
outI[0] = dataI[0];
|
|
|
|
|
outI[1] = dataI[1];
|
|
|
|
|
outI[2] = dataI[2];
|
|
|
|
|
outI[3] = dataI[3];
|
|
|
|
|
}
|
2023-05-18 10:19:01 +02:00
|
|
|
dataF = in->float_buffer.data + size_t(in->x) * y * 4 + 4 * x;
|
2015-05-29 13:38:20 +02:00
|
|
|
if (outF) {
|
|
|
|
|
outF[0] = dataF[0];
|
|
|
|
|
outF[1] = dataF[1];
|
|
|
|
|
outF[2] = dataF[2];
|
|
|
|
|
outF[3] = dataF[3];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 13:47:42 +01:00
|
|
|
void nearest_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int xout, int yout)
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
uchar *outI = nullptr;
|
|
|
|
|
float *outF = nullptr;
|
Split up the following imbuf functions in 2...
void bicubic_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void neareast_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float v, int xout, int yout);
Added...
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
This is needed so for projection painting but generally useful if you want to get the interpolated color of a pixel in an image without having a destination imbuf.
While editing these I noticed the functons are a bit dodgy, they assume the input ImBuf has matching float/chr buffer to the output.
2008-11-19 03:28:07 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (in == nullptr || (in->byte_buffer.data == nullptr && in->float_buffer.data == nullptr)) {
|
2012-10-01 06:18:45 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2019-08-14 23:29:46 +10:00
|
|
|
/* gcc warns these could be uninitialized, but its ok. */
|
|
|
|
|
pixel_from_buffer(out, &outI, &outF, xout, yout);
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
nearest_interpolation_color(in, outI, outF, u, v);
|
2008-11-20 00:34:24 +00:00
|
|
|
}
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
2012-08-07 16:47:46 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Threaded Image Processing
|
2020-09-14 16:11:13 +10:00
|
|
|
* \{ */
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2020-04-30 07:59:23 +02:00
|
|
|
static void processor_apply_func(TaskPool *__restrict pool, void *taskdata)
|
2013-12-25 20:32:13 +06:00
|
|
|
{
|
2020-04-21 15:36:35 +02:00
|
|
|
void (*do_thread)(void *) = (void (*)(void *))BLI_task_pool_user_data(pool);
|
2013-12-25 20:32:13 +06:00
|
|
|
do_thread(taskdata);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-07 16:47:46 +00:00
|
|
|
void IMB_processor_apply_threaded(
|
|
|
|
|
int buffer_lines,
|
|
|
|
|
int handle_size,
|
|
|
|
|
void *init_customdata,
|
|
|
|
|
void(init_handle)(void *handle, int start_line, int tot_line, void *customdata),
|
|
|
|
|
void *(do_thread)(void *))
|
|
|
|
|
{
|
2013-12-25 20:32:13 +06:00
|
|
|
const int lines_per_task = 64;
|
|
|
|
|
|
|
|
|
|
TaskPool *task_pool;
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2013-12-25 20:32:13 +06:00
|
|
|
void *handles;
|
|
|
|
|
int total_tasks = (buffer_lines + lines_per_task - 1) / lines_per_task;
|
|
|
|
|
int i, start_line;
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2023-05-02 11:32:27 +02:00
|
|
|
task_pool = BLI_task_pool_create(reinterpret_cast<void *>(do_thread), TASK_PRIORITY_HIGH);
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2013-12-25 20:32:13 +06:00
|
|
|
handles = MEM_callocN(handle_size * total_tasks, "processor apply threaded handles");
|
2012-08-07 16:47:46 +00:00
|
|
|
|
|
|
|
|
start_line = 0;
|
|
|
|
|
|
2013-12-25 20:32:13 +06:00
|
|
|
for (i = 0; i < total_tasks; i++) {
|
|
|
|
|
int lines_per_current_task;
|
2012-08-07 16:47:46 +00:00
|
|
|
void *handle = ((char *)handles) + handle_size * i;
|
|
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (i < total_tasks - 1) {
|
2013-12-25 20:32:13 +06:00
|
|
|
lines_per_current_task = lines_per_task;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2013-12-25 20:32:13 +06:00
|
|
|
lines_per_current_task = buffer_lines - start_line;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2013-12-25 20:32:13 +06:00
|
|
|
init_handle(handle, start_line, lines_per_current_task, init_customdata);
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2023-05-02 11:32:27 +02:00
|
|
|
BLI_task_pool_push(task_pool, processor_apply_func, handle, false, nullptr);
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2013-12-25 20:32:13 +06:00
|
|
|
start_line += lines_per_task;
|
2012-08-07 16:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-25 20:32:13 +06:00
|
|
|
/* work and wait until tasks are done */
|
|
|
|
|
BLI_task_pool_work_and_wait(task_pool);
|
2012-08-07 16:47:46 +00:00
|
|
|
|
2013-12-25 20:32:13 +06:00
|
|
|
/* Free memory. */
|
2016-05-05 13:15:51 +02:00
|
|
|
MEM_freeN(handles);
|
|
|
|
|
BLI_task_pool_free(task_pool);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 19:37:19 +10:00
|
|
|
struct ScanlineGlobalData {
|
2016-05-05 13:15:51 +02:00
|
|
|
void *custom_data;
|
|
|
|
|
ScanlineThreadFunc do_thread;
|
2023-07-02 19:37:19 +10:00
|
|
|
};
|
2016-05-05 13:15:51 +02:00
|
|
|
|
2021-06-11 15:55:09 +02:00
|
|
|
static void processor_apply_parallel(void *__restrict userdata,
|
|
|
|
|
const int scanline,
|
2023-05-02 11:32:27 +02:00
|
|
|
const TaskParallelTLS *__restrict /*tls*/)
|
2016-05-05 13:15:51 +02:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
ScanlineGlobalData *data = static_cast<ScanlineGlobalData *>(userdata);
|
2021-06-11 15:55:09 +02:00
|
|
|
data->do_thread(data->custom_data, scanline);
|
2016-05-05 13:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-05 14:18:11 +02:00
|
|
|
void IMB_processor_apply_threaded_scanlines(int total_scanlines,
|
2016-05-05 13:15:51 +02:00
|
|
|
ScanlineThreadFunc do_thread,
|
|
|
|
|
void *custom_data)
|
|
|
|
|
{
|
2021-06-11 15:55:09 +02:00
|
|
|
TaskParallelSettings settings;
|
2023-05-02 11:32:27 +02:00
|
|
|
ScanlineGlobalData data = {};
|
|
|
|
|
data.do_thread = do_thread;
|
|
|
|
|
data.custom_data = custom_data;
|
2021-06-11 15:55:09 +02:00
|
|
|
|
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
|
BLI_task_parallel_range(0, total_scanlines, &data, processor_apply_parallel, &settings);
|
2012-08-07 16:47:46 +00:00
|
|
|
}
|
2013-01-05 15:33:18 +00:00
|
|
|
|
|
|
|
|
/** \} */
|
2020-09-14 16:11:13 +10:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2013-01-05 15:33:18 +00:00
|
|
|
/** \name Alpha-under
|
2020-09-14 16:11:13 +10:00
|
|
|
* \{ */
|
2013-01-05 15:33:18 +00:00
|
|
|
|
|
|
|
|
void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3])
|
|
|
|
|
{
|
2023-05-02 20:09:09 +10:00
|
|
|
size_t a = size_t(x) * y;
|
2013-01-05 15:33:18 +00:00
|
|
|
float *fp = rect_float;
|
|
|
|
|
|
|
|
|
|
while (a--) {
|
2020-10-19 11:29:47 +02:00
|
|
|
const float mul = 1.0f - fp[3];
|
|
|
|
|
madd_v3_v3fl(fp, backcol, mul);
|
2013-01-05 15:33:18 +00:00
|
|
|
fp[3] = 1.0f;
|
|
|
|
|
|
|
|
|
|
fp += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 16:29:06 +10:00
|
|
|
void IMB_alpha_under_color_byte(uchar *rect, int x, int y, const float backcol[3])
|
2013-01-05 15:33:18 +00:00
|
|
|
{
|
2023-05-02 20:09:09 +10:00
|
|
|
size_t a = size_t(x) * y;
|
2022-09-13 16:29:06 +10:00
|
|
|
uchar *cp = rect;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-05 15:33:18 +00:00
|
|
|
while (a--) {
|
2013-08-23 08:27:01 +00:00
|
|
|
if (cp[3] == 255) {
|
|
|
|
|
/* pass */
|
|
|
|
|
}
|
|
|
|
|
else if (cp[3] == 0) {
|
2013-01-05 15:33:18 +00:00
|
|
|
cp[0] = backcol[0] * 255;
|
|
|
|
|
cp[1] = backcol[1] * 255;
|
|
|
|
|
cp[2] = backcol[2] * 255;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-08-23 08:27:01 +00:00
|
|
|
float alpha = cp[3] / 255.0;
|
|
|
|
|
float mul = 1.0f - alpha;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-23 08:27:01 +00:00
|
|
|
cp[0] = (cp[0] * alpha) + mul * backcol[0];
|
|
|
|
|
cp[1] = (cp[1] * alpha) + mul * backcol[1];
|
|
|
|
|
cp[2] = (cp[2] * alpha) + mul * backcol[2];
|
2013-01-05 15:33:18 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-05 15:33:18 +00:00
|
|
|
cp[3] = 255;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-05 15:33:18 +00:00
|
|
|
cp += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-09 16:27:24 +01:00
|
|
|
|
2020-09-14 16:11:13 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2020-03-09 16:27:24 +01:00
|
|
|
/** \name Sample Pixel
|
2020-09-14 16:11:13 +10:00
|
|
|
* \{ */
|
|
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
void IMB_sampleImageAtLocation(ImBuf *ibuf, float x, float y, bool make_linear_rgb, float color[4])
|
|
|
|
|
{
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->float_buffer.data) {
|
2023-05-02 11:32:27 +02:00
|
|
|
nearest_interpolation_color(ibuf, nullptr, color, x, y);
|
2020-03-09 16:27:24 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2022-09-13 16:29:06 +10:00
|
|
|
uchar byte_color[4];
|
2023-05-02 11:32:27 +02:00
|
|
|
nearest_interpolation_color(ibuf, byte_color, nullptr, x, y);
|
2020-03-09 16:27:24 +01:00
|
|
|
rgba_uchar_to_float(color, byte_color);
|
|
|
|
|
if (make_linear_rgb) {
|
2023-06-23 15:55:42 +02:00
|
|
|
IMB_colormanagement_colorspace_to_scene_linear_v4(
|
|
|
|
|
color, false, ibuf->byte_buffer.colorspace);
|
2020-03-09 16:27:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-14 16:11:13 +10:00
|
|
|
|
|
|
|
|
/** \} */
|