[Bf-blender-cvs] [1d4ed6ba296] master: Convert paint_image to cc.

Jeroen Bakker noreply at git.blender.org
Tue Feb 22 10:00:49 CET 2022


Commit: 1d4ed6ba2964eb6ec9bf0e0648f8bb60ab7a914a
Author: Jeroen Bakker
Date:   Tue Feb 22 09:57:11 2022 +0100
Branches: master
https://developer.blender.org/rB1d4ed6ba2964eb6ec9bf0e0648f8bb60ab7a914a

Convert paint_image to cc.

===================================================================

M	source/blender/editors/sculpt_paint/CMakeLists.txt
R089	source/blender/editors/sculpt_paint/paint_image.c	source/blender/editors/sculpt_paint/paint_image.cc

===================================================================

diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index fcde780fc58..c1febe5c86b 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -29,7 +29,7 @@ set(SRC
   paint_curve.c
   paint_curve_undo.c
   paint_hide.c
-  paint_image.c
+  paint_image.cc
   paint_image_2d.c
   paint_image_2d_curve_mask.cc
   paint_image_proj.c
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.cc
similarity index 89%
rename from source/blender/editors/sculpt_paint/paint_image.c
rename to source/blender/editors/sculpt_paint/paint_image.cc
index 2df42e6f532..dbc0398f807 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.cc
@@ -6,10 +6,10 @@
  * \brief Functions to paint images in 2D and 3D.
  */
 
-#include <float.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cfloat>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
 
 #include "MEM_guardedalloc.h"
 
@@ -96,7 +96,7 @@ void imapaint_region_tiles(
 {
   int srcx = 0, srcy = 0;
 
-  IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h);
+  IMB_rectclip(ibuf, nullptr, &x, &y, &srcx, &srcy, &w, &h);
 
   *tw = ((x + w - 1) >> ED_IMAGE_UNDO_TILE_BITS);
   *th = ((y + h - 1) >> ED_IMAGE_UNDO_TILE_BITS);
@@ -107,11 +107,11 @@ void imapaint_region_tiles(
 void ED_imapaint_dirty_region(
     Image *ima, ImBuf *ibuf, ImageUser *iuser, int x, int y, int w, int h, bool find_old)
 {
-  ImBuf *tmpibuf = NULL;
+  ImBuf *tmpibuf = nullptr;
   int tilex, tiley, tilew, tileh, tx, ty;
   int srcx = 0, srcy = 0;
 
-  IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h);
+  IMB_rectclip(ibuf, nullptr, &x, &y, &srcx, &srcy, &w, &h);
 
   if (w == 0 || h == 0) {
     return;
@@ -128,7 +128,7 @@ void ED_imapaint_dirty_region(
   for (ty = tiley; ty <= tileh; ty++) {
     for (tx = tilex; tx <= tilew; tx++) {
       ED_image_paint_tile_push(
-          undo_tiles, ima, ibuf, &tmpibuf, iuser, tx, ty, NULL, NULL, false, find_old);
+          undo_tiles, ima, ibuf, &tmpibuf, iuser, tx, ty, nullptr, nullptr, false, find_old);
     }
   }
 
@@ -169,17 +169,19 @@ void imapaint_image_update(
 BlurKernel *paint_new_blur_kernel(Brush *br, bool proj)
 {
   int i, j;
-  BlurKernel *kernel = MEM_mallocN(sizeof(BlurKernel), "blur kernel");
+  BlurKernel *kernel = MEM_new<BlurKernel>("BlurKernel");
+
   float radius;
   int side;
-  eBlurKernelType type = br->blur_mode;
+  eBlurKernelType type = static_cast<eBlurKernelType>(br->blur_mode);
 
   if (proj) {
     radius = 0.5f;
 
     side = kernel->side = 2;
     kernel->side_squared = kernel->side * kernel->side;
-    kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
+    kernel->wdata = static_cast<float *>(
+        MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data"));
     kernel->pixel_len = radius;
   }
   else {
@@ -191,7 +193,8 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj)
 
     side = kernel->side = radius * 2 + 1;
     kernel->side_squared = kernel->side * kernel->side;
-    kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
+    kernel->wdata = static_cast<float *>(
+        MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data"));
     kernel->pixel_len = br->blur_kernel_radius;
   }
 
@@ -224,9 +227,9 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj)
 
     default:
       printf("unidentified kernel type, aborting\n");
-      MEM_freeN(kernel->wdata);
-      MEM_freeN(kernel);
-      return NULL;
+      paint_delete_blur_kernel(kernel);
+      MEM_delete(kernel);
+      return nullptr;
   }
 
   return kernel;
@@ -267,7 +270,7 @@ static bool image_paint_poll_ex(bContext *C, bool check_tool)
     SpaceImage *sima = CTX_wm_space_image(C);
 
     if (sima) {
-      if (sima->image != NULL && ID_IS_LINKED(sima->image)) {
+      if (sima->image != nullptr && ID_IS_LINKED(sima->image)) {
         return false;
       }
       ARegion *region = CTX_wm_region(C);
@@ -307,12 +310,12 @@ static bool image_paint_2d_clone_poll(bContext *C)
 }
 
 /************************ paint operator ************************/
-typedef enum eTexPaintMode {
-  PAINT_MODE_2D,
-  PAINT_MODE_3D_PROJECT,
-} eTexPaintMode;
+enum class eTexPaintMode {
+  _2D,
+  _3D_PROJECT,
+};
 
-typedef struct PaintOperation {
+struct PaintOperation {
   eTexPaintMode mode;
 
   void *stroke_handle;
@@ -321,9 +324,9 @@ typedef struct PaintOperation {
   float startmouse[2];
   double starttime;
 
-  void *cursor;
+  wmPaintCursor *cursor;
   ViewContext vc;
-} PaintOperation;
+};
 
 bool paint_use_opacity_masking(Brush *brush)
 {
@@ -459,7 +462,7 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
   Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   Scene *scene = CTX_data_scene(C);
   ToolSettings *settings = scene->toolsettings;
-  PaintOperation *pop = MEM_callocN(sizeof(PaintOperation), "PaintOperation"); /* caller frees */
+  PaintOperation *pop = MEM_cnew<PaintOperation>("PaintOperation"); /* caller frees */
   Brush *brush = BKE_paint_brush(&settings->imapaint.paint);
   int mode = RNA_enum_get(op->ptr, "mode");
   ED_view3d_viewcontext_init(C, &pop->vc, depsgraph);
@@ -474,21 +477,21 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
     bool uvs, mat, tex, stencil;
     if (!ED_paint_proj_mesh_data_check(scene, ob, &uvs, &mat, &tex, &stencil)) {
       ED_paint_data_warning(op->reports, uvs, mat, tex, stencil);
-      MEM_freeN(pop);
-      WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
-      return NULL;
+      MEM_delete(pop);
+      WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, nullptr);
+      return nullptr;
     }
-    pop->mode = PAINT_MODE_3D_PROJECT;
+    pop->mode = eTexPaintMode::_3D_PROJECT;
     pop->stroke_handle = paint_proj_new_stroke(C, ob, mouse, mode);
   }
   else {
-    pop->mode = PAINT_MODE_2D;
+    pop->mode = eTexPaintMode::_2D;
     pop->stroke_handle = paint_2d_new_stroke(C, op, mode);
   }
 
   if (!pop->stroke_handle) {
-    MEM_freeN(pop);
-    return NULL;
+    MEM_delete(pop);
+    return nullptr;
   }
 
   if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
@@ -507,7 +510,7 @@ static void paint_stroke_update_step(bContext *C,
                                      struct PaintStroke *stroke,
                                      PointerRNA *itemptr)
 {
-  PaintOperation *pop = paint_stroke_mode_data(stroke);
+  PaintOperation *pop = static_cast<PaintOperation *>(paint_stroke_mode_data(stroke));
   Scene *scene = CTX_data_scene(C);
   ToolSettings *toolsettings = CTX_data_tool_settings(C);
   UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
@@ -548,11 +551,11 @@ static void paint_stroke_update_step(bContext *C,
   }
 
   switch (pop->mode) {
-    case PAINT_MODE_2D:
+    case eTexPaintMode::_2D:
       paint_2d_stroke(pop->stroke_handle, pop->prevmouse, mouse, eraser, pressure, distance, size);
       break;
 
-    case PAINT_MODE_3D_PROJECT:
+    case eTexPaintMode::_3D_PROJECT:
       paint_proj_stroke(
           C, pop->stroke_handle, pop->prevmouse, mouse, eraser, pressure, distance, size);
       break;
@@ -566,14 +569,14 @@ static void paint_stroke_update_step(bContext *C,
 
 static void paint_stroke_redraw(const bContext *C, struct PaintStroke *stroke, bool final)
 {
-  PaintOperation *pop = paint_stroke_mode_data(stroke);
+  PaintOperation *pop = static_cast<PaintOperation *>(paint_stroke_mode_data(stroke));
 
   switch (pop->mode) {
-    case PAINT_MODE_2D:
+    case eTexPaintMode::_2D:
       paint_2d_redraw(C, pop->stroke_handle, final);
       break;
 
-    case PAINT_MODE_3D_PROJECT:
+    case eTexPaintMode::_3D_PROJECT:
       paint_proj_redraw(C, pop->stroke_handle, final);
       break;
   }
@@ -583,7 +586,7 @@ static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
 {
   Scene *scene = CTX_data_scene(C);
   ToolSettings *toolsettings = scene->toolsettings;
-  PaintOperation *pop = paint_stroke_mode_data(stroke);
+  PaintOperation *pop = static_cast<PaintOperation *>(paint_stroke_mode_data(stroke));
   Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
 
   toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
@@ -591,11 +594,11 @@ static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
   if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
     if (brush->flag & BRUSH_USE_GRADIENT) {
       switch (pop->mode) {
-        case PAINT_MODE_2D:
+        case eTexPaintMode::_2D:
           paint_2d_gradient_fill(C, brush, pop->startmouse, pop->prevmouse, pop->stroke_handle);
           break;
 
-        case PAINT_MODE_3D_PROJECT:
+        case eTexPaintMode::_3D_PROJECT:
           paint_proj_stroke(C,
                             pop->stroke_handle,
                             pop->startmouse,
@@ -612,7 +615,7 @@ static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
     }
     else {
       switch (pop->mode) {
-        case PAINT_MODE_2D:
+        case eTexPaintMode::_2D:
           float color[3];
           if (paint_stroke_inverted(stroke)) {
             srgb_to_linearrgb_v3_v3(color, BKE_brush_secondary_color_get(scene, brush));
@@ -624,7 +627,7 @@ static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
               C, color, brush, pop->startmouse, pop->prevmouse, pop->stroke_handle);
           break;
 
-        case PAINT_MODE_3D_PROJECT:
+        case eTexPaintMode::_3D_PROJECT:
           paint_proj_stroke(C,
                             pop->stroke_handle,
                             pop->startmouse,
@@ -642,11 +645,11 @@ static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
   }
 
   switch (pop->mode) {
-    case PAINT_MODE_2D:
+    case eTexPaintMode::_2D:
       paint_2d_stroke_done(pop->stroke_handle);
       break;
 
-    case PAINT_MODE_3D_PROJECT:
+    case eTexPaintMode::_3D_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list