Skip to content

Commit

Permalink
Layer/ImageView: respect alpha value when cutting/copying/deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
dsizzle committed Nov 4, 2023
1 parent 8973a5f commit dd6966e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 7 additions & 2 deletions artpaint/layers/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions artpaint/paintwindow/ImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++;
}
}
Expand Down

0 comments on commit dd6966e

Please sign in to comment.