Blender V5.0
imageprocess.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 * SPDX-FileCopyrightText: 2024 Blender Authors
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later */
5
9
10#include "BLI_math_vector.h"
11#include "BLI_task.hh"
12
13#include "IMB_imbuf.hh"
14#include "IMB_imbuf_types.hh"
15
16/* -------------------------------------------------------------------- */
19
20void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3])
21{
22 using namespace blender;
23 threading::parallel_for(IndexRange(int64_t(x) * y), 32 * 1024, [&](const IndexRange i_range) {
24 float *pix = rect_float + i_range.first() * 4;
25 for ([[maybe_unused]] const int i : i_range) {
26 const float mul = 1.0f - pix[3];
27 madd_v3_v3fl(pix, backcol, mul);
28 pix[3] = 1.0f;
29 pix += 4;
30 }
31 });
32}
33
34void IMB_alpha_under_color_byte(uchar *rect, int x, int y, const float backcol[3])
35{
36 using namespace blender;
37 threading::parallel_for(IndexRange(int64_t(x) * y), 32 * 1024, [&](const IndexRange i_range) {
38 uchar *pix = rect + i_range.first() * 4;
39 for ([[maybe_unused]] const int i : i_range) {
40 if (pix[3] == 255) {
41 /* pass */
42 }
43 else if (pix[3] == 0) {
44 pix[0] = backcol[0] * 255;
45 pix[1] = backcol[1] * 255;
46 pix[2] = backcol[2] * 255;
47 }
48 else {
49 float alpha = pix[3] / 255.0;
50 float mul = 1.0f - alpha;
51
52 pix[0] = (pix[0] * alpha) + mul * backcol[0];
53 pix[1] = (pix[1] * alpha) + mul * backcol[1];
54 pix[2] = (pix[2] * alpha) + mul * backcol[2];
55 }
56 pix[3] = 255;
57 pix += 4;
58 }
59 });
60}
61
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
unsigned char uchar
long long int int64_t
static void mul(btAlignedObjectArray< T > &items, const Q &value)
constexpr int64_t first() const
void IMB_alpha_under_color_byte(uchar *rect, int x, int y, const float backcol[3])
void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3])
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:93
i
Definition text_draw.cc:230