Refactor: Convert ImBuf to C++

Pull Request: https://projects.blender.org/blender/blender/pulls/107503
This commit is contained in:
Sergey Sharybin
2023-05-02 11:32:27 +02:00
committed by Sergey Sharybin
parent a54c399b41
commit e3f14b99c3
41 changed files with 1290 additions and 1244 deletions

View File

@@ -11,9 +11,8 @@ extern "C" {
typedef struct OCIO_GPUShader OCIO_GPUShader;
#define OCIO_DECLARE_HANDLE(name) \
typedef struct name##__ { \
int unused; \
} * name
struct name; \
typedef struct name *name##Ptr;
#define OCIO_ROLE_DATA "data"
#define OCIO_ROLE_SCENE_LINEAR "scene_linear"
@@ -23,13 +22,13 @@ typedef struct OCIO_GPUShader OCIO_GPUShader;
#define OCIO_ROLE_DEFAULT_FLOAT "default_float"
#define OCIO_ROLE_DEFAULT_SEQUENCER "default_sequencer"
OCIO_DECLARE_HANDLE(OCIO_ConstConfigRcPtr);
OCIO_DECLARE_HANDLE(OCIO_ConstColorSpaceRcPtr);
OCIO_DECLARE_HANDLE(OCIO_ConstProcessorRcPtr);
OCIO_DECLARE_HANDLE(OCIO_ConstCPUProcessorRcPtr);
OCIO_DECLARE_HANDLE(OCIO_ConstContextRcPtr);
OCIO_DECLARE_HANDLE(OCIO_ConstConfigRc);
OCIO_DECLARE_HANDLE(OCIO_ConstColorSpaceRc);
OCIO_DECLARE_HANDLE(OCIO_ConstProcessorRc);
OCIO_DECLARE_HANDLE(OCIO_ConstCPUProcessorRc);
OCIO_DECLARE_HANDLE(OCIO_ConstContextRc);
OCIO_DECLARE_HANDLE(OCIO_PackedImageDesc);
OCIO_DECLARE_HANDLE(OCIO_ConstLookRcPtr);
OCIO_DECLARE_HANDLE(OCIO_ConstLookRc);
/* Standard XYZ (D65) to linear Rec.709 transform. */
static const float OCIO_XYZ_TO_REC709[3][3] = {{3.2404542f, -0.9692660f, 0.0556434f},
@@ -151,9 +150,10 @@ OCIO_ConstProcessorRcPtr *OCIO_configGetProcessorWithNames(OCIO_ConstConfigRcPtr
void OCIO_processorRelease(OCIO_ConstProcessorRcPtr *cpu_processor);
OCIO_ConstCPUProcessorRcPtr *OCIO_processorGetCPUProcessor(OCIO_ConstProcessorRcPtr *processor);
void OCIO_cpuProcessorApply(OCIO_ConstCPUProcessorRcPtr *cpu_processor, OCIO_PackedImageDesc *img);
void OCIO_cpuProcessorApply(OCIO_ConstCPUProcessorRcPtr *cpu_processor,
struct OCIO_PackedImageDesc *img);
void OCIO_cpuProcessorApply_predivide(OCIO_ConstCPUProcessorRcPtr *cpu_processor,
OCIO_PackedImageDesc *img);
struct OCIO_PackedImageDesc *img);
void OCIO_cpuProcessorApplyRGB(OCIO_ConstCPUProcessorRcPtr *cpu_processor, float *pixel);
void OCIO_cpuProcessorApplyRGBA(OCIO_ConstCPUProcessorRcPtr *cpu_processor, float *pixel);
void OCIO_cpuProcessorApplyRGBA_predivide(OCIO_ConstCPUProcessorRcPtr *cpu_processor,
@@ -175,15 +175,15 @@ OCIO_ConstProcessorRcPtr *OCIO_createDisplayProcessor(OCIO_ConstConfigRcPtr *con
const float exponent,
const bool inverse);
OCIO_PackedImageDesc *OCIO_createOCIO_PackedImageDesc(float *data,
long width,
long height,
long numChannels,
long chanStrideBytes,
long xStrideBytes,
long yStrideBytes);
struct OCIO_PackedImageDesc *OCIO_createOCIO_PackedImageDesc(float *data,
long width,
long height,
long numChannels,
long chanStrideBytes,
long xStrideBytes,
long yStrideBytes);
void OCIO_PackedImageDescRelease(OCIO_PackedImageDesc *p);
void OCIO_PackedImageDescRelease(struct OCIO_PackedImageDesc *p);
bool OCIO_supportGPUShader(void);
bool OCIO_gpuDisplayShaderBind(OCIO_ConstConfigRcPtr *config,

View File

@@ -21,13 +21,13 @@ set(INC_SYS
)
set(SRC
intern/allocimbuf.c
intern/anim_movie.c
intern/colormanagement.c
intern/colormanagement_inline.c
intern/divers.c
intern/filetype.c
intern/filter.c
intern/allocimbuf.cc
intern/anim_movie.cc
intern/colormanagement.cc
intern/colormanagement_inline.h
intern/divers.cc
intern/filetype.cc
intern/filter.cc
intern/format_bmp.cc
intern/format_dds.cc
intern/format_hdr.cc
@@ -35,25 +35,25 @@ set(SRC
intern/format_psd.cc
intern/format_targa.cc
intern/format_tiff.cc
intern/imageprocess.c
intern/indexer.c
intern/iris.c
intern/jpeg.c
intern/metadata.c
intern/module.c
intern/imageprocess.cc
intern/indexer.cc
intern/iris.cc
intern/jpeg.cc
intern/metadata.cc
intern/module.cc
intern/moviecache.cc
intern/readimage.c
intern/rectop.c
intern/rotate.c
intern/scaling.c
intern/stereoimbuf.c
intern/thumbs.c
intern/thumbs_blend.c
intern/thumbs_font.c
intern/readimage.cc
intern/rectop.cc
intern/rotate.cc
intern/scaling.cc
intern/stereoimbuf.cc
intern/thumbs.cc
intern/thumbs_blend.cc
intern/thumbs_font.cc
intern/transform.cc
intern/util.c
intern/util_gpu.c
intern/writeimage.c
intern/util.cc
intern/util_gpu.cc
intern/writeimage.cc
IMB_colormanagement.h
IMB_imbuf.h
@@ -102,7 +102,7 @@ if(WITH_IMAGE_OPENJPEG)
${OPENJPEG_INCLUDE_DIRS}
)
list(APPEND SRC
intern/jp2.c
intern/jp2.cc
)
list(APPEND LIB
${OPENJPEG_LIBRARIES}
@@ -147,7 +147,7 @@ endif()
if(WITH_IMAGE_WEBP)
list(APPEND SRC
intern/webp.c
intern/webp.cc
)
list(APPEND INC_SYS
${WEBP_INCLUDE_DIRS}
@@ -182,7 +182,7 @@ endif()
# no need to compile object files for inline headers.
set_source_files_properties(
intern/colormanagement_inline.c
intern/colormanagement_inline.cc
PROPERTIES HEADER_FILE_ONLY TRUE
)

View File

@@ -531,4 +531,4 @@ void IMB_colormanagement_wavelength_to_rgb_table(float *r_table, int width);
}
#endif
#include "intern/colormanagement_inline.c"
#include "intern/colormanagement_inline.h"

View File

@@ -339,7 +339,7 @@ void IMB_anim_get_fname(struct anim *anim, char *file, int size);
int IMB_anim_index_get_frame_index(struct anim *anim, IMB_Timecode_Type tc, int position);
IMB_Proxy_Size IMB_anim_proxy_get_existing(struct anim *anim);
int IMB_anim_proxy_get_existing(struct anim *anim);
struct IndexBuildContext;
@@ -348,7 +348,7 @@ struct IndexBuildContext;
*/
struct IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
IMB_Timecode_Type tcs_in_use,
IMB_Proxy_Size proxy_sizes_in_use,
int proxy_sizes_in_use,
int quality,
const bool overwrite,
struct GSet *file_list,

View File

@@ -43,9 +43,11 @@
#include "IMB_allocimbuf.h"
#ifdef WITH_FFMPEG
extern "C" {
# include <libavcodec/avcodec.h>
# include <libavformat/avformat.h>
# include <libswscale/swscale.h>
}
#endif
/* more endianness... should move to a separate file... */

View File

@@ -15,7 +15,8 @@ extern "C" {
#endif
struct ImBuf;
struct OCIO_ConstCPUProcessorRcPtr;
struct OCIO_ConstCPUProcessorRc;
typedef struct OCIO_ConstCPUProcessorRc *OCIO_ConstCPUProcessorRcPtr;
extern float imbuf_luma_coefficients[3];
extern float imbuf_scene_linear_to_xyz[3][3];
@@ -34,8 +35,8 @@ typedef struct ColorSpace {
char name[MAX_COLORSPACE_NAME];
char description[MAX_COLORSPACE_DESCRIPTION];
struct OCIO_ConstCPUProcessorRcPtr *to_scene_linear;
struct OCIO_ConstCPUProcessorRcPtr *from_scene_linear;
OCIO_ConstCPUProcessorRcPtr *to_scene_linear;
OCIO_ConstCPUProcessorRcPtr *from_scene_linear;
char (*aliases)[MAX_COLORSPACE_NAME];
int num_aliases;
@@ -57,8 +58,8 @@ typedef struct ColorManagedDisplay {
char name[MAX_COLORSPACE_NAME];
ListBase views; /* LinkData.data -> ColorManagedView */
struct OCIO_ConstCPUProcessorRcPtr *to_scene_linear;
struct OCIO_ConstCPUProcessorRcPtr *from_scene_linear;
OCIO_ConstCPUProcessorRcPtr *to_scene_linear;
OCIO_ConstCPUProcessorRcPtr *from_scene_linear;
} ColorManagedDisplay;
typedef struct ColorManagedView {

View File

@@ -68,9 +68,9 @@ void imb_freemipmapImBuf(ImBuf *ibuf)
/* 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++) {
if (ibuf->mipmap[a] != NULL) {
if (ibuf->mipmap[a] != nullptr) {
IMB_freeImBuf(ibuf->mipmap[a]);
ibuf->mipmap[a] = NULL;
ibuf->mipmap[a] = nullptr;
}
}
@@ -79,31 +79,31 @@ void imb_freemipmapImBuf(ImBuf *ibuf)
void imb_freerectfloatImBuf(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}
if (ibuf->rect_float && (ibuf->mall & IB_rectfloat)) {
MEM_freeN(ibuf->rect_float);
ibuf->rect_float = NULL;
ibuf->rect_float = nullptr;
}
imb_freemipmapImBuf(ibuf);
ibuf->rect_float = NULL;
ibuf->rect_float = nullptr;
ibuf->mall &= ~IB_rectfloat;
}
void imb_freerectImBuf(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}
if (ibuf->rect && (ibuf->mall & IB_rect)) {
MEM_freeN(ibuf->rect);
}
ibuf->rect = NULL;
ibuf->rect = nullptr;
imb_freemipmapImBuf(ibuf);
@@ -112,7 +112,7 @@ void imb_freerectImBuf(ImBuf *ibuf)
static void freeencodedbufferImBuf(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}
@@ -120,7 +120,7 @@ static void freeencodedbufferImBuf(ImBuf *ibuf)
MEM_freeN(ibuf->encodedbuffer);
}
ibuf->encodedbuffer = NULL;
ibuf->encodedbuffer = nullptr;
ibuf->encodedbuffersize = 0;
ibuf->encodedsize = 0;
ibuf->mall &= ~IB_mem;
@@ -128,7 +128,7 @@ static void freeencodedbufferImBuf(ImBuf *ibuf)
void IMB_freezbufImBuf(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}
@@ -136,13 +136,13 @@ void IMB_freezbufImBuf(ImBuf *ibuf)
MEM_freeN(ibuf->zbuf);
}
ibuf->zbuf = NULL;
ibuf->zbuf = nullptr;
ibuf->mall &= ~IB_zbuf;
}
void IMB_freezbuffloatImBuf(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}
@@ -150,7 +150,7 @@ void IMB_freezbuffloatImBuf(ImBuf *ibuf)
MEM_freeN(ibuf->zbuf_float);
}
ibuf->zbuf_float = NULL;
ibuf->zbuf_float = nullptr;
ibuf->mall &= ~IB_zbuffloat;
}
@@ -182,7 +182,7 @@ void IMB_freeImBuf(ImBuf *ibuf)
IMB_metadata_free(ibuf->metadata);
colormanage_cache_free(ibuf);
if (ibuf->dds_data.data != NULL) {
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);
}
@@ -212,7 +212,7 @@ ImBuf *IMB_makeSingleUser(ImBuf *ibuf)
}
}
else {
return NULL;
return nullptr;
}
rval = IMB_dupImBuf(ibuf);
@@ -226,13 +226,14 @@ ImBuf *IMB_makeSingleUser(ImBuf *ibuf)
bool addzbufImBuf(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
IMB_freezbufImBuf(ibuf);
if ((ibuf->zbuf = imb_alloc_pixels(ibuf->x, ibuf->y, 1, sizeof(uint), __func__))) {
if ((ibuf->zbuf = static_cast<int *>(
imb_alloc_pixels(ibuf->x, ibuf->y, 1, sizeof(uint), __func__)))) {
ibuf->mall |= IB_zbuf;
ibuf->flags |= IB_zbuf;
return true;
@@ -243,13 +244,14 @@ bool addzbufImBuf(ImBuf *ibuf)
bool addzbuffloatImBuf(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
IMB_freezbuffloatImBuf(ibuf);
if ((ibuf->zbuf_float = imb_alloc_pixels(ibuf->x, ibuf->y, 1, sizeof(float), __func__))) {
if ((ibuf->zbuf_float = static_cast<float *>(
imb_alloc_pixels(ibuf->x, ibuf->y, 1, sizeof(float), __func__)))) {
ibuf->mall |= IB_zbuffloat;
ibuf->flags |= IB_zbuffloat;
return true;
@@ -260,7 +262,7 @@ bool addzbuffloatImBuf(ImBuf *ibuf)
bool imb_addencodedbufferImBuf(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
@@ -272,7 +274,8 @@ bool imb_addencodedbufferImBuf(ImBuf *ibuf)
ibuf->encodedsize = 0;
if ((ibuf->encodedbuffer = MEM_mallocN(ibuf->encodedbuffersize, __func__))) {
if ((ibuf->encodedbuffer = static_cast<unsigned char *>(
MEM_mallocN(ibuf->encodedbuffersize, __func__)))) {
ibuf->mall |= IB_mem;
ibuf->flags |= IB_mem;
return true;
@@ -286,7 +289,7 @@ bool imb_enlargeencodedbufferImBuf(ImBuf *ibuf)
uint newsize, encodedsize;
void *newbuffer;
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
@@ -301,7 +304,7 @@ bool imb_enlargeencodedbufferImBuf(ImBuf *ibuf)
}
newbuffer = MEM_mallocN(newsize, __func__);
if (newbuffer == NULL) {
if (newbuffer == nullptr) {
return false;
}
@@ -318,7 +321,7 @@ bool imb_enlargeencodedbufferImBuf(ImBuf *ibuf)
ibuf->encodedbuffersize = newsize;
ibuf->encodedsize = encodedsize;
ibuf->encodedbuffer = newbuffer;
ibuf->encodedbuffer = static_cast<unsigned char *>(newbuffer);
ibuf->mall |= IB_mem;
ibuf->flags |= IB_mem;
@@ -330,7 +333,7 @@ void *imb_alloc_pixels(uint x, uint y, uint channels, size_t typesize, const cha
/* Protect against buffer overflow vulnerabilities from files specifying
* a width and height that overflow and alloc too little memory. */
if (!((uint64_t)x * (uint64_t)y < (SIZE_MAX / (channels * typesize)))) {
return NULL;
return nullptr;
}
size_t size = (size_t)x * (size_t)y * (size_t)channels * typesize;
@@ -339,7 +342,7 @@ void *imb_alloc_pixels(uint x, uint y, uint channels, size_t typesize, const cha
bool imb_addrectfloatImBuf(ImBuf *ibuf, const uint channels)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
@@ -348,7 +351,8 @@ bool imb_addrectfloatImBuf(ImBuf *ibuf, const uint channels)
}
ibuf->channels = channels;
if ((ibuf->rect_float = imb_alloc_pixels(ibuf->x, ibuf->y, channels, sizeof(float), __func__))) {
if ((ibuf->rect_float = static_cast<float *>(
imb_alloc_pixels(ibuf->x, ibuf->y, channels, sizeof(float), __func__)))) {
ibuf->mall |= IB_rectfloat;
ibuf->flags |= IB_rectfloat;
return true;
@@ -361,7 +365,7 @@ bool imb_addrectImBuf(ImBuf *ibuf)
{
/* Question; why also add ZBUF (when `planes > 32`)? */
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
@@ -370,9 +374,10 @@ bool imb_addrectImBuf(ImBuf *ibuf)
if (ibuf->rect && (ibuf->mall & IB_rect)) {
MEM_freeN(ibuf->rect);
}
ibuf->rect = NULL;
ibuf->rect = nullptr;
if ((ibuf->rect = imb_alloc_pixels(ibuf->x, ibuf->y, 4, sizeof(uchar), __func__))) {
if ((ibuf->rect = static_cast<unsigned int *>(
imb_alloc_pixels(ibuf->x, ibuf->y, 4, sizeof(uchar), __func__)))) {
ibuf->mall |= IB_rect;
ibuf->flags |= IB_rect;
if (ibuf->planes > 32) {
@@ -387,10 +392,10 @@ bool imb_addrectImBuf(ImBuf *ibuf)
struct ImBuf *IMB_allocFromBufferOwn(uint *rect, float *rectf, uint w, uint h, uint channels)
{
ImBuf *ibuf = NULL;
ImBuf *ibuf = nullptr;
if (!(rect || rectf)) {
return NULL;
return nullptr;
}
ibuf = IMB_allocImBuf(w, h, 32, 0);
@@ -419,10 +424,10 @@ struct ImBuf *IMB_allocFromBufferOwn(uint *rect, float *rectf, uint w, uint h, u
struct ImBuf *IMB_allocFromBuffer(
const uint *rect, const float *rectf, uint w, uint h, uint channels)
{
ImBuf *ibuf = NULL;
ImBuf *ibuf = nullptr;
if (!(rect || rectf)) {
return NULL;
return nullptr;
}
ibuf = IMB_allocImBuf(w, h, 32, 0);
@@ -432,7 +437,7 @@ struct ImBuf *IMB_allocFromBuffer(
/* Avoid #MEM_dupallocN since the buffers might not be allocated using guarded-allocation. */
if (rectf) {
const size_t size = sizeof(float[4]) * w * h;
ibuf->rect_float = MEM_mallocN(size, __func__);
ibuf->rect_float = static_cast<float *>(MEM_mallocN(size, __func__));
memcpy(ibuf->rect_float, rectf, size);
ibuf->flags |= IB_rectfloat;
@@ -440,7 +445,7 @@ struct ImBuf *IMB_allocFromBuffer(
}
if (rect) {
const size_t size = sizeof(uchar[4]) * w * h;
ibuf->rect = MEM_mallocN(size, __func__);
ibuf->rect = static_cast<unsigned int *>(MEM_mallocN(size, __func__));
memcpy(ibuf->rect, rect, size);
ibuf->flags |= IB_rect;
@@ -452,14 +457,12 @@ struct ImBuf *IMB_allocFromBuffer(
ImBuf *IMB_allocImBuf(uint x, uint y, uchar planes, uint flags)
{
ImBuf *ibuf;
ibuf = MEM_mallocN(sizeof(ImBuf), "ImBuf_struct");
ImBuf *ibuf = MEM_cnew<ImBuf>("ImBuf_struct");
if (ibuf) {
if (!IMB_initImBuf(ibuf, x, y, planes, flags)) {
IMB_freeImBuf(ibuf);
return NULL;
return nullptr;
}
}
@@ -517,8 +520,8 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1)
int flags = 0;
int a, x, y;
if (ibuf1 == NULL) {
return NULL;
if (ibuf1 == nullptr) {
return nullptr;
}
if (ibuf1->rect) {
@@ -538,8 +541,8 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1)
y = ibuf1->y;
ibuf2 = IMB_allocImBuf(x, y, ibuf1->planes, flags);
if (ibuf2 == NULL) {
return NULL;
if (ibuf2 == nullptr) {
return nullptr;
}
if (flags & IB_rect) {
@@ -563,7 +566,7 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1)
ibuf2->encodedbuffersize = ibuf1->encodedbuffersize;
if (imb_addencodedbufferImBuf(ibuf2) == false) {
IMB_freeImBuf(ibuf2);
return NULL;
return nullptr;
}
memcpy(ibuf2->encodedbuffer, ibuf1->encodedbuffer, ibuf1->encodedsize);
@@ -579,19 +582,19 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1)
tbuf.zbuf = ibuf2->zbuf;
tbuf.zbuf_float = ibuf2->zbuf_float;
for (a = 0; a < IMB_MIPMAP_LEVELS; a++) {
tbuf.mipmap[a] = NULL;
tbuf.mipmap[a] = nullptr;
}
tbuf.dds_data.data = NULL;
tbuf.dds_data.data = nullptr;
/* set malloc flag */
tbuf.mall = ibuf2->mall;
tbuf.refcounter = 0;
/* for now don't duplicate metadata */
tbuf.metadata = NULL;
tbuf.metadata = nullptr;
tbuf.display_buffer_flags = NULL;
tbuf.colormanage_cache = NULL;
tbuf.display_buffer_flags = nullptr;
tbuf.colormanage_cache = nullptr;
*ibuf2 = tbuf;

View File

@@ -63,6 +63,7 @@
#ifdef WITH_FFMPEG
# include "BKE_global.h" /* ENDIAN_ORDER */
extern "C" {
# include <libavcodec/avcodec.h>
# include <libavformat/avformat.h>
# include <libavutil/imgutils.h>
@@ -70,23 +71,25 @@
# include <libswscale/swscale.h>
# include "ffmpeg_compat.h"
}
#endif /* WITH_FFMPEG */
int ismovie(const char *UNUSED(filepath))
int ismovie(const char * /*filepath*/)
{
return 0;
}
/* never called, just keep the linker happy */
static int startmovie(struct anim *UNUSED(anim))
static int startmovie(struct anim * /*anim*/)
{
return 1;
}
static ImBuf *movie_fetchibuf(struct anim *UNUSED(anim), int UNUSED(position))
static ImBuf *movie_fetchibuf(struct anim * /*anim*/, int /*position*/)
{
return NULL;
return nullptr;
}
static void free_anim_movie(struct anim *UNUSED(anim))
static void free_anim_movie(struct anim * /*anim*/)
{
/* pass */
}
@@ -156,22 +159,22 @@ static void free_anim_avi(struct anim *anim)
int i;
# endif
if (anim == NULL) {
if (anim == nullptr) {
return;
}
if (anim->avi == NULL) {
if (anim->avi == nullptr) {
return;
}
AVI_close(anim->avi);
MEM_freeN(anim->avi);
anim->avi = NULL;
anim->avi = nullptr;
# if defined(_WIN32)
if (anim->pgf) {
AVIStreamGetFrameClose(anim->pgf);
anim->pgf = NULL;
anim->pgf = nullptr;
}
for (i = 0; i < anim->avistreams; i++) {
@@ -196,8 +199,8 @@ static void free_anim_ffmpeg(struct anim *anim);
void IMB_free_anim(struct anim *anim)
{
if (anim == NULL) {
printf("free anim, anim == NULL\n");
if (anim == nullptr) {
printf("free anim, anim == nullptr\n");
return;
}
@@ -218,7 +221,7 @@ void IMB_free_anim(struct anim *anim)
void IMB_close_anim(struct anim *anim)
{
if (anim == NULL) {
if (anim == nullptr) {
return;
}
@@ -227,7 +230,7 @@ void IMB_close_anim(struct anim *anim)
void IMB_close_anim_proxies(struct anim *anim)
{
if (anim == NULL) {
if (anim == nullptr) {
return;
}
@@ -239,14 +242,14 @@ struct IDProperty *IMB_anim_load_metadata(struct anim *anim)
switch (anim->curtype) {
case ANIM_FFMPEG: {
#ifdef WITH_FFMPEG
AVDictionaryEntry *entry = NULL;
AVDictionaryEntry *entry = nullptr;
BLI_assert(anim->pFormatCtx != NULL);
BLI_assert(anim->pFormatCtx != nullptr);
av_log(anim->pFormatCtx, AV_LOG_DEBUG, "METADATA FETCH\n");
while (true) {
entry = av_dict_get(anim->pFormatCtx->metadata, "", entry, AV_DICT_IGNORE_SUFFIX);
if (entry == NULL) {
if (entry == nullptr) {
break;
}
@@ -279,7 +282,7 @@ struct anim *IMB_open_anim(const char *name,
BLI_assert(!BLI_path_is_rel(name));
anim = (struct anim *)MEM_callocN(sizeof(struct anim), "anim struct");
if (anim != NULL) {
if (anim != nullptr) {
if (colorspace) {
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
BLI_strncpy(anim->colorspace, colorspace, sizeof(anim->colorspace));
@@ -303,12 +306,12 @@ bool IMB_anim_can_produce_frames(const struct anim *anim)
#endif
#ifdef WITH_AVI
if (anim->avi != NULL) {
if (anim->avi != nullptr) {
return true;
}
#endif
#ifdef WITH_FFMPEG
if (anim->pCodecCtx != NULL) {
if (anim->pCodecCtx != nullptr) {
return true;
}
#endif
@@ -337,9 +340,9 @@ static int startavi(struct anim *anim)
streamcount = anim->streamindex;
# endif
anim->avi = MEM_callocN(sizeof(AviMovie), "animavi");
anim->avi = MEM_cnew<AviMovie>("animavi");
if (anim->avi == NULL) {
if (anim->avi == nullptr) {
printf("Can't open avi: %s\n", anim->name);
return -1;
}
@@ -363,7 +366,7 @@ static int startavi(struct anim *anim)
streamcount--;
continue;
}
anim->pgf = AVIStreamGetFrameOpen(anim->pavi[i], NULL);
anim->pgf = AVIStreamGetFrameOpen(anim->pavi[i], nullptr);
if (anim->pgf) {
firstvideo = i;
@@ -416,7 +419,7 @@ static int startavi(struct anim *anim)
anim->duration_in_frames = anim->avi->header->TotalFrames;
anim->start_offset = 0.0f;
anim->params = NULL;
anim->params = nullptr;
anim->x = anim->avi->header->Width;
anim->y = anim->avi->header->Height;
@@ -442,12 +445,12 @@ static int startavi(struct anim *anim)
#ifdef WITH_AVI
static ImBuf *avi_fetchibuf(struct anim *anim, int position)
{
ImBuf *ibuf = NULL;
ImBuf *ibuf = nullptr;
int *tmp;
int y;
if (anim == NULL) {
return NULL;
if (anim == nullptr) {
return nullptr;
}
# if defined(_WIN32)
@@ -455,7 +458,8 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position)
LPBITMAPINFOHEADER lpbi;
if (anim->pgf) {
lpbi = AVIStreamGetFrame(anim->pgf, position + AVIStreamStart(anim->pavi[anim->firstvideo]));
lpbi = static_cast<LPBITMAPINFOHEADER>(
AVIStreamGetFrame(anim->pgf, position + AVIStreamStart(anim->pavi[anim->firstvideo])));
if (lpbi) {
ibuf = IMB_ibImageFromMemory(
(const uchar *)lpbi, 100, IB_rect, anim->colorspace, "<avi_fetchibuf>");
@@ -468,13 +472,13 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position)
{
ibuf = IMB_allocImBuf(anim->x, anim->y, 24, IB_rect);
tmp = AVI_read_frame(
anim->avi, AVI_FORMAT_RGB32, position, AVI_get_stream(anim->avi, AVIST_VIDEO, 0));
tmp = static_cast<int *>(AVI_read_frame(
anim->avi, AVI_FORMAT_RGB32, position, AVI_get_stream(anim->avi, AVIST_VIDEO, 0)));
if (tmp == NULL) {
if (tmp == nullptr) {
printf("Error reading frame from AVI: '%s'\n", anim->name);
IMB_freeImBuf(ibuf);
return NULL;
return nullptr;
}
for (y = 0; y < anim->y; y++) {
@@ -497,7 +501,7 @@ static int startffmpeg(struct anim *anim)
int i, video_stream_index;
const AVCodec *pCodec;
AVFormatContext *pFormatCtx = NULL;
AVFormatContext *pFormatCtx = nullptr;
AVCodecContext *pCodecCtx;
AVRational frame_rate;
AVStream *video_stream;
@@ -510,17 +514,17 @@ static int startffmpeg(struct anim *anim)
int *table;
const int *inv_table;
if (anim == NULL) {
if (anim == nullptr) {
return (-1);
}
streamcount = anim->streamindex;
if (avformat_open_input(&pFormatCtx, anim->name, NULL, NULL) != 0) {
if (avformat_open_input(&pFormatCtx, anim->name, nullptr, nullptr) != 0) {
return -1;
}
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
if (avformat_find_stream_info(pFormatCtx, nullptr) < 0) {
avformat_close_input(&pFormatCtx);
return -1;
}
@@ -550,12 +554,12 @@ static int startffmpeg(struct anim *anim)
/* Find the decoder for the video stream */
pCodec = avcodec_find_decoder(video_stream->codecpar->codec_id);
if (pCodec == NULL) {
if (pCodec == nullptr) {
avformat_close_input(&pFormatCtx);
return -1;
}
pCodecCtx = avcodec_alloc_context3(NULL);
pCodecCtx = avcodec_alloc_context3(nullptr);
avcodec_parameters_to_context(pCodecCtx, video_stream->codecpar);
pCodecCtx->workaround_bugs = FF_BUG_AUTODETECT;
@@ -573,7 +577,7 @@ static int startffmpeg(struct anim *anim)
pCodecCtx->thread_type = FF_THREAD_SLICE;
}
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0) {
avformat_close_input(&pFormatCtx);
return -1;
}
@@ -590,7 +594,7 @@ static int startffmpeg(struct anim *anim)
video_start = video_stream->start_time * pts_time_base;
}
frame_rate = av_guess_frame_rate(pFormatCtx, video_stream, NULL);
frame_rate = av_guess_frame_rate(pFormatCtx, video_stream, nullptr);
anim->duration_in_frames = 0;
/* Take from the stream if we can. */
@@ -705,7 +709,7 @@ static int startffmpeg(struct anim *anim)
av_frame_free(&anim->pFrameDeinterlaced);
av_frame_free(&anim->pFrame);
av_frame_free(&anim->pFrame_backup);
anim->pCodecCtx = NULL;
anim->pCodecCtx = nullptr;
return -1;
}
@@ -718,22 +722,22 @@ static int startffmpeg(struct anim *anim)
av_frame_free(&anim->pFrameDeinterlaced);
av_frame_free(&anim->pFrame);
av_frame_free(&anim->pFrame_backup);
anim->pCodecCtx = NULL;
anim->pCodecCtx = nullptr;
return -1;
}
if (anim->ib_flags & IB_animdeinterlace) {
av_image_fill_arrays(anim->pFrameDeinterlaced->data,
anim->pFrameDeinterlaced->linesize,
MEM_callocN(av_image_get_buffer_size(anim->pCodecCtx->pix_fmt,
anim->pCodecCtx->width,
anim->pCodecCtx->height,
1),
"ffmpeg deinterlace"),
anim->pCodecCtx->pix_fmt,
anim->pCodecCtx->width,
anim->pCodecCtx->height,
1);
av_image_fill_arrays(
anim->pFrameDeinterlaced->data,
anim->pFrameDeinterlaced->linesize,
static_cast<const uint8_t *>(MEM_callocN(
av_image_get_buffer_size(
anim->pCodecCtx->pix_fmt, anim->pCodecCtx->width, anim->pCodecCtx->height, 1),
"ffmpeg deinterlace")),
anim->pCodecCtx->pix_fmt,
anim->pCodecCtx->width,
anim->pCodecCtx->height,
1);
}
anim->img_convert_ctx = sws_getContext(anim->x,
@@ -743,9 +747,9 @@ static int startffmpeg(struct anim *anim)
anim->y,
AV_PIX_FMT_RGBA,
SWS_BILINEAR | SWS_PRINT_INFO | SWS_FULL_CHR_H_INT,
NULL,
NULL,
NULL);
nullptr,
nullptr,
nullptr);
if (!anim->img_convert_ctx) {
fprintf(stderr, "Can't transform color space??? Bailing out...\n");
@@ -756,7 +760,7 @@ static int startffmpeg(struct anim *anim)
av_frame_free(&anim->pFrameDeinterlaced);
av_frame_free(&anim->pFrame);
av_frame_free(&anim->pFrame_backup);
anim->pCodecCtx = NULL;
anim->pCodecCtx = nullptr;
return -1;
}
@@ -796,7 +800,7 @@ static double ffmpeg_steps_per_frame_get(struct anim *anim)
{
AVStream *v_st = anim->pFormatCtx->streams[anim->videoStream];
AVRational time_base = v_st->time_base;
AVRational frame_rate = av_guess_frame_rate(anim->pFormatCtx, v_st, NULL);
AVRational frame_rate = av_guess_frame_rate(anim->pFormatCtx, v_st, nullptr);
return av_q2d(av_inv_q(av_mul_q(frame_rate, time_base)));
}
@@ -843,7 +847,7 @@ static AVFrame *ffmpeg_double_buffer_frame_fallback_get(struct anim *anim)
if (anim->pFrame_backup_complete) {
return anim->pFrame_backup;
}
return NULL;
return nullptr;
}
/* postprocess the image in anim->pFrame and do color conversion
@@ -905,7 +909,7 @@ static void ffmpeg_postprocess(struct anim *anim, AVFrame *input)
* explicitly. */
const int src_linesize[4] = {-anim->pFrameRGB->linesize[0], 0, 0, 0};
int dst_size = av_image_get_buffer_size(
anim->pFrameRGB->format, anim->pFrameRGB->width, anim->pFrameRGB->height, 1);
AVPixelFormat(anim->pFrameRGB->format), anim->pFrameRGB->width, anim->pFrameRGB->height, 1);
av_image_copy_to_buffer(
(uint8_t *)ibuf->rect, dst_size, src, src_linesize, AV_PIX_FMT_RGBA, anim->x, anim->y, 1);
if (filter_y) {
@@ -931,15 +935,15 @@ static bool ffmpeg_pts_isect(int64_t pts_start, int64_t pts_end, int64_t pts_to_
return pts_start <= pts_to_search && pts_to_search < pts_end;
}
/* Return frame that matches `pts_to_search`, NULL if matching frame does not exist. */
/* Return frame that matches `pts_to_search`, nullptr if matching frame does not exist. */
static AVFrame *ffmpeg_frame_by_pts_get(struct anim *anim, int64_t pts_to_search)
{
/* NOTE: `frame->pts + frame->pkt_duration` does not always match pts of next frame.
* See footage from #86361. Here it is OK to use, because PTS must match current or backup frame.
* If there is no current frame, return NULL.
* If there is no current frame, return nullptr.
*/
if (!anim->pFrame_complete) {
return NULL;
return nullptr;
}
const bool backup_frame_ready = anim->pFrame_backup_complete;
@@ -947,7 +951,7 @@ static AVFrame *ffmpeg_frame_by_pts_get(struct anim *anim, int64_t pts_to_search
const int64_t recent_end = recent_start + anim->pFrame->pkt_duration;
const int64_t backup_start = backup_frame_ready ? av_get_pts_from_frame(anim->pFrame_backup) : 0;
AVFrame *best_frame = NULL;
AVFrame *best_frame = nullptr;
if (ffmpeg_pts_isect(recent_start, recent_end, pts_to_search)) {
final_frame_log(anim, recent_start, recent_end, "Recent");
best_frame = anim->pFrame;
@@ -1034,7 +1038,7 @@ static int ffmpeg_decode_video_frame(struct anim *anim)
if (rval == AVERROR_EOF) {
/* Flush any remaining frames out of the decoder. */
avcodec_send_packet(anim->pCodecCtx, NULL);
avcodec_send_packet(anim->pCodecCtx, nullptr);
anim->pFrame_complete = avcodec_receive_frame(anim->pCodecCtx, anim->pFrame) == 0;
if (anim->pFrame_complete) {
@@ -1047,11 +1051,14 @@ static int ffmpeg_decode_video_frame(struct anim *anim)
av_packet_unref(anim->cur_packet);
anim->cur_packet->stream_index = -1;
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, rval);
av_log(anim->pFormatCtx,
AV_LOG_ERROR,
" DECODE READ FAILED: av_read_frame() "
"returned error: %s\n",
av_err2str(rval));
error_str);
}
return (rval >= 0);
@@ -1392,8 +1399,8 @@ static bool ffmpeg_must_seek(struct anim *anim, int position)
static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Type tc)
{
if (anim == NULL) {
return NULL;
if (anim == nullptr) {
return nullptr;
}
av_log(anim->pFormatCtx, AV_LOG_DEBUG, "FETCH: seek_pos=%d\n", position);
@@ -1453,22 +1460,22 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Typ
}
anim->cur_frame_final = IMB_allocImBuf(anim->x, anim->y, planes, 0);
anim->cur_frame_final->rect = MEM_mallocN_aligned(
(size_t)4 * anim->x * anim->y, 32, "ffmpeg ibuf");
anim->cur_frame_final->rect = static_cast<unsigned int *>(
MEM_mallocN_aligned((size_t)4 * anim->x * anim->y, 32, "ffmpeg ibuf"));
anim->cur_frame_final->mall |= IB_rect;
anim->cur_frame_final->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
AVFrame *final_frame = ffmpeg_frame_by_pts_get(anim, pts_to_search);
if (final_frame == NULL) {
if (final_frame == nullptr) {
/* No valid frame was decoded for requested PTS, fall back on most recent decoded frame, even
* if it is incorrect. */
final_frame = ffmpeg_double_buffer_frame_fallback_get(anim);
}
/* Even with the fallback from above it is possible that the current decode frame is NULL. In
/* Even with the fallback from above it is possible that the current decode frame is nullptr. In
* this case skip post-processing and return current image buffer. */
if (final_frame != NULL) {
if (final_frame != nullptr) {
ffmpeg_postprocess(anim, final_frame);
}
@@ -1481,7 +1488,7 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Typ
static void free_anim_ffmpeg(struct anim *anim)
{
if (anim == NULL) {
if (anim == nullptr) {
return;
}
@@ -1510,7 +1517,7 @@ static void free_anim_ffmpeg(struct anim *anim)
static bool anim_getnew(struct anim *anim)
{
BLI_assert(anim->curtype == ANIM_NONE);
if (anim == NULL) {
if (anim == nullptr) {
/* Nothing to initialize. */
return false;
}
@@ -1566,7 +1573,7 @@ static bool anim_getnew(struct anim *anim)
struct ImBuf *IMB_anim_previewframe(struct anim *anim)
{
struct ImBuf *ibuf = NULL;
struct ImBuf *ibuf = nullptr;
int position = 0;
ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
@@ -1583,13 +1590,13 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim,
IMB_Timecode_Type tc,
IMB_Proxy_Size preview_size)
{
struct ImBuf *ibuf = NULL;
struct ImBuf *ibuf = nullptr;
char head[256], tail[256];
ushort digits;
int pic;
int filter_y;
if (anim == NULL) {
return NULL;
if (anim == nullptr) {
return nullptr;
}
filter_y = (anim->ib_flags & IB_animdeinterlace);
@@ -1597,15 +1604,15 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim,
if (preview_size == IMB_PROXY_NONE) {
if (anim->curtype == ANIM_NONE) {
if (!anim_getnew(anim)) {
return NULL;
return nullptr;
}
}
if (position < 0) {
return NULL;
return nullptr;
}
if (position >= anim->duration_in_frames) {
return NULL;
return nullptr;
}
}
else {

View File

@@ -21,11 +21,11 @@ set(SRC
logImageCore.h
logmemfile.h
cineon_dpx.c
cineonlib.c
dpxlib.c
logImageCore.c
logmemfile.c
cineon_dpx.cc
cineonlib.cc
dpxlib.cc
logImageCore.cc
logmemfile.cc
)
set(LIB

View File

@@ -34,24 +34,24 @@ static struct ImBuf *imb_load_dpx_cineon(
image = logImageOpenFromMemory(mem, size);
if (image == NULL) {
if (image == nullptr) {
printf("DPX/Cineon: error opening image.\n");
return NULL;
return nullptr;
}
logImageGetSize(image, &width, &height, &depth);
ibuf = IMB_allocImBuf(width, height, 32, IB_rectfloat | flags);
if (ibuf == NULL) {
if (ibuf == nullptr) {
logImageClose(image);
return NULL;
return nullptr;
}
if (!(flags & IB_test)) {
if (logImageGetDataRGBA(image, ibuf->rect_float, 1) != 0) {
logImageClose(image);
IMB_freeImBuf(ibuf);
return NULL;
return nullptr;
}
IMB_flipy(ibuf);
}
@@ -112,12 +112,12 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filepath, int use_cineon
-1,
"Blender");
if (logImage == NULL) {
if (logImage == nullptr) {
printf("DPX/Cineon: error creating file.\n");
return 0;
}
if (ibuf->rect_float != NULL && bitspersample != 8) {
if (ibuf->rect_float != nullptr && bitspersample != 8) {
/* Don't use the float buffer to save 8 BPP picture to prevent color banding
* (there's no dithering algorithm behind the #logImageSetDataRGBA function). */
@@ -136,13 +136,13 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filepath, int use_cineon
MEM_freeN(fbuf);
}
else {
if (ibuf->rect == NULL) {
if (ibuf->rect == nullptr) {
IMB_rect_from_float(ibuf);
}
fbuf = (float *)MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y,
"fbuf in imb_save_dpx_cineon");
if (fbuf == NULL) {
if (fbuf == nullptr) {
printf("DPX/Cineon: error allocating memory.\n");
logImageClose(logImage);
return 0;
@@ -178,7 +178,7 @@ bool imb_is_a_cineon(const uchar *buf, size_t size)
ImBuf *imb_load_cineon(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
{
if (!imb_is_a_cineon(mem, size)) {
return NULL;
return nullptr;
}
return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
}

View File

@@ -59,7 +59,7 @@ static void fillCineonMainHeader(LogImageFile *cineon,
cineon->isMSB);
STRNCPY(header->fileHeader.version, "v4.5");
STRNCPY(header->fileHeader.file_name, filepath);
fileClock = time(NULL);
fileClock = time(nullptr);
fileTime = localtime(&fileClock);
strftime(header->fileHeader.creation_date, 12, "%Y:%m:%d", fileTime);
strftime(header->fileHeader.creation_time, 12, "%H:%M:%S%Z", fileTime);
@@ -129,32 +129,32 @@ LogImageFile *cineonOpen(const uchar *byteStuff, int fromMemory, size_t bufferSi
int i;
uint dataOffset;
if (cineon == NULL) {
if (cineon == nullptr) {
if (verbose) {
printf("Cineon: Failed to malloc cineon file structure.\n");
}
return NULL;
return nullptr;
}
/* zero the header */
memset(&header, 0, sizeof(CineonMainHeader));
/* for close routine */
cineon->file = NULL;
cineon->file = nullptr;
if (fromMemory == 0) {
/* byteStuff is then the filepath */
cineon->file = BLI_fopen(filepath, "rb");
if (cineon->file == NULL) {
if (cineon->file == nullptr) {
if (verbose) {
printf("Cineon: Failed to open file \"%s\".\n", filepath);
}
logImageClose(cineon);
return NULL;
return nullptr;
}
/* not used in this case */
cineon->memBuffer = NULL;
cineon->memCursor = NULL;
cineon->memBuffer = nullptr;
cineon->memCursor = nullptr;
cineon->memBufferSize = 0;
}
else {
@@ -168,7 +168,7 @@ LogImageFile *cineonOpen(const uchar *byteStuff, int fromMemory, size_t bufferSi
printf("Cineon: Not enough data for header in \"%s\".\n", byteStuff);
}
logImageClose(cineon);
return NULL;
return nullptr;
}
/* endianness determination */
@@ -191,7 +191,7 @@ LogImageFile *cineonOpen(const uchar *byteStuff, int fromMemory, size_t bufferSi
byteStuff);
}
logImageClose(cineon);
return NULL;
return nullptr;
}
cineon->width = swap_uint(header.imageHeader.element[0].pixels_per_line, cineon->isMSB);
@@ -202,7 +202,7 @@ LogImageFile *cineonOpen(const uchar *byteStuff, int fromMemory, size_t bufferSi
printf("Cineon: Wrong image dimension: %dx%d\n", cineon->width, cineon->height);
}
logImageClose(cineon);
return NULL;
return nullptr;
}
cineon->depth = header.imageHeader.elements_per_image;
@@ -219,7 +219,7 @@ LogImageFile *cineonOpen(const uchar *byteStuff, int fromMemory, size_t bufferSi
printf("Cineon: Data interleave not supported: %d\n", header.imageHeader.interleave);
}
logImageClose(cineon);
return NULL;
return nullptr;
}
if (cineon->depth == 1) {
@@ -252,7 +252,7 @@ LogImageFile *cineonOpen(const uchar *byteStuff, int fromMemory, size_t bufferSi
printf("Cineon: Cineon image depth unsupported: %d\n", cineon->depth);
}
logImageClose(cineon);
return NULL;
return nullptr;
}
dataOffset = swap_uint(header.fileHeader.offset, cineon->isMSB);
@@ -288,7 +288,7 @@ LogImageFile *cineonOpen(const uchar *byteStuff, int fromMemory, size_t bufferSi
printf("Cineon: packing unsupported: %d\n", header.imageHeader.packing);
}
logImageClose(cineon);
return NULL;
return nullptr;
}
if (cineon->element[i].refLowData == CINEON_UNDEFINED_U32) {
@@ -354,15 +354,15 @@ LogImageFile *cineonCreate(
const char *filepath, int width, int height, int bitsPerSample, const char *creator)
{
CineonMainHeader header;
const char *shortFilename = NULL;
const char *shortFilename = nullptr;
/* uchar pad[6044]; */
LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
if (cineon == NULL) {
if (cineon == nullptr) {
if (verbose) {
printf("cineon: Failed to malloc cineon file structure.\n");
}
return NULL;
return nullptr;
}
/* Only 10 bits Cineon are supported */
@@ -371,7 +371,7 @@ LogImageFile *cineonCreate(
printf("cineon: Only 10 bits Cineon are supported.\n");
}
logImageClose(cineon);
return NULL;
return nullptr;
}
cineon->width = width;
@@ -395,7 +395,7 @@ LogImageFile *cineonCreate(
cineon->gamma = 1.7f;
shortFilename = strrchr(filepath, PATHSEP_CHAR);
if (shortFilename == NULL) {
if (shortFilename == nullptr) {
shortFilename = filepath;
}
else {
@@ -403,12 +403,12 @@ LogImageFile *cineonCreate(
}
cineon->file = BLI_fopen(filepath, "wb");
if (cineon->file == NULL) {
if (cineon->file == nullptr) {
if (verbose) {
printf("cineon: Couldn't open file %s\n", filepath);
}
logImageClose(cineon);
return NULL;
return nullptr;
}
fillCineonMainHeader(cineon, &header, shortFilename, creator);
@@ -418,7 +418,7 @@ LogImageFile *cineonCreate(
printf("cineon: Couldn't write image header\n");
}
logImageClose(cineon);
return NULL;
return nullptr;
}
return cineon;

View File

@@ -62,7 +62,7 @@ static void fillDpxMainHeader(LogImageFile *dpx,
dpx->isMSB);
header->fileHeader.user_data_size = DPX_UNDEFINED_U32;
STRNCPY(header->fileHeader.file_name, filename);
fileClock = time(NULL);
fileClock = time(nullptr);
fileTime = localtime(&fileClock);
strftime(header->fileHeader.creation_date, 24, "%Y:%m:%d:%H:%M:%S%Z", fileTime);
header->fileHeader.creation_date[23] = 0;
@@ -126,32 +126,32 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
const char *filepath = (const char *)byteStuff;
int i;
if (dpx == NULL) {
if (dpx == nullptr) {
if (verbose) {
printf("DPX: Failed to malloc dpx file structure.\n");
}
return NULL;
return nullptr;
}
/* zero the header */
memset(&header, 0, sizeof(DpxMainHeader));
/* for close routine */
dpx->file = NULL;
dpx->file = nullptr;
if (fromMemory == 0) {
/* byteStuff is then the filepath */
dpx->file = BLI_fopen(filepath, "rb");
if (dpx->file == NULL) {
if (dpx->file == nullptr) {
if (verbose) {
printf("DPX: Failed to open file \"%s\".\n", filepath);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
/* not used in this case */
dpx->memBuffer = NULL;
dpx->memCursor = NULL;
dpx->memBuffer = nullptr;
dpx->memCursor = nullptr;
dpx->memBufferSize = 0;
}
else {
@@ -165,7 +165,7 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
printf("DPX: Not enough data for header in \"%s\".\n", byteStuff);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
/* endianness determination */
@@ -186,7 +186,7 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
printf("DPX: Bad magic number %u in \"%s\".\n", header.fileHeader.magic_num, byteStuff);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
dpx->srcFormat = format_DPX;
@@ -197,7 +197,7 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
printf("DPX: Wrong number of elements: %d\n", dpx->numElements);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
dpx->width = swap_uint(header.imageHeader.pixels_per_line, dpx->isMSB);
@@ -208,7 +208,7 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
printf("DPX: Wrong image dimension: %dx%d\n", dpx->width, dpx->height);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
dpx->depth = 0;
@@ -257,7 +257,7 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
printf("DPX: Unsupported image depth: %d\n", dpx->depth);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
dpx->element[i].bitsPerSample = header.imageHeader.element[i].bits_per_sample;
@@ -268,7 +268,7 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
dpx->element[i].bitsPerSample);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
dpx->element[i].maxValue = powf(2, dpx->element[i].bitsPerSample) - 1.0f;
@@ -279,7 +279,7 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
printf("DPX: Unsupported packing for element %d: %d\n", i, dpx->element[i].packing);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
/* Sometimes, the offset is not set correctly in the header */
@@ -293,7 +293,7 @@ LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
printf("DPX: Image header is corrupted.\n");
}
logImageClose(dpx);
return NULL;
return nullptr;
}
dpx->element[i].transfer = header.imageHeader.element[i].transfer;
@@ -418,15 +418,15 @@ LogImageFile *dpxCreate(const char *filepath,
const char *creator)
{
DpxMainHeader header;
const char *shortFilename = NULL;
const char *shortFilename = nullptr;
uchar pad[6044];
LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
if (dpx == NULL) {
if (dpx == nullptr) {
if (verbose) {
printf("DPX: Failed to malloc dpx file structure.\n");
}
return NULL;
return nullptr;
}
dpx->width = width;
@@ -454,7 +454,7 @@ LogImageFile *dpxCreate(const char *filepath,
printf("DPX: bitsPerSample not supported: %d\n", bitsPerSample);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
if (hasAlpha == 0) {
@@ -503,7 +503,7 @@ LogImageFile *dpxCreate(const char *filepath,
}
shortFilename = strrchr(filepath, PATHSEP_CHAR);
if (shortFilename == NULL) {
if (shortFilename == nullptr) {
shortFilename = filepath;
}
else {
@@ -512,12 +512,12 @@ LogImageFile *dpxCreate(const char *filepath,
dpx->file = BLI_fopen(filepath, "wb");
if (dpx->file == NULL) {
if (dpx->file == nullptr) {
if (verbose) {
printf("DPX: Couldn't open file %s\n", filepath);
}
logImageClose(dpx);
return NULL;
return nullptr;
}
fillDpxMainHeader(dpx, &header, shortFilename, creator);
@@ -527,7 +527,7 @@ LogImageFile *dpxCreate(const char *filepath,
printf("DPX: Couldn't write image header\n");
}
logImageClose(dpx);
return NULL;
return nullptr;
}
/* Header should be rounded to next 8k block
@@ -538,7 +538,7 @@ LogImageFile *dpxCreate(const char *filepath,
printf("DPX: Couldn't write image header\n");
}
logImageClose(dpx);
return NULL;
return nullptr;
}
return dpx;

View File

@@ -108,13 +108,13 @@ LogImageFile *logImageOpenFromFile(const char *filepath, int cineon)
(void)cineon;
if (f == NULL) {
return NULL;
if (f == nullptr) {
return nullptr;
}
if (fread(&magicNum, sizeof(magicNum), 1, f) != 1) {
fclose(f);
return NULL;
return nullptr;
}
fclose(f);
@@ -126,7 +126,7 @@ LogImageFile *logImageOpenFromFile(const char *filepath, int cineon)
return cineonOpen((const uchar *)filepath, 0, 0);
}
return NULL;
return nullptr;
}
LogImageFile *logImageOpenFromMemory(const uchar *buffer, uint size)
@@ -138,7 +138,7 @@ LogImageFile *logImageOpenFromMemory(const uchar *buffer, uint size)
return cineonOpen(buffer, 1, size);
}
return NULL;
return nullptr;
}
LogImageFile *logImageCreate(const char *filepath,
@@ -169,15 +169,15 @@ LogImageFile *logImageCreate(const char *filepath,
gamma,
creator);
return NULL;
return nullptr;
}
void logImageClose(LogImageFile *logImage)
{
if (logImage != NULL) {
if (logImage != nullptr) {
if (logImage->file) {
fclose(logImage->file);
logImage->file = NULL;
logImage->file = nullptr;
}
MEM_freeN(logImage);
}
@@ -237,7 +237,7 @@ int logImageSetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
elementData = (float *)imb_alloc_pixels(
logImage->width, logImage->height, logImage->depth, sizeof(float), __func__);
if (elementData == NULL) {
if (elementData == nullptr) {
return 1;
}
@@ -280,7 +280,7 @@ static int logImageSetData8(LogImageFile *logImage, LogImageElement logElement,
uchar *row;
row = (uchar *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
if (row == nullptr) {
if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
}
@@ -312,7 +312,7 @@ static int logImageSetData10(LogImageFile *logImage, LogImageElement logElement,
uint *row;
row = (uint *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
if (row == nullptr) {
if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
}
@@ -356,7 +356,7 @@ static int logImageSetData12(LogImageFile *logImage, LogImageElement logElement,
ushort *row;
row = (ushort *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
if (row == nullptr) {
if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
}
@@ -388,7 +388,7 @@ static int logImageSetData16(LogImageFile *logImage, LogImageElement logElement,
ushort *row;
row = (ushort *)MEM_mallocN(rowLength, __func__);
if (row == NULL) {
if (row == nullptr) {
if (verbose) {
printf("DPX/Cineon: Cannot allocate row.\n");
}
@@ -437,14 +437,14 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
/* descriptor_Depth and descriptor_Composite are not supported */
if (!ELEM(logImage->element[i].descriptor, descriptor_Depth, descriptor_Composite)) {
/* Allocate memory */
elementData[i] = imb_alloc_pixels(
logImage->width, logImage->height, logImage->element[i].depth, sizeof(float), __func__);
if (elementData[i] == NULL) {
elementData[i] = static_cast<float *>(imb_alloc_pixels(
logImage->width, logImage->height, logImage->element[i].depth, sizeof(float), __func__));
if (elementData[i] == nullptr) {
if (verbose) {
printf("DPX/Cineon: Cannot allocate memory for elementData[%d]\n.", i);
}
for (j = 0; j < i; j++) {
if (elementData[j] != NULL) {
if (elementData[j] != nullptr) {
MEM_freeN(elementData[j]);
}
}
@@ -458,7 +458,7 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
printf("DPX/Cineon: Cannot read elementData[%d]\n.", i);
}
for (j = 0; j < i; j++) {
if (elementData[j] != NULL) {
if (elementData[j] != nullptr) {
MEM_freeN(elementData[j]);
}
}
@@ -624,12 +624,12 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
mergedData = (float *)imb_alloc_pixels(
logImage->width, logImage->height, mergedElement.depth, sizeof(float), __func__);
if (mergedData == NULL) {
if (mergedData == nullptr) {
if (verbose) {
printf("DPX/Cineon: Cannot allocate mergedData.\n");
}
for (i = 0; i < logImage->numElements; i++) {
if (elementData[i] != NULL) {
if (elementData[i] != nullptr) {
MEM_freeN(elementData[i]);
}
}
@@ -647,7 +647,7 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB
/* Done with elements data, clean-up */
for (i = 0; i < logImage->numElements; i++) {
if (elementData[i] != NULL) {
if (elementData[i] != nullptr) {
MEM_freeN(elementData[i]);
}
}
@@ -1077,7 +1077,7 @@ static float *getLinToLogLut(LogImageFile *logImage, LogImageElement logElement)
uint lutsize = (uint)(logElement.maxValue + 1);
uint i;
lut = MEM_mallocN(sizeof(float) * lutsize, "getLinToLogLut");
lut = static_cast<float *>(MEM_mallocN(sizeof(float) * lutsize, "getLinToLogLut"));
negativeFilmGamma = 0.6;
step = logElement.refHighQuantity / logElement.maxValue;
@@ -1105,7 +1105,7 @@ static float *getLogToLinLut(LogImageFile *logImage, LogImageElement logElement)
uint lutsize = (uint)(logElement.maxValue + 1);
uint i;
lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
lut = static_cast<float *>(MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut"));
/* Building the Log -> Lin LUT */
step = logElement.refHighQuantity / logElement.maxValue;
@@ -1155,7 +1155,7 @@ static float *getLinToSrgbLut(LogImageElement logElement)
uint lutsize = (uint)(logElement.maxValue + 1);
uint i;
lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
lut = static_cast<float *>(MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut"));
for (i = 0; i < lutsize; i++) {
col = (float)i / logElement.maxValue;
@@ -1176,7 +1176,7 @@ static float *getSrgbToLinLut(LogImageElement logElement)
uint lutsize = (uint)(logElement.maxValue + 1);
uint i;
lut = MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut");
lut = static_cast<float *>(MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut"));
for (i = 0; i < lutsize; i++) {
col = (float)i / logElement.maxValue;
@@ -1707,7 +1707,7 @@ static int convertRGBAToLogElement(
/* we need to convert src to sRGB */
srgbSrc = (float *)imb_alloc_pixels(
logImage->width, logImage->height, 4, sizeof(float), __func__);
if (srgbSrc == NULL) {
if (srgbSrc == nullptr) {
return 1;
}

View File

@@ -62,10 +62,10 @@ static char global_role_default_byte[MAX_COLORSPACE_NAME];
static char global_role_default_float[MAX_COLORSPACE_NAME];
static char global_role_default_sequencer[MAX_COLORSPACE_NAME];
static ListBase global_colorspaces = {NULL, NULL};
static ListBase global_displays = {NULL, NULL};
static ListBase global_views = {NULL, NULL};
static ListBase global_looks = {NULL, NULL};
static ListBase global_colorspaces = {nullptr, nullptr};
static ListBase global_displays = {nullptr, nullptr};
static ListBase global_views = {nullptr, nullptr};
static ListBase global_looks = {nullptr, nullptr};
static int global_tot_colorspace = 0;
static int global_tot_display = 0;
@@ -111,7 +111,7 @@ static struct global_color_picking_state {
OCIO_ConstCPUProcessorRcPtr *cpu_processor_to;
OCIO_ConstCPUProcessorRcPtr *cpu_processor_from;
bool failed;
} global_color_picking_state = {NULL};
} global_color_picking_state = {nullptr};
/** \} */
@@ -222,7 +222,7 @@ typedef struct ColormanageCache {
static struct MovieCache *colormanage_moviecache_get(const ImBuf *ibuf)
{
if (!ibuf->colormanage_cache) {
return NULL;
return nullptr;
}
return ibuf->colormanage_cache->moviecache;
@@ -231,7 +231,7 @@ static struct MovieCache *colormanage_moviecache_get(const ImBuf *ibuf)
static ColormanageCacheData *colormanage_cachedata_get(const ImBuf *ibuf)
{
if (!ibuf->colormanage_cache) {
return NULL;
return nullptr;
}
return ibuf->colormanage_cache->data;
@@ -239,7 +239,7 @@ static ColormanageCacheData *colormanage_cachedata_get(const ImBuf *ibuf)
static uint colormanage_hashhash(const void *key_v)
{
const ColormanageCacheKey *key = key_v;
const ColormanageCacheKey *key = static_cast<const ColormanageCacheKey *>(key_v);
uint rval = (key->display << 16) | (key->view % 0xffff);
@@ -248,8 +248,8 @@ static uint colormanage_hashhash(const void *key_v)
static bool colormanage_hashcmp(const void *av, const void *bv)
{
const ColormanageCacheKey *a = av;
const ColormanageCacheKey *b = bv;
const ColormanageCacheKey *a = static_cast<const ColormanageCacheKey *>(av);
const ColormanageCacheKey *b = static_cast<const ColormanageCacheKey *>(bv);
return ((a->view != b->view) || (a->display != b->display));
}
@@ -257,7 +257,7 @@ static bool colormanage_hashcmp(const void *av, const void *bv)
static struct MovieCache *colormanage_moviecache_ensure(ImBuf *ibuf)
{
if (!ibuf->colormanage_cache) {
ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage cache");
ibuf->colormanage_cache = MEM_cnew<ColormanageCache>("imbuf colormanage cache");
}
if (!ibuf->colormanage_cache->moviecache) {
@@ -277,7 +277,7 @@ static struct MovieCache *colormanage_moviecache_ensure(ImBuf *ibuf)
static void colormanage_cachedata_set(ImBuf *ibuf, ColormanageCacheData *data)
{
if (!ibuf->colormanage_cache) {
ibuf->colormanage_cache = MEM_callocN(sizeof(ColormanageCache), "imbuf colormanage cache");
ibuf->colormanage_cache = MEM_cnew<ColormanageCache>("imbuf colormanage cache");
}
ibuf->colormanage_cache->data = data;
@@ -326,12 +326,12 @@ static ImBuf *colormanage_cache_get_ibuf(ImBuf *ibuf,
if (!moviecache) {
/* If there's no moviecache it means no color management was applied
* on given image buffer before. */
return NULL;
return nullptr;
}
*cache_handle = NULL;
*cache_handle = nullptr;
cache_ibuf = IMB_moviecache_get(moviecache, key, NULL);
cache_ibuf = IMB_moviecache_get(moviecache, key, nullptr);
*cache_handle = cache_ibuf;
@@ -353,7 +353,7 @@ static uchar *colormanage_cache_get(ImBuf *ibuf,
/* check whether image was marked as dirty for requested transform */
if ((ibuf->display_buffer_flags[display_settings->display - 1] & view_flag) == 0) {
return NULL;
return nullptr;
}
cache_ibuf = colormanage_cache_get_ibuf(ibuf, &key, cache_handle);
@@ -378,17 +378,17 @@ static uchar *colormanage_cache_get(ImBuf *ibuf,
cache_data->flag != view_settings->flag || cache_data->curve_mapping != curve_mapping ||
cache_data->curve_mapping_timestamp != curve_mapping_timestamp)
{
*cache_handle = NULL;
*cache_handle = nullptr;
IMB_freeImBuf(cache_ibuf);
return NULL;
return nullptr;
}
return (uchar *)cache_ibuf->rect;
}
return NULL;
return nullptr;
}
static void colormanage_cache_put(ImBuf *ibuf,
@@ -419,7 +419,7 @@ static void colormanage_cache_put(ImBuf *ibuf,
/* Store data which is needed to check whether cached buffer
* could be used for color managed display settings. */
cache_data = MEM_callocN(sizeof(ColormanageCacheData), "color manage cache imbuf data");
cache_data = MEM_cnew<ColormanageCacheData>("color manage cache imbuf data");
cache_data->look = view_settings->look;
cache_data->exposure = view_settings->exposure;
cache_data->gamma = view_settings->gamma;
@@ -437,7 +437,7 @@ static void colormanage_cache_put(ImBuf *ibuf,
static void colormanage_cache_handle_release(void *cache_handle)
{
ImBuf *cache_ibuf = cache_handle;
ImBuf *cache_ibuf = static_cast<ImBuf *>(cache_handle);
IMB_freeImBuf(cache_ibuf);
}
@@ -480,13 +480,13 @@ static void colormanage_load_config(OCIO_ConstConfigRcPtr *config)
const char *name;
/* get roles */
colormanage_role_color_space_name_get(config, global_role_data, OCIO_ROLE_DATA, NULL);
colormanage_role_color_space_name_get(config, global_role_data, OCIO_ROLE_DATA, nullptr);
colormanage_role_color_space_name_get(
config, global_role_scene_linear, OCIO_ROLE_SCENE_LINEAR, NULL);
config, global_role_scene_linear, OCIO_ROLE_SCENE_LINEAR, nullptr);
colormanage_role_color_space_name_get(
config, global_role_color_picking, OCIO_ROLE_COLOR_PICKING, NULL);
config, global_role_color_picking, OCIO_ROLE_COLOR_PICKING, nullptr);
colormanage_role_color_space_name_get(
config, global_role_texture_painting, OCIO_ROLE_TEXTURE_PAINT, NULL);
config, global_role_texture_painting, OCIO_ROLE_TEXTURE_PAINT, nullptr);
colormanage_role_color_space_name_get(
config, global_role_default_sequencer, OCIO_ROLE_DEFAULT_SEQUENCER, OCIO_ROLE_SCENE_LINEAR);
colormanage_role_color_space_name_get(
@@ -512,8 +512,8 @@ static void colormanage_load_config(OCIO_ConstConfigRcPtr *config)
colorspace->num_aliases = OCIO_colorSpaceGetNumAliases(ocio_colorspace);
if (colorspace->num_aliases > 0) {
colorspace->aliases = MEM_callocN(sizeof(*colorspace->aliases) * colorspace->num_aliases,
"ColorSpace aliases");
colorspace->aliases = static_cast<char(*)[MAX_COLORSPACE_NAME]>(MEM_callocN(
sizeof(*colorspace->aliases) * colorspace->num_aliases, "ColorSpace aliases"));
for (int i = 0; i < colorspace->num_aliases; i++) {
BLI_strncpy(colorspace->aliases[i],
OCIO_colorSpaceGetAlias(ocio_colorspace, i),
@@ -595,7 +595,7 @@ static void colormanage_free_config(void)
ColorManagedDisplay *display;
/* free color spaces */
colorspace = global_colorspaces.first;
colorspace = static_cast<ColorSpace *>(global_colorspaces.first);
while (colorspace) {
ColorSpace *colorspace_next = colorspace->next;
@@ -617,7 +617,7 @@ static void colormanage_free_config(void)
global_tot_colorspace = 0;
/* free displays */
display = global_displays.first;
display = static_cast<ColorManagedDisplay *>(global_displays.first);
while (display) {
ColorManagedDisplay *display_next = display->next;
@@ -654,7 +654,7 @@ void colormanagement_init(void)
const char *ocio_env;
const char *configdir;
char configfile[FILE_MAX];
OCIO_ConstConfigRcPtr *config = NULL;
OCIO_ConstConfigRcPtr *config = nullptr;
OCIO_init();
@@ -662,12 +662,12 @@ void colormanagement_init(void)
if (ocio_env && ocio_env[0] != '\0') {
config = OCIO_configCreateFromEnv();
if (config != NULL) {
if (config != nullptr) {
printf("Color management: Using %s as a configuration file\n", ocio_env);
}
}
if (config == NULL) {
if (config == nullptr) {
configdir = BKE_appdir_folder_id(BLENDER_DATAFILES, "colormanagement");
if (configdir) {
@@ -677,7 +677,7 @@ void colormanagement_init(void)
}
}
if (config == NULL) {
if (config == nullptr) {
printf("Color management: using fallback mode for management\n");
config = OCIO_configCreateFallback();
@@ -772,7 +772,7 @@ void colormanage_cache_free(ImBuf *ibuf)
MEM_freeN(ibuf->colormanage_cache);
ibuf->colormanage_cache = NULL;
ibuf->colormanage_cache = nullptr;
}
}
@@ -789,7 +789,7 @@ void IMB_colormanagement_display_settings_from_ctx(
if (sima && sima->image) {
if ((sima->image->flag & IMA_VIEW_AS_RENDER) == 0) {
*r_view_settings = NULL;
*r_view_settings = nullptr;
}
}
}
@@ -820,7 +820,7 @@ static ColorSpace *display_transform_get_colorspace(
return colormanage_colorspace_get_named(colorspace_name);
}
return NULL;
return nullptr;
}
static OCIO_ConstCPUProcessorRcPtr *create_display_buffer_processor(const char *look,
@@ -846,8 +846,8 @@ static OCIO_ConstCPUProcessorRcPtr *create_display_buffer_processor(const char *
OCIO_configRelease(config);
if (processor == NULL) {
return NULL;
if (processor == nullptr) {
return nullptr;
}
OCIO_ConstCPUProcessorRcPtr *cpu_processor = OCIO_processorGetCPUProcessor(processor);
@@ -872,16 +872,16 @@ static OCIO_ConstProcessorRcPtr *create_colorspace_transform_processor(const cha
static OCIO_ConstCPUProcessorRcPtr *colorspace_to_scene_linear_cpu_processor(
ColorSpace *colorspace)
{
if (colorspace->to_scene_linear == NULL) {
if (colorspace->to_scene_linear == nullptr) {
BLI_mutex_lock(&processor_lock);
if (colorspace->to_scene_linear == NULL) {
if (colorspace->to_scene_linear == nullptr) {
OCIO_ConstProcessorRcPtr *processor = create_colorspace_transform_processor(
colorspace->name, global_role_scene_linear);
if (processor != NULL) {
colorspace->to_scene_linear = (struct OCIO_ConstCPUProcessorRcPtr *)
OCIO_processorGetCPUProcessor(processor);
if (processor != nullptr) {
colorspace->to_scene_linear = (OCIO_ConstCPUProcessorRcPtr *)OCIO_processorGetCPUProcessor(
processor);
OCIO_processorRelease(processor);
}
}
@@ -895,15 +895,15 @@ static OCIO_ConstCPUProcessorRcPtr *colorspace_to_scene_linear_cpu_processor(
static OCIO_ConstCPUProcessorRcPtr *colorspace_from_scene_linear_cpu_processor(
ColorSpace *colorspace)
{
if (colorspace->from_scene_linear == NULL) {
if (colorspace->from_scene_linear == nullptr) {
BLI_mutex_lock(&processor_lock);
if (colorspace->from_scene_linear == NULL) {
if (colorspace->from_scene_linear == nullptr) {
OCIO_ConstProcessorRcPtr *processor = create_colorspace_transform_processor(
global_role_scene_linear, colorspace->name);
if (processor != NULL) {
colorspace->from_scene_linear = (struct OCIO_ConstCPUProcessorRcPtr *)
if (processor != nullptr) {
colorspace->from_scene_linear = (OCIO_ConstCPUProcessorRcPtr *)
OCIO_processorGetCPUProcessor(processor);
OCIO_processorRelease(processor);
}
@@ -918,24 +918,30 @@ static OCIO_ConstCPUProcessorRcPtr *colorspace_from_scene_linear_cpu_processor(
static OCIO_ConstCPUProcessorRcPtr *display_from_scene_linear_processor(
ColorManagedDisplay *display)
{
if (display->from_scene_linear == NULL) {
if (display->from_scene_linear == nullptr) {
BLI_mutex_lock(&processor_lock);
if (display->from_scene_linear == NULL) {
if (display->from_scene_linear == nullptr) {
const char *view_name = colormanage_view_get_default_name(display);
OCIO_ConstConfigRcPtr *config = OCIO_getCurrentConfig();
OCIO_ConstProcessorRcPtr *processor = NULL;
OCIO_ConstProcessorRcPtr *processor = nullptr;
if (view_name && config) {
processor = OCIO_createDisplayProcessor(
config, global_role_scene_linear, view_name, display->name, NULL, 1.0f, 1.0f, false);
processor = OCIO_createDisplayProcessor(config,
global_role_scene_linear,
view_name,
display->name,
nullptr,
1.0f,
1.0f,
false);
OCIO_configRelease(config);
}
if (processor != NULL) {
display->from_scene_linear = (struct OCIO_ConstCPUProcessorRcPtr *)
OCIO_processorGetCPUProcessor(processor);
if (processor != nullptr) {
display->from_scene_linear = (OCIO_ConstCPUProcessorRcPtr *)OCIO_processorGetCPUProcessor(
processor);
OCIO_processorRelease(processor);
}
}
@@ -948,24 +954,24 @@ static OCIO_ConstCPUProcessorRcPtr *display_from_scene_linear_processor(
static OCIO_ConstCPUProcessorRcPtr *display_to_scene_linear_processor(ColorManagedDisplay *display)
{
if (display->to_scene_linear == NULL) {
if (display->to_scene_linear == nullptr) {
BLI_mutex_lock(&processor_lock);
if (display->to_scene_linear == NULL) {
if (display->to_scene_linear == nullptr) {
const char *view_name = colormanage_view_get_default_name(display);
OCIO_ConstConfigRcPtr *config = OCIO_getCurrentConfig();
OCIO_ConstProcessorRcPtr *processor = NULL;
OCIO_ConstProcessorRcPtr *processor = nullptr;
if (view_name && config) {
processor = OCIO_createDisplayProcessor(
config, global_role_scene_linear, view_name, display->name, NULL, 1.0f, 1.0f, true);
config, global_role_scene_linear, view_name, display->name, nullptr, 1.0f, 1.0f, true);
OCIO_configRelease(config);
}
if (processor != NULL) {
display->to_scene_linear = (struct OCIO_ConstCPUProcessorRcPtr *)
OCIO_processorGetCPUProcessor(processor);
if (processor != nullptr) {
display->to_scene_linear = (OCIO_ConstCPUProcessorRcPtr *)OCIO_processorGetCPUProcessor(
processor);
OCIO_processorRelease(processor);
}
}
@@ -984,13 +990,13 @@ void IMB_colormanagement_init_default_view_settings(
display_settings->display_device, "Standard");
/* If that fails, we fall back to the default view transform of the display
* as per OCIO configuration. */
if (default_view == NULL) {
if (default_view == nullptr) {
ColorManagedDisplay *display = colormanage_display_get_named(display_settings->display_device);
if (display != NULL) {
if (display != nullptr) {
default_view = colormanage_view_get_default(display);
}
}
if (default_view != NULL) {
if (default_view != nullptr) {
BLI_strncpy(
view_settings->view_transform, default_view->name, sizeof(view_settings->view_transform));
}
@@ -1003,7 +1009,7 @@ void IMB_colormanagement_init_default_view_settings(
view_settings->flag = 0;
view_settings->gamma = 1.0f;
view_settings->exposure = 0.0f;
view_settings->curve_mapping = NULL;
view_settings->curve_mapping = nullptr;
}
static void curve_mapping_apply_pixel(CurveMapping *curve_mapping, float *pixel, int channels)
@@ -1100,7 +1106,7 @@ static void colormanage_check_view_settings(ColorManagedDisplaySettings *display
const char *what)
{
ColorManagedDisplay *display;
ColorManagedView *default_view = NULL;
ColorManagedView *default_view = nullptr;
ColorManagedLook *default_look = (ColorManagedLook *)global_looks.first;
if (view_settings->view_transform[0] == '\0') {
@@ -1144,7 +1150,7 @@ static void colormanage_check_view_settings(ColorManagedDisplaySettings *display
}
else {
ColorManagedLook *look = colormanage_look_get_named(view_settings->look);
if (look == NULL) {
if (look == nullptr) {
printf("Color management: %s look \"%s\" not found, setting default \"%s\".\n",
what,
view_settings->look,
@@ -1182,7 +1188,7 @@ static void colormanage_check_colorspace_settings(
(void)what;
}
static bool seq_callback(Sequence *seq, void *UNUSED(user_data))
static bool seq_callback(Sequence *seq, void * /*user_data*/)
{
if (seq->strip) {
colormanage_check_colorspace_settings(&seq->strip->colorspace_settings, "sequencer strip");
@@ -1192,20 +1198,13 @@ static bool seq_callback(Sequence *seq, void *UNUSED(user_data))
void IMB_colormanagement_check_file_config(Main *bmain)
{
Scene *scene;
Image *image;
MovieClip *clip;
ColorManagedDisplay *default_display;
default_display = colormanage_display_get_default();
ColorManagedDisplay *default_display = colormanage_display_get_default();
if (!default_display) {
/* happens when OCIO configuration is incorrect */
return;
}
for (scene = bmain->scenes.first; scene; scene = scene->id.next) {
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
ColorManagedColorspaceSettings *sequencer_colorspace_settings;
/* check scene color management settings */
@@ -1222,18 +1221,18 @@ void IMB_colormanagement_check_file_config(Main *bmain)
}
/* check sequencer strip input color space settings */
if (scene->ed != NULL) {
SEQ_for_each_callback(&scene->ed->seqbase, seq_callback, NULL);
if (scene->ed != nullptr) {
SEQ_for_each_callback(&scene->ed->seqbase, seq_callback, nullptr);
}
}
/* ** check input color space settings ** */
for (image = bmain->images.first; image; image = image->id.next) {
LISTBASE_FOREACH (Image *, image, &bmain->images) {
colormanage_check_colorspace_settings(&image->colorspace_settings, "image");
}
for (clip = bmain->movieclips.first; clip; clip = clip->id.next) {
LISTBASE_FOREACH (MovieClip *, clip, &bmain->movieclips) {
colormanage_check_colorspace_settings(&clip->colorspace_settings, "clip");
}
}
@@ -1241,23 +1240,20 @@ void IMB_colormanagement_check_file_config(Main *bmain)
void IMB_colormanagement_validate_settings(const ColorManagedDisplaySettings *display_settings,
ColorManagedViewSettings *view_settings)
{
ColorManagedDisplay *display;
ColorManagedView *default_view = NULL;
LinkData *view_link;
ColorManagedDisplay *display = colormanage_display_get_named(display_settings->display_device);
ColorManagedView *default_view = colormanage_view_get_default(display);
display = colormanage_display_get_named(display_settings->display_device);
default_view = colormanage_view_get_default(display);
for (view_link = display->views.first; view_link; view_link = view_link->next) {
ColorManagedView *view = view_link->data;
bool found = false;
LISTBASE_FOREACH (LinkData *, view_link, &display->views) {
ColorManagedView *view = static_cast<ColorManagedView *>(view_link->data);
if (STREQ(view->name, view_settings->view_transform)) {
found = true;
break;
}
}
if (view_link == NULL && default_view) {
if (!found && default_view) {
BLI_strncpy(
view_settings->view_transform, default_view->name, sizeof(view_settings->view_transform));
}
@@ -1286,7 +1282,7 @@ const char *IMB_colormanagement_role_colorspace_name_get(int role)
break;
}
return NULL;
return nullptr;
}
void IMB_colormanagement_check_is_data(ImBuf *ibuf, const char *name)
@@ -1607,7 +1603,7 @@ static void *do_display_buffer_apply_thread(void *handle_v)
float dither = handle->dither;
bool is_data = handle->is_data;
if (cm_processor == NULL) {
if (cm_processor == nullptr) {
if (display_buffer_byte && display_buffer_byte != handle->byte_buffer) {
IMB_buffer_byte_from_byte(display_buffer_byte,
handle->byte_buffer,
@@ -1634,8 +1630,8 @@ static void *do_display_buffer_apply_thread(void *handle_v)
}
else {
bool is_straight_alpha;
float *linear_buffer = MEM_mallocN(((size_t)channels) * width * height * sizeof(float),
"color conversion linear buffer");
float *linear_buffer = static_cast<float *>(MEM_mallocN(
((size_t)channels) * width * height * sizeof(float), "color conversion linear buffer"));
display_buffer_apply_get_linear_buffer(handle, height, linear_buffer, &is_straight_alpha);
@@ -1685,7 +1681,7 @@ static void *do_display_buffer_apply_thread(void *handle_v)
MEM_freeN(linear_buffer);
}
return NULL;
return nullptr;
}
static void display_buffer_apply_threaded(ImBuf *ibuf,
@@ -1704,7 +1700,7 @@ static void display_buffer_apply_threaded(ImBuf *ibuf,
init_data.display_buffer = display_buffer;
init_data.display_buffer_byte = display_buffer_byte;
if (ibuf->rect_colorspace != NULL) {
if (ibuf->rect_colorspace != nullptr) {
init_data.byte_colorspace = ibuf->rect_colorspace->name;
}
else {
@@ -1714,12 +1710,12 @@ static void display_buffer_apply_threaded(ImBuf *ibuf,
init_data.byte_colorspace = global_role_default_byte;
}
if (ibuf->float_colorspace != NULL) {
if (ibuf->float_colorspace != nullptr) {
/* sequencer stores float buffers in non-linear space */
init_data.float_colorspace = ibuf->float_colorspace->name;
}
else {
init_data.float_colorspace = NULL;
init_data.float_colorspace = nullptr;
}
IMB_processor_apply_threaded(ibuf->y,
@@ -1739,7 +1735,7 @@ static bool is_ibuf_rect_in_display_space(ImBuf *ibuf,
const char *from_colorspace = ibuf->rect_colorspace->name;
const char *to_colorspace = get_display_colorspace_name(view_settings, display_settings);
ColorManagedLook *look_descr = colormanage_look_get_named(view_settings->look);
if (look_descr != NULL && !STREQ(look_descr->process_space, "")) {
if (look_descr != nullptr && !STREQ(look_descr->process_space, "")) {
return false;
}
@@ -1758,7 +1754,7 @@ static void colormanage_display_buffer_process_ex(
const ColorManagedViewSettings *view_settings,
const ColorManagedDisplaySettings *display_settings)
{
ColormanageProcessor *cm_processor = NULL;
ColormanageProcessor *cm_processor = nullptr;
bool skip_transform = false;
/* if we're going to transform byte buffer, check whether transformation would
@@ -1766,7 +1762,7 @@ static void colormanage_display_buffer_process_ex(
* this would save byte -> float -> byte conversions making display buffer
* computation noticeable faster
*/
if (ibuf->rect_float == NULL && ibuf->rect_colorspace) {
if (ibuf->rect_float == nullptr && ibuf->rect_colorspace) {
skip_transform = is_ibuf_rect_in_display_space(ibuf, view_settings, display_settings);
}
@@ -1792,7 +1788,7 @@ static void colormanage_display_buffer_process(ImBuf *ibuf,
const ColorManagedDisplaySettings *display_settings)
{
colormanage_display_buffer_process_ex(
ibuf, NULL, display_buffer, view_settings, display_settings);
ibuf, nullptr, display_buffer, view_settings, display_settings);
}
/** \} */
@@ -1843,11 +1839,11 @@ static void processor_transform_init_handle(void *handle_v,
handle->cm_processor = init_data->cm_processor;
if (init_data->byte_buffer != NULL) {
if (init_data->byte_buffer != nullptr) {
/* TODO(serge): Offset might be different for byte and float buffers. */
handle->byte_buffer = init_data->byte_buffer + offset;
}
if (init_data->float_buffer != NULL) {
if (init_data->float_buffer != nullptr) {
handle->float_buffer = init_data->float_buffer + offset;
}
@@ -1887,17 +1883,17 @@ static void *do_processor_transform_thread(void *handle_v)
IMB_premultiply_rect_float(float_buffer, 4, width, height);
}
else {
if (byte_buffer != NULL) {
if (byte_buffer != nullptr) {
IMB_colormanagement_processor_apply_byte(
handle->cm_processor, byte_buffer, width, height, channels);
}
if (float_buffer != NULL) {
if (float_buffer != nullptr) {
IMB_colormanagement_processor_apply(
handle->cm_processor, float_buffer, width, height, channels, predivide);
}
}
return NULL;
return nullptr;
}
static void processor_transform_apply_threaded(uchar *byte_buffer,
@@ -1965,10 +1961,10 @@ static void colormanagement_transform_ex(uchar *byte_buffer,
byte_buffer, float_buffer, width, height, channels, cm_processor, predivide, false);
}
else {
if (byte_buffer != NULL) {
if (byte_buffer != nullptr) {
IMB_colormanagement_processor_apply_byte(cm_processor, byte_buffer, width, height, channels);
}
if (float_buffer != NULL) {
if (float_buffer != nullptr) {
IMB_colormanagement_processor_apply(
cm_processor, float_buffer, width, height, channels, predivide);
}
@@ -1986,7 +1982,7 @@ void IMB_colormanagement_transform(float *buffer,
bool predivide)
{
colormanagement_transform_ex(
NULL, buffer, width, height, channels, from_colorspace, to_colorspace, predivide, false);
nullptr, buffer, width, height, channels, from_colorspace, to_colorspace, predivide, false);
}
void IMB_colormanagement_transform_threaded(float *buffer,
@@ -1998,7 +1994,7 @@ void IMB_colormanagement_transform_threaded(float *buffer,
bool predivide)
{
colormanagement_transform_ex(
NULL, buffer, width, height, channels, from_colorspace, to_colorspace, predivide, true);
nullptr, buffer, width, height, channels, from_colorspace, to_colorspace, predivide, true);
}
void IMB_colormanagement_transform_byte(uchar *buffer,
@@ -2009,7 +2005,7 @@ void IMB_colormanagement_transform_byte(uchar *buffer,
const char *to_colorspace)
{
colormanagement_transform_ex(
buffer, NULL, width, height, channels, from_colorspace, to_colorspace, false, false);
buffer, nullptr, width, height, channels, from_colorspace, to_colorspace, false, false);
}
void IMB_colormanagement_transform_byte_threaded(uchar *buffer,
int width,
@@ -2019,7 +2015,7 @@ void IMB_colormanagement_transform_byte_threaded(uchar *buffer,
const char *to_colorspace)
{
colormanagement_transform_ex(
buffer, NULL, width, height, channels, from_colorspace, to_colorspace, false, true);
buffer, nullptr, width, height, channels, from_colorspace, to_colorspace, false, true);
}
void IMB_colormanagement_transform_from_byte(float *float_buffer,
@@ -2051,7 +2047,7 @@ void IMB_colormanagement_transform_from_byte_threaded(float *float_buffer,
const char *to_colorspace)
{
ColormanageProcessor *cm_processor;
if (from_colorspace == NULL || from_colorspace[0] == '\0') {
if (from_colorspace == nullptr || from_colorspace[0] == '\0') {
return;
}
if (STREQ(from_colorspace, to_colorspace)) {
@@ -2113,7 +2109,7 @@ void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], ColorSpac
processor = colorspace_to_scene_linear_cpu_processor(colorspace);
if (processor != NULL) {
if (processor != nullptr) {
OCIO_cpuProcessorApplyRGB(processor, pixel);
}
}
@@ -2130,7 +2126,7 @@ void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], ColorSpac
processor = colorspace_from_scene_linear_cpu_processor(colorspace);
if (processor != NULL) {
if (processor != nullptr) {
OCIO_cpuProcessorApplyRGB(processor, pixel);
}
}
@@ -2149,7 +2145,7 @@ void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4],
processor = colorspace_to_scene_linear_cpu_processor(colorspace);
if (processor != NULL) {
if (processor != nullptr) {
if (predivide) {
OCIO_cpuProcessorApplyRGBA_predivide(processor, pixel);
}
@@ -2176,7 +2172,7 @@ void IMB_colormanagement_colorspace_to_scene_linear(float *buffer,
processor = colorspace_to_scene_linear_cpu_processor(colorspace);
if (processor != NULL) {
if (processor != nullptr) {
OCIO_PackedImageDesc *img;
img = OCIO_createOCIO_PackedImageDesc(buffer,
@@ -2208,7 +2204,7 @@ void IMB_colormanagement_imbuf_to_byte_texture(uchar *out_buffer,
{
/* Byte buffer storage, only for sRGB, scene linear and data texture since other
* color space conversions can't be done on the GPU. */
BLI_assert(ibuf->rect && ibuf->rect_float == NULL);
BLI_assert(ibuf->rect && ibuf->rect_float == nullptr);
BLI_assert(IMB_colormanagement_space_is_srgb(ibuf->rect_colorspace) ||
IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace) ||
IMB_colormanagement_space_is_data(ibuf->rect_colorspace));
@@ -2254,9 +2250,9 @@ typedef struct ImbufByteToFloatData {
static void imbuf_byte_to_float_cb(void *__restrict userdata,
const int y,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
ImbufByteToFloatData *data = userdata;
ImbufByteToFloatData *data = static_cast<ImbufByteToFloatData *>(userdata);
const size_t in_offset = data->offset + y * data->stride;
const size_t out_offset = y * data->width;
@@ -2341,17 +2337,16 @@ void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer,
OCIO_ConstCPUProcessorRcPtr *processor = (ibuf->rect_colorspace) ?
colorspace_to_scene_linear_cpu_processor(
ibuf->rect_colorspace) :
NULL;
nullptr;
ImbufByteToFloatData data = {
.processor = processor,
.width = width,
.offset = offset_y * ibuf->x + offset_x,
.stride = ibuf->x,
.in_buffer = in_buffer,
.out_buffer = out_buffer,
.use_premultiply = use_premultiply,
};
ImbufByteToFloatData data = {};
data.processor = processor;
data.width = width;
data.offset = offset_y * ibuf->x + offset_x;
data.stride = ibuf->x;
data.in_buffer = in_buffer;
data.out_buffer = out_buffer;
data.use_premultiply = use_premultiply;
TaskParallelSettings settings;
BLI_parallel_range_settings_defaults(&settings);
@@ -2371,7 +2366,7 @@ void IMB_colormanagement_scene_linear_to_color_picking_v3(float color_picking[3]
OCIO_ConstProcessorRcPtr *processor = create_colorspace_transform_processor(
global_role_scene_linear, global_role_color_picking);
if (processor != NULL) {
if (processor != nullptr) {
global_color_picking_state.cpu_processor_to = OCIO_processorGetCPUProcessor(processor);
OCIO_processorRelease(processor);
}
@@ -2401,7 +2396,7 @@ void IMB_colormanagement_color_picking_to_scene_linear_v3(float scene_linear[3],
OCIO_ConstProcessorRcPtr *processor = create_colorspace_transform_processor(
global_role_color_picking, global_role_scene_linear);
if (processor != NULL) {
if (processor != nullptr) {
global_color_picking_state.cpu_processor_from = OCIO_processorGetCPUProcessor(processor);
OCIO_processorRelease(processor);
}
@@ -2424,7 +2419,7 @@ void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], ColorManaged
{
OCIO_ConstCPUProcessorRcPtr *processor = display_from_scene_linear_processor(display);
if (processor != NULL) {
if (processor != nullptr) {
OCIO_cpuProcessorApplyRGB(processor, pixel);
}
}
@@ -2433,7 +2428,7 @@ void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], ColorManaged
{
OCIO_ConstCPUProcessorRcPtr *processor = display_to_scene_linear_processor(display);
if (processor != NULL) {
if (processor != nullptr) {
OCIO_cpuProcessorApplyRGB(processor, pixel);
}
}
@@ -2508,12 +2503,12 @@ static ImBuf *imbuf_ensure_editable(ImBuf *ibuf, ImBuf *colormanaged_ibuf, bool
* but it's re-using byte and float buffers from render result make copy of this buffers
* here sine this buffers would be transformed to other color space here. */
if (ibuf->rect && (ibuf->mall & IB_rect) == 0) {
ibuf->rect = MEM_dupallocN(ibuf->rect);
ibuf->rect = static_cast<unsigned int *>(MEM_dupallocN(ibuf->rect));
ibuf->mall |= IB_rect;
}
if (ibuf->rect_float && (ibuf->mall & IB_rectfloat) == 0) {
ibuf->rect_float = MEM_dupallocN(ibuf->rect_float);
ibuf->rect_float = static_cast<float *>(MEM_dupallocN(ibuf->rect_float));
ibuf->mall |= IB_rectfloat;
}
@@ -2584,7 +2579,7 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf,
if (colormanaged_ibuf->rect_float) {
/* Float buffer isn't linear anymore,
* image format write callback should check for this flag and assume
* no space conversion should happen if ibuf->float_colorspace != NULL. */
* no space conversion should happen if ibuf->float_colorspace != nullptr. */
colormanaged_ibuf->float_colorspace = display_transform_get_colorspace(
&image_format->view_settings, &image_format->display_settings);
if (byte_output) {
@@ -2682,10 +2677,10 @@ uchar *IMB_display_buffer_acquire(ImBuf *ibuf,
ColorManagedViewSettings default_view_settings;
const ColorManagedViewSettings *applied_view_settings;
*cache_handle = NULL;
*cache_handle = nullptr;
if (!ibuf->x || !ibuf->y) {
return NULL;
return nullptr;
}
if (view_settings) {
@@ -2701,7 +2696,7 @@ uchar *IMB_display_buffer_acquire(ImBuf *ibuf,
/* early out: no float buffer and byte buffer is already in display space,
* let's just use if
*/
if (ibuf->rect_float == NULL && ibuf->rect_colorspace && ibuf->channels == 4) {
if (ibuf->rect_float == nullptr && ibuf->rect_colorspace && ibuf->channels == 4) {
if (is_ibuf_rect_in_display_space(ibuf, applied_view_settings, display_settings)) {
return (uchar *)ibuf->rect;
}
@@ -2733,8 +2728,8 @@ uchar *IMB_display_buffer_acquire(ImBuf *ibuf,
/* ensure color management bit fields exists */
if (!ibuf->display_buffer_flags) {
ibuf->display_buffer_flags = MEM_callocN(sizeof(uint) * global_tot_display,
"imbuf display_buffer_flags");
ibuf->display_buffer_flags = static_cast<uint *>(
MEM_callocN(sizeof(uint) * global_tot_display, "imbuf display_buffer_flags"));
}
else if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) {
/* all display buffers were marked as invalid from other areas,
@@ -2754,7 +2749,7 @@ uchar *IMB_display_buffer_acquire(ImBuf *ibuf,
}
buffer_size = DISPLAY_BUFFER_CHANNELS * ((size_t)ibuf->x) * ibuf->y * sizeof(char);
display_buffer = MEM_callocN(buffer_size, "imbuf display buffer");
display_buffer = static_cast<uchar *>(MEM_callocN(buffer_size, "imbuf display buffer"));
colormanage_display_buffer_process(
ibuf, display_buffer, applied_view_settings, display_settings);
@@ -2790,8 +2785,8 @@ void IMB_display_buffer_transform_apply(uchar *display_buffer,
ColormanageProcessor *cm_processor = IMB_colormanagement_display_processor_new(view_settings,
display_settings);
buffer = MEM_mallocN((size_t)channels * width * height * sizeof(float),
"display transform temp buffer");
buffer = static_cast<float *>(MEM_mallocN((size_t)channels * width * height * sizeof(float),
"display transform temp buffer"));
memcpy(buffer, linear_buffer, (size_t)channels * width * height * sizeof(float));
IMB_colormanagement_processor_apply(cm_processor, buffer, width, height, channels, predivide);
@@ -2847,7 +2842,7 @@ ColorManagedDisplay *colormanage_display_get_default(void)
const char *display_name = colormanage_display_get_default_name();
if (display_name[0] == '\0') {
return NULL;
return nullptr;
}
return colormanage_display_get_named(display_name);
@@ -2859,12 +2854,12 @@ ColorManagedDisplay *colormanage_display_add(const char *name)
int index = 0;
if (global_displays.last) {
ColorManagedDisplay *last_display = global_displays.last;
ColorManagedDisplay *last_display = static_cast<ColorManagedDisplay *>(global_displays.last);
index = last_display->index;
}
display = MEM_callocN(sizeof(ColorManagedDisplay), "ColorManagedDisplay");
display = MEM_cnew<ColorManagedDisplay>("ColorManagedDisplay");
display->index = index + 1;
@@ -2877,21 +2872,19 @@ ColorManagedDisplay *colormanage_display_add(const char *name)
ColorManagedDisplay *colormanage_display_get_named(const char *name)
{
ColorManagedDisplay *display;
for (display = global_displays.first; display; display = display->next) {
LISTBASE_FOREACH (ColorManagedDisplay *, display, &global_displays) {
if (STREQ(display->name, name)) {
return display;
}
}
return NULL;
return nullptr;
}
ColorManagedDisplay *colormanage_display_get_indexed(int index)
{
/* display indices are 1-based */
return BLI_findlink(&global_displays, index - 1);
return static_cast<ColorManagedDisplay *>(BLI_findlink(&global_displays, index - 1));
}
int IMB_colormanagement_display_get_named_index(const char *name)
@@ -2917,7 +2910,7 @@ const char *IMB_colormanagement_display_get_indexed_name(int index)
return display->name;
}
return NULL;
return nullptr;
}
const char *IMB_colormanagement_display_get_default_name(void)
@@ -2934,7 +2927,7 @@ ColorManagedDisplay *IMB_colormanagement_display_get_named(const char *name)
const char *IMB_colormanagement_display_get_none_name(void)
{
if (colormanage_display_get_named("None") != NULL) {
if (colormanage_display_get_named("None") != nullptr) {
return "None";
}
@@ -2956,9 +2949,7 @@ const char *IMB_colormanagement_display_get_default_view_transform_name(
const char *colormanage_view_get_default_name(const ColorManagedDisplay *display)
{
OCIO_ConstConfigRcPtr *config = OCIO_getCurrentConfig();
const char *name;
name = OCIO_configGetDefaultView(config, display->name);
const char *name = OCIO_configGetDefaultView(config, display->name);
OCIO_configRelease(config);
@@ -2970,7 +2961,7 @@ ColorManagedView *colormanage_view_get_default(const ColorManagedDisplay *displa
const char *name = colormanage_view_get_default_name(display);
if (!name || name[0] == '\0') {
return NULL;
return nullptr;
}
return colormanage_view_get_named(name);
@@ -2981,7 +2972,7 @@ ColorManagedView *colormanage_view_add(const char *name)
ColorManagedView *view;
int index = global_tot_view;
view = MEM_callocN(sizeof(ColorManagedView), "ColorManagedView");
view = MEM_cnew<ColorManagedView>("ColorManagedView");
view->index = index + 1;
BLI_strncpy(view->name, name, sizeof(view->name));
@@ -2994,37 +2985,35 @@ ColorManagedView *colormanage_view_add(const char *name)
ColorManagedView *colormanage_view_get_named(const char *name)
{
ColorManagedView *view;
for (view = global_views.first; view; view = view->next) {
LISTBASE_FOREACH (ColorManagedView *, view, &global_views) {
if (STREQ(view->name, name)) {
return view;
}
}
return NULL;
return nullptr;
}
ColorManagedView *colormanage_view_get_indexed(int index)
{
/* view transform indices are 1-based */
return BLI_findlink(&global_views, index - 1);
return static_cast<ColorManagedView *>(BLI_findlink(&global_views, index - 1));
}
ColorManagedView *colormanage_view_get_named_for_display(const char *display_name,
const char *name)
{
ColorManagedDisplay *display = colormanage_display_get_named(display_name);
if (display == NULL) {
return NULL;
if (display == nullptr) {
return nullptr;
}
LISTBASE_FOREACH (LinkData *, view_link, &display->views) {
ColorManagedView *view = view_link->data;
ColorManagedView *view = static_cast<ColorManagedView *>(view_link->data);
if (STRCASEEQ(name, view->name)) {
return view;
}
}
return NULL;
return nullptr;
}
int IMB_colormanagement_view_get_named_index(const char *name)
@@ -3046,13 +3035,13 @@ const char *IMB_colormanagement_view_get_indexed_name(int index)
return view->name;
}
return NULL;
return nullptr;
}
const char *IMB_colormanagement_view_get_default_name(const char *display_name)
{
ColorManagedDisplay *display = colormanage_display_get_named(display_name);
ColorManagedView *view = NULL;
ColorManagedView *view = nullptr;
if (display) {
view = colormanage_view_get_default(display);
@@ -3062,7 +3051,7 @@ const char *IMB_colormanagement_view_get_default_name(const char *display_name)
return view->name;
}
return NULL;
return nullptr;
}
/** \} */
@@ -3099,7 +3088,7 @@ ColorSpace *colormanage_colorspace_add(const char *name,
ColorSpace *colorspace, *prev_space;
int counter = 1;
colorspace = MEM_callocN(sizeof(ColorSpace), "ColorSpace");
colorspace = MEM_cnew<ColorSpace>("ColorSpace");
BLI_strncpy(colorspace->name, name, sizeof(colorspace->name));
@@ -3112,7 +3101,9 @@ ColorSpace *colormanage_colorspace_add(const char *name,
colorspace->is_invertible = is_invertible;
colorspace->is_data = is_data;
for (prev_space = global_colorspaces.first; prev_space; prev_space = prev_space->next) {
for (prev_space = static_cast<ColorSpace *>(global_colorspaces.first); prev_space;
prev_space = prev_space->next)
{
if (BLI_strcasecmp(prev_space->name, colorspace->name) > 0) {
break;
}
@@ -3139,9 +3130,7 @@ ColorSpace *colormanage_colorspace_add(const char *name,
ColorSpace *colormanage_colorspace_get_named(const char *name)
{
ColorSpace *colorspace;
for (colorspace = global_colorspaces.first; colorspace; colorspace = colorspace->next) {
LISTBASE_FOREACH (ColorSpace *, colorspace, &global_colorspaces) {
if (STREQ(colorspace->name, name)) {
return colorspace;
}
@@ -3153,7 +3142,7 @@ ColorSpace *colormanage_colorspace_get_named(const char *name)
}
}
return NULL;
return nullptr;
}
ColorSpace *colormanage_colorspace_get_roled(int role)
@@ -3166,14 +3155,12 @@ ColorSpace *colormanage_colorspace_get_roled(int role)
ColorSpace *colormanage_colorspace_get_indexed(int index)
{
/* color space indices are 1-based */
return BLI_findlink(&global_colorspaces, index - 1);
return static_cast<ColorSpace *>(BLI_findlink(&global_colorspaces, index - 1));
}
int IMB_colormanagement_colorspace_get_named_index(const char *name)
{
ColorSpace *colorspace;
colorspace = colormanage_colorspace_get_named(name);
ColorSpace *colorspace = colormanage_colorspace_get_named(name);
if (colorspace) {
return colorspace->index;
@@ -3184,9 +3171,7 @@ int IMB_colormanagement_colorspace_get_named_index(const char *name)
const char *IMB_colormanagement_colorspace_get_indexed_name(int index)
{
ColorSpace *colorspace;
colorspace = colormanage_colorspace_get_indexed(index);
ColorSpace *colorspace = colormanage_colorspace_get_indexed(index);
if (colorspace) {
return colorspace->name;
@@ -3212,8 +3197,8 @@ void IMB_colormanagement_colorspace_from_ibuf_ftype(
/* Get color space from file type. */
const ImFileType *type = IMB_file_type_from_ibuf(ibuf);
if (type != NULL) {
if (type->save != NULL) {
if (type != nullptr) {
if (type->save != nullptr) {
const char *role_colorspace = IMB_colormanagement_role_colorspace_name_get(
type->default_save_role);
BLI_strncpy(colorspace_settings->name, role_colorspace, sizeof(colorspace_settings->name));
@@ -3232,7 +3217,7 @@ ColorManagedLook *colormanage_look_add(const char *name, const char *process_spa
ColorManagedLook *look;
int index = global_tot_looks;
look = MEM_callocN(sizeof(ColorManagedLook), "ColorManagedLook");
look = MEM_cnew<ColorManagedLook>("ColorManagedLook");
look->index = index + 1;
BLI_strncpy(look->name, name, sizeof(look->name));
BLI_strncpy(look->ui_name, name, sizeof(look->ui_name));
@@ -3255,28 +3240,24 @@ ColorManagedLook *colormanage_look_add(const char *name, const char *process_spa
ColorManagedLook *colormanage_look_get_named(const char *name)
{
ColorManagedLook *look;
for (look = global_looks.first; look; look = look->next) {
LISTBASE_FOREACH (ColorManagedLook *, look, &global_looks) {
if (STREQ(look->name, name)) {
return look;
}
}
return NULL;
return nullptr;
}
ColorManagedLook *colormanage_look_get_indexed(int index)
{
/* look indices are 1-based */
return BLI_findlink(&global_looks, index - 1);
return static_cast<ColorManagedLook *>(BLI_findlink(&global_looks, index - 1));
}
int IMB_colormanagement_look_get_named_index(const char *name)
{
ColorManagedLook *look;
look = colormanage_look_get_named(name);
ColorManagedLook *look = colormanage_look_get_named(name);
if (look) {
return look->index;
@@ -3295,7 +3276,7 @@ const char *IMB_colormanagement_look_get_indexed_name(int index)
return look->name;
}
return NULL;
return nullptr;
}
/** \} */
@@ -3306,9 +3287,7 @@ const char *IMB_colormanagement_look_get_indexed_name(int index)
void IMB_colormanagement_display_items_add(EnumPropertyItem **items, int *totitem)
{
ColorManagedDisplay *display;
for (display = global_displays.first; display; display = display->next) {
LISTBASE_FOREACH (ColorManagedDisplay *, display, &global_displays) {
EnumPropertyItem item;
item.value = display->index;
@@ -3341,13 +3320,10 @@ void IMB_colormanagement_view_items_add(EnumPropertyItem **items,
const char *display_name)
{
ColorManagedDisplay *display = colormanage_display_get_named(display_name);
ColorManagedView *view;
if (display) {
LinkData *display_view;
for (display_view = display->views.first; display_view; display_view = display_view->next) {
view = display_view->data;
LISTBASE_FOREACH (LinkData *, display_view, &display->views) {
ColorManagedView *view = static_cast<ColorManagedView *>(display_view->data);
colormanagement_view_item_add(items, totitem, view);
}
@@ -3358,9 +3334,7 @@ void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items,
int *totitem,
const char *view_name)
{
ColorManagedLook *look;
for (look = global_looks.first; look; look = look->next) {
LISTBASE_FOREACH (ColorManagedLook *, look, &global_looks) {
if (!colormanage_compatible_look(look, view_name)) {
continue;
}
@@ -3379,9 +3353,7 @@ void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items,
void IMB_colormanagement_colorspace_items_add(EnumPropertyItem **items, int *totitem)
{
ColorSpace *colorspace;
for (colorspace = global_colorspaces.first; colorspace; colorspace = colorspace->next) {
LISTBASE_FOREACH (ColorSpace *, colorspace, &global_colorspaces) {
EnumPropertyItem item;
if (!colorspace->is_invertible) {
@@ -3433,13 +3405,13 @@ static void partial_buffer_update_rect(ImBuf *ibuf,
int channels = ibuf->channels;
float dither = ibuf->dither;
ColorSpace *rect_colorspace = ibuf->rect_colorspace;
float *display_buffer_float = NULL;
float *display_buffer_float = nullptr;
const int width = xmax - xmin;
const int height = ymax - ymin;
bool is_data = (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) != 0;
if (dither != 0.0f) {
/* cm_processor is NULL in cases byte_buffer's space matches display
/* cm_processor is nullptr in cases byte_buffer's space matches display
* buffer's space
* in this case we could skip extra transform and only apply dither
* use 4 channels for easier byte->float->byte conversion here so
@@ -3450,8 +3422,8 @@ static void partial_buffer_update_rect(ImBuf *ibuf,
channels = 4;
}
display_buffer_float = MEM_callocN((size_t)channels * width * height * sizeof(float),
"display buffer for dither");
display_buffer_float = static_cast<float *>(MEM_callocN(
(size_t)channels * width * height * sizeof(float), "display buffer for dither"));
}
if (cm_processor) {
@@ -3614,8 +3586,8 @@ static void imb_partial_display_buffer_update_ex(
{
ColormanageCacheViewSettings cache_view_settings;
ColormanageCacheDisplaySettings cache_display_settings;
void *cache_handle = NULL;
uchar *display_buffer = NULL;
void *cache_handle = nullptr;
uchar *display_buffer = nullptr;
int buffer_width = ibuf->x;
if (ibuf->display_buffer_flags) {
@@ -3648,7 +3620,7 @@ static void imb_partial_display_buffer_update_ex(
}
if (display_buffer) {
ColormanageProcessor *cm_processor = NULL;
ColormanageProcessor *cm_processor = nullptr;
bool skip_transform = false;
/* Byte buffer is assumed to be in imbuf's rect space, so if byte buffer
@@ -3658,7 +3630,7 @@ static void imb_partial_display_buffer_update_ex(
* But if there's a float buffer it's likely operation was performed on
* it first and byte buffer is likely to be out of date here.
*/
if (linear_buffer == NULL && byte_buffer != NULL) {
if (linear_buffer == nullptr && byte_buffer != nullptr) {
skip_transform = is_ibuf_rect_in_display_space(ibuf, view_settings, display_settings);
}
@@ -3794,7 +3766,7 @@ ColormanageProcessor *IMB_colormanagement_display_processor_new(
const ColorManagedViewSettings *applied_view_settings;
ColorSpace *display_space;
cm_processor = MEM_callocN(sizeof(ColormanageProcessor), "colormanagement processor");
cm_processor = MEM_cnew<ColormanageProcessor>("colormanagement processor");
if (view_settings) {
applied_view_settings = view_settings;
@@ -3831,14 +3803,14 @@ ColormanageProcessor *IMB_colormanagement_colorspace_processor_new(const char *f
ColormanageProcessor *cm_processor;
ColorSpace *color_space;
cm_processor = MEM_callocN(sizeof(ColormanageProcessor), "colormanagement processor");
cm_processor = MEM_cnew<ColormanageProcessor>("colormanagement processor");
color_space = colormanage_colorspace_get_named(to_colorspace);
cm_processor->is_data_result = color_space->is_data;
OCIO_ConstProcessorRcPtr *processor = create_colorspace_transform_processor(from_colorspace,
to_colorspace);
if (processor != NULL) {
if (processor != nullptr) {
cm_processor->cpu_processor = OCIO_processorGetCPUProcessor(processor);
}
OCIO_processorRelease(processor);
@@ -4015,7 +3987,7 @@ static OCIO_CurveMappingSettings *update_glsl_curve_mapping(
/* Using curve mapping? */
const bool use_curve_mapping = (view_settings->flag & COLORMANAGE_VIEW_USE_CURVES) != 0;
if (!use_curve_mapping) {
return NULL;
return nullptr;
}
/* Already up to date? */
@@ -4028,7 +4000,7 @@ static OCIO_CurveMappingSettings *update_glsl_curve_mapping(
}
/* Need to update. */
CurveMapping *new_curve_mapping = NULL;
CurveMapping *new_curve_mapping = nullptr;
/* We're using curve mapping's address as a cache ID,
* so we need to make sure re-allocation gives new address here.
@@ -4040,8 +4012,8 @@ static OCIO_CurveMappingSettings *update_glsl_curve_mapping(
if (global_gpu_state.curve_mapping) {
BKE_curvemapping_free(global_gpu_state.curve_mapping);
MEM_freeN(curve_mapping_settings->lut);
global_gpu_state.curve_mapping = NULL;
curve_mapping_settings->lut = NULL;
global_gpu_state.curve_mapping = nullptr;
curve_mapping_settings->lut = nullptr;
}
/* Fill in OCIO's curve mapping settings. */
@@ -4054,14 +4026,14 @@ static OCIO_CurveMappingSettings *update_glsl_curve_mapping(
global_gpu_state.use_curve_mapping = true;
}
else {
global_gpu_state.orig_curve_mapping = NULL;
global_gpu_state.orig_curve_mapping = nullptr;
global_gpu_state.use_curve_mapping = false;
}
return curve_mapping_settings;
}
bool IMB_colormanagement_support_glsl_draw(const ColorManagedViewSettings *UNUSED(view_settings))
bool IMB_colormanagement_support_glsl_draw(const ColorManagedViewSettings * /*view_settings*/)
{
return OCIO_supportGPUShader();
}
@@ -4129,7 +4101,7 @@ bool IMB_colormanagement_setup_glsl_draw(const ColorManagedViewSettings *view_se
bool predivide)
{
return IMB_colormanagement_setup_glsl_draw_from_space(
view_settings, display_settings, NULL, dither, predivide, false);
view_settings, display_settings, nullptr, dither, predivide, false);
}
bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const bContext *C,
@@ -4148,7 +4120,7 @@ bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const bContext *C,
bool IMB_colormanagement_setup_glsl_draw_ctx(const bContext *C, float dither, bool predivide)
{
return IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, NULL, dither, predivide);
return IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, nullptr, dither, predivide);
}
void IMB_colormanagement_finish_glsl_draw(void)

View File

@@ -31,7 +31,7 @@ static DitherContext *create_dither_context(float dither)
{
DitherContext *di;
di = MEM_mallocN(sizeof(DitherContext), "dithering context");
di = MEM_cnew<DitherContext>("dithering context");
di->dither = dither;
return di;
@@ -105,7 +105,7 @@ void IMB_buffer_byte_from_float(uchar *rect_to,
{
float tmp[4];
int x, y;
DitherContext *di = NULL;
DitherContext *di = nullptr;
float inv_width = 1.0f / width;
float inv_height = 1.0f / height;
@@ -269,7 +269,7 @@ void IMB_buffer_byte_from_float_mask(uchar *rect_to,
char *mask)
{
int x, y;
DitherContext *di = NULL;
DitherContext *di = nullptr;
float inv_width = 1.0f / width, inv_height = 1.0f / height;
if (dither) {
@@ -696,27 +696,27 @@ void IMB_buffer_byte_from_byte(uchar *rect_to,
void IMB_rect_from_float(ImBuf *ibuf)
{
/* verify we have a float buffer */
if (ibuf->rect_float == NULL) {
if (ibuf->rect_float == nullptr) {
return;
}
/* create byte rect if it didn't exist yet */
if (ibuf->rect == NULL) {
if (ibuf->rect == nullptr) {
if (imb_addrectImBuf(ibuf) == 0) {
return;
}
}
const char *from_colorspace = (ibuf->float_colorspace == NULL) ?
const char *from_colorspace = (ibuf->float_colorspace == nullptr) ?
IMB_colormanagement_role_colorspace_name_get(
COLOR_ROLE_SCENE_LINEAR) :
ibuf->float_colorspace->name;
const char *to_colorspace = (ibuf->rect_colorspace == NULL) ?
const char *to_colorspace = (ibuf->rect_colorspace == nullptr) ?
IMB_colormanagement_role_colorspace_name_get(
COLOR_ROLE_DEFAULT_BYTE) :
ibuf->rect_colorspace->name;
float *buffer = MEM_dupallocN(ibuf->rect_float);
float *buffer = static_cast<float *>(MEM_dupallocN(ibuf->rect_float));
/* first make float buffer in byte space */
const bool predivide = IMB_alpha_affects_rgb(ibuf);
@@ -751,9 +751,9 @@ void IMB_float_from_rect_ex(struct ImBuf *dst,
const struct ImBuf *src,
const rcti *region_to_update)
{
BLI_assert_msg(dst->rect_float != NULL,
BLI_assert_msg(dst->rect_float != nullptr,
"Destination buffer should have a float buffer assigned.");
BLI_assert_msg(src->rect != NULL, "Source buffer should have a byte buffer assigned.");
BLI_assert_msg(src->rect != nullptr, "Source buffer should have a byte buffer assigned.");
BLI_assert_msg(dst->x == src->x, "Source and destination buffer should have the same dimension");
BLI_assert_msg(dst->y == src->y, "Source and destination buffer should have the same dimension");
BLI_assert_msg(dst->channels = 4, "Destination buffer should have 4 channels.");
@@ -807,7 +807,7 @@ void IMB_float_from_rect(ImBuf *ibuf)
float *rect_float;
/* verify if we byte and float buffers */
if (ibuf->rect == NULL) {
if (ibuf->rect == nullptr) {
return;
}
@@ -816,11 +816,11 @@ void IMB_float_from_rect(ImBuf *ibuf)
* interfere with other parts of blender
*/
rect_float = ibuf->rect_float;
if (rect_float == NULL) {
if (rect_float == nullptr) {
const size_t size = IMB_get_rect_len(ibuf) * sizeof(float[4]);
rect_float = MEM_callocN(size, "IMB_float_from_rect");
rect_float = static_cast<float *>(MEM_callocN(size, "IMB_float_from_rect"));
if (rect_float == NULL) {
if (rect_float == nullptr) {
return;
}

View File

@@ -1,240 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup imbuf
*/
#include <stddef.h>
#include "BLI_utildefines.h"
#include "IMB_filetype.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_colormanagement.h"
#include "oiio/openimageio_api.h"
#ifdef WITH_OPENEXR
# include "openexr/openexr_api.h"
#endif
const ImFileType IMB_FILE_TYPES[] = {
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_jpeg,
.load = imb_load_jpeg,
.load_filepath = NULL,
.load_filepath_thumbnail = imb_thumbnail_jpeg,
.save = imb_savejpeg,
.flag = 0,
.filetype = IMB_FTYPE_JPG,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_png,
.load = imb_load_png,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_save_png,
.flag = 0,
.filetype = IMB_FTYPE_PNG,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_bmp,
.load = imb_load_bmp,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_save_bmp,
.flag = 0,
.filetype = IMB_FTYPE_BMP,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_tga,
.load = imb_load_tga,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_save_tga,
.flag = 0,
.filetype = IMB_FTYPE_TGA,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_iris,
.load = imb_loadiris,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_saveiris,
.flag = 0,
.filetype = IMB_FTYPE_IMAGIC,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
#ifdef WITH_CINEON
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_dpx,
.load = imb_load_dpx,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_save_dpx,
.flag = IM_FTYPE_FLOAT,
.filetype = IMB_FTYPE_DPX,
.default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
},
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_cineon,
.load = imb_load_cineon,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_save_cineon,
.flag = IM_FTYPE_FLOAT,
.filetype = IMB_FTYPE_CINEON,
.default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
},
#endif
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_tiff,
.load = imb_load_tiff,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_save_tiff,
.flag = 0,
.filetype = IMB_FTYPE_TIF,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_hdr,
.load = imb_load_hdr,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_save_hdr,
.flag = IM_FTYPE_FLOAT,
.filetype = IMB_FTYPE_RADHDR,
.default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
},
#ifdef WITH_OPENEXR
{
.init = imb_initopenexr,
.exit = imb_exitopenexr,
.is_a = imb_is_a_openexr,
.load = imb_load_openexr,
.load_filepath = NULL,
.load_filepath_thumbnail = imb_load_filepath_thumbnail_openexr,
.save = imb_save_openexr,
.flag = IM_FTYPE_FLOAT,
.filetype = IMB_FTYPE_OPENEXR,
.default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
},
#endif
#ifdef WITH_OPENJPEG
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_jp2,
.load = imb_load_jp2,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = imb_save_jp2,
.flag = IM_FTYPE_FLOAT,
.filetype = IMB_FTYPE_JP2,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
#endif
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_dds,
.load = imb_load_dds,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = NULL,
.flag = 0,
.filetype = IMB_FTYPE_DDS,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_psd,
.load = imb_load_psd,
.load_filepath = NULL,
.load_filepath_thumbnail = NULL,
.save = NULL,
.flag = IM_FTYPE_FLOAT,
.filetype = IMB_FTYPE_PSD,
.default_save_role = COLOR_ROLE_DEFAULT_FLOAT,
},
#ifdef WITH_WEBP
{
.init = NULL,
.exit = NULL,
.is_a = imb_is_a_webp,
.load = imb_loadwebp,
.load_filepath = NULL,
.load_filepath_thumbnail = imb_load_filepath_thumbnail_webp,
.save = imb_savewebp,
.flag = 0,
.filetype = IMB_FTYPE_WEBP,
.default_save_role = COLOR_ROLE_DEFAULT_BYTE,
},
#endif
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0},
};
const ImFileType *IMB_FILE_TYPES_LAST = &IMB_FILE_TYPES[ARRAY_SIZE(IMB_FILE_TYPES) - 1];
const ImFileType *IMB_file_type_from_ftype(int ftype)
{
for (const ImFileType *type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (ftype == type->filetype) {
return type;
}
}
return NULL;
}
const ImFileType *IMB_file_type_from_ibuf(const ImBuf *ibuf)
{
return IMB_file_type_from_ftype(ibuf->ftype);
}
void imb_filetypes_init(void)
{
const ImFileType *type;
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->init) {
type->init();
}
}
}
void imb_filetypes_exit(void)
{
const ImFileType *type;
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->exit) {
type->exit();
}
}
}

View File

@@ -0,0 +1,240 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup imbuf
*/
#include <stddef.h>
#include "BLI_utildefines.h"
#include "IMB_filetype.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_colormanagement.h"
#include "oiio/openimageio_api.h"
#ifdef WITH_OPENEXR
# include "openexr/openexr_api.h"
#endif
const ImFileType IMB_FILE_TYPES[] = {
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_jpeg,
/*load*/ imb_load_jpeg,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ imb_thumbnail_jpeg,
/*save*/ imb_savejpeg,
/*flag*/ 0,
/*filetype*/ IMB_FTYPE_JPG,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_png,
/*load*/ imb_load_png,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_save_png,
/*flag*/ 0,
/*filetype*/ IMB_FTYPE_PNG,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_bmp,
/*load*/ imb_load_bmp,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_save_bmp,
/*flag*/ 0,
/*filetype*/ IMB_FTYPE_BMP,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_tga,
/*load*/ imb_load_tga,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_save_tga,
/*flag*/ 0,
/*filetype*/ IMB_FTYPE_TGA,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_iris,
/*load*/ imb_loadiris,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_saveiris,
/*flag*/ 0,
/*filetype*/ IMB_FTYPE_IMAGIC,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
#ifdef WITH_CINEON
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_dpx,
/*load*/ imb_load_dpx,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_save_dpx,
/*flag*/ IM_FTYPE_FLOAT,
/*filetype*/ IMB_FTYPE_DPX,
/*default_save_role*/ COLOR_ROLE_DEFAULT_FLOAT,
},
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_cineon,
/*load*/ imb_load_cineon,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_save_cineon,
/*flag*/ IM_FTYPE_FLOAT,
/*filetype*/ IMB_FTYPE_CINEON,
/*default_save_role*/ COLOR_ROLE_DEFAULT_FLOAT,
},
#endif
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_tiff,
/*load*/ imb_load_tiff,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_save_tiff,
/*flag*/ 0,
/*filetype*/ IMB_FTYPE_TIF,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_hdr,
/*load*/ imb_load_hdr,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_save_hdr,
/*flag*/ IM_FTYPE_FLOAT,
/*filetype*/ IMB_FTYPE_RADHDR,
/*default_save_role*/ COLOR_ROLE_DEFAULT_FLOAT,
},
#ifdef WITH_OPENEXR
{
/*init*/ imb_initopenexr,
/*exit*/ imb_exitopenexr,
/*is_a*/ imb_is_a_openexr,
/*load*/ imb_load_openexr,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ imb_load_filepath_thumbnail_openexr,
/*save*/ imb_save_openexr,
/*flag*/ IM_FTYPE_FLOAT,
/*filetype*/ IMB_FTYPE_OPENEXR,
/*default_save_role*/ COLOR_ROLE_DEFAULT_FLOAT,
},
#endif
#ifdef WITH_OPENJPEG
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_jp2,
/*load*/ imb_load_jp2,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ imb_save_jp2,
/*flag*/ IM_FTYPE_FLOAT,
/*filetype*/ IMB_FTYPE_JP2,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
#endif
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_dds,
/*load*/ imb_load_dds,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ nullptr,
/*flag*/ 0,
/*filetype*/ IMB_FTYPE_DDS,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_psd,
/*load*/ imb_load_psd,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ nullptr,
/*save*/ nullptr,
/*flag*/ IM_FTYPE_FLOAT,
/*filetype*/ IMB_FTYPE_PSD,
/*default_save_role*/ COLOR_ROLE_DEFAULT_FLOAT,
},
#ifdef WITH_WEBP
{
/*init*/ nullptr,
/*exit*/ nullptr,
/*is_a*/ imb_is_a_webp,
/*load*/ imb_loadwebp,
/*load_filepath*/ nullptr,
/*load_filepath_thumbnail*/ imb_load_filepath_thumbnail_webp,
/*save*/ imb_savewebp,
/*flag*/ 0,
/*filetype*/ IMB_FTYPE_WEBP,
/*default_save_role*/ COLOR_ROLE_DEFAULT_BYTE,
},
#endif
{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0, 0, 0},
};
const ImFileType *IMB_FILE_TYPES_LAST = &IMB_FILE_TYPES[ARRAY_SIZE(IMB_FILE_TYPES) - 1];
const ImFileType *IMB_file_type_from_ftype(int ftype)
{
for (const ImFileType *type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (ftype == type->filetype) {
return type;
}
}
return nullptr;
}
const ImFileType *IMB_file_type_from_ibuf(const ImBuf *ibuf)
{
return IMB_file_type_from_ftype(ibuf->ftype);
}
void imb_filetypes_init(void)
{
const ImFileType *type;
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->init) {
type->init();
}
}
}
void imb_filetypes_exit(void)
{
const ImFileType *type;
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->exit) {
type->exit();
}
}
}

View File

@@ -313,7 +313,7 @@ void IMB_mask_filter_extend(char *mask, int width, int height)
rowlen = width;
/* make a copy, to prevent flooding */
temprect = MEM_dupallocN(mask);
temprect = static_cast<char *>(MEM_dupallocN(mask));
for (y = 1; y <= height; y++) {
/* setup rows */
@@ -391,7 +391,7 @@ static int check_pixel_assigned(
if (index >= 0) {
const int alpha_index = depth * index + (depth - 1);
if (mask != NULL) {
if (mask != nullptr) {
res = mask[index] != 0 ? 1 : 0;
}
else if ((is_float && ((const float *)buffer)[alpha_index] != 0.0f) ||
@@ -411,10 +411,10 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
const int depth = 4; /* always 4 channels */
const int chsize = ibuf->rect_float ? sizeof(float) : sizeof(uchar);
const size_t bsize = ((size_t)width) * height * depth * chsize;
const bool is_float = (ibuf->rect_float != NULL);
const bool is_float = (ibuf->rect_float != nullptr);
void *dstbuf = (void *)MEM_dupallocN(ibuf->rect_float ? (void *)ibuf->rect_float :
(void *)ibuf->rect);
char *dstmask = mask == NULL ? NULL : (char *)MEM_dupallocN(mask);
char *dstmask = mask == nullptr ? nullptr : (char *)MEM_dupallocN(mask);
void *srcbuf = ibuf->rect_float ? (void *)ibuf->rect_float : (void *)ibuf->rect;
char *srcmask = mask;
int cannot_early_out = 1, r, n, k, i, j, c;
@@ -514,7 +514,7 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
}
}
if (dstmask != NULL) {
if (dstmask != nullptr) {
dstmask[index] = FILTER_MASK_MARGIN; /* assigned */
}
cannot_early_out = 1;
@@ -526,14 +526,14 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter)
/* keep the original buffer up to date. */
memcpy(srcbuf, dstbuf, bsize);
if (dstmask != NULL) {
if (dstmask != nullptr) {
memcpy(srcmask, dstmask, ((size_t)width) * height);
}
}
/* free memory */
MEM_freeN(dstbuf);
if (dstmask != NULL) {
if (dstmask != nullptr) {
MEM_freeN(dstmask);
}
}
@@ -665,7 +665,7 @@ void IMB_premultiply_rect_float(float *rect_float, int channels, int w, int h)
void IMB_premultiply_alpha(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}
@@ -727,7 +727,7 @@ void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h)
void IMB_unpremultiply_alpha(ImBuf *ibuf)
{
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}

View File

@@ -89,10 +89,10 @@ void bicubic_interpolation_color(
void bicubic_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int xout, int yout)
{
uchar *outI = NULL;
float *outF = NULL;
uchar *outI = nullptr;
float *outF = nullptr;
if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) {
if (in == nullptr || (in->rect == nullptr && in->rect_float == nullptr)) {
return;
}
@@ -109,7 +109,7 @@ void bicubic_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int xo
* \{ */
void bilinear_interpolation_color_fl(
const struct ImBuf *in, uchar UNUSED(outI[4]), float outF[4], float u, float v)
const struct ImBuf *in, uchar /*outI*/[4], float outF[4], float u, float v)
{
BLI_assert(outF);
BLI_assert(in->rect_float);
@@ -117,7 +117,7 @@ void bilinear_interpolation_color_fl(
}
void bilinear_interpolation_color_char(
const struct ImBuf *in, uchar outI[4], float UNUSED(outF[4]), float u, float v)
const struct ImBuf *in, uchar outI[4], float /*outF*/[4], float u, float v)
{
BLI_assert(outI);
BLI_assert(in->rect);
@@ -212,10 +212,10 @@ void bilinear_interpolation_color_wrap(
void bilinear_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int xout, int yout)
{
uchar *outI = NULL;
float *outF = NULL;
uchar *outI = nullptr;
float *outF = nullptr;
if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) {
if (in == nullptr || (in->rect == nullptr && in->rect_float == nullptr)) {
return;
}
@@ -232,7 +232,7 @@ void bilinear_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int x
* \{ */
void nearest_interpolation_color_char(
const struct ImBuf *in, uchar outI[4], float UNUSED(outF[4]), float u, float v)
const struct ImBuf *in, uchar outI[4], float /*outF*/[4], float u, float v)
{
BLI_assert(outI);
BLI_assert(in->rect);
@@ -255,7 +255,7 @@ void nearest_interpolation_color_char(
}
void nearest_interpolation_color_fl(
const struct ImBuf *in, uchar UNUSED(outI[4]), float outF[4], float u, float v)
const struct ImBuf *in, uchar /*outI*/[4], float outF[4], float u, float v)
{
BLI_assert(outF);
BLI_assert(in->rect_float);
@@ -326,10 +326,10 @@ void nearest_interpolation_color_wrap(
void nearest_interpolation(const ImBuf *in, ImBuf *out, float u, float v, int xout, int yout)
{
uchar *outI = NULL;
float *outF = NULL;
uchar *outI = nullptr;
float *outF = nullptr;
if (in == NULL || (in->rect == NULL && in->rect_float == NULL)) {
if (in == nullptr || (in->rect == nullptr && in->rect_float == nullptr)) {
return;
}
@@ -366,7 +366,7 @@ void IMB_processor_apply_threaded(
int total_tasks = (buffer_lines + lines_per_task - 1) / lines_per_task;
int i, start_line;
task_pool = BLI_task_pool_create(do_thread, TASK_PRIORITY_HIGH);
task_pool = BLI_task_pool_create(reinterpret_cast<void *>(do_thread), TASK_PRIORITY_HIGH);
handles = MEM_callocN(handle_size * total_tasks, "processor apply threaded handles");
@@ -385,7 +385,7 @@ void IMB_processor_apply_threaded(
init_handle(handle, start_line, lines_per_current_task, init_customdata);
BLI_task_pool_push(task_pool, processor_apply_func, handle, false, NULL);
BLI_task_pool_push(task_pool, processor_apply_func, handle, false, nullptr);
start_line += lines_per_task;
}
@@ -405,9 +405,9 @@ typedef struct ScanlineGlobalData {
static void processor_apply_parallel(void *__restrict userdata,
const int scanline,
const TaskParallelTLS *__restrict UNUSED(tls))
const TaskParallelTLS *__restrict /*tls*/)
{
ScanlineGlobalData *data = userdata;
ScanlineGlobalData *data = static_cast<ScanlineGlobalData *>(userdata);
data->do_thread(data->custom_data, scanline);
}
@@ -416,10 +416,9 @@ void IMB_processor_apply_threaded_scanlines(int total_scanlines,
void *custom_data)
{
TaskParallelSettings settings;
ScanlineGlobalData data = {
.do_thread = do_thread,
.custom_data = custom_data,
};
ScanlineGlobalData data = {};
data.do_thread = do_thread;
data.custom_data = custom_data;
BLI_parallel_range_settings_defaults(&settings);
BLI_task_parallel_range(0, total_scanlines, &data, processor_apply_parallel, &settings);
@@ -483,11 +482,11 @@ void IMB_alpha_under_color_byte(uchar *rect, int x, int y, const float backcol[3
void IMB_sampleImageAtLocation(ImBuf *ibuf, float x, float y, bool make_linear_rgb, float color[4])
{
if (ibuf->rect_float) {
nearest_interpolation_color(ibuf, NULL, color, x, y);
nearest_interpolation_color(ibuf, nullptr, color, x, y);
}
else {
uchar byte_color[4];
nearest_interpolation_color(ibuf, byte_color, NULL, x, y);
nearest_interpolation_color(ibuf, byte_color, nullptr, x, y);
rgba_uchar_to_float(color, byte_color);
if (make_linear_rgb) {
IMB_colormanagement_colorspace_to_scene_linear_v4(color, false, ibuf->rect_colorspace);

View File

@@ -26,6 +26,7 @@
#include "PIL_time.h"
#include "IMB_anim.h"
#include "IMB_imbuf.h"
#include "IMB_indexer.h"
#include "imbuf.h"
@@ -34,18 +35,21 @@
#endif
#ifdef WITH_FFMPEG
extern "C" {
# include "ffmpeg_compat.h"
# include <libavutil/imgutils.h>
}
#endif
static const char binary_header_str[] = "BlenMIdx";
static const char temp_ext[] = "_part";
static const int proxy_sizes[] = {IMB_PROXY_25, IMB_PROXY_50, IMB_PROXY_75, IMB_PROXY_100};
static const IMB_Proxy_Size proxy_sizes[] = {
IMB_PROXY_25, IMB_PROXY_50, IMB_PROXY_75, IMB_PROXY_100};
static const float proxy_fac[] = {0.25, 0.50, 0.75, 1.00};
#ifdef WITH_FFMPEG
static int tc_types[] = {
static IMB_Timecode_Type tc_types[] = {
IMB_TC_RECORD_RUN,
IMB_TC_FREE_RUN,
IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN,
@@ -62,7 +66,7 @@ static int tc_types[] = {
anim_index_builder *IMB_index_builder_create(const char *name)
{
anim_index_builder *rv = MEM_callocN(sizeof(struct anim_index_builder), "index builder");
anim_index_builder *rv = MEM_cnew<anim_index_builder>("index builder");
fprintf(stderr, "Starting work on index: %s\n", name);
@@ -81,7 +85,7 @@ anim_index_builder *IMB_index_builder_create(const char *name)
"Index build broken!\n",
rv->temp_name);
MEM_freeN(rv);
return NULL;
return nullptr;
}
fprintf(rv->fp,
@@ -158,13 +162,13 @@ struct anim_index *IMB_indexer_open(const char *name)
int i;
if (!fp) {
return NULL;
return nullptr;
}
if (fread(header, 12, 1, fp) != 1) {
fprintf(stderr, "Couldn't read indexer file: %s\n", name);
fclose(fp);
return NULL;
return nullptr;
}
header[12] = 0;
@@ -172,16 +176,16 @@ struct anim_index *IMB_indexer_open(const char *name)
if (memcmp(header, binary_header_str, 8) != 0) {
fprintf(stderr, "Error reading %s: Binary file type string mismatch\n", name);
fclose(fp);
return NULL;
return nullptr;
}
if (atoi(header + 9) != INDEX_FILE_VERSION) {
fprintf(stderr, "Error reading %s: File version mismatch\n", name);
fclose(fp);
return NULL;
return nullptr;
}
idx = MEM_callocN(sizeof(struct anim_index), "anim_index");
idx = MEM_cnew<anim_index>("anim_index");
BLI_strncpy(idx->name, name, sizeof(idx->name));
@@ -196,8 +200,8 @@ struct anim_index *IMB_indexer_open(const char *name)
fseek(fp, 12, SEEK_SET);
idx->entries = MEM_callocN(sizeof(struct anim_index_entry) * idx->num_entries,
"anim_index_entries");
idx->entries = static_cast<anim_index_entry *>(
MEM_callocN(sizeof(anim_index_entry) * idx->num_entries, "anim_index_entries"));
size_t items_read = 0;
for (i = 0; i < idx->num_entries; i++) {
@@ -213,7 +217,7 @@ struct anim_index *IMB_indexer_open(const char *name)
MEM_freeN(idx->entries);
MEM_freeN(idx);
fclose(fp);
return NULL;
return nullptr;
}
if ((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V')) {
@@ -483,15 +487,15 @@ struct proxy_output_ctx {
struct SwsContext *sws_ctx;
AVFrame *frame;
int cfra;
int proxy_size;
IMB_Proxy_Size proxy_size;
int orig_height;
struct anim *anim;
};
static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
struct anim *anim, AVStream *st, int proxy_size, int width, int height, int quality)
struct anim *anim, AVStream *st, IMB_Proxy_Size proxy_size, int width, int height, int quality)
{
struct proxy_output_ctx *rv = MEM_callocN(sizeof(struct proxy_output_ctx), "alloc_proxy_output");
proxy_output_ctx *rv = MEM_cnew<proxy_output_ctx>("alloc_proxy_output");
char filepath[FILE_MAX];
@@ -500,17 +504,17 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
get_proxy_filepath(rv->anim, rv->proxy_size, filepath, true);
if (!BLI_make_existing_file(filepath)) {
return NULL;
return nullptr;
}
rv->of = avformat_alloc_context();
rv->of->oformat = av_guess_format("avi", NULL, NULL);
rv->of->oformat = av_guess_format("avi", nullptr, nullptr);
rv->of->url = av_strdup(filepath);
fprintf(stderr, "Starting work on proxy: %s\n", rv->of->url);
rv->st = avformat_new_stream(rv->of, NULL);
rv->st = avformat_new_stream(rv->of, nullptr);
rv->st->id = 0;
rv->codec = avcodec_find_encoder(AV_CODEC_ID_H264);
@@ -524,7 +528,7 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
avcodec_free_context(&rv->c);
avformat_free_context(rv->of);
MEM_freeN(rv);
return NULL;
return nullptr;
}
rv->c->width = width;
@@ -551,7 +555,7 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
const int crf_range_max = 17;
int crf = round_fl_to_int((quality / 100.0f) * (crf_range_max - crf_range_min) + crf_range_min);
AVDictionary *codec_opts = NULL;
AVDictionary *codec_opts = nullptr;
/* High quality preset value. */
av_dict_set_int(&codec_opts, "crf", crf, 0);
/* Prefer smaller file-size. Presets from `veryslow` to `veryfast` produce output with very
@@ -583,26 +587,32 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
int ret = avio_open(&rv->of->pb, filepath, AVIO_FLAG_WRITE);
if (ret < 0) {
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
fprintf(stderr,
"Couldn't open IO: %s\n"
"Proxy not built!\n",
av_err2str(ret));
error_str);
avcodec_free_context(&rv->c);
avformat_free_context(rv->of);
MEM_freeN(rv);
return NULL;
return nullptr;
}
ret = avcodec_open2(rv->c, rv->codec, &codec_opts);
if (ret < 0) {
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
fprintf(stderr,
"Couldn't open codec: %s\n"
"Proxy not built!\n",
av_err2str(ret));
error_str);
avcodec_free_context(&rv->c);
avformat_free_context(rv->of);
MEM_freeN(rv);
return NULL;
return nullptr;
}
rv->orig_height = st->codecpar->height;
@@ -614,8 +624,9 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
av_image_fill_arrays(rv->frame->data,
rv->frame->linesize,
MEM_mallocN(av_image_get_buffer_size(rv->c->pix_fmt, width, height, 1),
"alloc proxy output frame"),
static_cast<const uint8_t *>(MEM_mallocN(
av_image_get_buffer_size(rv->c->pix_fmt, width, height, 1),
"alloc proxy output frame")),
rv->c->pix_fmt,
width,
height,
@@ -627,22 +638,25 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
rv->sws_ctx = sws_getContext(st->codecpar->width,
rv->orig_height,
st->codecpar->format,
AVPixelFormat(st->codecpar->format),
width,
height,
rv->c->pix_fmt,
SWS_FAST_BILINEAR | SWS_PRINT_INFO,
NULL,
NULL,
NULL);
nullptr,
nullptr,
nullptr);
}
ret = avformat_write_header(rv->of, NULL);
ret = avformat_write_header(rv->of, nullptr);
if (ret < 0) {
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
fprintf(stderr,
"Couldn't write header: %s\n"
"Proxy not built!\n",
av_err2str(ret));
error_str);
if (rv->frame) {
av_frame_free(&rv->frame);
@@ -651,7 +665,7 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
avcodec_free_context(&rv->c);
avformat_free_context(rv->of);
MEM_freeN(rv);
return NULL;
return nullptr;
}
return rv;
@@ -684,7 +698,10 @@ static void add_to_proxy_output_ffmpeg(struct proxy_output_ctx *ctx, AVFrame *fr
int ret = avcodec_send_frame(ctx->c, frame);
if (ret < 0) {
/* Can't send frame to encoder. This shouldn't happen. */
fprintf(stderr, "Can't send video frame: %s\n", av_err2str(ret));
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
fprintf(stderr, "Can't send video frame: %s\n", error_str);
return;
}
AVPacket *packet = av_packet_alloc();
@@ -697,11 +714,14 @@ static void add_to_proxy_output_ffmpeg(struct proxy_output_ctx *ctx, AVFrame *fr
break;
}
if (ret < 0) {
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
fprintf(stderr,
"Error encoding proxy frame %d for '%s': %s\n",
ctx->cfra - 1,
ctx->of->url,
av_err2str(ret));
error_str);
break;
}
@@ -713,12 +733,15 @@ static void add_to_proxy_output_ffmpeg(struct proxy_output_ctx *ctx, AVFrame *fr
int write_ret = av_interleaved_write_frame(ctx->of, packet);
if (write_ret != 0) {
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, write_ret);
fprintf(stderr,
"Error writing proxy frame %d "
"into '%s': %s\n",
ctx->cfra - 1,
ctx->of->url,
av_err2str(write_ret));
error_str);
break;
}
}
@@ -737,7 +760,7 @@ static void free_proxy_output_ffmpeg(struct proxy_output_ctx *ctx, int rollback)
if (!rollback) {
/* Flush the remaining packets. */
add_to_proxy_output_ffmpeg(ctx, NULL);
add_to_proxy_output_ffmpeg(ctx, nullptr);
}
avcodec_flush_buffers(ctx->c);
@@ -789,8 +812,8 @@ typedef struct FFmpegIndexBuilderContext {
struct proxy_output_ctx *proxy_ctx[IMB_PROXY_MAX_SLOT];
anim_index_builder *indexer[IMB_TC_MAX_SLOT];
IMB_Timecode_Type tcs_in_use;
IMB_Proxy_Size proxy_sizes_in_use;
int tcs_in_use;
int proxy_sizes_in_use;
uint64_t seek_pos;
uint64_t seek_pos_pts;
@@ -809,13 +832,13 @@ typedef struct FFmpegIndexBuilderContext {
} FFmpegIndexBuilderContext;
static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
IMB_Timecode_Type tcs_in_use,
IMB_Proxy_Size proxy_sizes_in_use,
int tcs_in_use,
int proxy_sizes_in_use,
int quality,
bool build_only_on_bad_performance)
{
FFmpegIndexBuilderContext *context = MEM_callocN(sizeof(FFmpegIndexBuilderContext),
"FFmpeg index builder context");
FFmpegIndexBuilderContext *context = MEM_cnew<FFmpegIndexBuilderContext>(
"FFmpeg index builder context");
int num_proxy_sizes = IMB_PROXY_MAX_SLOT;
int num_indexers = IMB_TC_MAX_SLOT;
int i, streamcount;
@@ -829,15 +852,15 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
memset(context->proxy_ctx, 0, sizeof(context->proxy_ctx));
memset(context->indexer, 0, sizeof(context->indexer));
if (avformat_open_input(&context->iFormatCtx, anim->name, NULL, NULL) != 0) {
if (avformat_open_input(&context->iFormatCtx, anim->name, nullptr, nullptr) != 0) {
MEM_freeN(context);
return NULL;
return nullptr;
}
if (avformat_find_stream_info(context->iFormatCtx, NULL) < 0) {
if (avformat_find_stream_info(context->iFormatCtx, nullptr) < 0) {
avformat_close_input(&context->iFormatCtx);
MEM_freeN(context);
return NULL;
return nullptr;
}
streamcount = anim->streamindex;
@@ -858,20 +881,20 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
if (context->videoStream == -1) {
avformat_close_input(&context->iFormatCtx);
MEM_freeN(context);
return NULL;
return nullptr;
}
context->iStream = context->iFormatCtx->streams[context->videoStream];
context->iCodec = avcodec_find_decoder(context->iStream->codecpar->codec_id);
if (context->iCodec == NULL) {
if (context->iCodec == nullptr) {
avformat_close_input(&context->iFormatCtx);
MEM_freeN(context);
return NULL;
return nullptr;
}
context->iCodecCtx = avcodec_alloc_context3(NULL);
context->iCodecCtx = avcodec_alloc_context3(nullptr);
avcodec_parameters_to_context(context->iCodecCtx, context->iStream->codecpar);
context->iCodecCtx->workaround_bugs = FF_BUG_AUTODETECT;
@@ -889,11 +912,11 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
context->iCodecCtx->thread_type = FF_THREAD_SLICE;
}
if (avcodec_open2(context->iCodecCtx, context->iCodec, NULL) < 0) {
if (avcodec_open2(context->iCodecCtx, context->iCodec, nullptr) < 0) {
avformat_close_input(&context->iFormatCtx);
avcodec_free_context(&context->iCodecCtx);
MEM_freeN(context);
return NULL;
return nullptr;
}
for (i = 0; i < num_proxy_sizes; i++) {
@@ -905,18 +928,18 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
context->iCodecCtx->height * proxy_fac[i],
quality);
if (!context->proxy_ctx[i]) {
proxy_sizes_in_use &= ~proxy_sizes[i];
proxy_sizes_in_use &= ~int(proxy_sizes[i]);
}
}
}
if (context->proxy_ctx[0] == NULL && context->proxy_ctx[1] == NULL &&
context->proxy_ctx[2] == NULL && context->proxy_ctx[3] == NULL)
if (context->proxy_ctx[0] == nullptr && context->proxy_ctx[1] == nullptr &&
context->proxy_ctx[2] == nullptr && context->proxy_ctx[3] == nullptr)
{
avformat_close_input(&context->iFormatCtx);
avcodec_free_context(&context->iCodecCtx);
MEM_freeN(context);
return NULL; /* Nothing to transcode. */
return nullptr; /* Nothing to transcode. */
}
for (i = 0; i < num_indexers; i++) {
@@ -927,7 +950,7 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim,
context->indexer[i] = IMB_index_builder_create(filepath);
if (!context->indexer[i]) {
tcs_in_use &= ~tc_types[i];
tcs_in_use &= ~int(tc_types[i]);
}
}
}
@@ -1026,7 +1049,8 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
stream_size = avio_size(context->iFormatCtx->pb);
context->frame_rate = av_q2d(av_guess_frame_rate(context->iFormatCtx, context->iStream, NULL));
context->frame_rate = av_q2d(
av_guess_frame_rate(context->iFormatCtx, context->iStream, nullptr));
context->pts_time_base = av_q2d(context->iStream->time_base);
while (av_read_frame(context->iFormatCtx, next_packet) >= 0) {
@@ -1053,7 +1077,9 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
break;
}
if (ret < 0) {
fprintf(stderr, "Error decoding proxy frame: %s\n", av_err2str(ret));
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
fprintf(stderr, "Error decoding proxy frame: %s\n", error_str);
break;
}
@@ -1074,12 +1100,12 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
}
/* process pictures still stuck in decoder engine after EOF
* according to ffmpeg docs using NULL packets.
* according to ffmpeg docs using nullptr packets.
*
* At least, if we haven't already stopped... */
if (!*stop) {
int ret = avcodec_send_packet(context->iCodecCtx, NULL);
int ret = avcodec_send_packet(context->iCodecCtx, nullptr);
while (ret >= 0) {
ret = avcodec_receive_frame(context->iCodecCtx, in_frame);
@@ -1089,7 +1115,9 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
break;
}
if (ret < 0) {
fprintf(stderr, "Error flushing proxy frame: %s\n", av_err2str(ret));
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
fprintf(stderr, "Error flushing proxy frame: %s\n", error_str);
break;
}
index_rebuild_ffmpeg_proc_decoded_frame(context, next_packet, in_frame);
@@ -1127,7 +1155,9 @@ static int indexer_performance_get_decode_rate(FFmpegIndexBuilderContext *contex
}
if (ret < 0) {
fprintf(stderr, "Error decoding proxy frame: %s\n", av_err2str(ret));
char error_str[AV_ERROR_MAX_STRING_SIZE];
av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
fprintf(stderr, "Error decoding proxy frame: %s\n", error_str);
break;
}
frames_decoded++;
@@ -1228,7 +1258,7 @@ typedef struct FallbackIndexBuilderContext {
struct anim *anim;
AviMovie *proxy_ctx[IMB_PROXY_MAX_SLOT];
IMB_Proxy_Size proxy_sizes_in_use;
int proxy_sizes_in_use;
} FallbackIndexBuilderContext;
static AviMovie *alloc_proxy_output_avi(
@@ -1249,13 +1279,13 @@ static AviMovie *alloc_proxy_output_avi(
framerate = (double)frs_sec / (double)frs_sec_base;
avi = MEM_mallocN(sizeof(AviMovie), "avimovie");
avi = MEM_cnew<AviMovie>("avimovie");
format = AVI_FORMAT_MJPEG;
if (AVI_open_compress(filepath, avi, 1, format) != AVI_ERROR_NONE) {
MEM_freeN(avi);
return NULL;
return nullptr;
}
AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &x);
@@ -1270,8 +1300,8 @@ static AviMovie *alloc_proxy_output_avi(
}
static IndexBuildContext *index_fallback_create_context(struct anim *anim,
IMB_Timecode_Type UNUSED(tcs_in_use),
IMB_Proxy_Size proxy_sizes_in_use,
int /*tcs_in_use*/,
int proxy_sizes_in_use,
int quality)
{
FallbackIndexBuilderContext *context;
@@ -1283,10 +1313,10 @@ static IndexBuildContext *index_fallback_create_context(struct anim *anim,
* so no proxies...
*/
if (proxy_sizes_in_use == IMB_PROXY_NONE) {
return NULL;
return nullptr;
}
context = MEM_callocN(sizeof(FallbackIndexBuilderContext), "fallback index builder context");
context = MEM_cnew<FallbackIndexBuilderContext>("fallback index builder context");
context->anim = anim;
context->proxy_sizes_in_use = proxy_sizes_in_use;
@@ -1373,7 +1403,7 @@ static void index_rebuild_fallback(FallbackIndexBuilderContext *context,
AVI_write_frame(context->proxy_ctx[i], pos, AVI_FORMAT_RGB32, s_ibuf->rect, x * y * 4);
/* note that libavi free's the buffer... */
s_ibuf->rect = NULL;
s_ibuf->rect = nullptr;
IMB_freeImBuf(s_ibuf);
}
@@ -1392,14 +1422,14 @@ static void index_rebuild_fallback(FallbackIndexBuilderContext *context,
IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
IMB_Timecode_Type tcs_in_use,
IMB_Proxy_Size proxy_sizes_in_use,
int proxy_sizes_in_use,
int quality,
const bool overwrite,
GSet *file_list,
bool build_only_on_bad_performance)
{
IndexBuildContext *context = NULL;
IMB_Proxy_Size proxy_sizes_to_build = proxy_sizes_in_use;
IndexBuildContext *context = nullptr;
int proxy_sizes_to_build = proxy_sizes_in_use;
int i;
/* Don't generate the same file twice! */
@@ -1409,14 +1439,14 @@ IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
if (proxy_size & proxy_sizes_to_build) {
char filename[FILE_MAX];
if (get_proxy_filepath(anim, proxy_size, filename, false) == false) {
return NULL;
return nullptr;
}
void **filename_key_p;
if (!BLI_gset_ensure_p_ex(file_list, filename, &filename_key_p)) {
*filename_key_p = BLI_strdup(filename);
}
else {
proxy_sizes_to_build &= ~proxy_size;
proxy_sizes_to_build &= ~int(proxy_size);
printf("Proxy: %s already registered for generation, skipping\n", filename);
}
}
@@ -1424,7 +1454,7 @@ IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
}
if (!overwrite) {
IMB_Proxy_Size built_proxies = IMB_anim_proxy_get_existing(anim);
int built_proxies = IMB_anim_proxy_get_existing(anim);
if (built_proxies != 0) {
for (i = 0; i < IMB_PROXY_MAX_SLOT; i++) {
@@ -1432,7 +1462,7 @@ IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
if (proxy_size & built_proxies) {
char filename[FILE_MAX];
if (get_proxy_filepath(anim, proxy_size, filename, false) == false) {
return NULL;
return nullptr;
}
printf("Skipping proxy: %s\n", filename);
}
@@ -1444,7 +1474,7 @@ IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim,
fflush(stdout);
if (proxy_sizes_to_build == 0) {
return NULL;
return nullptr;
}
switch (anim->curtype) {
@@ -1525,14 +1555,14 @@ void IMB_free_indices(struct anim *anim)
for (i = 0; i < IMB_PROXY_MAX_SLOT; i++) {
if (anim->proxy_anim[i]) {
IMB_close_anim(anim->proxy_anim[i]);
anim->proxy_anim[i] = NULL;
anim->proxy_anim[i] = nullptr;
}
}
for (i = 0; i < IMB_TC_MAX_SLOT; i++) {
if (anim->curr_idx[i]) {
IMB_indexer_close(anim->curr_idx[i]);
anim->curr_idx[i] = NULL;
anim->curr_idx[i] = nullptr;
}
}
@@ -1556,7 +1586,7 @@ struct anim *IMB_anim_open_proxy(struct anim *anim, IMB_Proxy_Size preview_size)
int i = IMB_proxy_size_to_array_index(preview_size);
if (i < 0) {
return NULL;
return nullptr;
}
if (anim->proxy_anim[i]) {
@@ -1564,7 +1594,7 @@ struct anim *IMB_anim_open_proxy(struct anim *anim, IMB_Proxy_Size preview_size)
}
if (anim->proxies_tried & preview_size) {
return NULL;
return nullptr;
}
get_proxy_filepath(anim, preview_size, filepath, false);
@@ -1583,7 +1613,7 @@ struct anim_index *IMB_anim_open_index(struct anim *anim, IMB_Timecode_Type tc)
int i = IMB_timecode_to_array_index(tc);
if (i < 0) {
return NULL;
return nullptr;
}
if (anim->curr_idx[i]) {
@@ -1591,7 +1621,7 @@ struct anim_index *IMB_anim_open_index(struct anim *anim, IMB_Timecode_Type tc)
}
if (anim->indices_tried & tc) {
return NULL;
return nullptr;
}
get_tc_filename(anim, tc, filepath);
@@ -1614,17 +1644,17 @@ int IMB_anim_index_get_frame_index(struct anim *anim, IMB_Timecode_Type tc, int
return IMB_indexer_get_frame_index(idx, position);
}
IMB_Proxy_Size IMB_anim_proxy_get_existing(struct anim *anim)
int IMB_anim_proxy_get_existing(struct anim *anim)
{
const int num_proxy_sizes = IMB_PROXY_MAX_SLOT;
IMB_Proxy_Size existing = 0;
int existing = IMB_PROXY_NONE;
int i;
for (i = 0; i < num_proxy_sizes; i++) {
IMB_Proxy_Size proxy_size = proxy_sizes[i];
char filename[FILE_MAX];
get_proxy_filepath(anim, proxy_size, filename, false);
if (BLI_exists(filename)) {
existing |= proxy_size;
existing |= int(proxy_size);
}
}
return existing;

View File

@@ -210,7 +210,7 @@ static void test_endian_zbuf(struct ImBuf *ibuf)
return;
#endif
if (ibuf->zbuf == NULL) {
if (ibuf->zbuf == nullptr) {
return;
}
@@ -239,25 +239,25 @@ bool imb_is_a_iris(const uchar *mem, size_t size)
struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
{
uint *base, *lptr = NULL;
float *fbase, *fptr = NULL;
uint *base, *lptr = nullptr;
float *fbase, *fptr = nullptr;
uint *zbase, *zptr;
const uchar *rledat;
const uchar *mem_end = mem + size;
MFileOffset _inf_data = {mem, 0}, *inf = &_inf_data;
IMAGE image;
int bpp, rle, cur, badorder;
ImBuf *ibuf = NULL;
ImBuf *ibuf = nullptr;
uchar dirty_flag = 0;
if (!imb_is_a_iris(mem, size)) {
return NULL;
return nullptr;
}
/* Could be part of the magic check above,
* by convention this check only requests the size needed to read it's magic though. */
if (size < HEADER_SIZE) {
return NULL;
return nullptr;
}
/* OCIO_TODO: only tested with 1 byte per pixel, not sure how to test with other settings */
@@ -266,18 +266,18 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
readheader(inf, &image);
if (image.imagic != IMAGIC) {
fprintf(stderr, "longimagedata: bad magic number in image file\n");
return NULL;
return nullptr;
}
rle = ISRLE(image.type);
bpp = BPP(image.type);
if (!ELEM(bpp, 1, 2)) {
fprintf(stderr, "longimagedata: image must have 1 or 2 byte per pix chan\n");
return NULL;
return nullptr;
}
if ((uint)image.zsize > 8) {
fprintf(stderr, "longimagedata: channels over 8 not supported\n");
return NULL;
return nullptr;
}
const int xsize = image.xsize;
@@ -296,8 +296,8 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
size_t tablen = (size_t)ysize * (size_t)zsize * sizeof(int);
MFILE_SEEK(inf, HEADER_SIZE);
uint *starttab = MEM_mallocN(tablen, "iris starttab");
uint *lengthtab = MEM_mallocN(tablen, "iris endtab");
uint *starttab = static_cast<uint *>(MEM_mallocN(tablen, "iris starttab"));
uint *lengthtab = static_cast<uint *>(MEM_mallocN(tablen, "iris endtab"));
#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \
if (UNLIKELY((p) > mem_end)) { \
@@ -430,7 +430,7 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
MEM_freeN(lengthtab);
if (!ibuf) {
return NULL;
return nullptr;
}
}
else {
@@ -506,7 +506,7 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
#undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL
fail_uncompressed:
if (!ibuf) {
return NULL;
return nullptr;
}
}
@@ -783,7 +783,7 @@ fail:
/**
* \param filepath: The file path to write to.
* \param lptr: an array of integers to an iris image file (each int represents one pixel).
* \param zptr: depth-buffer (optional, may be NULL).
* \param zptr: depth-buffer (optional, may be nullptr).
* \param xsize: with width of the pixel-array.
* \param ysize: height of the pixel-array.
* \param zsize: specifies what kind of image file to write out.
@@ -965,7 +965,7 @@ bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags)
short zsize;
zsize = (ibuf->planes + 7) >> 3;
if (flags & IB_zbuf && ibuf->zbuf != NULL) {
if (flags & IB_zbuf && ibuf->zbuf != nullptr) {
zsize = 8;
}

View File

@@ -123,14 +123,14 @@ struct BufInfo {
OPJ_OFF_T len;
};
static void opj_read_from_buffer_free(void *UNUSED(p_user_data))
static void opj_read_from_buffer_free(void * /*p_user_data*/)
{
/* NOP. */
}
static OPJ_SIZE_T opj_read_from_buffer(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
{
struct BufInfo *p_file = p_user_data;
struct BufInfo *p_file = static_cast<struct BufInfo *>(p_user_data);
OPJ_UINT32 l_nb_read;
if (p_file->cur + p_nb_bytes < p_file->buf + p_file->len) {
@@ -158,7 +158,7 @@ static OPJ_SIZE_T opj_write_from_buffer(void *p_buffer, OPJ_SIZE_T p_nb_bytes, v
static OPJ_OFF_T opj_skip_from_buffer(OPJ_OFF_T p_nb_bytes, void *p_user_data)
{
struct BufInfo *p_file = p_user_data;
struct BufInfo *p_file = static_cast<struct BufInfo *>(p_user_data);
if (p_file->cur + p_nb_bytes < p_file->buf + p_file->len) {
p_file->cur += p_nb_bytes;
return p_nb_bytes;
@@ -169,7 +169,7 @@ static OPJ_OFF_T opj_skip_from_buffer(OPJ_OFF_T p_nb_bytes, void *p_user_data)
static OPJ_BOOL opj_seek_from_buffer(OPJ_OFF_T p_nb_bytes, void *p_user_data)
{
struct BufInfo *p_file = p_user_data;
struct BufInfo *p_file = static_cast<struct BufInfo *>(p_user_data);
if (p_nb_bytes < p_file->len) {
p_file->cur = p_file->buf + p_nb_bytes;
return OPJ_TRUE;
@@ -187,8 +187,8 @@ static opj_stream_t *opj_stream_create_from_buffer(struct BufInfo *p_file,
OPJ_BOOL p_is_read_stream)
{
opj_stream_t *l_stream = opj_stream_create(p_size, p_is_read_stream);
if (l_stream == NULL) {
return NULL;
if (l_stream == nullptr) {
return nullptr;
}
opj_stream_set_user_data(l_stream, p_file, opj_read_from_buffer_free);
opj_stream_set_user_data_length(l_stream, p_file->len);
@@ -210,13 +210,13 @@ static opj_stream_t *opj_stream_create_from_buffer(struct BufInfo *p_file,
static void opj_free_from_file(void *p_user_data)
{
FILE *f = p_user_data;
FILE *f = static_cast<FILE *>(p_user_data);
fclose(f);
}
static OPJ_UINT64 opj_get_data_length_from_file(void *p_user_data)
{
FILE *p_file = p_user_data;
FILE *p_file = static_cast<FILE *>(p_user_data);
OPJ_OFF_T file_length = 0;
fseek(p_file, 0, SEEK_END);
@@ -228,20 +228,20 @@ static OPJ_UINT64 opj_get_data_length_from_file(void *p_user_data)
static OPJ_SIZE_T opj_read_from_file(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
{
FILE *p_file = p_user_data;
FILE *p_file = static_cast<FILE *>(p_user_data);
OPJ_SIZE_T l_nb_read = fread(p_buffer, 1, p_nb_bytes, p_file);
return l_nb_read ? l_nb_read : (OPJ_SIZE_T)-1;
}
static OPJ_SIZE_T opj_write_from_file(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
{
FILE *p_file = p_user_data;
FILE *p_file = static_cast<FILE *>(p_user_data);
return fwrite(p_buffer, 1, p_nb_bytes, p_file);
}
static OPJ_OFF_T opj_skip_from_file(OPJ_OFF_T p_nb_bytes, void *p_user_data)
{
FILE *p_file = p_user_data;
FILE *p_file = static_cast<FILE *>(p_user_data);
if (fseek(p_file, p_nb_bytes, SEEK_CUR)) {
return -1;
}
@@ -250,7 +250,7 @@ static OPJ_OFF_T opj_skip_from_file(OPJ_OFF_T p_nb_bytes, void *p_user_data)
static OPJ_BOOL opj_seek_from_file(OPJ_OFF_T p_nb_bytes, void *p_user_data)
{
FILE *p_file = p_user_data;
FILE *p_file = static_cast<FILE *>(p_user_data);
if (fseek(p_file, p_nb_bytes, SEEK_SET)) {
return OPJ_FALSE;
}
@@ -268,14 +268,14 @@ static opj_stream_t *opj_stream_create_from_file(const char *filepath,
FILE **r_file)
{
FILE *p_file = BLI_fopen(filepath, p_is_read_stream ? "rb" : "wb");
if (p_file == NULL) {
return NULL;
if (p_file == nullptr) {
return nullptr;
}
opj_stream_t *l_stream = opj_stream_create(p_size, p_is_read_stream);
if (l_stream == NULL) {
if (l_stream == nullptr) {
fclose(p_file);
return NULL;
return nullptr;
}
opj_stream_set_user_data(l_stream, p_file, opj_free_from_file);
@@ -302,11 +302,10 @@ ImBuf *imb_load_jp2(const uchar *mem, size_t size, int flags, char colorspace[IM
{
const OPJ_CODEC_FORMAT format = (size > JP2_FILEHEADER_SIZE) ? format_from_header(mem, size) :
OPJ_CODEC_UNKNOWN;
struct BufInfo buf_wrapper = {
.buf = mem,
.cur = mem,
.len = size,
};
struct BufInfo buf_wrapper = {};
buf_wrapper.buf = mem;
buf_wrapper.cur = mem;
buf_wrapper.len = OPJ_OFF_T(size);
opj_stream_t *stream = opj_stream_create_from_buffer(
&buf_wrapper, OPJ_J2K_STREAM_CHUNK_SIZE, true);
ImBuf *ibuf = imb_load_jp2_stream(stream, format, flags, colorspace);
@@ -316,17 +315,17 @@ ImBuf *imb_load_jp2(const uchar *mem, size_t size, int flags, char colorspace[IM
ImBuf *imb_load_jp2_filepath(const char *filepath, int flags, char colorspace[IM_MAX_SPACE])
{
FILE *p_file = NULL;
FILE *p_file = nullptr;
uchar mem[JP2_FILEHEADER_SIZE];
opj_stream_t *stream = opj_stream_create_from_file(
filepath, OPJ_J2K_STREAM_CHUNK_SIZE, true, &p_file);
if (stream) {
return NULL;
return nullptr;
}
if (fread(mem, sizeof(mem), 1, p_file) != sizeof(mem)) {
opj_stream_destroy(stream);
return NULL;
return nullptr;
}
fseek(p_file, 0, SEEK_SET);
@@ -343,10 +342,10 @@ static ImBuf *imb_load_jp2_stream(opj_stream_t *stream,
char colorspace[IM_MAX_SPACE])
{
if (format == OPJ_CODEC_UNKNOWN) {
return NULL;
return nullptr;
}
struct ImBuf *ibuf = NULL;
struct ImBuf *ibuf = nullptr;
bool use_float = false; /* for precision higher than 8 use float */
bool use_alpha = false;
@@ -359,8 +358,8 @@ static ImBuf *imb_load_jp2_stream(opj_stream_t *stream,
opj_dparameters_t parameters; /* decompression parameters */
opj_image_t *image = NULL;
opj_codec_t *codec = NULL; /* handle to a decompressor */
opj_image_t *image = nullptr;
opj_codec_t *codec = nullptr; /* handle to a decompressor */
/* both 8, 12 and 16 bit JP2Ks are default to standard byte colorspace */
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -438,7 +437,7 @@ static ImBuf *imb_load_jp2_stream(opj_stream_t *stream,
ibuf = IMB_allocImBuf(w, h, planes, use_float ? IB_rectfloat : IB_rect);
if (ibuf == NULL) {
if (ibuf == nullptr) {
goto finally;
}
@@ -455,7 +454,7 @@ static ImBuf *imb_load_jp2_stream(opj_stream_t *stream,
if (image->numcomps < 3) {
r = image->comps[0].data;
a = (use_alpha) ? image->comps[1].data : NULL;
a = (use_alpha) ? image->comps[1].data : nullptr;
/* Gray-scale 12bits+ */
if (use_alpha) {
@@ -508,7 +507,7 @@ static ImBuf *imb_load_jp2_stream(opj_stream_t *stream,
if (image->numcomps < 3) {
r = image->comps[0].data;
a = (use_alpha) ? image->comps[1].data : NULL;
a = (use_alpha) ? image->comps[1].data : nullptr;
/* Gray-scale. */
if (use_alpha) {
@@ -817,7 +816,7 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
int *r, *g, *b, *a; /* matching 'opj_image_comp.data' type */
OPJ_COLOR_SPACE color_space;
opj_image_cmptparm_t cmptparm[4]; /* maximum of 4 components */
opj_image_t *image = NULL;
opj_image_t *image = nullptr;
float (*chanel_colormanage_cb)(float);
@@ -898,7 +897,7 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
image = opj_image_create(numcomps, &cmptparm[0], color_space);
if (!image) {
printf("Error: opj_image_create() failed\n");
return NULL;
return nullptr;
}
/* set image offset and reference grid */
@@ -915,11 +914,11 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
a = (numcomps == 4) ? image->comps[3].data : NULL;
a = (numcomps == 4) ? image->comps[3].data : nullptr;
if (rect_float && rect_uchar && prec == 8) {
/* No need to use the floating point buffer, just write the 8 bits from the char buffer */
rect_float = NULL;
rect_float = nullptr;
}
if (rect_float) {
@@ -1185,8 +1184,8 @@ bool imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int flags);
bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags)
{
opj_stream_t *stream = opj_stream_create_from_file(
filepath, OPJ_J2K_STREAM_CHUNK_SIZE, false, NULL);
if (stream == NULL) {
filepath, OPJ_J2K_STREAM_CHUNK_SIZE, false, nullptr);
if (stream == nullptr) {
return 0;
}
const bool ok = imb_save_jp2_stream(ibuf, stream, flags);
@@ -1195,12 +1194,12 @@ bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags)
}
/* Found write info at http://users.ece.gatech.edu/~slabaugh/personal/c/bitmapUnix.c */
bool imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int UNUSED(flags))
bool imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int /*flags*/)
{
int quality = ibuf->foptions.quality;
opj_cparameters_t parameters; /* compression parameters */
opj_image_t *image = NULL;
opj_image_t *image = nullptr;
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters);
@@ -1215,7 +1214,7 @@ bool imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int UNUSED(fl
image = ibuftoimage(ibuf, &parameters);
opj_codec_t *codec = NULL;
opj_codec_t *codec = nullptr;
bool ok = false;
/* JP2 format output */
{

View File

@@ -12,6 +12,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -148,7 +149,7 @@ static void memory_source(j_decompress_ptr cinfo, const uchar *buffer, size_t si
{
my_src_ptr src;
if (cinfo->src == NULL) { /* first time for this JPEG object? */
if (cinfo->src == nullptr) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)(
(j_common_ptr)cinfo, JPOOL_PERMANENT, sizeof(my_source_mgr));
}
@@ -257,10 +258,10 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo,
size_t *r_height)
{
JSAMPARRAY row_pointer;
JSAMPLE *buffer = NULL;
JSAMPLE *buffer = nullptr;
int row_stride;
int x, y, depth, r, g, b, k;
struct ImBuf *ibuf = NULL;
struct ImBuf *ibuf = nullptr;
uchar *rect;
jpeg_saved_marker_ptr marker;
char *str, *key, *value;
@@ -304,7 +305,7 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo,
jpeg_abort_decompress(cinfo);
ibuf = IMB_allocImBuf(x, y, 8 * depth, 0);
}
else if ((ibuf = IMB_allocImBuf(x, y, 8 * depth, IB_rect)) == NULL) {
else if ((ibuf = IMB_allocImBuf(x, y, 8 * depth, IB_rect)) == nullptr) {
jpeg_abort_decompress(cinfo);
}
else {
@@ -452,7 +453,7 @@ ImBuf *imb_load_jpeg(const uchar *buffer, size_t size, int flags, char colorspac
ImBuf *ibuf;
if (!imb_is_a_jpeg(buffer, size)) {
return NULL;
return nullptr;
}
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -466,13 +467,13 @@ ImBuf *imb_load_jpeg(const uchar *buffer, size_t size, int flags, char colorspac
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(cinfo);
return NULL;
return nullptr;
}
jpeg_create_decompress(cinfo);
memory_source(cinfo, buffer, size);
ibuf = ibJpegImageFromCinfo(cinfo, flags, -1, NULL, NULL);
ibuf = ibJpegImageFromCinfo(cinfo, flags, -1, nullptr, nullptr);
return ibuf;
}
@@ -492,7 +493,7 @@ struct ImBuf *imb_thumbnail_jpeg(const char *filepath,
{
struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr;
FILE *infile = NULL;
FILE *infile = nullptr;
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -505,12 +506,12 @@ struct ImBuf *imb_thumbnail_jpeg(const char *filepath,
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(cinfo);
return NULL;
return nullptr;
}
if ((infile = BLI_fopen(filepath, "rb")) == NULL) {
if ((infile = BLI_fopen(filepath, "rb")) == nullptr) {
fprintf(stderr, "can't open %s\n", filepath);
return NULL;
return nullptr;
}
/* If file contains an embedded thumbnail, let's return that instead. */
@@ -527,8 +528,8 @@ struct ImBuf *imb_thumbnail_jpeg(const char *filepath,
}
if (i > 0 && !feof(infile)) {
/* We found a JPEG thumbnail inside this image. */
ImBuf *ibuf = NULL;
uchar *buffer = MEM_callocN(JPEG_APP1_MAX, "thumbbuffer");
ImBuf *ibuf = nullptr;
uchar *buffer = static_cast<uchar *>(MEM_callocN(JPEG_APP1_MAX, "thumbbuffer"));
/* Just put SOI directly in buffer rather than seeking back 2 bytes. */
buffer[0] = JPEG_MARKER_MSB;
buffer[1] = JPEG_MARKER_SOI;
@@ -562,7 +563,7 @@ struct ImBuf *imb_thumbnail_jpeg(const char *filepath,
static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
{
JSAMPLE *buffer = NULL;
JSAMPLE *buffer = nullptr;
JSAMPROW row_pointer[1];
uchar *rect;
int x, y;
@@ -577,11 +578,11 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
neogeo_word->quality = ibuf->foptions.quality;
jpeg_write_marker(cinfo, 0xe1, (JOCTET *)neogeo, 10);
if (ibuf->metadata) {
IDProperty *prop;
/* Static storage array for the short metadata. */
char static_text[1024];
const int static_text_size = ARRAY_SIZE(static_text);
for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) {
LISTBASE_FOREACH (IDProperty *, prop, &ibuf->metadata->data.group) {
if (prop->type == IDP_STRING) {
int text_len;
if (STREQ(prop->name, "None")) {
@@ -591,10 +592,10 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
char *text = static_text;
int text_size = static_text_size;
/* 7 is for Blender, 2 colon separators, length of property
* name and property value, followed by the NULL-terminator. */
* name and property value, followed by the nullptr-terminator. */
const int text_length_required = 7 + 2 + strlen(prop->name) + strlen(IDP_String(prop)) + 1;
if (text_length_required <= static_text_size) {
text = MEM_mallocN(text_length_required, "jpeg metadata field");
text = static_cast<char *>(MEM_mallocN(text_length_required, "jpeg metadata field"));
text_size = text_length_required;
}
@@ -621,8 +622,8 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf)
}
}
row_pointer[0] = MEM_mallocN(sizeof(JSAMPLE) * cinfo->input_components * cinfo->image_width,
"jpeg row_pointer");
row_pointer[0] = static_cast<JSAMPROW>(MEM_mallocN(
sizeof(JSAMPLE) * cinfo->input_components * cinfo->image_width, "jpeg row_pointer"));
for (y = ibuf->y - 1; y >= 0; y--) {
rect = (uchar *)(ibuf->rect + y * ibuf->x);
@@ -720,7 +721,7 @@ static bool save_stdjpeg(const char *name, struct ImBuf *ibuf)
struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo;
struct my_error_mgr jerr;
if ((outfile = BLI_fopen(name, "wb")) == NULL) {
if ((outfile = BLI_fopen(name, "wb")) == nullptr) {
return 0;
}

View File

@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -24,7 +25,7 @@
void IMB_metadata_ensure(struct IDProperty **metadata)
{
if (*metadata != NULL) {
if (*metadata != nullptr) {
return;
}
@@ -34,7 +35,7 @@ void IMB_metadata_ensure(struct IDProperty **metadata)
void IMB_metadata_free(struct IDProperty *metadata)
{
if (metadata == NULL) {
if (metadata == nullptr) {
return;
}
@@ -48,7 +49,7 @@ bool IMB_metadata_get_field(struct IDProperty *metadata,
{
IDProperty *prop;
if (metadata == NULL) {
if (metadata == nullptr) {
return false;
}
@@ -75,15 +76,15 @@ void IMB_metadata_set_field(struct IDProperty *metadata, const char *key, const
BLI_assert(metadata);
IDProperty *prop = IDP_GetPropertyFromGroup(metadata, key);
if (prop != NULL && prop->type != IDP_STRING) {
if (prop != nullptr && prop->type != IDP_STRING) {
IDP_FreeFromGroup(metadata, prop);
prop = NULL;
prop = nullptr;
}
if (prop) {
IDP_AssignString(prop, value);
}
else if (prop == NULL) {
else if (prop == nullptr) {
prop = IDP_NewString(value, key);
IDP_AddToGroup(metadata, prop);
}
@@ -91,10 +92,10 @@ void IMB_metadata_set_field(struct IDProperty *metadata, const char *key, const
void IMB_metadata_foreach(struct ImBuf *ibuf, IMBMetadataForeachCb callback, void *userdata)
{
if (ibuf->metadata == NULL) {
if (ibuf->metadata == nullptr) {
return;
}
for (IDProperty *prop = ibuf->metadata->data.group.first; prop != NULL; prop = prop->next) {
LISTBASE_FOREACH (IDProperty *, prop, &ibuf->metadata->data.group) {
callback(prop->name, IDP_String(prop), userdata);
}
}

View File

@@ -35,7 +35,7 @@ static void imb_handle_alpha(ImBuf *ibuf,
char effective_colorspace[IM_MAX_SPACE])
{
if (colorspace) {
if (ibuf->rect != NULL && ibuf->rect_float == NULL) {
if (ibuf->rect != nullptr && ibuf->rect_float == nullptr) {
/* byte buffer is never internally converted to some standard space,
* store pointer to its color space descriptor instead
*/
@@ -88,9 +88,9 @@ ImBuf *IMB_ibImageFromMemory(
const ImFileType *type;
char effective_colorspace[IM_MAX_SPACE] = "";
if (mem == NULL) {
fprintf(stderr, "%s: NULL pointer\n", __func__);
return NULL;
if (mem == nullptr) {
fprintf(stderr, "%s: nullptr pointer\n", __func__);
return nullptr;
}
if (colorspace) {
@@ -111,7 +111,7 @@ ImBuf *IMB_ibImageFromMemory(
fprintf(stderr, "%s: unknown file-format (%s)\n", __func__, descr);
}
return NULL;
return nullptr;
}
ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const char *descr)
@@ -121,7 +121,7 @@ ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const
size_t size;
if (file == -1) {
return NULL;
return nullptr;
}
size = BLI_file_descriptor_size(file);
@@ -129,12 +129,12 @@ ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const
imb_mmap_lock();
BLI_mmap_file *mmap_file = BLI_mmap_open(file);
imb_mmap_unlock();
if (mmap_file == NULL) {
if (mmap_file == nullptr) {
fprintf(stderr, "%s: couldn't get mapping %s\n", __func__, descr);
return NULL;
return nullptr;
}
mem = BLI_mmap_get_pointer(mmap_file);
mem = static_cast<uchar *>(BLI_mmap_get_pointer(mmap_file));
ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, descr);
@@ -154,7 +154,7 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_S
file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
if (file == -1) {
return NULL;
return nullptr;
}
ibuf = IMB_loadifffile(file, flags, colorspace, filepath);
@@ -173,11 +173,11 @@ struct ImBuf *IMB_thumb_load_image(const char *filepath,
char colorspace[IM_MAX_SPACE])
{
const ImFileType *type = IMB_file_type_from_ftype(IMB_ispic_type(filepath));
if (type == NULL) {
return NULL;
if (type == nullptr) {
return nullptr;
}
ImBuf *ibuf = NULL;
ImBuf *ibuf = nullptr;
int flags = IB_rect | IB_metadata;
/* Size of the original image. */
size_t width = 0;
@@ -196,7 +196,7 @@ struct ImBuf *IMB_thumb_load_image(const char *filepath,
/* Skip images of other types if over 100MB. */
const size_t file_size = BLI_file_size(filepath);
if (file_size != (size_t)-1 && file_size > THUMB_SIZE_MAX) {
return NULL;
return nullptr;
}
ibuf = IMB_loadiffname(filepath, flags, colorspace);
if (ibuf) {
@@ -233,7 +233,7 @@ ImBuf *IMB_testiffname(const char *filepath, int flags)
file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
if (file == -1) {
return NULL;
return nullptr;
}
ibuf = IMB_loadifffile(file, flags | IB_test | IB_multilayer, colorspace, filepath);

View File

@@ -202,14 +202,14 @@ void IMB_blend_color_float(float dst[4],
static void rect_crop_4bytes(void **buf_p, const int size_src[2], const rcti *crop)
{
if (*buf_p == NULL) {
if (*buf_p == nullptr) {
return;
}
const int size_dst[2] = {
BLI_rcti_size_x(crop) + 1,
BLI_rcti_size_y(crop) + 1,
};
uint *src = *buf_p;
uint *src = static_cast<uint *>(*buf_p);
uint *dst = src + crop->ymin * size_src[0] + crop->xmin;
for (int y = 0; y < size_dst[1]; y++, src += size_dst[0], dst += size_src[0]) {
memmove(src, dst, sizeof(uint) * size_dst[0]);
@@ -219,14 +219,14 @@ static void rect_crop_4bytes(void **buf_p, const int size_src[2], const rcti *cr
static void rect_crop_16bytes(void **buf_p, const int size_src[2], const rcti *crop)
{
if (*buf_p == NULL) {
if (*buf_p == nullptr) {
return;
}
const int size_dst[2] = {
BLI_rcti_size_x(crop) + 1,
BLI_rcti_size_y(crop) + 1,
};
uint(*src)[4] = *buf_p;
uint(*src)[4] = static_cast<uint(*)[4]>(*buf_p);
uint(*dst)[4] = src + crop->ymin * size_src[0] + crop->xmin;
for (int y = 0; y < size_dst[1]; y++, src += size_dst[0], dst += size_src[0]) {
memmove(src, dst, sizeof(uint[4]) * size_dst[0]);
@@ -266,7 +266,7 @@ void IMB_rect_crop(ImBuf *ibuf, const rcti *crop)
*/
static void rect_realloc_4bytes(void **buf_p, const uint size[2])
{
if (*buf_p == NULL) {
if (*buf_p == nullptr) {
return;
}
MEM_freeN(*buf_p);
@@ -275,7 +275,7 @@ static void rect_realloc_4bytes(void **buf_p, const uint size[2])
static void rect_realloc_16bytes(void **buf_p, const uint size[2])
{
if (*buf_p == NULL) {
if (*buf_p == nullptr) {
return;
}
MEM_freeN(*buf_p);
@@ -313,7 +313,7 @@ void IMB_rectclip(ImBuf *dbuf,
{
int tmp;
if (dbuf == NULL) {
if (dbuf == nullptr) {
return;
}
@@ -378,7 +378,7 @@ static void imb_rectclip3(ImBuf *dbuf,
{
int tmp;
if (dbuf == NULL) {
if (dbuf == nullptr) {
return;
}
@@ -471,9 +471,9 @@ void IMB_rectcpy(ImBuf *dbuf,
IMB_rectblend(dbuf,
dbuf,
sbuf,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
0,
destx,
desty,
@@ -508,16 +508,16 @@ void IMB_rectblend(ImBuf *dbuf,
IMB_BlendMode mode,
bool accumulate)
{
uint *drect = NULL, *orect = NULL, *srect = NULL, *dr, * or, *sr;
float *drectf = NULL, *orectf = NULL, *srectf = NULL, *drf, *orf, *srf;
uint *drect = nullptr, *orect = nullptr, *srect = nullptr, *dr, *outr, *sr;
float *drectf = nullptr, *orectf = nullptr, *srectf = nullptr, *drf, *orf, *srf;
const ushort *cmaskrect = curvemask, *cmr;
ushort *dmaskrect = dmask, *dmr;
const ushort *texmaskrect = texmask, *tmr;
int srcskip, destskip, origskip, x;
IMB_blend_func func = NULL;
IMB_blend_func_float func_float = NULL;
IMB_blend_func func = nullptr;
IMB_blend_func_float func_float = nullptr;
if (dbuf == NULL || obuf == NULL) {
if (dbuf == nullptr || obuf == nullptr) {
return;
}
@@ -752,7 +752,7 @@ void IMB_rectblend(ImBuf *dbuf,
for (; height > 0; height--) {
if (do_char) {
dr = drect;
or = orect;
outr = orect;
sr = srect;
if (cmaskrect) {
@@ -763,7 +763,7 @@ void IMB_rectblend(ImBuf *dbuf,
/* destination mask present, do max alpha masking */
if (dmaskrect) {
dmr = dmaskrect;
for (x = width; x > 0; x--, dr++, or ++, sr++, dmr++, cmr++) {
for (x = width; x > 0; x--, dr++, outr++, sr++, dmr++, cmr++) {
uchar *src = (uchar *)sr;
float mask_lim = mask_max * (*cmr);
@@ -795,11 +795,11 @@ void IMB_rectblend(ImBuf *dbuf,
if (mode == IMB_BLEND_INTERPOLATE) {
mask_src[3] = src[3];
blend_color_interpolate_byte(
(uchar *)dr, (uchar *) or, mask_src, mask / 65535.0f);
(uchar *)dr, (uchar *)outr, mask_src, mask / 65535.0f);
}
else {
mask_src[3] = divide_round_i(src[3] * mask, 65535);
func((uchar *)dr, (uchar *) or, mask_src);
func((uchar *)dr, (uchar *)outr, mask_src);
}
}
}
@@ -808,7 +808,7 @@ void IMB_rectblend(ImBuf *dbuf,
}
/* no destination mask buffer, do regular blend with masktexture if present */
else {
for (x = width; x > 0; x--, dr++, or ++, sr++, cmr++) {
for (x = width; x > 0; x--, dr++, outr++, sr++, cmr++) {
uchar *src = (uchar *)sr;
float mask = (float)mask_max * (float)(*cmr);
@@ -828,11 +828,11 @@ void IMB_rectblend(ImBuf *dbuf,
if (mode == IMB_BLEND_INTERPOLATE) {
mask_src[3] = src[3];
blend_color_interpolate_byte(
(uchar *)dr, (uchar *) or, mask_src, mask / 65535.0f);
(uchar *)dr, (uchar *)outr, mask_src, mask / 65535.0f);
}
else {
mask_src[3] = divide_round_i(src[3] * mask, 65535);
func((uchar *)dr, (uchar *) or, mask_src);
func((uchar *)dr, (uchar *)outr, mask_src);
}
}
}
@@ -845,9 +845,9 @@ void IMB_rectblend(ImBuf *dbuf,
}
else {
/* regular blending */
for (x = width; x > 0; x--, dr++, or ++, sr++) {
for (x = width; x > 0; x--, dr++, outr++, sr++) {
if (((uchar *)sr)[3]) {
func((uchar *)dr, (uchar *) or, (uchar *)sr);
func((uchar *)dr, (uchar *)outr, (uchar *)sr);
}
}
}
@@ -1104,7 +1104,8 @@ void IMB_rectfill_area_replace(
return;
}
uchar col_char[4] = {col[0] * 255, col[1] * 255, col[2] * 255, col[3] * 255};
uchar col_char[4] = {
uchar(col[0] * 255), uchar(col[1] * 255), uchar(col[2] * 255), uchar(col[3] * 255)};
for (int y = y1; y < y2; y++) {
for (int x = x1; x < x2; x++) {

View File

@@ -17,7 +17,7 @@ void IMB_flipy(struct ImBuf *ibuf)
{
size_t x_size, y_size;
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}
@@ -31,7 +31,7 @@ void IMB_flipy(struct ImBuf *ibuf)
top = ibuf->rect;
bottom = top + ((y_size - 1) * x_size);
line = MEM_mallocN(stride, "linebuf");
line = static_cast<uint *>(MEM_mallocN(stride, "linebuf"));
y_size >>= 1;
@@ -47,7 +47,7 @@ void IMB_flipy(struct ImBuf *ibuf)
}
if (ibuf->rect_float) {
float *topf = NULL, *bottomf = NULL, *linef = NULL;
float *topf = nullptr, *bottomf = nullptr, *linef = nullptr;
x_size = ibuf->x;
y_size = ibuf->y;
@@ -56,7 +56,7 @@ void IMB_flipy(struct ImBuf *ibuf)
topf = ibuf->rect_float;
bottomf = topf + 4 * ((y_size - 1) * x_size);
linef = MEM_mallocN(stride, "linebuf");
linef = static_cast<float *>(MEM_mallocN(stride, "linebuf"));
y_size >>= 1;
@@ -77,7 +77,7 @@ void IMB_flipx(struct ImBuf *ibuf)
int x, y, xr, xl, yi;
float px_f[4];
if (ibuf == NULL) {
if (ibuf == nullptr) {
return;
}

View File

@@ -28,8 +28,8 @@ static void imb_half_x_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
float af, rf, gf, bf, *p1f, *_p1f, *destf;
bool do_rect, do_float;
do_rect = (ibuf1->rect != NULL);
do_float = (ibuf1->rect_float != NULL && ibuf2->rect_float != NULL);
do_rect = (ibuf1->rect != nullptr);
do_float = (ibuf1->rect_float != nullptr && ibuf2->rect_float != nullptr);
_p1 = (uchar *)ibuf1->rect;
dest = (uchar *)ibuf2->rect;
@@ -83,11 +83,11 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
if (ibuf1 == NULL) {
return NULL;
if (ibuf1 == nullptr) {
return nullptr;
}
if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return NULL;
if (ibuf1->rect == nullptr && ibuf1->rect_float == nullptr) {
return nullptr;
}
if (ibuf1->x <= 1) {
@@ -95,8 +95,8 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1)
}
ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, ibuf1->y, ibuf1->planes, ibuf1->flags);
if (ibuf2 == NULL) {
return NULL;
if (ibuf2 == nullptr) {
return nullptr;
}
imb_half_x_no_alloc(ibuf2, ibuf1);
@@ -110,19 +110,19 @@ struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1)
int *p1, *dest, i, col, do_rect, do_float;
float *p1f, *destf;
if (ibuf1 == NULL) {
return NULL;
if (ibuf1 == nullptr) {
return nullptr;
}
if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return NULL;
if (ibuf1->rect == nullptr && ibuf1->rect_float == nullptr) {
return nullptr;
}
do_rect = (ibuf1->rect != NULL);
do_float = (ibuf1->rect_float != NULL);
do_rect = (ibuf1->rect != nullptr);
do_float = (ibuf1->rect_float != nullptr);
ibuf2 = IMB_allocImBuf(2 * ibuf1->x, ibuf1->y, ibuf1->planes, ibuf1->flags);
if (ibuf2 == NULL) {
return NULL;
if (ibuf2 == nullptr) {
return nullptr;
}
p1 = (int *)ibuf1->rect;
@@ -153,11 +153,11 @@ struct ImBuf *IMB_double_x(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
if (ibuf1 == NULL) {
return NULL;
if (ibuf1 == nullptr) {
return nullptr;
}
if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return NULL;
if (ibuf1->rect == nullptr && ibuf1->rect_float == nullptr) {
return nullptr;
}
ibuf2 = IMB_double_fast_x(ibuf1);
@@ -173,11 +173,11 @@ static void imb_half_y_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
int x, y;
float af, rf, gf, bf, *p1f, *p2f, *_p1f, *destf;
p1 = p2 = NULL;
p1f = p2f = NULL;
p1 = p2 = nullptr;
p1f = p2f = nullptr;
const bool do_rect = (ibuf1->rect != NULL);
const bool do_float = (ibuf1->rect_float != NULL && ibuf2->rect_float != NULL);
const bool do_rect = (ibuf1->rect != nullptr);
const bool do_float = (ibuf1->rect_float != nullptr && ibuf2->rect_float != nullptr);
_p1 = (uchar *)ibuf1->rect;
dest = (uchar *)ibuf2->rect;
@@ -236,11 +236,11 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
if (ibuf1 == NULL) {
return NULL;
if (ibuf1 == nullptr) {
return nullptr;
}
if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return NULL;
if (ibuf1->rect == nullptr && ibuf1->rect_float == nullptr) {
return nullptr;
}
if (ibuf1->y <= 1) {
@@ -248,8 +248,8 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1)
}
ibuf2 = IMB_allocImBuf(ibuf1->x, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags);
if (ibuf2 == NULL) {
return NULL;
if (ibuf2 == nullptr) {
return nullptr;
}
imb_half_y_no_alloc(ibuf2, ibuf1);
@@ -264,19 +264,19 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1)
float *p1f, *dest1f, *dest2f;
int x, y;
if (ibuf1 == NULL) {
return NULL;
if (ibuf1 == nullptr) {
return nullptr;
}
if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return NULL;
if (ibuf1->rect == nullptr && ibuf1->rect_float == nullptr) {
return nullptr;
}
const bool do_rect = (ibuf1->rect != NULL);
const bool do_float = (ibuf1->rect_float != NULL);
const bool do_rect = (ibuf1->rect != nullptr);
const bool do_float = (ibuf1->rect_float != nullptr);
ibuf2 = IMB_allocImBuf(ibuf1->x, 2 * ibuf1->y, ibuf1->planes, ibuf1->flags);
if (ibuf2 == NULL) {
return NULL;
if (ibuf2 == nullptr) {
return nullptr;
}
p1 = (int *)ibuf1->rect;
@@ -308,11 +308,11 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
if (ibuf1 == NULL) {
return NULL;
if (ibuf1 == nullptr) {
return nullptr;
}
if (ibuf1->rect == NULL) {
return NULL;
if (ibuf1->rect == nullptr) {
return nullptr;
}
ibuf2 = IMB_double_fast_y(ibuf1);
@@ -355,10 +355,10 @@ MINLINE void premul_ushort_to_straight_uchar(uchar *result, const ushort color[4
void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
{
int x, y;
const bool do_rect = (ibuf1->rect != NULL);
const bool do_float = (ibuf1->rect_float != NULL) && (ibuf2->rect_float != NULL);
const bool do_rect = (ibuf1->rect != nullptr);
const bool do_float = (ibuf1->rect_float != nullptr) && (ibuf2->rect_float != nullptr);
if (do_rect && (ibuf2->rect == NULL)) {
if (do_rect && (ibuf2->rect == nullptr)) {
imb_addrectImBuf(ibuf2);
}
@@ -433,11 +433,11 @@ ImBuf *IMB_onehalf(struct ImBuf *ibuf1)
{
struct ImBuf *ibuf2;
if (ibuf1 == NULL) {
return NULL;
if (ibuf1 == nullptr) {
return nullptr;
}
if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) {
return NULL;
if (ibuf1->rect == nullptr && ibuf1->rect_float == nullptr) {
return nullptr;
}
if (ibuf1->x <= 1) {
@@ -448,8 +448,8 @@ ImBuf *IMB_onehalf(struct ImBuf *ibuf1)
}
ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags);
if (ibuf2 == NULL) {
return NULL;
if (ibuf2 == nullptr) {
return nullptr;
}
imb_onehalf_no_alloc(ibuf2, ibuf1);
@@ -533,8 +533,8 @@ static void shrink_picture_byte(
intptr_t y_counter;
uchar *dst_begin = dst;
struct scale_outpix_byte *dst_line1 = NULL;
struct scale_outpix_byte *dst_line2 = NULL;
struct scale_outpix_byte *dst_line1 = nullptr;
struct scale_outpix_byte *dst_line2 = nullptr;
dst_line1 = (struct scale_outpix_byte *)MEM_callocN(
(dst_width + 1) * sizeof(struct scale_outpix_byte), "shrink_picture_byte 1");
@@ -855,7 +855,7 @@ static bool q_scale_linear_interpolation(struct ImBuf *ibuf, int newx, int newy)
}
if (ibuf->rect) {
uchar *newrect = MEM_mallocN(sizeof(int) * newx * newy, "q_scale rect");
uchar *newrect = static_cast<uchar *>(MEM_mallocN(sizeof(int) * newx * newy, "q_scale rect"));
q_scale_byte((uchar *)ibuf->rect, newrect, ibuf->x, ibuf->y, newx, newy);
imb_freerectImBuf(ibuf);
@@ -863,7 +863,8 @@ static bool q_scale_linear_interpolation(struct ImBuf *ibuf, int newx, int newy)
ibuf->rect = (uint *)newrect;
}
if (ibuf->rect_float) {
float *newrect = MEM_mallocN(sizeof(float[4]) * newx * newy, "q_scale rectfloat");
float *newrect = static_cast<float *>(
MEM_mallocN(sizeof(float[4]) * newx * newy, "q_scale rectfloat"));
q_scale_float(ibuf->rect_float, newrect, ibuf->x, ibuf->y, newx, newy);
imb_freerectfloatImBuf(ibuf);
ibuf->mall |= IB_rectfloat;
@@ -877,8 +878,8 @@ static bool q_scale_linear_interpolation(struct ImBuf *ibuf, int newx, int newy)
static ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
{
const bool do_rect = (ibuf->rect != NULL);
const bool do_float = (ibuf->rect_float != NULL);
const bool do_rect = (ibuf->rect != nullptr);
const bool do_float = (ibuf->rect_float != nullptr);
const size_t rect_size = IMB_get_rect_len(ibuf) * 4;
uchar *rect, *_newrect, *newrect;
@@ -886,8 +887,8 @@ static ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
float sample, add, val[4], nval[4], valf[4], nvalf[4];
int x, y;
rectf = _newrectf = newrectf = NULL;
rect = _newrect = newrect = NULL;
rectf = _newrectf = newrectf = nullptr;
rect = _newrect = newrect = nullptr;
nval[0] = nval[1] = nval[2] = nval[3] = 0.0f;
nvalf[0] = nvalf[1] = nvalf[2] = nvalf[3] = 0.0f;
@@ -896,14 +897,15 @@ static ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
}
if (do_rect) {
_newrect = MEM_mallocN(sizeof(uchar[4]) * newx * ibuf->y, "scaledownx");
if (_newrect == NULL) {
_newrect = static_cast<uchar *>(MEM_mallocN(sizeof(uchar[4]) * newx * ibuf->y, "scaledownx"));
if (_newrect == nullptr) {
return ibuf;
}
}
if (do_float) {
_newrectf = MEM_mallocN(sizeof(float[4]) * newx * ibuf->y, "scaledownxf");
if (_newrectf == NULL) {
_newrectf = static_cast<float *>(
MEM_mallocN(sizeof(float[4]) * newx * ibuf->y, "scaledownxf"));
if (_newrectf == nullptr) {
if (_newrect) {
MEM_freeN(_newrect);
}
@@ -1018,8 +1020,8 @@ static ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
static ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
{
const bool do_rect = (ibuf->rect != NULL);
const bool do_float = (ibuf->rect_float != NULL);
const bool do_rect = (ibuf->rect != nullptr);
const bool do_float = (ibuf->rect_float != nullptr);
const size_t rect_size = IMB_get_rect_len(ibuf) * 4;
uchar *rect, *_newrect, *newrect;
@@ -1027,8 +1029,8 @@ static ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
float sample, add, val[4], nval[4], valf[4], nvalf[4];
int x, y, skipx;
rectf = _newrectf = newrectf = NULL;
rect = _newrect = newrect = NULL;
rectf = _newrectf = newrectf = nullptr;
rect = _newrect = newrect = nullptr;
nval[0] = nval[1] = nval[2] = nval[3] = 0.0f;
nvalf[0] = nvalf[1] = nvalf[2] = nvalf[3] = 0.0f;
@@ -1037,14 +1039,15 @@ static ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
}
if (do_rect) {
_newrect = MEM_mallocN(sizeof(uchar[4]) * newy * ibuf->x, "scaledowny");
if (_newrect == NULL) {
_newrect = static_cast<uchar *>(MEM_mallocN(sizeof(uchar[4]) * newy * ibuf->x, "scaledowny"));
if (_newrect == nullptr) {
return ibuf;
}
}
if (do_float) {
_newrectf = MEM_mallocN(sizeof(float[4]) * newy * ibuf->x, "scaledownyf");
if (_newrectf == NULL) {
_newrectf = static_cast<float *>(
MEM_mallocN(sizeof(float[4]) * newy * ibuf->x, "scaledownyf"));
if (_newrectf == nullptr) {
if (_newrect) {
MEM_freeN(_newrect);
}
@@ -1160,29 +1163,29 @@ static ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
static ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
{
uchar *rect, *_newrect = NULL, *newrect;
float *rectf, *_newrectf = NULL, *newrectf;
uchar *rect, *_newrect = nullptr, *newrect;
float *rectf, *_newrectf = nullptr, *newrectf;
int x, y;
bool do_rect = false, do_float = false;
if (ibuf == NULL) {
return NULL;
if (ibuf == nullptr) {
return nullptr;
}
if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
if (ibuf->rect == nullptr && ibuf->rect_float == nullptr) {
return ibuf;
}
if (ibuf->rect) {
do_rect = true;
_newrect = MEM_mallocN(newx * ibuf->y * sizeof(int), "scaleupx");
if (_newrect == NULL) {
_newrect = static_cast<uchar *>(MEM_mallocN(newx * ibuf->y * sizeof(int), "scaleupx"));
if (_newrect == nullptr) {
return ibuf;
}
}
if (ibuf->rect_float) {
do_float = true;
_newrectf = MEM_mallocN(sizeof(float[4]) * newx * ibuf->y, "scaleupxf");
if (_newrectf == NULL) {
_newrectf = static_cast<float *>(MEM_mallocN(sizeof(float[4]) * newx * ibuf->y, "scaleupxf"));
if (_newrectf == nullptr) {
if (_newrect) {
MEM_freeN(_newrect);
}
@@ -1362,29 +1365,29 @@ static ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
static ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
{
uchar *rect, *_newrect = NULL, *newrect;
float *rectf, *_newrectf = NULL, *newrectf;
uchar *rect, *_newrect = nullptr, *newrect;
float *rectf, *_newrectf = nullptr, *newrectf;
int x, y, skipx;
bool do_rect = false, do_float = false;
if (ibuf == NULL) {
return NULL;
if (ibuf == nullptr) {
return nullptr;
}
if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
if (ibuf->rect == nullptr && ibuf->rect_float == nullptr) {
return ibuf;
}
if (ibuf->rect) {
do_rect = true;
_newrect = MEM_mallocN(ibuf->x * newy * sizeof(int), "scaleupy");
if (_newrect == NULL) {
_newrect = static_cast<uchar *>(MEM_mallocN(ibuf->x * newy * sizeof(int), "scaleupy"));
if (_newrect == nullptr) {
return ibuf;
}
}
if (ibuf->rect_float) {
do_float = true;
_newrectf = MEM_mallocN(sizeof(float[4]) * ibuf->x * newy, "scaleupyf");
if (_newrectf == NULL) {
_newrectf = static_cast<float *>(MEM_mallocN(sizeof(float[4]) * ibuf->x * newy, "scaleupyf"));
if (_newrectf == nullptr) {
if (_newrect) {
MEM_freeN(_newrect);
}
@@ -1565,21 +1568,22 @@ static ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
static void scalefast_Z_ImBuf(ImBuf *ibuf, int newx, int newy)
{
int *zbuf, *newzbuf, *_newzbuf = NULL;
float *zbuf_float, *newzbuf_float, *_newzbuf_float = NULL;
int *zbuf, *newzbuf, *_newzbuf = nullptr;
float *zbuf_float, *newzbuf_float, *_newzbuf_float = nullptr;
int x, y;
int ofsx, ofsy, stepx, stepy;
if (ibuf->zbuf) {
_newzbuf = MEM_mallocN(newx * newy * sizeof(int), __func__);
if (_newzbuf == NULL) {
_newzbuf = static_cast<int *>(MEM_mallocN(newx * newy * sizeof(int), __func__));
if (_newzbuf == nullptr) {
IMB_freezbufImBuf(ibuf);
}
}
if (ibuf->zbuf_float) {
_newzbuf_float = MEM_mallocN((size_t)newx * newy * sizeof(float), __func__);
if (_newzbuf_float == NULL) {
_newzbuf_float = static_cast<float *>(
MEM_mallocN((size_t)newx * newy * sizeof(float), __func__));
if (_newzbuf_float == nullptr) {
IMB_freezbuffloatImBuf(ibuf);
}
}
@@ -1632,10 +1636,10 @@ bool IMB_scaleImBuf(struct ImBuf *ibuf, uint newx, uint newy)
{
BLI_assert_msg(newx > 0 && newy > 0, "Images must be at least 1 on both dimensions!");
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
if (ibuf->rect == nullptr && ibuf->rect_float == nullptr) {
return false;
}
@@ -1683,14 +1687,14 @@ bool IMB_scalefastImBuf(struct ImBuf *ibuf, uint newx, uint newy)
bool do_float = false, do_rect = false;
size_t ofsx, ofsy, stepx, stepy;
rect = NULL;
_newrect = NULL;
newrect = NULL;
rectf = NULL;
_newrectf = NULL;
newrectf = NULL;
rect = nullptr;
_newrect = nullptr;
newrect = nullptr;
rectf = nullptr;
_newrectf = nullptr;
newrectf = nullptr;
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
if (ibuf->rect) {
@@ -1708,16 +1712,17 @@ bool IMB_scalefastImBuf(struct ImBuf *ibuf, uint newx, uint newy)
}
if (do_rect) {
_newrect = MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf");
if (_newrect == NULL) {
_newrect = static_cast<uint *>(MEM_mallocN(newx * newy * sizeof(int), "scalefastimbuf"));
if (_newrect == nullptr) {
return false;
}
newrect = _newrect;
}
if (do_float) {
_newrectf = MEM_mallocN(sizeof(float[4]) * newx * newy, "scalefastimbuf f");
if (_newrectf == NULL) {
_newrectf = static_cast<imbufRGBA *>(
MEM_mallocN(sizeof(float[4]) * newx * newy, "scalefastimbuf f"));
if (_newrectf == nullptr) {
if (_newrect) {
MEM_freeN(_newrect);
}
@@ -1843,14 +1848,14 @@ static void *do_scale_thread(void *data_v)
}
}
return NULL;
return nullptr;
}
void IMB_scaleImBuf_threaded(ImBuf *ibuf, uint newx, uint newy)
{
BLI_assert_msg(newx > 0 && newy > 0, "Images must be at least 1 on both dimensions!");
ScaleTreadInitData init_data = {NULL};
ScaleTreadInitData init_data = {nullptr};
/* prepare initialization data */
init_data.ibuf = ibuf;
@@ -1859,13 +1864,13 @@ void IMB_scaleImBuf_threaded(ImBuf *ibuf, uint newx, uint newy)
init_data.newy = newy;
if (ibuf->rect) {
init_data.byte_buffer = MEM_mallocN(4 * newx * newy * sizeof(char),
"threaded scale byte buffer");
init_data.byte_buffer = static_cast<uchar *>(
MEM_mallocN(4 * newx * newy * sizeof(char), "threaded scale byte buffer"));
}
if (ibuf->rect_float) {
init_data.float_buffer = MEM_mallocN(ibuf->channels * newx * newy * sizeof(float),
"threaded scale float buffer");
init_data.float_buffer = static_cast<float *>(
MEM_mallocN(ibuf->channels * newx * newy * sizeof(float), "threaded scale float buffer"));
}
/* actual scaling threads */

View File

@@ -703,16 +703,25 @@ int *IMB_stereo3d_from_rect(const ImageFormatData *im_format,
int *rect_right)
{
int *rect_result;
Stereo3DData s3d_data = {{NULL}};
Stereo3DData s3d_data = {{nullptr}};
size_t width, height;
const bool is_float = im_format->depth > 8;
IMB_stereo3d_write_dimensions(
im_format->stereo3d_format.display_mode, false, x, y, &width, &height);
rect_result = MEM_mallocN(channels * sizeof(int) * width * height, __func__);
rect_result = static_cast<int *>(MEM_mallocN(channels * sizeof(int) * width * height, __func__));
imb_stereo3d_data_init(
&s3d_data, is_float, x, y, channels, rect_left, rect_right, rect_result, NULL, NULL, NULL);
imb_stereo3d_data_init(&s3d_data,
is_float,
x,
y,
channels,
rect_left,
rect_right,
rect_result,
nullptr,
nullptr,
nullptr);
imb_stereo3d_write_doit(&s3d_data, &im_format->stereo3d_format);
imb_stereo3d_squeeze_rect(rect_result, &im_format->stereo3d_format, x, y, channels);
@@ -727,22 +736,23 @@ float *IMB_stereo3d_from_rectf(const ImageFormatData *im_format,
float *rectf_right)
{
float *rectf_result;
Stereo3DData s3d_data = {{NULL}};
Stereo3DData s3d_data = {{nullptr}};
size_t width, height;
const bool is_float = im_format->depth > 8;
IMB_stereo3d_write_dimensions(
im_format->stereo3d_format.display_mode, false, x, y, &width, &height);
rectf_result = MEM_mallocN(channels * sizeof(float) * width * height, __func__);
rectf_result = static_cast<float *>(
MEM_mallocN(channels * sizeof(float) * width * height, __func__));
imb_stereo3d_data_init(&s3d_data,
is_float,
x,
y,
channels,
NULL,
NULL,
NULL,
nullptr,
nullptr,
nullptr,
rectf_left,
rectf_right,
rectf_result);
@@ -754,8 +764,8 @@ float *IMB_stereo3d_from_rectf(const ImageFormatData *im_format,
ImBuf *IMB_stereo3d_ImBuf(const ImageFormatData *im_format, ImBuf *ibuf_left, ImBuf *ibuf_right)
{
ImBuf *ibuf_stereo = NULL;
Stereo3DData s3d_data = {{NULL}};
ImBuf *ibuf_stereo = nullptr;
Stereo3DData s3d_data = {{nullptr}};
size_t width, height;
const bool is_float = im_format->depth > 8;
@@ -796,11 +806,12 @@ static void imb_stereo3d_write_doit(Stereo3DData *s3d_data, const Stereo3dFormat
{
switch (s3d->display_mode) {
case S3D_DISPLAY_ANAGLYPH:
imb_stereo3d_write_anaglyph(s3d_data, s3d->anaglyph_type);
imb_stereo3d_write_anaglyph(s3d_data, eStereo3dAnaglyphType(s3d->anaglyph_type));
break;
case S3D_DISPLAY_INTERLACE:
imb_stereo3d_write_interlace(
s3d_data, s3d->interlace_type, (s3d->flag & S3D_INTERLACE_SWAP) != 0);
imb_stereo3d_write_interlace(s3d_data,
eStereo3dInterlaceType(s3d->interlace_type),
(s3d->flag & S3D_INTERLACE_SWAP) != 0);
break;
case S3D_DISPLAY_SIDEBYSIDE:
imb_stereo3d_write_sidebyside(s3d_data, (s3d->flag & S3D_SIDEBYSIDE_CROSSEYED) != 0);
@@ -1279,10 +1290,10 @@ void IMB_ImBufFromStereo3d(const Stereo3dFormat *s3d,
ImBuf **r_ibuf_left,
ImBuf **r_ibuf_right)
{
Stereo3DData s3d_data = {{NULL}};
Stereo3DData s3d_data = {{nullptr}};
ImBuf *ibuf_left, *ibuf_right;
size_t width, height;
const bool is_float = (ibuf_stereo3d->rect_float != NULL);
const bool is_float = (ibuf_stereo3d->rect_float != nullptr);
IMB_stereo3d_read_dimensions(s3d->display_mode,
((s3d->flag & S3D_SQUEEZED_FRAME) == 0),
@@ -1364,11 +1375,12 @@ static void imb_stereo3d_read_doit(Stereo3DData *s3d_data, const Stereo3dFormat
{
switch (s3d->display_mode) {
case S3D_DISPLAY_ANAGLYPH:
imb_stereo3d_read_anaglyph(s3d_data, s3d->anaglyph_type);
imb_stereo3d_read_anaglyph(s3d_data, eStereo3dAnaglyphType(s3d->anaglyph_type));
break;
case S3D_DISPLAY_INTERLACE:
imb_stereo3d_read_interlace(
s3d_data, s3d->interlace_type, (s3d->flag & S3D_INTERLACE_SWAP) != 0);
imb_stereo3d_read_interlace(s3d_data,
eStereo3dInterlaceType(s3d->interlace_type),
(s3d->flag & S3D_INTERLACE_SWAP) != 0);
break;
case S3D_DISPLAY_SIDEBYSIDE:
imb_stereo3d_read_sidebyside(s3d_data, (s3d->flag & S3D_SIDEBYSIDE_CROSSEYED) != 0);

View File

@@ -201,7 +201,7 @@ static void escape_uri_string(const char *string,
/* --- End of adapted code from glib. --- */
static bool thumbhash_from_path(const char *UNUSED(path), ThumbSource source, char *r_hash)
static bool thumbhash_from_path(const char * /*path*/, ThumbSource source, char *r_hash)
{
switch (source) {
case THB_SOURCE_FONT:
@@ -277,12 +277,12 @@ static bool thumbpathname_from_uri(
static void thumbname_from_uri(const char *uri, char *thumb, const int thumb_len)
{
thumbpathname_from_uri(uri, NULL, 0, thumb, thumb_len, THB_FAIL);
thumbpathname_from_uri(uri, nullptr, 0, thumb, thumb_len, THB_FAIL);
}
static bool thumbpath_from_uri(const char *uri, char *path, const int path_len, ThumbSize size)
{
return thumbpathname_from_uri(uri, path, path_len, NULL, 0, size);
return thumbpathname_from_uri(uri, path, path_len, nullptr, 0, size);
}
void IMB_thumb_makedirs(void)
@@ -332,7 +332,7 @@ static ImBuf *thumb_create_ex(const char *file_path,
tsize = 1;
break;
default:
return NULL; /* unknown size */
return nullptr; /* unknown size */
}
if (get_thumb_dir(tdir, size)) {
@@ -340,21 +340,21 @@ static ImBuf *thumb_create_ex(const char *file_path,
// thumb[8] = '\0'; /* shorten for tempname, not needed anymore */
BLI_snprintf(temp, FILE_MAX, "%sblender_%d_%s.png", tdir, abs(getpid()), thumb);
if (BLI_path_ncmp(file_path, tdir, sizeof(tdir)) == 0) {
return NULL;
return nullptr;
}
if (size == THB_FAIL) {
img = IMB_allocImBuf(1, 1, 32, IB_rect | IB_metadata);
if (!img) {
return NULL;
return nullptr;
}
}
else {
if (ELEM(source, THB_SOURCE_IMAGE, THB_SOURCE_BLEND, THB_SOURCE_FONT)) {
/* only load if we didn't give an image */
if (img == NULL) {
if (img == nullptr) {
switch (source) {
case THB_SOURCE_IMAGE:
img = IMB_thumb_load_image(file_path, tsize, NULL);
img = IMB_thumb_load_image(file_path, tsize, nullptr);
break;
case THB_SOURCE_BLEND:
img = IMB_thumb_load_blend(file_path, blen_group, blen_id);
@@ -367,18 +367,18 @@ static ImBuf *thumb_create_ex(const char *file_path,
}
}
if (img != NULL) {
if (img != nullptr) {
if (BLI_stat(file_path, &info) != -1) {
BLI_snprintf(mtime, sizeof(mtime), "%ld", (long int)info.st_mtime);
}
}
}
else if (THB_SOURCE_MOVIE == source) {
struct anim *anim = NULL;
anim = IMB_open_anim(file_path, IB_rect | IB_metadata, 0, NULL);
if (anim != NULL) {
struct anim *anim = nullptr;
anim = IMB_open_anim(file_path, IB_rect | IB_metadata, 0, nullptr);
if (anim != nullptr) {
img = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
if (img == NULL) {
if (img == nullptr) {
printf("not an anim; %s\n", file_path);
}
else {
@@ -392,7 +392,7 @@ static ImBuf *thumb_create_ex(const char *file_path,
}
}
if (!img) {
return NULL;
return nullptr;
}
if (img->x > tsize || img->y > tsize) {
@@ -402,7 +402,7 @@ static ImBuf *thumb_create_ex(const char *file_path,
short ey = MAX2(1, (short)(img->y * scale));
/* Save some time by only scaling byte buf */
if (img->rect_float) {
if (img->rect == NULL) {
if (img->rect == nullptr) {
IMB_rect_from_float(img);
}
imb_freerectfloatImBuf(img);
@@ -449,16 +449,16 @@ static ImBuf *thumb_create_or_fail(const char *file_path,
ThumbSource source)
{
ImBuf *img = thumb_create_ex(
file_path, uri, thumb, use_hash, hash, blen_group, blen_id, size, source, NULL);
file_path, uri, thumb, use_hash, hash, blen_group, blen_id, size, source, nullptr);
if (!img) {
/* thumb creation failed, write fail thumb */
img = thumb_create_ex(
file_path, uri, thumb, use_hash, hash, blen_group, blen_id, THB_FAIL, source, NULL);
file_path, uri, thumb, use_hash, hash, blen_group, blen_id, THB_FAIL, source, nullptr);
if (img) {
/* we don't need failed thumb anymore */
IMB_freeImBuf(img);
img = NULL;
img = nullptr;
}
}
@@ -471,25 +471,25 @@ ImBuf *IMB_thumb_create(const char *filepath, ThumbSize size, ThumbSource source
char thumb_name[40];
if (!uri_from_filename(filepath, uri)) {
return NULL;
return nullptr;
}
thumbname_from_uri(uri, thumb_name, sizeof(thumb_name));
return thumb_create_ex(
filepath, uri, thumb_name, false, THUMB_DEFAULT_HASH, NULL, NULL, size, source, img);
filepath, uri, thumb_name, false, THUMB_DEFAULT_HASH, nullptr, nullptr, size, source, img);
}
ImBuf *IMB_thumb_read(const char *filepath, ThumbSize size)
{
char thumb[FILE_MAX];
char uri[URI_MAX];
ImBuf *img = NULL;
ImBuf *img = nullptr;
if (!uri_from_filename(filepath, uri)) {
return NULL;
return nullptr;
}
if (thumbpath_from_uri(uri, thumb, sizeof(thumb), size)) {
img = IMB_loadiffname(thumb, IB_rect | IB_metadata, NULL);
img = IMB_loadiffname(thumb, IB_rect | IB_metadata, nullptr);
}
return img;
@@ -522,8 +522,8 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
const char *file_path;
const char *path;
BLI_stat_t st;
ImBuf *img = NULL;
char *blen_group = NULL, *blen_id = NULL;
ImBuf *img = nullptr;
char *blen_group = nullptr, *blen_id = nullptr;
path = file_path = filepath;
if (source == THB_SOURCE_BLEND) {
@@ -531,7 +531,7 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
if (blen_group) {
if (!blen_id) {
/* No preview for blen groups */
return NULL;
return nullptr;
}
file_path = path_buff; /* path needs to be a valid file! */
}
@@ -539,10 +539,10 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
}
if (BLI_stat(file_path, &st) == -1) {
return NULL;
return nullptr;
}
if (!uri_from_filename(path, uri)) {
return NULL;
return nullptr;
}
if (thumbpath_from_uri(uri, thumb_path, sizeof(thumb_path), THB_FAIL)) {
/* failure thumb exists, don't try recreating */
@@ -552,7 +552,7 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
BLI_delete(thumb_path, false, false);
}
else {
return NULL;
return nullptr;
}
}
}
@@ -561,10 +561,10 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
uri, thumb_path, sizeof(thumb_path), thumb_name, sizeof(thumb_name), size))
{
if (BLI_path_ncmp(path, thumb_path, sizeof(thumb_path)) == 0) {
img = IMB_loadiffname(path, IB_rect, NULL);
img = IMB_loadiffname(path, IB_rect, nullptr);
}
else {
img = IMB_loadiffname(thumb_path, IB_rect | IB_metadata, NULL);
img = IMB_loadiffname(thumb_path, IB_rect | IB_metadata, nullptr);
if (img) {
bool regenerate = false;
@@ -596,7 +596,7 @@ ImBuf *IMB_thumb_manage(const char *filepath, ThumbSize size, ThumbSource source
if (regenerate) {
/* recreate all thumbs */
IMB_freeImBuf(img);
img = NULL;
img = nullptr;
IMB_thumb_delete(path, THB_NORMAL);
IMB_thumb_delete(path, THB_LARGE);
IMB_thumb_delete(path, THB_FAIL);
@@ -643,13 +643,13 @@ void IMB_thumb_locks_acquire(void)
BLI_thread_lock(LOCK_IMAGE);
if (thumb_locks.lock_counter == 0) {
BLI_assert(thumb_locks.locked_paths == NULL);
BLI_assert(thumb_locks.locked_paths == nullptr);
thumb_locks.locked_paths = BLI_gset_str_new(__func__);
BLI_condition_init(&thumb_locks.cond);
}
thumb_locks.lock_counter++;
BLI_assert(thumb_locks.locked_paths != NULL);
BLI_assert(thumb_locks.locked_paths != nullptr);
BLI_assert(thumb_locks.lock_counter > 0);
BLI_thread_unlock(LOCK_IMAGE);
}
@@ -657,12 +657,12 @@ void IMB_thumb_locks_acquire(void)
void IMB_thumb_locks_release(void)
{
BLI_thread_lock(LOCK_IMAGE);
BLI_assert((thumb_locks.locked_paths != NULL) && (thumb_locks.lock_counter > 0));
BLI_assert((thumb_locks.locked_paths != nullptr) && (thumb_locks.lock_counter > 0));
thumb_locks.lock_counter--;
if (thumb_locks.lock_counter == 0) {
BLI_gset_free(thumb_locks.locked_paths, MEM_freeN);
thumb_locks.locked_paths = NULL;
thumb_locks.locked_paths = nullptr;
BLI_condition_end(&thumb_locks.cond);
}
@@ -674,7 +674,7 @@ void IMB_thumb_path_lock(const char *path)
void *key = BLI_strdup(path);
BLI_thread_lock(LOCK_IMAGE);
BLI_assert((thumb_locks.locked_paths != NULL) && (thumb_locks.lock_counter > 0));
BLI_assert((thumb_locks.locked_paths != nullptr) && (thumb_locks.lock_counter > 0));
if (thumb_locks.locked_paths) {
while (!BLI_gset_add(thumb_locks.locked_paths, key)) {
@@ -690,7 +690,7 @@ void IMB_thumb_path_unlock(const char *path)
const void *key = path;
BLI_thread_lock(LOCK_IMAGE);
BLI_assert((thumb_locks.locked_paths != NULL) && (thumb_locks.lock_counter > 0));
BLI_assert((thumb_locks.locked_paths != nullptr) && (thumb_locks.lock_counter > 0));
if (thumb_locks.locked_paths) {
if (!BLI_gset_remove(thumb_locks.locked_paths, key, MEM_freeN)) {

View File

@@ -34,12 +34,13 @@ static ImBuf *imb_thumb_load_from_blend_id(const char *blen_path,
const char *blen_group,
const char *blen_id)
{
ImBuf *ima = NULL;
BlendFileReadReport bf_reports = {.reports = NULL};
ImBuf *ima = nullptr;
BlendFileReadReport bf_reports = {};
bf_reports.reports = nullptr;
struct BlendHandle *libfiledata = BLO_blendhandle_from_file(blen_path, &bf_reports);
if (libfiledata == NULL) {
return NULL;
if (libfiledata == nullptr) {
return nullptr;
}
int idcode = BKE_idtype_idcode_from_name(blen_group);
@@ -56,7 +57,7 @@ static ImBuf *imb_thumb_load_from_blend_id(const char *blen_path,
static ImBuf *imb_thumb_load_from_blendfile(const char *blen_path)
{
BlendThumbnail *data = BLO_thumbnail_from_file(blen_path);
ImBuf *ima = BKE_main_thumbnail_to_imbuf(NULL, data);
ImBuf *ima = BKE_main_thumbnail_to_imbuf(nullptr, data);
if (data) {
MEM_freeN(data);

View File

@@ -29,7 +29,7 @@ struct ImBuf *IMB_thumb_load_font(const char *filename, uint x, uint y)
if (!BLF_thumb_preview(filename, (uchar *)ibuf->rect, ibuf->x, ibuf->y, ibuf->channels)) {
IMB_freeImBuf(ibuf);
ibuf = NULL;
ibuf = nullptr;
}
return ibuf;

View File

@@ -30,12 +30,15 @@
# include "BKE_global.h" /* G.debug */
extern "C" {
# include <libavcodec/avcodec.h>
# include <libavdevice/avdevice.h>
# include <libavformat/avformat.h>
# include <libavutil/log.h>
# include "ffmpeg_compat.h"
}
#endif
#define UTIL_DEBUG 0
@@ -56,13 +59,13 @@ const char *imb_ext_image[] = {
#ifdef WITH_WEBP
".webp",
#endif
NULL,
nullptr,
};
const char *imb_ext_movie[] = {
".avi", ".flc", ".mov", ".movie", ".mp4", ".m4v", ".m2v", ".m2t", ".m2ts", ".mts",
".ts", ".mv", ".avs", ".wmv", ".ogv", ".ogg", ".r3d", ".dv", ".mpeg", ".mpg",
".mpg2", ".vob", ".mkv", ".flv", ".divx", ".xvid", ".mxf", ".webm", NULL,
".mpg2", ".vob", ".mkv", ".flv", ".divx", ".xvid", ".mxf", ".webm", nullptr,
};
/** Sort of wrong having audio extensions in imbuf. */
@@ -82,7 +85,7 @@ const char *imb_ext_audio[] = {
".aiff",
".m4a",
".mka",
NULL,
nullptr,
};
/* Increased from 32 to 64 because of the bitmaps header size. */
@@ -119,7 +122,7 @@ static ssize_t imb_ispic_read_header_from_filepath(const char *filepath, uchar b
int IMB_ispic_type_from_memory(const uchar *buf, const size_t buf_size)
{
for (const ImFileType *type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
if (type->is_a != NULL) {
if (type->is_a != nullptr) {
if (type->is_a(buf, buf_size)) {
return type->filetype;
}
@@ -148,11 +151,11 @@ bool IMB_ispic_type_matches(const char *filepath, int filetype)
}
const ImFileType *type = IMB_file_type_from_ftype(filetype);
if (type != NULL) {
if (type != nullptr) {
/* Requesting to load a type that can't check its own header doesn't make sense.
* Keep the check for developers. */
BLI_assert(type->is_a != NULL);
if (type->is_a != NULL) {
BLI_assert(type->is_a != nullptr);
if (type->is_a != nullptr) {
return type->is_a(buf, (size_t)buf_size);
}
}
@@ -231,7 +234,7 @@ const char *IMB_ffmpeg_last_error(void)
static int isffmpeg(const char *filepath)
{
AVFormatContext *pFormatCtx = NULL;
AVFormatContext *pFormatCtx = nullptr;
uint i;
int videoStream;
const AVCodec *pCodec;
@@ -249,19 +252,19 @@ static int isffmpeg(const char *filepath)
".exr",
".cin",
".wav",
NULL))
nullptr))
{
return 0;
}
if (avformat_open_input(&pFormatCtx, filepath, NULL, NULL) != 0) {
if (avformat_open_input(&pFormatCtx, filepath, nullptr, nullptr) != 0) {
if (UTIL_DEBUG) {
fprintf(stderr, "isffmpeg: av_open_input_file failed\n");
}
return 0;
}
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
if (avformat_find_stream_info(pFormatCtx, nullptr) < 0) {
if (UTIL_DEBUG) {
fprintf(stderr, "isffmpeg: avformat_find_stream_info failed\n");
}
@@ -293,7 +296,7 @@ static int isffmpeg(const char *filepath)
/* Find the decoder for the video stream */
pCodec = avcodec_find_decoder(codec_par->codec_id);
if (pCodec == NULL) {
if (pCodec == nullptr) {
avformat_close_input(&pFormatCtx);
return 0;
}

View File

@@ -45,7 +45,7 @@ static void imb_gpu_get_format(const ImBuf *ibuf,
eGPUDataFormat *r_data_format,
eGPUTextureFormat *r_texture_format)
{
const bool float_rect = (ibuf->rect_float != NULL);
const bool float_rect = (ibuf->rect_float != nullptr);
const bool is_grayscale = use_grayscale && imb_is_grayscale_texture_format_compatible(ibuf);
if (float_rect) {
@@ -114,7 +114,7 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
const bool store_premultiplied,
bool *r_freedata)
{
bool is_float_rect = (ibuf->rect_float != NULL);
bool is_float_rect = (ibuf->rect_float != nullptr);
const bool is_grayscale = imb_is_grayscale_texture_format_compatible(ibuf);
void *data_rect = (is_float_rect) ? (void *)ibuf->rect_float : (void *)ibuf->rect;
bool freedata = false;
@@ -127,8 +127,8 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
data_rect = MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y, __func__);
*r_freedata = freedata = true;
if (data_rect == NULL) {
return NULL;
if (data_rect == nullptr) {
return nullptr;
}
IMB_colormanagement_imbuf_to_float_texture(
@@ -151,8 +151,8 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
(is_grayscale ? sizeof(float[4]) : sizeof(uchar[4])) * ibuf->x * ibuf->y, __func__);
*r_freedata = freedata = true;
if (data_rect == NULL) {
return NULL;
if (data_rect == nullptr) {
return nullptr;
}
/* Texture storage of images is defined by the alpha mode of the image. The
@@ -177,8 +177,8 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
*r_freedata = freedata = true;
is_float_rect = true;
if (data_rect == NULL) {
return NULL;
if (data_rect == nullptr) {
return nullptr;
}
/* Texture storage of images is defined by the alpha mode of the image. The
@@ -192,8 +192,8 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
}
if (do_rescale) {
uint *rect = (is_float_rect) ? NULL : (uint *)data_rect;
float *rect_float = (is_float_rect) ? (float *)data_rect : NULL;
uint *rect = (is_float_rect) ? nullptr : (uint *)data_rect;
float *rect_float = (is_float_rect) ? (float *)data_rect : nullptr;
ImBuf *scale_ibuf = IMB_allocFromBuffer(rect, rect_float, ibuf->x, ibuf->y, 4);
IMB_scaleImBuf(scale_ibuf, UNPACK2(rescale_size));
@@ -205,8 +205,8 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
data_rect = (is_float_rect) ? (void *)scale_ibuf->rect_float : (void *)scale_ibuf->rect;
*r_freedata = freedata = true;
/* Steal the rescaled buffer to avoid double free. */
scale_ibuf->rect_float = NULL;
scale_ibuf->rect = NULL;
scale_ibuf->rect_float = nullptr;
scale_ibuf->rect = nullptr;
IMB_freeImBuf(scale_ibuf);
}
@@ -220,8 +220,8 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
*r_freedata = freedata = true;
}
if (data_rect == NULL) {
return NULL;
if (data_rect == nullptr) {
return nullptr;
}
int buffer_size = do_rescale ? rescale_size[0] * rescale_size[1] : ibuf->x * ibuf->y;
@@ -261,7 +261,7 @@ GPUTexture *IMB_touch_gpu_texture(const char *name,
tex_format,
GPU_TEXTURE_USAGE_SHADER_READ |
GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
NULL);
nullptr);
}
else {
tex = GPU_texture_create_2d(name,
@@ -270,7 +270,7 @@ GPUTexture *IMB_touch_gpu_texture(const char *name,
9999,
tex_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
NULL);
nullptr);
}
GPU_texture_swizzle_set(tex, imb_gpu_get_swizzle(ibuf));
@@ -313,7 +313,7 @@ GPUTexture *IMB_create_gpu_texture(const char *name,
bool use_high_bitdepth,
bool use_premult)
{
GPUTexture *tex = NULL;
GPUTexture *tex = nullptr;
int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)};
bool do_rescale = (ibuf->x != size[0]) || (ibuf->y != size[1]);
@@ -347,7 +347,7 @@ GPUTexture *IMB_create_gpu_texture(const char *name,
GPU_TEXTURE_USAGE_GENERAL,
ibuf->dds_data.data);
if (tex != NULL) {
if (tex != nullptr) {
return tex;
}
@@ -369,8 +369,8 @@ GPUTexture *IMB_create_gpu_texture(const char *name,
9999,
tex_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
NULL);
if (tex == NULL) {
nullptr);
if (tex == nullptr) {
size[0] = max_ii(1, size[0] / 2);
size[1] = max_ii(1, size[1] / 2);
tex = GPU_texture_create_2d(name,
@@ -378,10 +378,10 @@ GPUTexture *IMB_create_gpu_texture(const char *name,
9999,
tex_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW,
NULL);
nullptr);
do_rescale = true;
}
BLI_assert(tex != NULL);
BLI_assert(tex != nullptr);
void *data = imb_gpu_get_data(ibuf, do_rescale, size, use_premult, &freebuf);
GPU_texture_update(tex, data_format, data);

View File

@@ -31,7 +31,7 @@
bool imb_is_a_webp(const uchar *buf, size_t size)
{
if (WebPGetInfo(buf, size, NULL, NULL)) {
if (WebPGetInfo(buf, size, nullptr, nullptr)) {
return true;
}
return false;
@@ -40,7 +40,7 @@ bool imb_is_a_webp(const uchar *buf, size_t size)
ImBuf *imb_loadwebp(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
{
if (!imb_is_a_webp(mem, size)) {
return NULL;
return nullptr;
}
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
@@ -48,15 +48,15 @@ ImBuf *imb_loadwebp(const uchar *mem, size_t size, int flags, char colorspace[IM
WebPBitstreamFeatures features;
if (WebPGetFeatures(mem, size, &features) != VP8_STATUS_OK) {
fprintf(stderr, "WebP: Failed to parse features\n");
return NULL;
return nullptr;
}
const int planes = features.has_alpha ? 32 : 24;
ImBuf *ibuf = IMB_allocImBuf(features.width, features.height, planes, 0);
if (ibuf == NULL) {
if (ibuf == nullptr) {
fprintf(stderr, "WebP: Failed to allocate image memory\n");
return NULL;
return nullptr;
}
if ((flags & IB_test) == 0) {
@@ -65,7 +65,7 @@ ImBuf *imb_loadwebp(const uchar *mem, size_t size, int flags, char colorspace[IM
/* Flip the image during decoding to match Blender. */
uchar *last_row = (uchar *)(ibuf->rect + (ibuf->y - 1) * ibuf->x);
if (WebPDecodeRGBAInto(mem, size, last_row, (size_t)(ibuf->x) * ibuf->y * 4, -4 * ibuf->x) ==
NULL) {
nullptr) {
fprintf(stderr, "WebP: Failed to decode image\n");
}
}
@@ -74,7 +74,7 @@ ImBuf *imb_loadwebp(const uchar *mem, size_t size, int flags, char colorspace[IM
}
struct ImBuf *imb_load_filepath_thumbnail_webp(const char *filepath,
const int UNUSED(flags),
const int /*flags*/,
const size_t max_thumb_size,
char colorspace[],
size_t *r_width,
@@ -82,7 +82,7 @@ struct ImBuf *imb_load_filepath_thumbnail_webp(const char *filepath,
{
const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
if (file == -1) {
return NULL;
return nullptr;
}
const size_t data_size = BLI_file_descriptor_size(file);
@@ -91,11 +91,11 @@ struct ImBuf *imb_load_filepath_thumbnail_webp(const char *filepath,
BLI_mmap_file *mmap_file = BLI_mmap_open(file);
imb_mmap_unlock();
close(file);
if (mmap_file == NULL) {
return NULL;
if (mmap_file == nullptr) {
return nullptr;
}
const uchar *data = BLI_mmap_get_pointer(mmap_file);
const uchar *data = static_cast<const uchar *>(BLI_mmap_get_pointer(mmap_file));
WebPDecoderConfig config;
if (!data || !WebPInitDecoderConfig(&config) ||
@@ -105,7 +105,7 @@ struct ImBuf *imb_load_filepath_thumbnail_webp(const char *filepath,
imb_mmap_lock();
BLI_mmap_free(mmap_file);
imb_mmap_unlock();
return NULL;
return nullptr;
}
/* Return full size of the image. */
@@ -118,12 +118,12 @@ struct ImBuf *imb_load_filepath_thumbnail_webp(const char *filepath,
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
struct ImBuf *ibuf = IMB_allocImBuf(dest_w, dest_h, 32, IB_rect);
if (ibuf == NULL) {
if (ibuf == nullptr) {
fprintf(stderr, "WebP: Failed to allocate image memory\n");
imb_mmap_lock();
BLI_mmap_free(mmap_file);
imb_mmap_unlock();
return NULL;
return nullptr;
}
config.options.no_fancy_upsampling = 1;
@@ -144,7 +144,7 @@ struct ImBuf *imb_load_filepath_thumbnail_webp(const char *filepath,
imb_mmap_lock();
BLI_mmap_free(mmap_file);
imb_mmap_unlock();
return NULL;
return nullptr;
}
/* Free the output buffer. */
@@ -157,7 +157,7 @@ struct ImBuf *imb_load_filepath_thumbnail_webp(const char *filepath,
return ibuf;
}
bool imb_savewebp(struct ImBuf *ibuf, const char *name, int UNUSED(flags))
bool imb_savewebp(struct ImBuf *ibuf, const char *name, int /*flags*/)
{
const int bytesperpixel = (ibuf->planes + 7) >> 3;
uchar *encoded_data, *last_row;
@@ -167,7 +167,8 @@ bool imb_savewebp(struct ImBuf *ibuf, const char *name, int UNUSED(flags))
/* We must convert the ImBuf RGBA buffer to RGB as WebP expects a RGB buffer. */
const size_t num_pixels = ibuf->x * ibuf->y;
const uint8_t *rgba_rect = (uint8_t *)ibuf->rect;
uint8_t *rgb_rect = MEM_mallocN(sizeof(uint8_t) * num_pixels * 3, "webp rgb_rect");
uint8_t *rgb_rect = static_cast<uint8_t *>(
MEM_mallocN(sizeof(uint8_t) * num_pixels * 3, "webp rgb_rect"));
for (int i = 0; i < num_pixels; i++) {
rgb_rect[i * 3 + 0] = rgba_rect[i * 4 + 0];
rgb_rect[i * 3 + 1] = rgba_rect[i * 4 + 1];
@@ -203,7 +204,7 @@ bool imb_savewebp(struct ImBuf *ibuf, const char *name, int UNUSED(flags))
return false;
}
if (encoded_data != NULL) {
if (encoded_data != nullptr) {
FILE *fp = BLI_fopen(name, "wb");
if (!fp) {
free(encoded_data);

View File

@@ -25,13 +25,13 @@ bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags)
BLI_assert(!BLI_path_is_rel(filepath));
if (ibuf == NULL) {
if (ibuf == nullptr) {
return false;
}
ibuf->flags = flags;
const ImFileType *type = IMB_file_type_from_ibuf(ibuf);
if (type == NULL || type->save == NULL) {
if (type == nullptr || type->save == nullptr) {
fprintf(stderr, "Couldn't save picture.\n");
return false;
}
@@ -42,7 +42,7 @@ bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags)
* have already created this byte buffer. This is a basic fallback for other
* cases where we do not have a specific desired output colorspace. */
if (!(type->flag & IM_FTYPE_FLOAT)) {
if (ibuf->rect == NULL && ibuf->rect_float) {
if (ibuf->rect == nullptr && ibuf->rect_float) {
ibuf->rect_colorspace = colormanage_colorspace_get_roled(COLOR_ROLE_DEFAULT_BYTE);
IMB_rect_from_float(ibuf);
}

View File

@@ -25,6 +25,10 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "BLI_sys_types.h"
#include <stdio.h> /* for FILE */
@@ -279,3 +283,7 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...);
* Unused but still external
*/
AviError AVI_print_error(AviError error);
#ifdef __cplusplus
}
#endif

View File

@@ -393,7 +393,7 @@ static bool seq_proxy_need_rebuild(Sequence *seq, struct anim *anim)
}
IMB_Proxy_Size required_proxies = seq->strip->proxy->build_size_flags;
IMB_Proxy_Size built_proxies = IMB_anim_proxy_get_existing(anim);
int built_proxies = IMB_anim_proxy_get_existing(anim);
return (required_proxies & built_proxies) != required_proxies;
}