Blender V5.0
BKE_image_wrappers.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "DNA_image_types.h"
12
13#include "BLI_math_color.h"
14#include "BLI_math_vector.h"
16#include "BLI_memory_utils.hh"
17
18#include "IMB_imbuf_types.hh"
19
20namespace blender::bke::image {
21
24
28
30 {
31 return image_tile->tile_number;
32 }
33
35 {
37 }
38
40 {
41 TileNumber tile_number = get_tile_number();
42 return (tile_number - 1001) % 10;
43 }
44
46 {
47 TileNumber tile_number = get_tile_number();
48 return (tile_number - 1001) / 10;
49 }
50};
51
52template<typename T, int Channels = 4> struct ImageBufferAccessor {
53 static_assert(is_same_any_v<T, int, float4>);
54
56
58
59 float4 read_pixel(const int2 coordinate)
60 {
61 if constexpr ((std::is_same_v<T, float4>)) {
62 int offset = (coordinate.y * image_buffer.x + coordinate.x) * Channels;
63 return float4(&image_buffer.float_buffer.data[offset]);
64 }
65 if constexpr ((std::is_same_v<T, int>)) {
66 int offset = (coordinate.y * image_buffer.x + coordinate.x) * Channels;
69 result,
70 static_cast<uchar *>(static_cast<void *>(&image_buffer.byte_buffer.data[offset])));
71 return result;
72 }
73 return float4();
74 }
75
76 void write_pixel(const int2 coordinate, float4 new_value)
77 {
78 if constexpr ((std::is_same_v<T, float>)) {
79 int offset = (coordinate.y * image_buffer.x + coordinate.x) * Channels;
80 copy_v4_v4(&image_buffer.float_buffer.data[offset], new_value);
81 }
82 if constexpr ((std::is_same_v<T, int>)) {
83 int offset = (coordinate.y * image_buffer.x + coordinate.x) * Channels;
85 static_cast<uchar *>(static_cast<void *>(&image_buffer.byte_buffer.data[offset])),
86 new_value);
87 }
88 }
89};
90
91} // namespace blender::bke::image
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
unsigned char uchar
constexpr bool is_same_any_v
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
void write_pixel(const int2 coordinate, float4 new_value)
float4 read_pixel(const int2 coordinate)