Fix #130271: Flip the color threshold interpretation to match Blender 4.2

The color threshold in Blender 4.2 is interpreted to mean that colors above the
threshold are "background" and colors below threshold are "foreground".
This is arbitrary but works well for black-on-white drawings.

Pull Request: https://projects.blender.org/blender/blender/pulls/131324
This commit is contained in:
Lukas Tönne
2024-12-05 10:32:46 +01:00
committed by Falk David
parent 1148df0f5c
commit 03f2f1b5b3
2 changed files with 8 additions and 2 deletions

View File

@@ -179,9 +179,11 @@ static int ensure_background_material(Main *bmain, Object *ob, const StringRefNu
static bke::CurvesGeometry grease_pencil_trace_image(TraceJob &trace_job, const ImBuf &ibuf)
{
/* Trace the image. */
/* Trace the image.
* Note: Colors above threshold are interpreted as "background". This works well for images with
* black-on-white drawings, but is quite arbitrary. */
potrace_bitmap_t *bm = image_trace::image_to_bitmap(ibuf, [&](const ColorGeometry4f &color) {
return math::average(float3(color.r, color.g, color.b)) * color.a > trace_job.threshold;
return math::average(float3(color.r, color.g, color.b)) * color.a <= trace_job.threshold;
});
image_trace::TraceParams params;

View File

@@ -98,6 +98,10 @@ bke::CurvesGeometry trace_to_curves(const Trace &trace,
/* Inline functions. */
/**
* Convert an image to a potrace bitmap representing foreground and background regions.
* \param fn Function that returns true if the given color is a foreground color.
*/
template<typename ThresholdFn> Bitmap *image_to_bitmap(const ImBuf &ibuf, ThresholdFn fn)
{
#ifdef WITH_POTRACE