Skip to content

Commit

Permalink
AirbrushTool: simplify code for Spray; make it work with alpha select…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
dsizzle committed Nov 4, 2023
1 parent a77b587 commit 4c47833
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions artpaint/tools/AirBrushTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ AirBrushTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint)
int32 step_factor = max_c(1.0, fToolSettings.size / 5);
while (coordinate_reader->GetPoint(point, step_factor) == B_OK) {
the_script->AddPoint(point);

float half_size = fToolSettings.size / 2;
// we should only consider points that are inside this rectangle
rc = BRect(point.x - half_size, point.y - half_size, point.x + half_size,
Expand All @@ -154,39 +154,25 @@ AirBrushTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint)
|| selection->ContainsPoint(left + x, top + y))) {
float change = (half_size - distance) / half_size;
change *= ((float)fToolSettings.pressure) / 100.0;
change *= 32768;

// This is experimental for doing a real transparency
// Seems to work quite well
union color_conversion color1, color2, color3, color4;
color1.word = drawer->GetPixel(left + x, top + y);
color2.word = drawer->GetPixel(right - x, top + y);
color3.word = drawer->GetPixel(left + x, bottom - y);
color4.word = drawer->GetPixel(right - x, bottom - y);
if (color1.bytes[3] == 0x00)
color1.word = clear_color.word;
if (color2.bytes[3] == 0x00)
color2.word = clear_color.word;
if (color3.bytes[3] == 0x00)
color3.word = clear_color.word;
if (color4.bytes[3] == 0x00)
color4.word = clear_color.word;
drawer->SetPixel(left + x, top + y,
mix_2_pixels_fixed(
target_color, color1.word, (uint32)(change)),
selection, NULL);
change *= 255;
float sel_alpha = selection->Value(left + x, top + y) / 255.;
if (selection->IsEmpty())
sel_alpha = 1.0;

union color_conversion target2;
target2.word = 0xffffff;
target2.bytes[3] = change * sel_alpha;
if (x < width && y < height)
drawer->SetPixel(left + x, top + y,
target2.word, selection);
drawer->SetPixel(right - x, top + y,
mix_2_pixels_fixed(
target_color, color2.word, (uint32)(change)),
selection, NULL);
target2.word, selection);
drawer->SetPixel(left + x, bottom - y,
mix_2_pixels_fixed(
target_color, color3.word, (uint32)(change)),
selection, NULL);
drawer->SetPixel(right - x, bottom - y,
mix_2_pixels_fixed(
target_color, color4.word, (uint32)(change)),
selection, NULL);
target2.word, selection);
if (x < width && y < height)
drawer->SetPixel(right - x, bottom - y,
target2.word, selection);

}
}
}
Expand All @@ -195,7 +181,8 @@ AirBrushTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint)
prev_point = point;
imageUpdater->AddRect(rc);
SetLastUpdatedRect(LastUpdatedRect() | rc);
BitmapUtilities::CompositeBitmapOnSource(bitmap, srcBuffer, tmpBuffer, rc);
BitmapUtilities::CompositeBitmapOnSource(bitmap, srcBuffer, tmpBuffer, rc,
src_over_fixed, target_color);
}
} else if (fToolSettings.mode == HS_SPRAY_MODE) { // Do the spray
RandomNumberGenerator* generator = new RandomNumberGenerator(0, 10000);
Expand Down

0 comments on commit 4c47833

Please sign in to comment.