[Bf-blender-cvs] [eb2b85de6c0] temp-lineart-contained: LineArt: Revert accidental changes
YimingWu
noreply at git.blender.org
Fri Nov 13 09:45:05 CET 2020
Commit: eb2b85de6c087b652ba1753e4b88ed6a2aee61ff
Author: YimingWu
Date: Fri Nov 13 10:35:00 2020 +0800
Branches: temp-lineart-contained
https://developer.blender.org/rBeb2b85de6c087b652ba1753e4b88ed6a2aee61ff
LineArt: Revert accidental changes
===================================================================
M source/blender/editors/sculpt_paint/paint_utils.c
M source/blender/editors/space_image/image_ops.c
===================================================================
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index 6139adaea1a..2484f382ed4 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -66,6 +66,7 @@
#include "RE_texture.h"
+#include "ED_image.h"
#include "ED_screen.h"
#include "ED_view3d.h"
@@ -458,8 +459,6 @@ void paint_sample_color(
Palette *palette = BKE_paint_palette(paint);
PaletteColor *color = NULL;
Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C));
- uint col;
- const uchar *cp;
CLAMP(x, 0, region->winx);
CLAMP(y, 0, region->winy);
@@ -474,12 +473,14 @@ void paint_sample_color(
palette->active_color = BLI_listbase_count(&palette->colors) - 1;
}
- if (CTX_wm_view3d(C) && texpaint_proj) {
+ SpaceImage *sima = CTX_wm_space_image(C);
+ const View3D *v3d = CTX_wm_view3d(C);
+
+ if (v3d && texpaint_proj) {
/* first try getting a color directly from the mesh faces if possible */
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = OBACT(view_layer);
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
- bool sample_success = false;
ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL);
@@ -539,8 +540,6 @@ void paint_sample_color(
ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, NULL);
if (ibuf && (ibuf->rect || ibuf->rect_float)) {
- sample_success = true;
-
u = u * ibuf->x;
v = v * ibuf->y;
@@ -568,6 +567,8 @@ void paint_sample_color(
BKE_brush_color_set(scene, br, rgba_f);
}
}
+ BKE_image_release_ibuf(image, ibuf, NULL);
+ return;
}
BKE_image_release_ibuf(image, ibuf, NULL);
@@ -575,28 +576,39 @@ void paint_sample_color(
}
}
}
+ }
+ else if (sima != NULL) {
+ /* Sample from the active image buffer. The sampled color is in
+ * Linear Scene Reference Space. */
+ float rgba_f[3];
+ bool is_data;
+ if (ED_space_image_color_sample(sima, region, (int[2]){x, y}, rgba_f, &is_data)) {
+ if (!is_data) {
+ linearrgb_to_srgb_v3_v3(rgba_f, rgba_f);
+ }
- if (!sample_success) {
- GPU_frontbuffer_read_pixels(
- x + region->winrct.xmin, y + region->winrct.ymin, 1, 1, 4, GPU_DATA_UNSIGNED_BYTE, &col);
- }
- else {
+ if (use_palette) {
+ copy_v3_v3(color->rgb, rgba_f);
+ }
+ else {
+ BKE_brush_color_set(scene, br, rgba_f);
+ }
return;
}
}
- else {
+
+ /* No sample found; sample directly from the GPU front buffer. */
+ {
+ float rgba_f[4];
GPU_frontbuffer_read_pixels(
- x + region->winrct.xmin, y + region->winrct.ymin, 1, 1, 4, GPU_DATA_UNSIGNED_BYTE, &col);
- }
- cp = (uchar *)&col;
+ x + region->winrct.xmin, y + region->winrct.ymin, 1, 1, 4, GPU_DATA_FLOAT, &rgba_f);
- if (use_palette) {
- rgb_uchar_to_float(color->rgb, cp);
- }
- else {
- float rgba_f[3];
- rgb_uchar_to_float(rgba_f, cp);
- BKE_brush_color_set(scene, br, rgba_f);
+ if (use_palette) {
+ copy_v3_v3(color->rgb, rgba_f);
+ }
+ else {
+ BKE_brush_color_set(scene, br, rgba_f);
+ }
}
}
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 69e9c975bd1..0fa48059cdc 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -3037,8 +3037,12 @@ void IMAGE_OT_unpack(wmOperatorType *ot)
* \{ */
/* Returns color in linear space, matching ED_space_node_color_sample(). */
-bool ED_space_image_color_sample(SpaceImage *sima, ARegion *region, int mval[2], float r_col[3])
+bool ED_space_image_color_sample(
+ SpaceImage *sima, ARegion *region, int mval[2], float r_col[3], bool *r_is_data)
{
+ if (r_is_data) {
+ *r_is_data = false;
+ }
if (sima->image == NULL) {
return false;
}
@@ -3076,6 +3080,10 @@ bool ED_space_image_color_sample(SpaceImage *sima, ARegion *region, int mval[2],
}
}
+ if (r_is_data) {
+ *r_is_data = (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) != 0;
+ }
+
ED_space_image_release_buffer(sima, ibuf, lock);
return ret;
}
More information about the Bf-blender-cvs
mailing list