diff --git a/extern/drawdance/libengine/dpengine/brush_engine.c b/extern/drawdance/libengine/dpengine/brush_engine.c index af2036e8f..9076bb0ef 100644 --- a/extern/drawdance/libengine/dpengine/brush_engine.c +++ b/extern/drawdance/libengine/dpengine/brush_engine.c @@ -596,13 +596,13 @@ static void get_color_mypaint_pigment(MyPaintSurface2 *self, float x, float y, DP_LayerContent *lc = be->lc; if (lc) { int diameter = DP_min_int(DP_float_to_int(radius * 2.0f + 0.5f), 255); - DP_UPixel15 color = DP_layer_content_sample_color_at( + DP_UPixelFloat color = DP_layer_content_sample_color_at( lc, be->stamp_buffer, DP_float_to_int(x + 0.5f), DP_float_to_int(y + 0.5f), diameter, &be->last_diameter); - *color_r = DP_channel15_to_float(color.r); - *color_g = DP_channel15_to_float(color.g); - *color_b = DP_channel15_to_float(color.b); - *color_a = DP_channel15_to_float(color.a); + *color_r = color.r; + *color_g = color.g; + *color_b = color.b; + *color_a = color.a; } else { *color_r = 0.0f; @@ -940,9 +940,9 @@ static DP_UPixelFloat sample_classic_smudge(DP_BrushEngine *be, float y, float pressure) { int diameter = get_classic_smudge_diameter(cb, pressure); - return DP_upixel15_to_float(DP_layer_content_sample_color_at( + return DP_layer_content_sample_color_at( lc, be->stamp_buffer, DP_float_to_int(x), DP_float_to_int(y), diameter, - &be->last_diameter)); + &be->last_diameter); } static void update_classic_smudge(DP_BrushEngine *be, DP_ClassicBrush *cb, diff --git a/extern/drawdance/libengine/dpengine/layer_content.c b/extern/drawdance/libengine/dpengine/layer_content.c index 7c00a1a30..b40192a49 100644 --- a/extern/drawdance/libengine/dpengine/layer_content.c +++ b/extern/drawdance/libengine/dpengine/layer_content.c @@ -355,7 +355,7 @@ bool DP_layer_content_pick_at(DP_LayerContent *lc, int x, int y, return false; } -static DP_UPixel15 sample_dab_color(DP_LayerContent *lc, DP_BrushStamp stamp) +static DP_UPixelFloat sample_dab_color(DP_LayerContent *lc, DP_BrushStamp stamp) { uint16_t *weights = stamp.data; int diameter = stamp.diameter; @@ -405,7 +405,7 @@ static DP_UPixel15 sample_dab_color(DP_LayerContent *lc, DP_BrushStamp stamp) float required_alpha = DP_int_to_float(DP_square_int(diameter) * 30) / (float)DP_BIT15; if (alpha < required_alpha) { - return DP_upixel15_zero(); + return DP_upixel_float_zero(); } // Calculate final average @@ -419,23 +419,23 @@ static DP_UPixel15 sample_dab_color(DP_LayerContent *lc, DP_BrushStamp stamp) green = CLAMP(green / alpha, 0.0f, 1.0f); blue = CLAMP(blue / alpha, 0.0f, 1.0f); - return (DP_UPixel15){ - .b = DP_channel_float_to_15(blue), - .g = DP_channel_float_to_15(green), - .r = DP_channel_float_to_15(red), - .a = DP_channel_float_to_15(alpha), + return (DP_UPixelFloat){ + .b = blue, + .g = green, + .r = red, + .a = alpha, }; } -DP_UPixel15 DP_layer_content_sample_color_at(DP_LayerContent *lc, - uint16_t *stamp_buffer, int x, - int y, int diameter, - int *in_out_last_diameter) +DP_UPixelFloat DP_layer_content_sample_color_at(DP_LayerContent *lc, + uint16_t *stamp_buffer, int x, + int y, int diameter, + int *in_out_last_diameter) { if (x >= 0 && y >= 0 && x < lc->width && y < lc->height) { if (diameter < 2) { DP_Pixel15 pixel = DP_layer_content_pixel_at(lc, x, y); - return DP_pixel15_unpremultiply(pixel); + return DP_upixel15_to_float(DP_pixel15_unpremultiply(pixel)); } else { int last_diameter; @@ -452,7 +452,7 @@ DP_UPixel15 DP_layer_content_sample_color_at(DP_LayerContent *lc, } } else { - return DP_upixel15_zero(); + return DP_upixel_float_zero(); } } diff --git a/extern/drawdance/libengine/dpengine/layer_content.h b/extern/drawdance/libengine/dpengine/layer_content.h index 40adf9f75..8a738a20e 100644 --- a/extern/drawdance/libengine/dpengine/layer_content.h +++ b/extern/drawdance/libengine/dpengine/layer_content.h @@ -84,10 +84,10 @@ DP_Pixel15 DP_layer_content_pixel_at(DP_LayerContent *lc, int x, int y); bool DP_layer_content_pick_at(DP_LayerContent *lc, int x, int y, unsigned int *out_context_id); -DP_UPixel15 DP_layer_content_sample_color_at(DP_LayerContent *lc, - uint16_t *stamp_buffer, int x, - int y, int diameter, - int *in_out_last_diameter); +DP_UPixelFloat DP_layer_content_sample_color_at(DP_LayerContent *lc, + uint16_t *stamp_buffer, int x, + int y, int diameter, + int *in_out_last_diameter); DP_LayerList *DP_layer_content_sub_contents_noinc(DP_LayerContent *lc); diff --git a/extern/drawdance/libengine/dpengine/pixels.h b/extern/drawdance/libengine/dpengine/pixels.h index abaedc38e..52409869e 100644 --- a/extern/drawdance/libengine/dpengine/pixels.h +++ b/extern/drawdance/libengine/dpengine/pixels.h @@ -89,6 +89,7 @@ DP_UPixel15 DP_upixel8_to_15(DP_UPixel8 pixel); DP_UPixel8 DP_upixel15_to_8(DP_UPixel15 pixel); DP_UPixelFloat DP_upixel8_to_float(DP_UPixel8 pixel); DP_UPixelFloat DP_upixel15_to_float(DP_UPixel15 pixel); +DP_UPixelFloat DP_upixel15_to_float_round(DP_UPixel15 pixel); DP_UPixel8 DP_upixel_float_to_8(DP_UPixelFloat pixel); void DP_pixels8_to_15(DP_Pixel15 *dst, const DP_Pixel8 *src, int count); @@ -132,6 +133,12 @@ DP_INLINE DP_UPixel15 DP_upixel15_from_color(uint32_t color) return DP_upixel8_to_15(pixel); } +DP_INLINE DP_UPixelFloat DP_upixel_float_zero(void) +{ + DP_UPixelFloat pixel = {0.0f, 0.0f, 0.0f, 0.0f}; + return pixel; +} + DP_INLINE DP_UPixelFloat DP_upixel_float_from_color(uint32_t color) { DP_UPixel8 pixel = {color}; diff --git a/src/libclient/drawdance/layercontent.cpp b/src/libclient/drawdance/layercontent.cpp index d7a86b9e4..c435ba0bd 100644 --- a/src/libclient/drawdance/layercontent.cpp +++ b/src/libclient/drawdance/layercontent.cpp @@ -68,11 +68,11 @@ bool LayerContent::isNull() const QColor LayerContent::sampleColorAt( uint16_t *stampBuffer, int x, int y, int diameter, int &lastDiameter) const { - DP_UPixel15 pixel = DP_layer_content_sample_color_at( + DP_UPixelFloat pixel = DP_layer_content_sample_color_at( m_data, stampBuffer, x, y, diameter, &lastDiameter); - return QColor{ - DP_channel15_to_8(pixel.r), DP_channel15_to_8(pixel.g), - DP_channel15_to_8(pixel.b), DP_channel15_to_8(pixel.a)}; + QColor color; + color.setRgbF(pixel.r, pixel.g, pixel.b, pixel.a); + return color; } QImage LayerContent::toImage(const QRect &rect) const