From dd6966e615d81c3bb904eb83e3a8d032c7494f70 Mon Sep 17 00:00:00 2001 From: Dale Cieslak Date: Fri, 3 Nov 2023 21:26:49 -0700 Subject: [PATCH] Layer/ImageView: respect alpha value when cutting/copying/deleting --- artpaint/layers/Layer.cpp | 9 +++++++-- artpaint/paintwindow/ImageView.cpp | 13 +++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/artpaint/layers/Layer.cpp b/artpaint/layers/Layer.cpp index 0c6759aa..fb933a68 100644 --- a/artpaint/layers/Layer.cpp +++ b/artpaint/layers/Layer.cpp @@ -155,8 +155,13 @@ Layer::Clear(rgb_color color) int32 bpr = fLayerData->BytesPerRow() / 4; for (int32 y = top; y <= bottom; ++y) { for (int32 x = left; x <= right; ++x) { - if (selection->ContainsPoint(x, y)) - *(bits + x + y * bpr) = color_bits; + if (selection->ContainsPoint(x, y)) { + union color_conversion norm_color; + norm_color.word = color_bits; + norm_color.bytes[3] = selection->Value(x, y); + + *(bits + x + y * bpr) = dst_out_fixed(*(bits + x + y * bpr), norm_color.word); + } } } } diff --git a/artpaint/paintwindow/ImageView.cpp b/artpaint/paintwindow/ImageView.cpp index dee69c99..a5f8db94 100644 --- a/artpaint/paintwindow/ImageView.cpp +++ b/artpaint/paintwindow/ImageView.cpp @@ -2353,10 +2353,7 @@ ImageView::DoCopyOrCut(int32 layers, bool cut) BBitmap* to_be_archived = new BBitmap(bounds, B_RGBA32, 0); // stargater, Pete uint32* target_bits = (uint32*)to_be_archived->Bits(); int32 bits_length = to_be_archived->BitsLength() / 4; - union { - uint8 bytes[4]; - uint32 word; - } color; + union color_conversion color, norm_color; color.bytes[0] = 0xFF; color.bytes[1] = 0xFF; color.bytes[2] = 0xFF; @@ -2376,9 +2373,13 @@ ImageView::DoCopyOrCut(int32 layers, bool cut) for (int32 y = top; y <= bottom; y++) { for (int32 x = left; x <= right; x++) { - if (selection->ContainsPoint(x, y)) - *target_bits = *(source_bits + x + y * source_bpr); + if (selection->ContainsPoint(x, y)) { + norm_color.word = color.word; + norm_color.bytes[3] = 0xFF - selection->Value(x, y); + *target_bits = + dst_out_fixed(*(source_bits + x + y * source_bpr), norm_color.word); + } target_bits++; } }