[Bf-blender-cvs] [0ef8a6179d2] master: Cleanup: Move image.c to c++
Jesse Yurkovich
noreply at git.blender.org
Thu Mar 10 06:04:08 CET 2022
Commit: 0ef8a6179d2a773b2570352bd0cb7eb18b666da2
Author: Jesse Yurkovich
Date: Wed Mar 9 20:55:17 2022 -0800
Branches: master
https://developer.blender.org/rB0ef8a6179d2a773b2570352bd0cb7eb18b666da2
Cleanup: Move image.c to c++
Passing on all platforms:
https://builder.blender.org/admin/#/builders/18/builds/329
Differential Revision: https://developer.blender.org/D13962
===================================================================
M source/blender/blenkernel/BKE_image.h
M source/blender/blenkernel/CMakeLists.txt
R086 source/blender/blenkernel/intern/image.c source/blender/blenkernel/intern/image.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index a5a2d57f9d3..ea0202e3b5f 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -486,7 +486,7 @@ bool BKE_image_is_dirty(struct Image *image);
void BKE_image_mark_dirty(struct Image *image, struct ImBuf *ibuf);
bool BKE_image_buffer_format_writable(struct ImBuf *ibuf);
-bool BKE_image_is_dirty_writable(struct Image *image, bool *is_format_writable);
+bool BKE_image_is_dirty_writable(struct Image *image, bool *r_is_writable);
/**
* Guess offset for the first frame in the sequence.
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index a12a956cbf5..3828d442f58 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -150,7 +150,7 @@ set(SRC
intern/idprop_serialize.cc
intern/idprop_utils.c
intern/idtype.c
- intern/image.c
+ intern/image.cc
intern/image_partial_update.cc
intern/image_gen.c
intern/image_gpu.cc
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.cc
similarity index 86%
rename from source/blender/blenkernel/intern/image.c
rename to source/blender/blenkernel/intern/image.cc
index e01f8cb76c8..967f0f61e07 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.cc
@@ -5,18 +5,20 @@
* \ingroup bke
*/
-#include <ctype.h>
+#include <cctype>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
#include <fcntl.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
#ifndef WIN32
# include <unistd.h>
#else
# include <io.h>
#endif
-#include <time.h>
+#include <ctime>
+
+#include "BLI_array.hh"
#include "CLG_log.h"
@@ -99,6 +101,8 @@
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
+using blender::Array;
+
static CLG_LogRef LOG = {"bke.image"};
static void image_init(Image *ima, short source, short type);
@@ -110,28 +114,28 @@ static void image_runtime_reset(struct Image *image)
{
memset(&image->runtime, 0, sizeof(image->runtime));
image->runtime.cache_mutex = MEM_mallocN(sizeof(ThreadMutex), "image runtime cache_mutex");
- BLI_mutex_init(image->runtime.cache_mutex);
+ BLI_mutex_init(static_cast<ThreadMutex *>(image->runtime.cache_mutex));
}
/* Reset runtime image fields when data-block is being copied. */
static void image_runtime_reset_on_copy(struct Image *image)
{
image->runtime.cache_mutex = MEM_mallocN(sizeof(ThreadMutex), "image runtime cache_mutex");
- BLI_mutex_init(image->runtime.cache_mutex);
+ BLI_mutex_init(static_cast<ThreadMutex *>(image->runtime.cache_mutex));
- image->runtime.partial_update_register = NULL;
- image->runtime.partial_update_user = NULL;
+ image->runtime.partial_update_register = nullptr;
+ image->runtime.partial_update_user = nullptr;
}
static void image_runtime_free_data(struct Image *image)
{
- BLI_mutex_end(image->runtime.cache_mutex);
+ BLI_mutex_end(static_cast<ThreadMutex *>(image->runtime.cache_mutex));
MEM_freeN(image->runtime.cache_mutex);
- image->runtime.cache_mutex = NULL;
+ image->runtime.cache_mutex = nullptr;
- if (image->runtime.partial_update_user != NULL) {
+ if (image->runtime.partial_update_user != nullptr) {
BKE_image_partial_update_free(image->runtime.partial_update_user);
- image->runtime.partial_update_user = NULL;
+ image->runtime.partial_update_user = nullptr;
}
BKE_image_partial_update_register_free(image);
}
@@ -140,7 +144,7 @@ static void image_init_data(ID *id)
{
Image *image = (Image *)id;
- if (image != NULL) {
+ if (image != nullptr) {
image_init(image, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
}
}
@@ -155,16 +159,17 @@ static void image_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
copy_image_packedfiles(&image_dst->packedfiles, &image_src->packedfiles);
- image_dst->stereo3d_format = MEM_dupallocN(image_src->stereo3d_format);
+ image_dst->stereo3d_format = static_cast<Stereo3dFormat *>(
+ MEM_dupallocN(image_src->stereo3d_format));
BLI_duplicatelist(&image_dst->views, &image_src->views);
/* Cleanup stuff that cannot be copied. */
- image_dst->cache = NULL;
- image_dst->rr = NULL;
+ image_dst->cache = nullptr;
+ image_dst->rr = nullptr;
BLI_duplicatelist(&image_dst->renderslots, &image_src->renderslots);
LISTBASE_FOREACH (RenderSlot *, slot, &image_dst->renderslots) {
- slot->render = NULL;
+ slot->render = nullptr;
}
BLI_listbase_clear(&image_dst->anims);
@@ -174,7 +179,7 @@ static void image_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
for (int eye = 0; eye < 2; eye++) {
for (int i = 0; i < TEXTARGET_COUNT; i++) {
for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
- image_dst->gputexture[i][eye][resolution] = NULL;
+ image_dst->gputexture[i][eye][resolution] = nullptr;
}
}
}
@@ -183,7 +188,7 @@ static void image_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
BKE_previewimg_id_copy(&image_dst->id, &image_src->id);
}
else {
- image_dst->preview = NULL;
+ image_dst->preview = nullptr;
}
image_runtime_reset_on_copy(image_dst);
@@ -201,7 +206,7 @@ static void image_free_data(ID *id)
LISTBASE_FOREACH (RenderSlot *, slot, &image->renderslots) {
if (slot->render) {
RE_FreeRenderResult(slot->render);
- slot->render = NULL;
+ slot->render = nullptr;
}
}
BLI_freelistN(&image->renderslots);
@@ -222,21 +227,28 @@ static void image_foreach_cache(ID *id,
void *user_data)
{
Image *image = (Image *)id;
- IDCacheKey key = {
- .id_session_uuid = id->session_uuid,
- .offset_in_ID = offsetof(Image, cache),
- .cache_v = image->cache,
- };
+ IDCacheKey key;
+ key.id_session_uuid = id->session_uuid;
+ key.offset_in_ID = offsetof(Image, cache);
+ key.cache_v = image->cache;
function_callback(id, &key, (void **)&image->cache, 0, user_data);
+ auto gputexture_offset = [image](int target, int eye, int resolution) {
+ constexpr size_t base_offset = offsetof(Image, gputexture);
+ const auto first = &image->gputexture[0][0][0];
+ const size_t array_offset = sizeof(*first) *
+ (&image->gputexture[target][eye][resolution] - first);
+ return base_offset + array_offset;
+ };
+
for (int eye = 0; eye < 2; eye++) {
for (int a = 0; a < TEXTARGET_COUNT; a++) {
for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
GPUTexture *texture = image->gputexture[a][eye][resolution];
- if (texture == NULL) {
+ if (texture == nullptr) {
continue;
}
- key.offset_in_ID = offsetof(Image, gputexture[a][eye][resolution]);
+ key.offset_in_ID = gputexture_offset(a, eye, resolution);
key.cache_v = texture;
function_callback(id, &key, (void **)&image->gputexture[a][eye][resolution], 0, user_data);
}
@@ -302,7 +314,7 @@ static void image_foreach_path(ID *id, BPathForeachPathData *bpath_data)
if (!BKE_image_has_packedfile(ima) &&
/* Image may have been painted onto (and not saved, T44543). */
!BKE_image_is_dirty(ima)) {
- BKE_image_signal(bpath_data->bmain, ima, NULL, IMA_SIGNAL_RELOAD);
+ BKE_image_signal(bpath_data->bmain, ima, nullptr, IMA_SIGNAL_RELOAD);
}
}
}
@@ -316,22 +328,22 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
/* Clear all data that isn't read to reduce false detection of changed image during memfile undo.
*/
ima->lastused = 0;
- ima->cache = NULL;
+ ima->cache = nullptr;
ima->gpuflag = 0;
BLI_listbase_clear(&ima->anims);
- ima->runtime.partial_update_register = NULL;
- ima->runtime.partial_update_user = NULL;
+ ima->runtime.partial_update_register = nullptr;
+ ima->runtime.partial_update_user = nullptr;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
- ima->gputexture[i][j][resolution] = NULL;
+ ima->gputexture[i][j][resolution] = nullptr;
}
}
}
ImagePackedFile *imapf;
- BLI_assert(ima->packedfile == NULL);
+ BLI_assert(ima->packedfile == nullptr);
if (!is_undo) {
/* Do not store packed files in case this is a library override ID. */
if (ID_IS_OVERRIDE_LIBRARY(ima)) {
@@ -339,8 +351,8 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
}
else {
/* Some trickery to keep forward compatibility of packed images. */
- if (ima->packedfiles.first != NULL) {
- imapf = ima->packedfiles.first;
+ if (ima->packedfiles.first != nullptr) {
+ imapf = static_cast<ImagePackedFile *>(ima->packedfiles.first);
ima->packedfile = imapf->packedfile;
}
}
@@ -350,7 +362,8 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
BLO_write_id_struct(writer, Image, id_address, &ima->id);
BKE_id_blend_write(writer, &ima->id);
- for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
+ for (imapf = static_cast<ImagePackedFile *>(ima->packedfiles.first); imapf;
+ imapf = imapf->next) {
BLO_write_struct(writer, ImagePackedFile, imapf);
BKE_packedfile_blend_write(writer, imapf->packedfile);
}
@@ -364,7 +377,7 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
BLO_write_struct_list(writer, ImageTile, &ima->tiles);
- ima->packedfile = NULL;
+ ima->packedfile = nullptr;
BLO_write_struct_list(writer, RenderSlot, &ima->renderslots);
}
@@ -387,7 +400,7 @@ static void image_blend_read_data(BlendDataReader *reader, ID *id)
LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) {
BKE_packedfile_blend_read(reader, &imapf->packedfile);
}
- ima->packedfile = NULL;
+ ima->packedfile = nullptr;
}
else {
BKE_packedfile_blend_re
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list