Core: Make _mix public

This commit is contained in:
Vicki Pfau 2020-11-21 19:28:36 -08:00
parent ce97e265a3
commit 0b0a70d9b7
3 changed files with 67 additions and 69 deletions

View File

@ -73,6 +73,68 @@ static inline color_t mColorFrom555(uint16_t value) {
#endif
return color;
}
ATTRIBUTE_UNUSED static unsigned mColorMix5Bit(int weightA, unsigned colorA, int weightB, unsigned colorB) {
unsigned c = 0;
unsigned a, b;
#ifdef COLOR_16_BIT
#ifdef COLOR_5_6_5
a = colorA & 0xF81F;
b = colorB & 0xF81F;
a |= (colorA & 0x7C0) << 16;
b |= (colorB & 0x7C0) << 16;
c = ((a * weightA + b * weightB) / 16);
if (c & 0x08000000) {
c = (c & ~0x0FC00000) | 0x07C00000;
}
if (c & 0x0020) {
c = (c & ~0x003F) | 0x001F;
}
if (c & 0x10000) {
c = (c & ~0x1F800) | 0xF800;
}
c = (c & 0xF81F) | ((c >> 16) & 0x07C0);
#else
a = colorA & 0x7C1F;
b = colorB & 0x7C1F;
a |= (colorA & 0x3E0) << 16;
b |= (colorB & 0x3E0) << 16;
c = ((a * weightA + b * weightB) / 16);
if (c & 0x04000000) {
c = (c & ~0x07E00000) | 0x03E00000;
}
if (c & 0x0020) {
c = (c & ~0x003F) | 0x001F;
}
if (c & 0x8000) {
c = (c & ~0xF800) | 0x7C00;
}
c = (c & 0x7C1F) | ((c >> 16) & 0x03E0);
#endif
#else
a = colorA & 0xFF;
b = colorB & 0xFF;
c |= ((a * weightA + b * weightB) / 16) & 0x1FF;
if (c & 0x00000100) {
c = 0x000000FF;
}
a = colorA & 0xFF00;
b = colorB & 0xFF00;
c |= ((a * weightA + b * weightB) / 16) & 0x1FF00;
if (c & 0x00010000) {
c = (c & 0x000000FF) | 0x0000FF00;
}
a = colorA & 0xFF0000;
b = colorB & 0xFF0000;
c |= ((a * weightA + b * weightB) / 16) & 0x1FF0000;
if (c & 0x01000000) {
c = (c & 0x0000FFFF) | 0x00FF0000;
}
#endif
return c;
}
#endif
struct blip_t;

View File

