14#include <lagrange/common.h>
15#include <lagrange/image/api.h>
52 luminance = ((1) << 8) | 0x0,
53 luminance_alpha = ((2) << 8) | 0x1,
54 alpha_luminance = ((2) << 8) | 0x2,
55 rgb = ((3) << 8) | 0x4,
56 bgr = ((3) << 8) | 0x8,
57 rgba = ((4) << 8) | 0x10,
58 argb = ((4) << 8) | 0x12,
59 bgra = ((4) << 8) | 0x14,
60 max = ((4) << 8) | ((1 << 8) - 1)
66 first_pixel_row_at_bottom,
67 first_pixel_row_at_top
81 template <
typename Scalar, u
int32_t NumChannels>
85 size_t get_width()
const {
return m_width; }
86 size_t get_height()
const {
return m_height; }
87 size_t get_row_byte_stride()
const {
return m_row_byte_stride; }
88 precision_semantic get_pixel_precision()
const {
return m_pixel_precision; }
89 color_space get_color_space()
const {
return m_color_space; }
90 texture_format get_tex_format()
const {
return m_tex_format; }
91 wrap_mode get_wrap_u()
const {
return m_wrap_u; }
92 wrap_mode get_wrap_v()
const {
return m_wrap_v; }
93 image_storage_format get_storage_format()
const {
return m_storage_format; }
95 size_t get_size_precision()
const
97 return static_cast<size_t>(1llu << static_cast<uint32_t>(m_pixel_precision));
100 size_t get_num_channels()
const
102 return static_cast<size_t>(
static_cast<uint32_t
>(m_tex_format) >> 8u);
105 size_t get_size_pixel()
const {
return get_size_precision() * get_num_channels(); }
107 size_t get_row_stride()
const
109 return (0 == m_row_byte_stride ? get_size_pixel() * m_width : m_row_byte_stride);
112 size_t get_pixel_data_offset()
const
114 return image_storage_format::first_pixel_row_at_top == m_storage_format
116 : get_row_stride() * (m_height - 1);
119 const void* get_pixel_data()
const;
121 void set_width(
size_t x) { m_width = x; }
122 void set_height(
size_t x) { m_height = x; }
123 void set_row_byte_stride(
size_t x) { m_row_byte_stride = x; }
124 void set_pixel_precision(precision_semantic x) { m_pixel_precision = x; }
125 void set_color_space(color_space x) { m_color_space = x; }
126 void set_tex_format(texture_format x) { m_tex_format = x; }
127 void set_wrap_u(wrap_mode x) { m_wrap_u = x; }
128 void set_wrap_v(wrap_mode x) { m_wrap_v = x; }
129 void set_storage_format(image_storage_format x) { m_storage_format = x; }
138 void set_pixel_data(
const void* pixel_data,
const bool copy_to_local);
142 void set_pixel_data_buffer(std::vector<unsigned char> pixel_data_buffer);
144 bool operator==(
const RawInputImage& other)
const;
145 bool operator!=(
const RawInputImage& other)
const {
return !(*
this == other); }
160 template <
typename TexcoordScalar,
typename Scalar, u
int32_t NumChannels>
161 typename PixelTraits<Scalar, NumChannels>::Pixel sample(
162 const TexcoordScalar u,
163 const TexcoordScalar v,
164 const texture_filtering filtering = texture_filtering::bilinear)
const;
180 template <
typename TexcoordScalar,
typename Scalar, u
int32_t NumChannels>
181 typename PixelTraits<Scalar, NumChannels>::Pixel sample_float(
182 const TexcoordScalar u,
183 const TexcoordScalar v,
184 const texture_filtering filtering = texture_filtering::bilinear)
const;
188 template <
typename Archive>
189 void serialize_impl(Archive& ar);
193 typename TexcoordScalar,
195 uint32_t NumChannels,
196 typename InternalScalar,
197 uint32_t InternalNumChannels>
198 typename PixelTraits<Scalar, NumChannels>::Pixel sample(
199 const TexcoordScalar u,
200 const TexcoordScalar v,
201 const texture_filtering filtering = texture_filtering::bilinear)
const;
206 size_t m_row_byte_stride = 0;
207 precision_semantic m_pixel_precision = precision_semantic::single_p;
208 color_space m_color_space = color_space::linear;
209 texture_format m_tex_format = texture_format::rgba;
210 wrap_mode m_wrap_u = wrap_mode::clamp;
211 wrap_mode m_wrap_v = wrap_mode::clamp;
212 image_storage_format m_storage_format = image_storage_format::first_pixel_row_at_top;
215 const void* m_pixel_data =
nullptr;
217 std::vector<unsigned char> m_local_pixel_data;
220template <
typename Scalar, u
int32_t NumChannels>
224 0u < NumChannels && NumChannels <= (static_cast<uint32_t>(texture_format::max) >> 8u));
226 std::is_same<unsigned char, Scalar>::value || std::is_same<Eigen::half, Scalar>::value ||
227 std::is_same<float, Scalar>::value || std::is_same<double, Scalar>::value);
229 using Pixel = Eigen::Matrix<Scalar, NumChannels, 1>;
231 static Pixel zero() {
return Pixel::Zero(); }
233 static Scalar coeff(
const Pixel& p,
const size_t i)
235 assert(i < NumChannels);
239 static Scalar& coeff(Pixel& p,
const size_t i)
241 assert(i < NumChannels);
246template <
typename Scalar>
250 std::is_same<unsigned char, Scalar>::value || std::is_same<Eigen::half, Scalar>::value ||
251 std::is_same<float, Scalar>::value || std::is_same<double, Scalar>::value);
253 using Pixel = Scalar;
255 static Pixel zero() {
return static_cast<Scalar
>(0); }
257 static Scalar coeff(
const Pixel& p, [[maybe_unused]]
const size_t i)
263 static Scalar& coeff(Pixel& p, [[maybe_unused]]
const size_t i)
271template <
typename Archive>
278LA_IMAGE_API RawInputImage
282LA_IMAGE_API RawInputImage
290 return std::clamp(u,
static_cast<T
>(0),
static_cast<T
>(1));
292 return u - std::floor(u);
294 const auto f =
static_cast<int>(std::floor(u));
295 auto _u = u -
static_cast<T
>(f);
297 _u =
static_cast<T
>(1) - _u;
308#include <lagrange/image/RawInputImage.impl.h>
LA_IMAGE_API RawInputImage make_default_rgba_image(std::size_t i_width, std::size_t i_height, const void *i_pixels)
Wrap a void * data into a Linear 4-component image. Pixel memory ownership is not transferred.
Definition: RawInputImage.cpp:83
T wrap_uv(const T u, const RawInputImage::wrap_mode m)
wrap uv coordinate
Definition: RawInputImage.h:287
void serialize(lagrange::image::RawInputImage &image, Archive &ar)
Serialization of RawInputImage.
Definition: RawInputImage.h:272
LA_IMAGE_API RawInputImage make_default_luminance_image(std::size_t i_width, std::size_t i_height, const void *i_pixels)
Wrap a void * data into a Linear 1-component image. Pixel memory ownership is not transferred.
Definition: RawInputImage.cpp:101
bool operator==(const shared_ptr< T > &sp1, const shared_ptr< U > &sp2)
Operator == overloading.
Definition: shared_ptr.h:344
bool operator!=(const shared_ptr< T > &sp1, const shared_ptr< U > &sp2)
Operator != overloading.
Definition: shared_ptr.h:363
Main namespace for Lagrange.
Definition: AABBIGL.h:30