@@ -239,7 +239,7 @@ internal val SRC_OVER_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
239
239
if (top.color == Color.TRANSPARENT) {
240
240
bot.copy(Color.TRANSPARENT)
241
241
} else {
242
-
val color = Color.color(
242
+
val color = newColor(
243
243
top.R + bot.R * (1 - top.R),
244
244
top.G + bot.G * (1 - top.G),
245
245
top.B + bot.B * (1 - top.B),
@@ -254,7 +254,7 @@ internal val SRC_ATOP_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
254
254
if (top.color == Color.TRANSPARENT) {
255
255
bot.copy(Color.TRANSPARENT)
256
256
} else {
257
-
val color = Color.color(
257
+
val color = newColor(
258
258
top.R * bot.A + bot.R * (1 - top.R),
259
259
top.G * bot.A + bot.G * (1 - top.G),
260
260
top.B * bot.A + bot.B * (1 - top.B),
@@ -269,7 +269,7 @@ internal val ADD_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
269
269
if (top.color == Color.TRANSPARENT) {
270
270
bot.copy(Color.TRANSPARENT)
271
271
} else {
272
-
val color = Color.color(
272
+
val color = newColor(
273
273
minOf(1.0, bot.color.red + top.color.red),
274
274
minOf(1.0, bot.color.green + top.color.green),
275
275
minOf(1.0, bot.color.blue + top.color.blue),
@@ -284,7 +284,7 @@ internal val MULTIPLY_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
284
284
if (top.color == Color.TRANSPARENT) {
285
285
bot.copy(Color.TRANSPARENT)
286
286
} else {
287
-
val color = Color.color(
287
+
val color = newColor(
288
288
top.R * bot.R,
289
289
top.G * bot.G,
290
290
top.B * bot.B,
@@ -299,7 +299,7 @@ internal val SCREEN_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
299
299
if (top.color == Color.TRANSPARENT) {
300
300
bot.copy(Color.TRANSPARENT)
301
301
} else {
302
-
val color = Color.color(
302
+
val color = newColor(
303
303
1 - (1 - top.R) * (1 - bot.R),
304
304
1 - (1 - top.G) * (1 - bot.G),
305
305
1 - (1 - top.B) * (1 - bot.B),
@@ -336,7 +336,7 @@ internal val OVERLAY_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
336
336
1 - 2 * (1 - bot.B) * (1 - top.B)
337
337
}
338
338
339
-
val color = Color.color(
339
+
val color = newColor(
340
340
r,
341
341
g,
342
342
b,
@@ -351,7 +351,7 @@ internal val DARKEN_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
351
351
if (top.color == Color.TRANSPARENT) {
352
352
bot.copy(Color.TRANSPARENT)
353
353
} else {
354
-
val color = Color.color(
354
+
val color = newColor(
355
355
min(top.R, bot.R),
356
356
min(top.G, bot.G),
357
357
min(top.B, bot.B),
@@ -366,7 +366,7 @@ internal val LIGHTEN_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
366
366
if (top.color == Color.TRANSPARENT) {
367
367
bot.copy(Color.TRANSPARENT)
368
368
} else {
369
-
val color = Color.color(
369
+
val color = newColor(
370
370
max(top.R, bot.R),
371
371
max(top.G, bot.G),
372
372
max(top.B, bot.B),
@@ -381,7 +381,7 @@ internal val COLOR_DODGE_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
381
381
if (top.color == Color.TRANSPARENT) {
382
382
bot.copy(Color.TRANSPARENT)
383
383
} else {
384
-
val color = Color.color(
384
+
val color = newColor(
385
385
bot.R / (1 - top.R),
386
386
bot.G / (1 - top.G),
387
387
bot.B / (1 - top.B),
@@ -396,7 +396,7 @@ internal val COLOR_BURN_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
396
396
if (top.color == Color.TRANSPARENT) {
397
397
bot.copy(Color.TRANSPARENT)
398
398
} else {
399
-
val color = Color.color(
399
+
val color = newColor(
400
400
1 - ((1 - bot.R) / top.R),
401
401
1 - ((1 - bot.G) / top.G),
402
402
1 - ((1 - bot.B) / top.B),
@@ -428,7 +428,7 @@ internal val SOFT_LIGHT_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
428
428
429
429
val b = (1 - 2 * top.B) * bot.B * bot.B + 2 * top.B * bot.B
430
430
431
-
val color = Color.color(
431
+
val color = newColor(
432
432
r,
433
433
g,
434
434
b,
@@ -444,7 +444,7 @@ internal val DIFFERENCE_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
444
444
bot.copy(Color.TRANSPARENT)
445
445
} else {
446
446
447
-
val color = Color.color(
447
+
val color = newColor(
448
448
abs(top.R - bot.R),
449
449
abs(top.G - bot.G),
450
450
abs(top.B - bot.B),
@@ -460,7 +460,7 @@ internal val EXCLUSION_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
460
460
bot.copy(Color.TRANSPARENT)
461
461
} else {
462
462
463
-
val color = Color.color(
463
+
val color = newColor(
464
464
top.R + bot.R - 2 * top.R * bot.R,
465
465
top.G + bot.G - 2 * top.G * bot.G,
466
466
top.B + bot.B - 2 * top.B * bot.B,
@@ -475,7 +475,7 @@ internal val RED_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
475
475
if (top.color == Color.TRANSPARENT) {
476
476
bot.copy(Color.TRANSPARENT)
477
477
} else {
478
-
val color = Color.color(
478
+
val color = newColor(
479
479
top.R,
480
480
bot.G,
481
481
bot.B,
@@ -490,7 +490,7 @@ internal val GREEN_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
490
490
if (top.color == Color.TRANSPARENT) {
491
491
bot.copy(Color.TRANSPARENT)
492
492
} else {
493
-
val color = Color.color(
493
+
val color = newColor(
494
494
bot.R,
495
495
top.G,
496
496
bot.B,
@@ -505,7 +505,7 @@ internal val BLUE_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
505
505
if (top.color == Color.TRANSPARENT) {
506
506
bot.copy(Color.TRANSPARENT)
507
507
} else {
508
-
val color = Color.color(
508
+
val color = newColor(
509
509
bot.R,
510
510
bot.G,
511
511
top.B,
@@ -516,6 +516,15 @@ internal val BLUE_BLEND: (Pixel, Pixel) -> Pixel = { bot, top ->
516
516
}
517
517
}
518
518
519
+
private fun newColor(r: Double, g: Double, b: Double, a: Double): Color {
520
+
return Color.color(
521
+
max(0.0, min(1.0, r)),
522
+
max(0.0, min(1.0, g)),
523
+
max(0.0, min(1.0, b)),
524
+
max(0.0, min(1.0, a))
525
+
)
526
+
}
527
+
519
528
/**
520
529
* @return pixel at given [x] and [y]
521
530
*/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4