Blender V5.3
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_c.hh"
11#include "BLI_task.hh"
12
13#include "IMB_imbuf.hh"
14#include "IMB_imbuf_types.hh"
15
16namespace blender {
17
18/* -------------------------------------------------------------------- */
21
22void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3])
23{
24 threading::parallel_for(IndexRange(int64_t(x) * y), 32 * 1024, [&](const IndexRange i_range) {
25 float *pix = rect_float + i_range.first() * 4;
26 for ([[maybe_unused]] const int i : i_range) {
27 const float mul = 1.0f - pix[3];
28 madd_v3_v3fl(pix, backcol, mul);
29 pix[3] = 1.0f;
30 pix += 4;
31 }
32 });
33}
34
35void IMB_alpha_under_color_byte(uchar *rect, int x, int y, const float backcol[3])
36{
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
63
64} // namespace blender
constexpr int64_t first() const
constexpr IndexRange()=default
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:69
BMesh Iterators.
void IMB_alpha_under_color_byte(unsigned char *rect, int x, int y, const float backcol[3])
__int64 int64_t
Definition BKE_text.h:90
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
unsigned char uchar
Definition BKE_text.h:58
void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3])