[Bf-blender-cvs] [a1f7ef4285a] greasepencil-object: GPencil: Refactor how sample pixel
Antonio Vazquez
noreply at git.blender.org
Mon Dec 9 18:24:29 CET 2019
Commit: a1f7ef4285ab45485f06b52b16ff9c5ef217f24f
Author: Antonio Vazquez
Date: Mon Dec 9 18:24:15 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBa1f7ef4285ab45485f06b52b16ff9c5ef217f24f
GPencil: Refactor how sample pixel
===================================================================
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
M source/blender/imbuf/IMB_imbuf.h
M source/blender/imbuf/intern/imageprocess.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index 7223611ecf2..82c831ae8e0 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -338,8 +338,6 @@ 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 0ea8a723c2f..1d9e0594b65 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -40,6 +40,7 @@
#include "BLT_translation.h"
#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
#include "DNA_anim_types.h"
#include "DNA_meshdata_types.h"
@@ -3592,8 +3593,7 @@ bool BKE_gpencil_from_image(SpaceImage *sima, bGPDframe *gpf, const float size,
bGPDstroke *gps = BKE_gpencil_add_stroke(gpf, 0, img_x, size * 1000);
done = true;
for (int col = 0; col < img_x; col++) {
- int pix = ((row * img_x) + col);
- BKE_image_buffer_pixel_get(ibuf, pix, color);
+ IMB_sampleImageAtLocation(ibuf, col, row, false, 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 040d2959baa..4c81bd4b019 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -5442,22 +5442,3 @@ 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 6491b164742..22156c0a13c 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -27,6 +27,7 @@
#include "BLI_string.h"
#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
#include "DNA_customdata_types.h"
#include "DNA_object_types.h"
@@ -315,7 +316,6 @@ static int palette_extract_img_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
bool done = false;
- int totpal = 0;
SpaceImage *sima = CTX_wm_space_image(C);
Image *image = sima->image;
@@ -327,21 +327,20 @@ static int palette_extract_img_exec(bContext *C, wmOperator *op)
ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
if (ibuf->rect) {
- const int maxpixel = (ibuf->x * ibuf->y) - 1;
-
/* Extract all colors. */
- for (int v = maxpixel; v != 0; v--) {
- 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;
- col[1] = truncf(col[1] * range) / range;
- col[2] = truncf(col[2] * range) / range;
-
- uint key = rgb_to_cpack(col[0], col[1], col[2]);
- if (!BLI_ghash_haskey(color_table, POINTER_FROM_INT(key))) {
- BLI_ghash_insert(color_table, POINTER_FROM_INT(key), POINTER_FROM_INT(key));
+ for (int row = 0; row < ibuf->y; row++) {
+ for (int col = 0; col < ibuf->x; col++) {
+ float color[4];
+ IMB_sampleImageAtLocation(ibuf, (float)col, (float)row, false, color);
+ const float range = pow(10.0f, threshold);
+ color[0] = truncf(color[0] * range) / range;
+ color[1] = truncf(color[1] * range) / range;
+ color[2] = truncf(color[2] * range) / range;
+
+ uint key = rgb_to_cpack(color[0], color[1], color[2]);
+ if (!BLI_ghash_haskey(color_table, POINTER_FROM_INT(key))) {
+ BLI_ghash_insert(color_table, POINTER_FROM_INT(key), POINTER_FROM_INT(key));
+ }
}
}
@@ -353,7 +352,7 @@ static int palette_extract_img_exec(bContext *C, wmOperator *op)
BKE_image_release_ibuf(image, ibuf, lock);
if (done) {
- BKE_reportf(op->reports, RPT_INFO, "Palette created with %d swatches", totpal);
+ BKE_reportf(op->reports, RPT_INFO, "Palette created");
}
return OPERATOR_FINISHED;
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 173c8135f96..836e2c794ab 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -597,6 +597,9 @@ void bilinear_interpolation_color_wrap(
void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3]);
void IMB_alpha_under_color_byte(unsigned char *rect, int x, int y, float backcol[3]);
+void IMB_sampleImageAtLocation(
+ struct ImBuf *ibuf, float x, float y, bool make_linear_rgb, float color[4]);
+
/**
*
* \attention defined in readimage.c
diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c
index ec03a0a07b8..0b2e2466c58 100644
--- a/source/blender/imbuf/intern/imageprocess.c
+++ b/source/blender/imbuf/intern/imageprocess.c
@@ -37,6 +37,7 @@
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
+#include "IMB_colormanagement.h"
#include <math.h>
/* Only this one is used liberally here, and in imbuf */
@@ -493,3 +494,19 @@ void IMB_alpha_under_color_byte(unsigned char *rect, int x, int y, float backcol
cp += 4;
}
}
+
+/* Sample pixel of image using NEAREST method. */
+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);
+ }
+ else {
+ unsigned char byte_color[4];
+ nearest_interpolation_color(ibuf, byte_color, NULL, 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);
+ }
+ }
+}
More information about the Bf-blender-cvs
mailing list