Skip to content

Commit 5f0f3db

Browse files
committed
fix MixColor again
1 parent f96eb1e commit 5f0f3db

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

common/color.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ inline OverDriveColor MixColors(OverDriveColor a, OverDriveColor b, int x, int s
352352
inline RGBA MixColors(RGBA a, RGBA b, int x, int shift) {
353353
return RGBA( (a.c * ((1 << shift) - x) + b.c * x) >> shift,
354354
x > (1 << (shift - 1)) ? b.overdrive : a.overdrive,
355-
(a.alpha * ((1 << shift) - x) + b.alpha * x + 0x7fff) >> shift);
355+
(a.alpha * ((1 << shift) - x) + b.alpha * x + ((1<<shift) - 1)) >> shift);
356356
}
357357

358358
// Paint over operators

common/tests.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,13 @@ std::set<int> N16;
509509
std::set<int> N15;
510510
int64_t tests = 0;
511511

512+
#define CHECK_RET(EXTRAOUT) do { \
513+
if (ret.c.r > ret.alpha * 2 || ret.alpha > 32768) { \
514+
STDOUT << " ret = " << ret << " @ " << __LINE__ << " " << EXTRAOUT << "\n"; \
515+
exit(1); \
516+
} \
517+
} while (0)
518+
512519
void add2set(int i) {
513520
if (i < 0) return;
514521
if (i > 65535) return;
@@ -520,32 +527,29 @@ template<class T1, class T2>
520527
void runPaintTest(T1 A, T2 B) {
521528
RGBA ret = A << B;
522529
tests++;
523-
if (ret.c.r > ret.alpha * 2) {
524-
STDOUT << "A = " << A << "B = " << B << "\n";
525-
CHECK_LE(ret.c.r, ret.alpha * 2);
526-
}
530+
CHECK_RET("A = " << A << "B = " << B);
527531

528532
// Test mixing
529533
for (int d : N15) {
530534
tests++;
531535
ret = MixColors(A, B, d, 15);
532-
if (ret.c.r > ret.alpha * 2) {
533-
STDOUT << "A = " << A << " B = " << B << " mix = " << d << "\n";
534-
CHECK_LE(ret.c.r, ret.alpha * 2);
535-
}
536+
CHECK_RET("A = " << A << " B = " << B << " mix = " << d);
537+
}
538+
539+
// Test mixing
540+
for (int d : N15) {
541+
tests++;
542+
ret = MixColors(A, B, d>>1, 14);
543+
CHECK_RET("A = " << A << " B = " << B << " mix = " << (d >> 1));
536544
}
537545
}
538546

539547
template<class T1>
540548
void runPaintTest(T1 A) {
541549
for (int d : N15) {
542-
543550
tests++;
544551
RGBA ret = A * d;
545-
if (ret.c.r > ret.alpha * 2) {
546-
STDOUT << "A = " << A << " mult = " << d << "\n";
547-
CHECK_LE(ret.c.r, ret.alpha * 2);
548-
}
552+
CHECK_RET("A = " << A << " mult = " << d);
549553

550554
for (int c : N16) {
551555
RGBA_um B(Color16(c,c,c), false, d);

0 commit comments

Comments
 (0)