@ -31,8 +31,6 @@ void GBAVideoSoftwareRendererPostprocessSprite(struct GBAVideoSoftwareRenderer*
static inline unsigned _brighten(unsigned color, int y);
static inline unsigned _darken(unsigned color, int y);
static unsigned _mix(int weightA, unsigned colorA, int weightB, unsigned colorB);
// We stash the priority on the top bits so we can do a one-operator comparison
// The lower the number, the higher the priority, and sprites take precedence over backgrounds
@ -41,7 +39,7 @@ static unsigned _mix(int weightA, unsigned colorA, int weightB, unsigned colorB)
static inline void _compositeBlendObjwin(struct GBAVideoSoftwareRenderer* renderer, uint32_t* pixel, uint32_t color, uint32_t current) {
if (color >= current) {
if (current & FLAG_TARGET_1 && color & FLAG_TARGET_2) {
color = _mix(renderer->blda, current, renderer->bldb, color);
color = mColorMix5Bit(renderer->blda, current, renderer->bldb, color);
} else {
color = current & (0x00FFFFFF | FLAG_REBLEND | FLAG_OBJWIN);
}
@ -54,7 +52,7 @@ static inline void _compositeBlendObjwin(struct GBAVideoSoftwareRenderer* render
static inline void _compositeBlendNoObjwin(struct GBAVideoSoftwareRenderer* renderer, uint32_t* pixel, uint32_t color, uint32_t current) {
if (color >= current) {
if (current & FLAG_TARGET_1 && color & FLAG_TARGET_2) {
color = _mix(renderer->blda, current, renderer->bldb, color);
color = mColorMix5Bit(renderer->blda, current, renderer->bldb, color);
} else {
color = current & (0x00FFFFFF | FLAG_REBLEND | FLAG_OBJWIN);
}
@ -234,66 +232,4 @@ static inline unsigned _darken(unsigned color, int y) {
return c;
}
static unsigned _mix(int weightA, unsigned colorA, int weightB, unsigned colorB) {
unsigned c = 0;
unsigned a, b;
#ifdef COLOR_16_BIT
#ifdef COLOR_5_6_5
a = colorA & 0xF81F;
b = colorB & 0xF81F;
a |= (colorA & 0x7C0) << 16;
b |= (colorB & 0x7C0) << 16;
c = ((a * weightA + b * weightB) / 16);
if (c & 0x08000000) {
c = (c & ~0x0FC00000) | 0x07C00000;
}
if (c & 0x0020) {
c = (c & ~0x003F) | 0x001F;
}
if (c & 0x10000) {
c = (c & ~0x1F800) | 0xF800;
}
c = (c & 0xF81F) | ((c >> 16) & 0x07C0);
#else
a = colorA & 0x7C1F;
b = colorB & 0x7C1F;
a |= (colorA & 0x3E0) << 16;
b |= (colorB & 0x3E0) << 16;
c = ((a * weightA + b * weightB) / 16);
if (c & 0x04000000) {
c = (c & ~0x07E00000) | 0x03E00000;
}
if (c & 0x0020) {
c = (c & ~0x003F) | 0x001F;
}
if (c & 0x8000) {
c = (c & ~0xF800) | 0x7C00;
}
c = (c & 0x7C1F) | ((c >> 16) & 0x03E0);
#endif
#else
a = colorA & 0xFF;
b = colorB & 0xFF;
c |= ((a * weightA + b * weightB) / 16) & 0x1FF;
if (c & 0x00000100) {
c = 0x000000FF;
}
a = colorA & 0xFF00;
b = colorB & 0xFF00;
c |= ((a * weightA + b * weightB) / 16) & 0x1FF00;
if (c & 0x00010000) {
c = (c & 0x000000FF) | 0x0000FF00;
}
a = colorA & 0xFF0000;
b = colorB & 0xFF0000;
c |= ((a * weightA + b * weightB) / 16) & 0x1FF0000;
if (c & 0x01000000) {
c = (c & 0x0000FFFF) | 0x00FF0000;
}
#endif
return c;
}
#endif

View File

@ -640,7 +640,7 @@ static void GBAVideoSoftwareRendererDrawScanline(struct GBAVideoRenderer* render
for (; x < end; ++x) {
uint32_t color = softwareRenderer->row[x];
if (color & FLAG_TARGET_1) {
softwareRenderer->row[x] = _mix(softwareRenderer->bldb, backdrop, softwareRenderer->blda, color);
softwareRenderer->row[x] = mColorMix5Bit(softwareRenderer->bldb, backdrop, softwareRenderer->blda, color);
}
}
}
@ -975,8 +975,8 @@ static void _updatePalettes(struct GBAVideoSoftwareRenderer* renderer) {
if (highlightAmount) {
for (i = 0; i < 512; ++i) {
renderer->highlightPalette[i] = _mix(0x10 - highlightAmount, renderer->normalPalette[i], highlightAmount, renderer->d.highlightColor);
renderer->highlightVariantPalette[i] = _mix(0x10 - highlightAmount, renderer->variantPalette[i], highlightAmount, renderer->d.highlightColor);
renderer->highlightPalette[i] = mColorMix5Bit(0x10 - highlightAmount, renderer->normalPalette[i], highlightAmount, renderer->d.highlightColor);
renderer->highlightVariantPalette[i] = mColorMix5Bit(0x10 - highlightAmount, renderer->variantPalette[i], highlightAmount, renderer->d.highlightColor);
}
}
}