63 *r_texture_format = is_grayscale ? (use_high_bitdepth ?
GPU_R32F :
GPU_R16F) :
117 const bool do_rescale,
118 const int rescale_size[2],
119 const bool store_premultiplied,
120 const bool allow_grayscale,
128 bool freedata =
false;
134 if (ibuf->
channels != 4 || !store_premultiplied) {
136 *r_freedata = freedata =
true;
138 if (data_rect ==
nullptr) {
143 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
158 data_rect =
MEM_mallocN((is_grayscale ?
sizeof(
float[4]) :
sizeof(
uchar[4])) *
161 *r_freedata = freedata =
true;
163 if (data_rect ==
nullptr) {
175 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
176 is_float_rect =
true;
180 (
uchar *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
186 *r_freedata = freedata =
true;
187 is_float_rect =
true;
189 if (data_rect ==
nullptr) {
199 (
float *)data_rect, 0, 0, ibuf->
x, ibuf->
y, ibuf, store_premultiplied);
204 const uint8_t *rect = (is_float_rect) ?
nullptr : (uint8_t *)data_rect;
205 const float *rect_float = (is_float_rect) ? (
float *)data_rect :
nullptr;
216 *r_freedata = freedata =
true;
225 void *src_rect = data_rect;
227 if (freedata ==
false) {
230 *r_freedata = freedata =
true;
233 if (data_rect ==
nullptr) {
237 size_t buffer_size = do_rescale ? size_t(rescale_size[0]) * size_t(rescale_size[1]) :
238 size_t(ibuf->
x) * size_t(ibuf->
y);
240 for (
size_t i = 0;
i < buffer_size;
i++) {
241 ((
float *)data_rect)[
i] = ((
float *)src_rect)[
i * 4];
245 for (
size_t i = 0;
i < buffer_size;
i++) {
260 bool use_high_bitdepth,
288 bool use_high_bitdepth,
292 const bool do_rescale = (ibuf->
x !=
w || ibuf->
y != h);
293 const int size[2] = {
w, h};
298 bool freebuf =
false;
302 ibuf, do_rescale,
size, use_premult, use_grayscale, &freebuf, &data_format);
314 bool use_high_bitdepth,
317 GPUTexture *tex =
nullptr;
319 bool do_rescale = (ibuf->
x !=
size[0]) || (ibuf->
y !=
size[1]);
322 if (do_rescale && ibuf->
x != ibuf->
y) {
324 size[1] = int(ibuf->
y * (
float(
size[0]) / ibuf->
x));
327 size[0] = int(ibuf->
x * (
float(
size[1]) / ibuf->
y));
334 fprintf(stderr,
"Unable to find a suitable DXT compression,");
336 else if (do_rescale) {
337 fprintf(stderr,
"Unable to load DXT image resolution,");
344 fprintf(stderr,
"Unable to load non-power-of-two DXT image resolution,");
355 if (tex !=
nullptr) {
359 fprintf(stderr,
"ST3C support not found,");
362 fprintf(stderr,
" falling back to uncompressed (%s, %ix%i).\n", name, ibuf->
x, ibuf->
y);
368 bool freebuf =
false;
374 if (tex ==
nullptr) {
401 return gpu_texture_format;
406 const float half_min = -65504;
407 const float half_max = 65504;
414 int rect_float_len = image_buffer->
x * image_buffer->
y *
417 for (
int i = 0;
i < rect_float_len;
i++) {
418 rect_float[
i] =
clamp_f(rect_float[
i], half_min, half_max);
MINLINE float clamp_f(float value, float min, float max)
MINLINE int max_ii(int a, int b)
MINLINE int is_power_of_2_i(int n)
int GPU_texture_size_with_limit(int res)
GPUTexture * GPU_texture_create_compressed_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_anisotropic_filter(GPUTexture *texture, bool use_aniso)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
@ GPU_TEXTURE_USAGE_GENERAL
void GPU_texture_update_sub(GPUTexture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
GPUTexture * GPU_texture_create_2d_array(const char *name, int width, int height, int layer_len, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4])
void IMB_colormanagement_imbuf_to_byte_texture(unsigned char *out_buffer, int offset_x, int offset_y, int width, int height, const ImBuf *ibuf, bool store_premultiplied)
bool IMB_colormanagement_space_is_scene_linear(const ColorSpace *colorspace)
bool IMB_colormanagement_space_is_data(const ColorSpace *colorspace)
void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, int offset_x, int offset_y, int width, int height, const ImBuf *ibuf, bool store_premultiplied)
bool IMB_colormanagement_space_is_srgb(const ColorSpace *colorspace)
float * IMB_steal_float_buffer(ImBuf *ibuf)
uint8_t * IMB_steal_byte_buffer(ImBuf *ibuf)
ImBuf * IMB_allocFromBuffer(const uint8_t *byte_buffer, const float *float_buffer, unsigned int w, unsigned int h, unsigned int channels)
void IMB_freeImBuf(ImBuf *ibuf)
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
bool IMB_scale(ImBuf *ibuf, unsigned int newx, unsigned int newy, IMBScaleFilter filter, bool threaded=true)
Read Guarded memory(de)allocation.
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void * MEM_mallocN(size_t len, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImbFormatOptions foptions
ImBufByteBuffer byte_buffer
static bool imb_is_grayscale_texture_format_compatible(const ImBuf *ibuf)
static bool IMB_gpu_get_compressed_format(const ImBuf *ibuf, eGPUTextureFormat *r_texture_format)
GPUTexture * IMB_touch_gpu_texture(const char *name, ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth, bool use_grayscale)
static const char * imb_gpu_get_swizzle(const ImBuf *ibuf)
static void * imb_gpu_get_data(const ImBuf *ibuf, const bool do_rescale, const int rescale_size[2], const bool store_premultiplied, const bool allow_grayscale, bool *r_freedata, eGPUDataFormat *r_data_format)
eGPUTextureFormat IMB_gpu_get_texture_format(const ImBuf *ibuf, bool high_bitdepth, bool use_grayscale)
void IMB_update_gpu_texture_sub(GPUTexture *tex, ImBuf *ibuf, int x, int y, int z, int w, int h, bool use_high_bitdepth, bool use_grayscale, bool use_premult)
static void imb_gpu_get_format(const ImBuf *ibuf, bool high_bitdepth, bool use_grayscale, eGPUTextureFormat *r_texture_format)
GPUTexture * IMB_create_gpu_texture(const char *name, ImBuf *ibuf, bool use_high_bitdepth, bool use_premult)
void IMB_gpu_clamp_half_float(ImBuf *image_buffer)