[Bf-blender-cvs] [c5892a1c7d4] greasepencil-object: GPencil: Move get pixel function to shared module

Antonio Vazquez noreply at git.blender.org
Mon Dec 9 16:57:32 CET 2019


Commit: c5892a1c7d4cfc85efcf76dfa6109148c22c5c3a
Author: Antonio Vazquez
Date:   Mon Dec 9 16:56:24 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBc5892a1c7d4cfc85efcf76dfa6109148c22c5c3a

GPencil: Move get pixel function to shared module

Instead to have the code two times, move to BKE and share.

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

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/editors/sculpt_paint/paint_ops.c

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index 82c831ae8e0..7223611ecf2 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -338,6 +338,8 @@ bool BKE_image_has_loaded_ibuf(struct Image *image);
 struct ImBuf *BKE_image_get_ibuf_with_name(struct Image *image, const char *name);
 struct ImBuf *BKE_image_get_first_ibuf(struct Image *image);
 
+void BKE_image_buffer_pixel_get(struct ImBuf *ibuf, const int index, float r_col[4]);
+
 struct RenderSlot *BKE_image_add_renderslot(struct Image *ima, const char *name);
 bool BKE_image_remove_renderslot(struct Image *ima, struct ImageUser *iuser, int slot);
 struct RenderSlot *BKE_image_get_renderslot(struct Image *ima, int slot);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 15ad638cb2a..0ea8a723c2f 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -3565,24 +3565,6 @@ void BKE_gpencil_palette_ensure(Main *bmain, Scene *scene)
   }
 }
 
-static void BKE_gpencil_get_pixel(const ImBuf *ibuf, const int idx, float r_col[4])
-{
-  if (ibuf->rect_float) {
-    const float *frgba = &ibuf->rect_float[idx * 4];
-    copy_v4_v4(r_col, frgba);
-  }
-  else if (ibuf->rect) {
-    unsigned char *cp = (unsigned char *)(ibuf->rect + idx);
-    r_col[0] = (float)cp[0] / 255.0f;
-    r_col[1] = (float)cp[1] / 255.0f;
-    r_col[2] = (float)cp[2] / 255.0f;
-    r_col[3] = (float)cp[3] / 255.0f;
-  }
-  else {
-    zero_v4(r_col);
-  }
-}
-
 bool BKE_gpencil_from_image(SpaceImage *sima, bGPDframe *gpf, const float size, const bool mask)
 {
   Image *image = sima->image;
@@ -3611,7 +3593,7 @@ bool BKE_gpencil_from_image(SpaceImage *sima, bGPDframe *gpf, const float size,
       done = true;
       for (int col = 0; col < img_x; col++) {
         int pix = ((row * img_x) + col);
-        BKE_gpencil_get_pixel(ibuf, pix, color);
+        BKE_image_buffer_pixel_get(ibuf, pix, color);
         pt = &gps->points[col];
         pt->pressure = 1.0f;
         pt->x = col * size;
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 4c81bd4b019..040d2959baa 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -5442,3 +5442,22 @@ RenderSlot *BKE_image_get_renderslot(Image *ima, int index)
   /* Can be NULL for images without render slots. */
   return BLI_findlink(&ima->renderslots, index);
 }
+
+/* Get RGBA pixel from image at index. */
+void BKE_image_buffer_pixel_get(ImBuf *ibuf, const int index, float r_col[4])
+{
+  if (ibuf->rect_float) {
+    const float *frgba = &ibuf->rect_float[index * 4];
+    copy_v4_v4(r_col, frgba);
+  }
+  else if (ibuf->rect) {
+    unsigned char *cp = (unsigned char *)(ibuf->rect + index);
+    r_col[0] = (float)cp[0] / 255.0f;
+    r_col[1] = (float)cp[1] / 255.0f;
+    r_col[2] = (float)cp[2] / 255.0f;
+    r_col[3] = (float)cp[3] / 255.0f;
+  }
+  else {
+    zero_v4(r_col);
+  }
+}
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 04db5a2817d..6491b164742 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -299,28 +299,6 @@ static void PALETTE_OT_color_delete(wmOperatorType *ot)
 }
 
 /* --- Extract Palette from Image. */
-
-/* Return pixel data (rgba) at index. */
-static void get_image_pixel(const ImBuf *ibuf, const int idx, float r_col[3])
-{
-  if (ibuf->rect_float) {
-    const float *frgba = &ibuf->rect_float[idx * 4];
-    copy_v3_v3(r_col, frgba);
-  }
-  else if (ibuf->rect) {
-    float r, g, b;
-    uint *cp = &ibuf->rect[idx];
-    uint a = *cp;
-    cpack_to_rgb(a, &r, &g, &b);
-    r_col[0] = r;
-    r_col[1] = g;
-    r_col[2] = b;
-  }
-  else {
-    zero_v4(r_col);
-  }
-}
-
 static bool palette_extract_img_poll(bContext *C)
 {
   SpaceLink *sl = CTX_wm_space_data(C);
@@ -353,8 +331,8 @@ static int palette_extract_img_exec(bContext *C, wmOperator *op)
 
     /* Extract all colors. */
     for (int v = maxpixel; v != 0; v--) {
-      float col[3];
-      get_image_pixel(ibuf, v, col);
+      float col[4];
+      BKE_image_buffer_pixel_get(ibuf, v, col);
 
       const float range = pow(10.0f, threshold);
       col[0] = truncf(col[0] * range) / range;



More information about the Bf-blender-cvs mailing list