2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup imbuf
|
2011-02-27 20:23:21 +00:00
|
|
|
*/
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* It's become a bit messy... Basically, only the IMB_ prefixed files
|
|
|
|
|
* should remain. */
|
|
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cstddef>
|
2010-09-15 06:43:36 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "IMB_imbuf.h"
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
#include "IMB_imbuf_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
#include "IMB_allocimbuf.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "IMB_colormanagement_intern.h"
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
#include "IMB_filetype.h"
|
|
|
|
|
#include "IMB_metadata.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
#include "imbuf.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-04-01 13:14:37 +06:00
|
|
|
#include "BLI_threads.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2014-04-01 13:14:37 +06:00
|
|
|
|
2023-07-10 16:33:32 +02:00
|
|
|
#include "GPU_texture.h"
|
|
|
|
|
|
2014-04-01 13:14:37 +06:00
|
|
|
static SpinLock refcounter_spin;
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
void imb_refcounter_lock_init()
|
2014-04-01 13:14:37 +06:00
|
|
|
{
|
|
|
|
|
BLI_spin_init(&refcounter_spin);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
void imb_refcounter_lock_exit()
|
2014-04-01 13:14:37 +06:00
|
|
|
{
|
|
|
|
|
BLI_spin_end(&refcounter_spin);
|
|
|
|
|
}
|
2013-09-10 05:57:54 +00:00
|
|
|
|
2021-01-14 22:02:48 +01:00
|
|
|
#ifndef WIN32
|
2015-09-29 19:54:25 +02:00
|
|
|
static SpinLock mmap_spin;
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
void imb_mmap_lock_init()
|
2015-09-29 19:54:25 +02:00
|
|
|
{
|
|
|
|
|
BLI_spin_init(&mmap_spin);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
void imb_mmap_lock_exit()
|
2015-09-29 19:54:25 +02:00
|
|
|
{
|
|
|
|
|
BLI_spin_end(&mmap_spin);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
void imb_mmap_lock()
|
2015-09-29 19:54:25 +02:00
|
|
|
{
|
|
|
|
|
BLI_spin_lock(&mmap_spin);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
void imb_mmap_unlock()
|
2015-09-29 19:54:25 +02:00
|
|
|
{
|
|
|
|
|
BLI_spin_unlock(&mmap_spin);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
/* Free the specified buffer storage, freeing memory when needed and restoring the state of the
|
|
|
|
|
* buffer to its defaults. */
|
|
|
|
|
template<class BufferType> static void imb_free_buffer(BufferType &buffer)
|
|
|
|
|
{
|
2023-07-10 16:33:32 +02:00
|
|
|
if (buffer.data) {
|
2023-05-18 10:19:01 +02:00
|
|
|
switch (buffer.ownership) {
|
|
|
|
|
case IB_DO_NOT_TAKE_OWNERSHIP:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IB_TAKE_OWNERSHIP:
|
|
|
|
|
MEM_freeN(buffer.data);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Reset buffer to defaults. */
|
|
|
|
|
buffer.data = nullptr;
|
|
|
|
|
buffer.ownership = IB_DO_NOT_TAKE_OWNERSHIP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allocate pixel storage of the given buffer. The buffer owns the allocated memory.
|
|
|
|
|
* Returns true of allocation succeeded, false otherwise. */
|
|
|
|
|
template<class BufferType>
|
|
|
|
|
bool imb_alloc_buffer(
|
|
|
|
|
BufferType &buffer, const uint x, const uint y, const uint channels, const size_t type_size)
|
|
|
|
|
{
|
|
|
|
|
buffer.data = static_cast<decltype(BufferType::data)>(
|
|
|
|
|
imb_alloc_pixels(x, y, channels, type_size, __func__));
|
|
|
|
|
if (!buffer.data) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer.ownership = IB_TAKE_OWNERSHIP;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make the buffer available for modification.
|
|
|
|
|
* Is achieved by ensuring that the buffer is the only owner of its data. */
|
|
|
|
|
template<class BufferType> void imb_make_writeable_buffer(BufferType &buffer)
|
|
|
|
|
{
|
|
|
|
|
if (!buffer.data) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (buffer.ownership) {
|
|
|
|
|
case IB_DO_NOT_TAKE_OWNERSHIP:
|
|
|
|
|
buffer.data = static_cast<decltype(BufferType::data)>(MEM_dupallocN(buffer.data));
|
|
|
|
|
buffer.ownership = IB_TAKE_OWNERSHIP;
|
2023-05-23 09:19:37 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
case IB_TAKE_OWNERSHIP:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class BufferType>
|
|
|
|
|
auto imb_steal_buffer_data(BufferType &buffer) -> decltype(BufferType::data)
|
|
|
|
|
{
|
|
|
|
|
if (!buffer.data) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (buffer.ownership) {
|
|
|
|
|
case IB_DO_NOT_TAKE_OWNERSHIP:
|
|
|
|
|
BLI_assert(!"Unexpected behavior: stealing non-owned data pointer");
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
case IB_TAKE_OWNERSHIP: {
|
|
|
|
|
decltype(BufferType::data) data = buffer.data;
|
|
|
|
|
|
|
|
|
|
buffer.data = nullptr;
|
|
|
|
|
buffer.ownership = IB_DO_NOT_TAKE_OWNERSHIP;
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
void imb_freemipmapImBuf(ImBuf *ibuf)
|
2006-12-20 17:57:56 +00:00
|
|
|
{
|
|
|
|
|
int a;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-02 09:44:41 +01:00
|
|
|
/* Do not trust ibuf->miptot, in some cases IMB_remakemipmap can leave unfreed unused levels,
|
|
|
|
|
* leading to memory leaks... */
|
|
|
|
|
for (a = 0; a < IMB_MIPMAP_LEVELS; a++) {
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf->mipmap[a] != nullptr) {
|
2016-12-02 09:44:41 +01:00
|
|
|
IMB_freeImBuf(ibuf->mipmap[a]);
|
2023-05-02 11:32:27 +02:00
|
|
|
ibuf->mipmap[a] = nullptr;
|
2016-12-02 09:44:41 +01:00
|
|
|
}
|
2006-12-20 17:57:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
ibuf->miptot = 0;
|
2006-12-20 17:57:56 +00:00
|
|
|
}
|
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
void imb_freerectfloatImBuf(ImBuf *ibuf)
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf == nullptr) {
|
2012-05-13 22:05:51 +00:00
|
|
|
return;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
imb_free_buffer(ibuf->float_buffer);
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
|
2006-12-20 17:57:56 +00:00
|
|
|
imb_freemipmapImBuf(ibuf);
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ibuf->flags &= ~IB_rectfloat;
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
void imb_freerectImBuf(ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf == nullptr) {
|
2012-05-13 22:05:51 +00:00
|
|
|
return;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2011-05-13 04:53:20 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
imb_free_buffer(ibuf->byte_buffer);
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2006-12-20 17:57:56 +00:00
|
|
|
imb_freemipmapImBuf(ibuf);
|
2011-05-13 04:53:20 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ibuf->flags &= ~IB_rect;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
static void freeencodedbufferImBuf(ImBuf *ibuf)
|
|
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf == nullptr) {
|
2012-05-13 22:05:51 +00:00
|
|
|
return;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
imb_free_buffer(ibuf->encoded_buffer);
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ibuf->encoded_buffer_size = 0;
|
|
|
|
|
ibuf->encoded_size = 0;
|
|
|
|
|
|
|
|
|
|
ibuf->flags &= ~IB_mem;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-15 11:47:11 +11:00
|
|
|
void imb_freerectImbuf_all(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
imb_freerectImBuf(ibuf);
|
|
|
|
|
imb_freerectfloatImBuf(ibuf);
|
|
|
|
|
freeencodedbufferImBuf(ibuf);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 16:33:32 +02:00
|
|
|
void IMB_free_gpu_textures(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
if (!ibuf || !ibuf->gpu.texture) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPU_texture_free(ibuf->gpu.texture);
|
|
|
|
|
ibuf->gpu.texture = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
void IMB_freeImBuf(ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2023-05-04 13:18:42 +10:00
|
|
|
if (ibuf == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-04 13:18:42 +10:00
|
|
|
bool needs_free = false;
|
|
|
|
|
|
|
|
|
|
BLI_spin_lock(&refcounter_spin);
|
|
|
|
|
if (ibuf->refcounter > 0) {
|
|
|
|
|
ibuf->refcounter--;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
needs_free = true;
|
|
|
|
|
}
|
|
|
|
|
BLI_spin_unlock(&refcounter_spin);
|
|
|
|
|
|
|
|
|
|
if (needs_free) {
|
2023-05-04 13:40:32 +10:00
|
|
|
/* Include this check here as the path may be manipulated after creation. */
|
|
|
|
|
BLI_assert_msg(!(ibuf->filepath[0] == '/' && ibuf->filepath[1] == '/'),
|
|
|
|
|
"'.blend' relative \"//\" must not be used in ImBuf!");
|
|
|
|
|
|
2023-05-04 13:18:42 +10:00
|
|
|
imb_freerectImbuf_all(ibuf);
|
2023-07-10 16:33:32 +02:00
|
|
|
IMB_free_gpu_textures(ibuf);
|
2023-05-04 13:18:42 +10:00
|
|
|
IMB_metadata_free(ibuf->metadata);
|
|
|
|
|
colormanage_cache_free(ibuf);
|
|
|
|
|
|
|
|
|
|
if (ibuf->dds_data.data != nullptr) {
|
|
|
|
|
/* dds_data.data is allocated by DirectDrawSurface::readData(), so don't use MEM_freeN! */
|
|
|
|
|
free(ibuf->dds_data.data);
|
2006-02-05 19:23:34 +00:00
|
|
|
}
|
2023-05-04 13:18:42 +10:00
|
|
|
MEM_freeN(ibuf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
void IMB_refImBuf(ImBuf *ibuf)
|
2006-02-05 19:23:34 +00:00
|
|
|
{
|
2014-04-01 13:14:37 +06:00
|
|
|
BLI_spin_lock(&refcounter_spin);
|
2006-02-05 19:23:34 +00:00
|
|
|
ibuf->refcounter++;
|
2014-04-01 13:14:37 +06:00
|
|
|
BLI_spin_unlock(&refcounter_spin);
|
2006-02-05 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-13 22:05:51 +00:00
|
|
|
ImBuf *IMB_makeSingleUser(ImBuf *ibuf)
|
== Sequencer ==
This patch adds:
* support for proxy building again (missing feature from Blender 2.49)
additionally to the way, Blender 2.49 worked, you can select several
strips at once and make Blender build proxies in the background (using
the job system)
Also a new thing: movie proxies are now build into AVI files, and
the proxy system is moved into ImBuf-library, so that other parts
of blender can also benefit from it.
* Timecode support: to fix seeking issues with files, that have
a) varying frame rates
b) very large GOP lengths
c) are broken inbetween
d) use different time code tracks
the proxy builder can now also build timecode indices, which are
used (optionally) for seeking.
For the first time, it is possible, to do frame exact seeking on
all file types.
* Support for different video-streams in one video file (can be
selected in sequencer, other parts of blender can also use it,
but UI has to be added accordingly)
* IMPORTANT: this patch *requires* ffmpeg 0.7 or newer, since
older versions don't support the pkt_pts field, that is essential
for building timecode indices.
Windows and Mac libs are already updated, Linux-users have to build
their own ffmpeg verions until distros keep up.
2011-08-28 14:46:03 +00:00
|
|
|
{
|
2023-05-04 13:18:42 +10:00
|
|
|
if (ibuf == nullptr) {
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2015-09-02 23:23:44 +10:00
|
|
|
}
|
== Sequencer ==
This patch adds:
* support for proxy building again (missing feature from Blender 2.49)
additionally to the way, Blender 2.49 worked, you can select several
strips at once and make Blender build proxies in the background (using
the job system)
Also a new thing: movie proxies are now build into AVI files, and
the proxy system is moved into ImBuf-library, so that other parts
of blender can also benefit from it.
* Timecode support: to fix seeking issues with files, that have
a) varying frame rates
b) very large GOP lengths
c) are broken inbetween
d) use different time code tracks
the proxy builder can now also build timecode indices, which are
used (optionally) for seeking.
For the first time, it is possible, to do frame exact seeking on
all file types.
* Support for different video-streams in one video file (can be
selected in sequencer, other parts of blender can also use it,
but UI has to be added accordingly)
* IMPORTANT: this patch *requires* ffmpeg 0.7 or newer, since
older versions don't support the pkt_pts field, that is essential
for building timecode indices.
Windows and Mac libs are already updated, Linux-users have to build
their own ffmpeg verions until distros keep up.
2011-08-28 14:46:03 +00:00
|
|
|
|
2023-05-04 13:18:42 +10:00
|
|
|
BLI_spin_lock(&refcounter_spin);
|
|
|
|
|
const bool is_single = (ibuf->refcounter == 0);
|
|
|
|
|
BLI_spin_unlock(&refcounter_spin);
|
|
|
|
|
if (is_single) {
|
|
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImBuf *rval = IMB_dupImBuf(ibuf);
|
== Sequencer ==
This patch adds:
* support for proxy building again (missing feature from Blender 2.49)
additionally to the way, Blender 2.49 worked, you can select several
strips at once and make Blender build proxies in the background (using
the job system)
Also a new thing: movie proxies are now build into AVI files, and
the proxy system is moved into ImBuf-library, so that other parts
of blender can also benefit from it.
* Timecode support: to fix seeking issues with files, that have
a) varying frame rates
b) very large GOP lengths
c) are broken inbetween
d) use different time code tracks
the proxy builder can now also build timecode indices, which are
used (optionally) for seeking.
For the first time, it is possible, to do frame exact seeking on
all file types.
* Support for different video-streams in one video file (can be
selected in sequencer, other parts of blender can also use it,
but UI has to be added accordingly)
* IMPORTANT: this patch *requires* ffmpeg 0.7 or newer, since
older versions don't support the pkt_pts field, that is essential
for building timecode indices.
Windows and Mac libs are already updated, Linux-users have to build
their own ffmpeg verions until distros keep up.
2011-08-28 14:46:03 +00:00
|
|
|
|
2015-05-04 12:52:58 +02:00
|
|
|
IMB_metadata_copy(rval, ibuf);
|
|
|
|
|
|
== Sequencer ==
This patch adds:
* support for proxy building again (missing feature from Blender 2.49)
additionally to the way, Blender 2.49 worked, you can select several
strips at once and make Blender build proxies in the background (using
the job system)
Also a new thing: movie proxies are now build into AVI files, and
the proxy system is moved into ImBuf-library, so that other parts
of blender can also benefit from it.
* Timecode support: to fix seeking issues with files, that have
a) varying frame rates
b) very large GOP lengths
c) are broken inbetween
d) use different time code tracks
the proxy builder can now also build timecode indices, which are
used (optionally) for seeking.
For the first time, it is possible, to do frame exact seeking on
all file types.
* Support for different video-streams in one video file (can be
selected in sequencer, other parts of blender can also use it,
but UI has to be added accordingly)
* IMPORTANT: this patch *requires* ffmpeg 0.7 or newer, since
older versions don't support the pkt_pts field, that is essential
for building timecode indices.
Windows and Mac libs are already updated, Linux-users have to build
their own ffmpeg verions until distros keep up.
2011-08-28 14:46:03 +00:00
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 01:00:03 +00:00
|
|
|
bool imb_addencodedbufferImBuf(ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf == nullptr) {
|
2013-09-10 01:00:03 +00:00
|
|
|
return false;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
freeencodedbufferImBuf(ibuf);
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->encoded_buffer_size == 0) {
|
|
|
|
|
ibuf->encoded_buffer_size = 10000;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ibuf->encoded_size = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (!imb_alloc_buffer(ibuf->encoded_buffer, ibuf->encoded_buffer_size, 1, 1, sizeof(uint8_t))) {
|
|
|
|
|
return false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ibuf->flags |= IB_mem;
|
|
|
|
|
|
|
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-10 01:00:03 +00:00
|
|
|
bool imb_enlargeencodedbufferImBuf(ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf == nullptr) {
|
2013-09-10 01:00:03 +00:00
|
|
|
return false;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->encoded_buffer_size < ibuf->encoded_size) {
|
2013-09-10 01:00:03 +00:00
|
|
|
printf("%s: error in parameters\n", __func__);
|
|
|
|
|
return false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
uint newsize = 2 * ibuf->encoded_buffer_size;
|
2019-04-22 12:20:14 +10:00
|
|
|
if (newsize < 10000) {
|
2012-03-24 06:38:07 +00:00
|
|
|
newsize = 10000;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ImBufByteBuffer new_buffer;
|
|
|
|
|
if (!imb_alloc_buffer(new_buffer, newsize, 1, 1, sizeof(uint8_t))) {
|
2013-09-10 01:00:03 +00:00
|
|
|
return false;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->encoded_buffer.data) {
|
|
|
|
|
memcpy(new_buffer.data, ibuf->encoded_buffer.data, ibuf->encoded_size);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-18 10:19:01 +02:00
|
|
|
ibuf->encoded_size = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
imb_free_buffer(ibuf->encoded_buffer);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-05-25 09:59:23 +02:00
|
|
|
ibuf->encoded_buffer = new_buffer;
|
2023-05-18 10:19:01 +02:00
|
|
|
ibuf->encoded_buffer_size = newsize;
|
2006-01-09 19:17:37 +00:00
|
|
|
ibuf->flags |= IB_mem;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-09-10 01:00:03 +00:00
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-03 14:13:27 +10:00
|
|
|
void *imb_alloc_pixels(uint x, uint y, uint channels, size_t typesize, const char *alloc_name)
|
2018-01-14 14:19:57 +01:00
|
|
|
{
|
|
|
|
|
/* Protect against buffer overflow vulnerabilities from files specifying
|
|
|
|
|
* a width and height that overflow and alloc too little memory. */
|
2023-05-02 20:09:09 +10:00
|
|
|
if (!(uint64_t(x) * uint64_t(y) < (SIZE_MAX / (channels * typesize)))) {
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2018-01-14 14:19:57 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-02 20:09:09 +10:00
|
|
|
size_t size = size_t(x) * size_t(y) * size_t(channels) * typesize;
|
2023-05-03 14:13:27 +10:00
|
|
|
return MEM_callocN(size, alloc_name);
|
2018-01-14 14:19:57 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-13 16:29:06 +10:00
|
|
|
bool imb_addrectfloatImBuf(ImBuf *ibuf, const uint channels)
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf == nullptr) {
|
2013-09-10 01:00:03 +00:00
|
|
|
return false;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
/* NOTE: Follows the historical code.
|
|
|
|
|
* Is unclear if it is desired or not to free mipmaps. If mipmaps are to be preserved a simple
|
|
|
|
|
* `imb_free_buffer(ibuf->float_buffer)` can be used instead. */
|
|
|
|
|
if (ibuf->float_buffer.data) {
|
2012-05-13 22:05:51 +00:00
|
|
|
imb_freerectfloatImBuf(ibuf); /* frees mipmap too, hrm */
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (!imb_alloc_buffer(ibuf->float_buffer, ibuf->x, ibuf->y, channels, sizeof(float))) {
|
|
|
|
|
return false;
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ibuf->channels = channels;
|
|
|
|
|
ibuf->flags |= IB_rectfloat;
|
|
|
|
|
|
|
|
|
|
return true;
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-09-10 01:00:03 +00:00
|
|
|
bool imb_addrectImBuf(ImBuf *ibuf)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2021-12-09 20:01:45 +11:00
|
|
|
/* Question; why also add ZBUF (when `planes > 32`)? */
|
|
|
|
|
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf == nullptr) {
|
2013-09-10 01:00:03 +00:00
|
|
|
return false;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 01:18:55 +10:00
|
|
|
/* Don't call imb_freerectImBuf, it frees mipmaps,
|
|
|
|
|
* this call is used only too give float buffers display. */
|
2023-05-18 10:19:01 +02:00
|
|
|
imb_free_buffer(ibuf->byte_buffer);
|
|
|
|
|
|
|
|
|
|
if (!imb_alloc_buffer(ibuf->byte_buffer, ibuf->x, ibuf->y, 4, sizeof(uint8_t))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ibuf->flags |= IB_rect;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t *IMB_steal_byte_buffer(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *data = imb_steal_buffer_data(ibuf->byte_buffer);
|
|
|
|
|
ibuf->flags &= ~IB_rect;
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float *IMB_steal_float_buffer(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
float *data = imb_steal_buffer_data(ibuf->float_buffer);
|
|
|
|
|
ibuf->flags &= ~IB_rectfloat;
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t *IMB_steal_encoded_buffer(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *data = imb_steal_buffer_data(ibuf->encoded_buffer);
|
|
|
|
|
|
|
|
|
|
ibuf->encoded_size = 0;
|
|
|
|
|
ibuf->encoded_buffer_size = 0;
|
|
|
|
|
|
|
|
|
|
ibuf->flags &= ~IB_mem;
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMB_make_writable_byte_buffer(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
imb_make_writeable_buffer(ibuf->byte_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMB_make_writable_float_buffer(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
imb_make_writeable_buffer(ibuf->float_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMB_assign_byte_buffer(ImBuf *ibuf, uint8_t *buffer_data, const ImBufOwnership ownership)
|
|
|
|
|
{
|
|
|
|
|
imb_free_buffer(ibuf->byte_buffer);
|
|
|
|
|
ibuf->flags &= ~IB_rect;
|
|
|
|
|
|
|
|
|
|
if (buffer_data) {
|
|
|
|
|
ibuf->byte_buffer.data = buffer_data;
|
|
|
|
|
ibuf->byte_buffer.ownership = ownership;
|
|
|
|
|
|
2006-01-09 19:17:37 +00:00
|
|
|
ibuf->flags |= IB_rect;
|
2023-05-18 10:19:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 12:39:50 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
void IMB_assign_float_buffer(ImBuf *ibuf, float *buffer_data, const ImBufOwnership ownership)
|
|
|
|
|
{
|
|
|
|
|
imb_free_buffer(ibuf->float_buffer);
|
|
|
|
|
ibuf->flags &= ~IB_rectfloat;
|
|
|
|
|
|
|
|
|
|
if (buffer_data) {
|
|
|
|
|
ibuf->float_buffer.data = buffer_data;
|
|
|
|
|
ibuf->float_buffer.ownership = ownership;
|
|
|
|
|
|
|
|
|
|
ibuf->flags |= IB_rectfloat;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2023-05-18 10:19:01 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ImBuf *IMB_allocFromBufferOwn(
|
|
|
|
|
uint8_t *byte_buffer, float *float_buffer, uint w, uint h, uint channels)
|
|
|
|
|
{
|
|
|
|
|
if (!(byte_buffer || float_buffer)) {
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2021-09-06 20:04:26 +10:00
|
|
|
}
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
ImBuf *ibuf = IMB_allocImBuf(w, h, 32, 0);
|
2021-09-06 20:04:26 +10:00
|
|
|
|
|
|
|
|
ibuf->channels = channels;
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (float_buffer) {
|
|
|
|
|
/* TODO(sergey): The 4 channels is the historical code. Should probably be `channels`, but
|
|
|
|
|
* needs a dedicated investigation. */
|
|
|
|
|
BLI_assert(MEM_allocN_len(float_buffer) == sizeof(float[4]) * w * h);
|
|
|
|
|
IMB_assign_float_buffer(ibuf, float_buffer, IB_TAKE_OWNERSHIP);
|
2021-09-06 20:04:26 +10:00
|
|
|
}
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (byte_buffer) {
|
|
|
|
|
BLI_assert(MEM_allocN_len(byte_buffer) == sizeof(uint8_t[4]) * w * h);
|
|
|
|
|
IMB_assign_byte_buffer(ibuf, byte_buffer, IB_TAKE_OWNERSHIP);
|
2021-09-06 20:04:26 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
ImBuf *IMB_allocFromBuffer(
|
2023-05-18 10:19:01 +02:00
|
|
|
const uint8_t *byte_buffer, const float *float_buffer, uint w, uint h, uint channels)
|
2015-02-23 17:19:06 +01:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
ImBuf *ibuf = nullptr;
|
2015-02-23 17:19:06 +01:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (!(byte_buffer || float_buffer)) {
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2015-02-23 17:19:06 +01:00
|
|
|
|
|
|
|
|
ibuf = IMB_allocImBuf(w, h, 32, 0);
|
|
|
|
|
|
2019-08-27 08:42:50 +02:00
|
|
|
ibuf->channels = channels;
|
2021-09-06 20:04:25 +10:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
/* NOTE: Avoid #MEM_dupallocN since the buffers might not be allocated using guarded-allocation.
|
|
|
|
|
*/
|
|
|
|
|
if (float_buffer) {
|
|
|
|
|
/* TODO(sergey): The 4 channels is the historical code. Should probably be `channels`, but
|
|
|
|
|
* needs a dedicated investigation. */
|
|
|
|
|
imb_alloc_buffer(ibuf->float_buffer, w, h, 4, sizeof(float));
|
2021-09-06 20:04:25 +10:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
memcpy(ibuf->float_buffer.data, float_buffer, sizeof(float[4]) * w * h);
|
2015-02-23 17:19:06 +01:00
|
|
|
}
|
2021-09-06 20:04:25 +10:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (byte_buffer) {
|
|
|
|
|
imb_alloc_buffer(ibuf->byte_buffer, w, h, 4, sizeof(uint8_t));
|
|
|
|
|
|
|
|
|
|
memcpy(ibuf->byte_buffer.data, byte_buffer, sizeof(uint8_t[4]) * w * h);
|
2015-02-23 17:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 16:29:06 +10:00
|
|
|
ImBuf *IMB_allocImBuf(uint x, uint y, uchar planes, uint flags)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2023-05-02 11:32:27 +02:00
|
|
|
ImBuf *ibuf = MEM_cnew<ImBuf>("ImBuf_struct");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ibuf) {
|
2016-05-06 11:48:07 +02:00
|
|
|
if (!IMB_initImBuf(ibuf, x, y, planes, flags)) {
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
}
|
2016-05-06 11:48:07 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-08 11:02:11 +10:00
|
|
|
return ibuf;
|
2016-05-06 11:48:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
bool IMB_initImBuf(ImBuf *ibuf, uint x, uint y, uchar planes, uint flags)
|
2016-05-06 11:48:07 +02:00
|
|
|
{
|
|
|
|
|
memset(ibuf, 0, sizeof(ImBuf));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-06 11:48:07 +02:00
|
|
|
ibuf->x = x;
|
|
|
|
|
ibuf->y = y;
|
|
|
|
|
ibuf->planes = planes;
|
|
|
|
|
ibuf->ftype = IMB_FTYPE_PNG;
|
2019-07-02 22:17:22 +10:00
|
|
|
/* The '15' means, set compression to low ratio but not time consuming. */
|
|
|
|
|
ibuf->foptions.quality = 15;
|
|
|
|
|
/* float option, is set to other values when buffers get assigned. */
|
|
|
|
|
ibuf->channels = 4;
|
|
|
|
|
/* IMB_DPI_DEFAULT -> pixels-per-meter. */
|
2023-09-20 12:11:37 +10:00
|
|
|
ibuf->ppm[0] = ibuf->ppm[1] = IMB_DPI_DEFAULT / 0.0254;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-06 11:48:07 +02:00
|
|
|
if (flags & IB_rect) {
|
|
|
|
|
if (imb_addrectImBuf(ibuf) == false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-06 11:48:07 +02:00
|
|
|
if (flags & IB_rectfloat) {
|
2022-09-12 19:39:24 +02:00
|
|
|
if (imb_addrectfloatImBuf(ibuf, ibuf->channels) == false) {
|
2016-05-06 11:48:07 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-06 11:48:07 +02:00
|
|
|
/* assign default spaces */
|
|
|
|
|
colormanage_imbuf_set_default_spaces(ibuf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-06 11:48:07 +02:00
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2017-06-14 22:36:30 +02:00
|
|
|
ImBuf *IMB_dupImBuf(const ImBuf *ibuf1)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
ImBuf *ibuf2, tbuf;
|
2002-10-12 11:37:38 +00:00
|
|
|
int flags = 0;
|
2006-12-20 17:57:56 +00:00
|
|
|
int a, x, y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf1 == nullptr) {
|
|
|
|
|
return nullptr;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf1->byte_buffer.data) {
|
2012-03-24 06:38:07 +00:00
|
|
|
flags |= IB_rect;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf1->float_buffer.data) {
|
2015-11-12 19:17:25 +05:00
|
|
|
flags |= IB_rectfloat;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
x = ibuf1->x;
|
|
|
|
|
y = ibuf1->y;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-21 20:47:19 +00:00
|
|
|
ibuf2 = IMB_allocImBuf(x, y, ibuf1->planes, flags);
|
2023-05-02 11:32:27 +02:00
|
|
|
if (ibuf2 == nullptr) {
|
|
|
|
|
return nullptr;
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 12:20:14 +10:00
|
|
|
if (flags & IB_rect) {
|
2023-05-18 10:19:01 +02:00
|
|
|
memcpy(ibuf2->byte_buffer.data, ibuf1->byte_buffer.data, size_t(x) * y * 4 * sizeof(uint8_t));
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 12:20:14 +10:00
|
|
|
if (flags & IB_rectfloat) {
|
2023-05-18 10:19:01 +02:00
|
|
|
memcpy(ibuf2->float_buffer.data,
|
|
|
|
|
ibuf1->float_buffer.data,
|
|
|
|
|
size_t(ibuf1->channels) * x * y * sizeof(float));
|
2019-04-22 12:20:14 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf1->encoded_buffer.data) {
|
|
|
|
|
ibuf2->encoded_buffer_size = ibuf1->encoded_buffer_size;
|
2013-09-10 01:00:03 +00:00
|
|
|
if (imb_addencodedbufferImBuf(ibuf2) == false) {
|
2002-10-12 11:37:38 +00:00
|
|
|
IMB_freeImBuf(ibuf2);
|
2023-05-02 11:32:27 +02:00
|
|
|
return nullptr;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
memcpy(ibuf2->encoded_buffer.data, ibuf1->encoded_buffer.data, ibuf1->encoded_size);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-23 15:55:42 +02:00
|
|
|
ibuf2->byte_buffer.colorspace = ibuf1->byte_buffer.colorspace;
|
|
|
|
|
ibuf2->float_buffer.colorspace = ibuf1->float_buffer.colorspace;
|
|
|
|
|
|
Orange branch: OpenEXR finally in Blender!
Credits go to Gernot Ziegler, who originally coded EXR support, and to
Austin Benesh for bringing it further. Kent Mein provided a lot of code
for integrating float buffers in Blender imbuf and ImBuf API cleanup,
and provided Make and Scons and static linking.
At this moment; the EXR libraries are a *dependency*, so you cannot get
the Orange branch compiled without having OpenEXR installed. Get the
(precompiled or sources) stuff from www.openexr.com. Current default is
that the headers and lib resides in /user/local/
Several changes/additions/fixes were added:
- EXR code only supported 'half' format (16 bits per channel). I've added
float writing, but for reading it I need tomorrow. :)
- Quite some clumsy copying of data happened in EXR code.
- cleaned up the api calls already a bit, preparing for more advanced
support
- Zbuffers were saved 16 bits, now 32 bits
- automatic adding of .exr extensions went wrong
Imbuf:
- added proper imbuf->flags and imbuf->mall support for float buffers, it
was created for *each* imbuf. :)
- found bugs for float buffers in scaling and flipping. Code there will
need more checks still
- imbuf also needs to be verified to behave properly when no 32 bits
rect exists (for saving for example)
TODO:
- support internal float images for textures, backbuf, AO probes, and
display in Image window
Hope this commit won't screwup syncing with bf-blender... :/
2006-01-09 00:40:35 +00:00
|
|
|
/* silly trick to copy the entire contents of ibuf1 struct over to ibuf */
|
2002-10-12 11:37:38 +00:00
|
|
|
tbuf = *ibuf1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* fix pointers */
|
2023-05-18 10:19:01 +02:00
|
|
|
tbuf.byte_buffer = ibuf2->byte_buffer;
|
|
|
|
|
tbuf.float_buffer = ibuf2->float_buffer;
|
|
|
|
|
tbuf.encoded_buffer = ibuf2->encoded_buffer;
|
2019-04-23 11:01:30 +10:00
|
|
|
for (a = 0; a < IMB_MIPMAP_LEVELS; a++) {
|
2023-05-02 11:32:27 +02:00
|
|
|
tbuf.mipmap[a] = nullptr;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2023-05-02 11:32:27 +02:00
|
|
|
tbuf.dds_data.data = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* set malloc flag */
|
2008-03-23 17:56:44 +00:00
|
|
|
tbuf.refcounter = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* for now don't duplicate metadata */
|
2023-05-02 11:32:27 +02:00
|
|
|
tbuf.metadata = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-02 11:32:27 +02:00
|
|
|
tbuf.display_buffer_flags = nullptr;
|
|
|
|
|
tbuf.colormanage_cache = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
*ibuf2 = tbuf;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-08 11:02:11 +10:00
|
|
|
return ibuf2;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2006-02-05 19:23:34 +00:00
|
|
|
|
2021-12-10 10:37:46 +01:00
|
|
|
size_t IMB_get_rect_len(const ImBuf *ibuf)
|
|
|
|
|
{
|
2023-05-02 20:09:09 +10:00
|
|
|
return size_t(ibuf->x) * size_t(ibuf->y);
|
2021-12-10 10:37:46 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-28 14:13:41 -07:00
|
|
|
size_t IMB_get_size_in_memory(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
size_t size = 0, channel_size = 0;
|
|
|
|
|
|
|
|
|
|
size += sizeof(ImBuf);
|
|
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->byte_buffer.data) {
|
2019-04-28 14:13:41 -07:00
|
|
|
channel_size += sizeof(char);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-28 14:13:41 -07:00
|
|
|
|
2023-05-18 10:19:01 +02:00
|
|
|
if (ibuf->float_buffer.data) {
|
2019-04-28 14:13:41 -07:00
|
|
|
channel_size += sizeof(float);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-28 14:13:41 -07:00
|
|
|
|
|
|
|
|
size += channel_size * ibuf->x * ibuf->y * ibuf->channels;
|
|
|
|
|
|
|
|
|
|
if (ibuf->miptot) {
|
|
|
|
|
for (a = 0; a < ibuf->miptot; a++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (ibuf->mipmap[a]) {
|
2019-04-28 14:13:41 -07:00
|
|
|
size += IMB_get_size_in_memory(ibuf->mipmap[a]);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-28 14:13:41 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|