Blender V4.3
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
9#pragma once
10
11#include "DNA_image_types.h"
12
13#include "BLI_math_color.h"
14#include "BLI_math_vector.h"
16
17#include "IMB_imbuf_types.hh"
18
19namespace blender::bke::image {
20
23
27
29 {
30 return image_tile->tile_number;
31 }
32
34 {
36 }
37
39 {
40 TileNumber tile_number = get_tile_number();
41 return (tile_number - 1001) % 10;
42 }
43
45 {
46 TileNumber tile_number = get_tile_number();
47 return (tile_number - 1001) / 10;
48 }
49};
50
51template<typename T, int Channels = 4> struct ImageBufferAccessor {
52 static_assert(std::is_same_v<T, int> || std::is_same_v<T, float4>);
53
55
57
58 float4 read_pixel(const int2 coordinate)
59 {
60 if constexpr ((std::is_same_v<T, float4>)) {
61 int offset = (coordinate.y * image_buffer.x + coordinate.x) * Channels;
62 return float4(&image_buffer.float_buffer.data[offset]);
63 }
64 if constexpr ((std::is_same_v<T, int>)) {
65 int offset = (coordinate.y * image_buffer.x + coordinate.x);
68 result,
69 static_cast<uchar *>(static_cast<void *>(&image_buffer.byte_buffer.data[offset])));
70 return result;
71 }
72 return float4();
73 }
74
75 void write_pixel(const int2 coordinate, float4 new_value)
76 {
77 if constexpr ((std::is_same_v<T, float>)) {
78 int offset = (coordinate.y * image_buffer.x + coordinate.x) * Channels;
79 copy_v4_v4(&image_buffer.float_buffer.data[offset], new_value);
80 }
81 if constexpr ((std::is_same_v<T, int>)) {
82 int offset = (coordinate.y * image_buffer.x + coordinate.x);
84 static_cast<uchar *>(static_cast<void *>(&image_buffer.byte_buffer.data[offset])),
85 new_value);
86 }
87 }
88};
89
90} // namespace blender::bke::image
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
unsigned char uchar
Contains defines and structs used throughout the imbuf module.
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
signed int int32_t
Definition stdint.h:77
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
void write_pixel(const int2 coordinate, float4 new_value)
float4 read_pixel(const int2 coordinate)