Skip to content

Commit 76bbe50

Browse files
HiCaminohumdingerb
authored andcommitted
Make transparency faster by reducing snooze and only calculate y offset once per loop
- replace 3 mult per loop with one mult of real_y * bpr per loop - also fix math error so alpha of brush is range 0-1 instead of 0-255 which fixes look of the brush mode Fixes #689
1 parent 3054076 commit 76bbe50

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

artpaint/tools/TransparencyTool.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ TransparencyTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint)
147147
y_sqr = (int32)(point.y - rc.top - y);
148148
y_sqr *= y_sqr;
149149
int32 real_y = (int32)(rc.top + y);
150+
int32 real_y_times_bpr = real_y * bpr;
150151
int32 real_x;
151152
for (int32 x = 0; x < width + 1; x++) {
152153
x_dist = (int32)(point.x - rc.left - x);
@@ -155,26 +156,26 @@ TransparencyTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint)
155156
if (fToolSettings.use_current_brush == true) {
156157
union color_conversion brush_color;
157158
brush_color.word = *(brush_bits + x + y * brush_bpr);
158-
brush_val = brush_color.bytes[3];
159+
brush_val = brush_color.bytes[3] / 255.;
159160
}
160161
if ((fToolSettings.use_current_brush == true && brush_val > 0.0)
161162
|| (fToolSettings.use_current_brush == false
162163
&& sqrt_table[x_dist * x_dist + y_sqr] <= half_width)) {
163-
color.word = *(bits_origin + real_y * bpr + real_x);
164+
color.word = *(bits_origin + real_y_times_bpr + real_x);
164165
if (selection == NULL || selection->IsEmpty() == true
165166
|| selection->ContainsPoint(real_x, real_y)) {
166167

167168
uint8 diff = fabs(color.bytes[3] - transparency_value);
168-
uint8 step = (uint8)(ceil(diff * pressure * brush_val / 2));
169+
uint8 step = (uint8)(ceil(diff * pressure * brush_val));
169170

170171
if (color.bytes[3] < transparency_value) {
171172
color.bytes[3]
172173
= (uint8)min_c(color.bytes[3] + step, transparency_value);
173-
*(bits_origin + real_y * bpr + real_x) = color.word;
174+
*(bits_origin + real_y_times_bpr + real_x) = color.word;
174175
} else if (color.bytes[3] > transparency_value) {
175176
color.bytes[3]
176177
= (uint8)max_c(color.bytes[3] - step, transparency_value);
177-
*(bits_origin + real_y * bpr + real_x) = color.word;
178+
*(bits_origin + real_y_times_bpr + real_x) = color.word;
178179
}
179180
}
180181
}
@@ -184,7 +185,7 @@ TransparencyTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint)
184185
imageUpdater->AddRect(rc);
185186

186187
SetLastUpdatedRect(LastUpdatedRect() | rc);
187-
snooze(20 * 1000);
188+
snooze(500);
188189
}
189190
}
190191

0 commit comments

Comments
 (0)