diff options
Diffstat (limited to 'src/image_processing_effects.c')
-rw-r--r-- | src/image_processing_effects.c | 254 |
1 files changed, 128 insertions, 126 deletions
diff --git a/src/image_processing_effects.c b/src/image_processing_effects.c index cbd8b9b37..fa6867f2c 100644 --- a/src/image_processing_effects.c +++ b/src/image_processing_effects.c @@ -51,7 +51,9 @@ static u16 QuantizePixel_GrayscaleSmall(u16*); static u16 QuantizePixel_Grayscale(u16*); static u16 QuantizePixel_PrimaryColors(u16*); -extern const u8 gPointillismPoints[][3]; +#define MAX_DIMENSION 64 + +#include "data/pointillism_points.h" void ApplyImageProcessingEffects(struct ImageProcessingContext *context) { @@ -129,11 +131,11 @@ static void ApplyImageEffect_RedChannelGrayscale(u8 delta) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) { // Gets the grayscale value, based on the pixel's red channel. // Also adds a delta to skew lighter or darker. - u8 grayValue = (31 & *pixel); + u8 grayValue = (*pixel & RGB_RED); grayValue += delta; if (grayValue > 31) grayValue = 31; @@ -154,9 +156,9 @@ static void ApplyImageEffect_RedChannelGrayscaleHighlight(u8 highlight) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) { - u8 grayValue = (31 & *pixel); + u8 grayValue = (*pixel & RGB_RED); if (grayValue > 31 - highlight) grayValue = 31 - (highlight >> 1); @@ -169,7 +171,7 @@ static void ApplyImageEffect_RedChannelGrayscaleHighlight(u8 highlight) static void ApplyImageEffect_Pointillism(void) { u32 i; - for (i = 0; i < 3200; i++) + for (i = 0; i < ARRAY_COUNT(sPointillismPoints); i++) AddPointillismPoints(i); } @@ -183,7 +185,7 @@ static void ApplyImageEffect_Grayscale(void) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) *pixel = ConvertColorToGrayscale(pixel); } } @@ -203,7 +205,7 @@ static void ApplyImageEffect_Blur(void) pixel += gCanvasWidth; while (j < gCanvasRowEnd - 1) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) { *pixel = QuantizePixel_Blur(&prevPixel, pixel, pixel + gCanvasWidth); prevPixel = *pixel; @@ -225,7 +227,7 @@ static void ApplyImageEffect_PersonalityColor(u8 personality) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) *pixel = QuantizePixel_PersonalityColor(pixel, personality); } } @@ -241,7 +243,7 @@ static void ApplyImageEffect_BlackAndWhite(void) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) *pixel = QuantizePixel_BlackAndWhite(pixel); } } @@ -293,7 +295,7 @@ static void ApplyImageEffect_Invert(void) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) *pixel = QuantizePixel_Invert(pixel); } } @@ -307,55 +309,55 @@ static void ApplyImageEffect_Shimmer(void) // First, invert all of the colors. pixel = gCanvasPixels; - for (i = 0; i < 64; i++) + for (i = 0; i < MAX_DIMENSION; i++) { - for (j = 0; j < 64; j++, pixel++) + for (j = 0; j < MAX_DIMENSION; j++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) *pixel = QuantizePixel_Invert(pixel); } } // Blur the pixels twice. - for (j = 0; j < 64; j++) + for (j = 0; j < MAX_DIMENSION; j++) { pixel = &gCanvasPixels[j]; prevPixel = *pixel; - *pixel = 0x8000; - for (i = 1, pixel += 64; i < 63; i++, pixel += 64) + *pixel = RGB_ALPHA; + for (i = 1, pixel += MAX_DIMENSION; i < MAX_DIMENSION - 1; i++, pixel += MAX_DIMENSION) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) { - *pixel = QuantizePixel_BlurHard(&prevPixel, pixel, pixel + 64); + *pixel = QuantizePixel_BlurHard(&prevPixel, pixel, pixel + MAX_DIMENSION); prevPixel = *pixel; } } - *pixel = 0x8000; + *pixel = RGB_ALPHA; pixel = &gCanvasPixels[j]; prevPixel = *pixel; - *pixel = 0x8000; - for (i = 1, pixel += 64; i < 63; i++, pixel += 64) + *pixel = RGB_ALPHA; + for (i = 1, pixel += MAX_DIMENSION; i < MAX_DIMENSION - 1; i++, pixel += MAX_DIMENSION) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) { - *pixel = QuantizePixel_BlurHard(&prevPixel, pixel, pixel + 64); + *pixel = QuantizePixel_BlurHard(&prevPixel, pixel, pixel + MAX_DIMENSION); prevPixel = *pixel; } } - *pixel = 0x8000; + *pixel = RGB_ALPHA; } // Finally, invert colors back to the original color space. // The above blur causes the outline areas to darken, which makes // this inversion give the effect of light outlines. pixel = gCanvasPixels; - for (i = 0; i < 64; i++) + for (i = 0; i < MAX_DIMENSION; i++) { - for (j = 0; j < 64; j++, pixel++) + for (j = 0; j < MAX_DIMENSION; j++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) *pixel = QuantizePixel_Invert(pixel); } } @@ -372,7 +374,7 @@ static void ApplyImageEffect_BlurRight(void) u16 prevPixel = *pixel; for (i = 1, pixel++; i < gCanvasColumnEnd - 1; i++, pixel++) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) { *pixel = QuantizePixel_MotionBlur(&prevPixel, pixel); prevPixel = *pixel; @@ -392,7 +394,7 @@ static void ApplyImageEffect_BlurDown(void) u16 prevPixel = *pixel; for (j = 1, pixel += gCanvasWidth; j < gCanvasRowEnd - 1; j++, pixel += gCanvasWidth) { - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) { *pixel = QuantizePixel_MotionBlur(&prevPixel, pixel); prevPixel = *pixel; @@ -408,19 +410,19 @@ struct PointillismPoint u16 delta; }; -static void AddPointillismPoints(u16 arg0) +static void AddPointillismPoints(u16 point) { u8 i; bool8 offsetDownLeft; u8 colorType; struct PointillismPoint points[6]; - points[0].column = gPointillismPoints[arg0][0]; - points[0].row = gPointillismPoints[arg0][1]; - points[0].delta = (gPointillismPoints[arg0][2] >> 3) & 7; + points[0].column = sPointillismPoints[point][0]; + points[0].row = sPointillismPoints[point][1]; + points[0].delta = GET_POINT_DELTA(sPointillismPoints[point][2]); - colorType = (gPointillismPoints[arg0][2] >> 1) & 3; - offsetDownLeft = gPointillismPoints[arg0][2] & 1; + colorType = GET_POINT_COLOR_TYPE(sPointillismPoints[point][2]); + offsetDownLeft = GET_POINT_OFFSET_DL(sPointillismPoints[point][2]); for (i = 1; i < points[0].delta; i++) { if (!offsetDownLeft) @@ -434,7 +436,7 @@ static void AddPointillismPoints(u16 arg0) points[i].row = points[0].row - 1; } - if (points[i].column > 63 || points[i].row > 63) + if (points[i].column >= MAX_DIMENSION || points[i].row >= MAX_DIMENSION) { points[0].delta = i - 1; break; @@ -445,19 +447,19 @@ static void AddPointillismPoints(u16 arg0) for (i = 0; i < points[0].delta; i++) { - u16 *pixel = &gCanvasPixels[points[i].row * 64] + points[i].column; + u16 *pixel = &gCanvasPixels[points[i].row * MAX_DIMENSION] + points[i].column; - if (!(0x8000 & *pixel)) + if (!IS_ALPHA(*pixel)) { - u16 red = (*pixel) & 0x1F; - u16 green = (*pixel >> 5) & 0x1F; - u16 blue = (*pixel >> 10) & 0x1F; + u16 red = GET_R(*pixel); + u16 green = GET_G(*pixel); + u16 blue = GET_B(*pixel); switch (colorType) { case 0: case 1: - switch (((gPointillismPoints[arg0][2] >> 3) & 7) % 3) + switch (GET_POINT_DELTA(sPointillismPoints[point][2]) % 3) { case 0: if (red >= points[i].delta) @@ -501,9 +503,9 @@ static void AddPointillismPoints(u16 arg0) static u16 ConvertColorToGrayscale(u16 *color) { s32 clr = *color; - s32 r = clr & 0x1F; - s32 g = (clr >> 5) & 0x1F; - s32 b = (clr >> 10) & 0x1F; + s32 r = GET_R(clr); + s32 g = GET_G(clr); + s32 b = GET_B(clr); s32 gray = (r * Q_8_8(0.3) + g * Q_8_8(0.59) + b * Q_8_8(0.1133)) >> 8; return RGB2(gray, gray, gray); } @@ -512,9 +514,9 @@ static u16 ConvertColorToGrayscale(u16 *color) // Everything else is white. static u16 QuantizePixel_PersonalityColor(u16 *color, u8 personality) { - u16 red = *color & 0x1F; - u16 green = (*color >> 5) & 0x1F; - u16 blue = (*color >> 10) & 0x1F; + u16 red = GET_R(*color); + u16 green = GET_G(*color); + u16 blue = GET_B(*color); if (red < 17 && green < 17 && blue < 17) return GetColorFromPersonality(personality); @@ -526,9 +528,9 @@ static u16 QuantizePixel_PersonalityColor(u16 *color, u8 personality) // the mon's personality value, return a color. static u16 GetColorFromPersonality(u8 personality) { - u16 red = 0; + u16 red = 0; u16 green = 0; - u16 blue = 0; + u16 blue = 0; u8 strength = (personality / 6) % 3; u8 colorType = personality % 6; @@ -577,9 +579,9 @@ static u16 GetColorFromPersonality(u8 personality) static u16 QuantizePixel_BlackAndWhite(u16 *color) { - u16 red = *color & 0x1F; - u16 green = (*color >> 5) & 0x1F; - u16 blue = (*color >> 10) & 0x1F; + u16 red = GET_R(*color); + u16 green = GET_G(*color); + u16 blue = GET_B(*color); if (red < 17 && green < 17 && blue < 17) return RGB_BLACK; @@ -591,9 +593,9 @@ static u16 QuantizePixel_BlackOutline(u16 *pixelA, u16 *pixelB) { if (*pixelA != RGB_BLACK) { - if (*pixelA & 0x8000) - return 0x8000; - if (*pixelB & 0x8000) + if (IS_ALPHA(*pixelA)) + return RGB_ALPHA; + if (IS_ALPHA(*pixelB)) return RGB_BLACK; return *pixelA; @@ -604,13 +606,13 @@ static u16 QuantizePixel_BlackOutline(u16 *pixelA, u16 *pixelB) static u16 QuantizePixel_Invert(u16 *color) { - u16 red = *color & 0x1F; - u16 green = (*color >> 5) & 0x1F; - u16 blue = (*color >> 10) & 0x1F; + u16 red = GET_R(*color); + u16 green = GET_G(*color); + u16 blue = GET_B(*color); - red = 31 - red; + red = 31 - red; green = 31 - green; - blue = 31 - blue; + blue = 31 - blue; return RGB2(red, green, blue); } @@ -626,12 +628,12 @@ static u16 QuantizePixel_MotionBlur(u16 *prevPixel, u16 *curPixel) if (*prevPixel == *curPixel) return *curPixel; - pixelChannels[0][0] = (*prevPixel >> 0) & 0x1F; - pixelChannels[0][1] = (*prevPixel >> 5) & 0x1F; - pixelChannels[0][2] = (*prevPixel >> 10) & 0x1F; - pixelChannels[1][0] = (*curPixel >> 0) & 0x1F; - pixelChannels[1][1] = (*curPixel >> 5) & 0x1F; - pixelChannels[1][2] = (*curPixel >> 10) & 0x1F; + pixelChannels[0][0] = GET_R(*prevPixel); + pixelChannels[0][1] = GET_G(*prevPixel); + pixelChannels[0][2] = GET_B(*prevPixel); + pixelChannels[1][0] = GET_R(*curPixel); + pixelChannels[1][1] = GET_G(*curPixel); + pixelChannels[1][2] = GET_B(*curPixel); // Don't blur light colors. if (pixelChannels[0][0] > 25 && pixelChannels[0][1] > 25 && pixelChannels[0][2] > 25) @@ -667,9 +669,9 @@ static u16 QuantizePixel_MotionBlur(u16 *prevPixel, u16 *curPixel) largestDiff = diffs[0]; } - red = (pixelChannels[1][0] * (31 - largestDiff / 2)) / 31; + red = (pixelChannels[1][0] * (31 - largestDiff / 2)) / 31; green = (pixelChannels[1][1] * (31 - largestDiff / 2)) / 31; - blue = (pixelChannels[1][2] * (31 - largestDiff / 2)) / 31; + blue = (pixelChannels[1][2] * (31 - largestDiff / 2)) / 31; return RGB2(red, green, blue); } @@ -684,13 +686,13 @@ static u16 QuantizePixel_Blur(u16 *prevPixel, u16 *curPixel, u16 *nextPixel) if (*prevPixel == *curPixel && *nextPixel == *curPixel) return *curPixel; - red = (*curPixel >> 0) & 0x1F; - green = (*curPixel >> 5) & 0x1F; - blue = (*curPixel >> 10) & 0x1F; + red = GET_R(*curPixel); + green = GET_G(*curPixel); + blue = GET_B(*curPixel); - prevAvg = (((*prevPixel >> 0) & 0x1F) + ((*prevPixel >> 5) & 0x1F) + ((*prevPixel >> 10) & 0x1F)) / 3; - curAvg = (((*curPixel >> 0) & 0x1F) + ((*curPixel >> 5) & 0x1F) + ((*curPixel >> 10) & 0x1F)) / 3; - nextAvg = (((*nextPixel >> 0) & 0x1F) + ((*nextPixel >> 5) & 0x1F) + ((*nextPixel >> 10) & 0x1F)) / 3; + prevAvg = (GET_R(*prevPixel) + GET_G(*prevPixel) + GET_B(*prevPixel)) / 3; + curAvg = (GET_R(*curPixel) + GET_G(*curPixel) + GET_B(*curPixel)) / 3; + nextAvg = (GET_R(*nextPixel) + GET_G(*nextPixel) + GET_B(*nextPixel)) / 3; if (prevAvg == curAvg && nextAvg == curAvg) return *curPixel; @@ -728,14 +730,14 @@ static u16 QuantizePixel_BlurHard(u16 *prevPixel, u16 *curPixel, u16 *nextPixel) if (*prevPixel == *curPixel && *nextPixel == *curPixel) return *curPixel; - red = (*curPixel >> 0) & 0x1F; - green = (*curPixel >> 5) & 0x1F; - blue = (*curPixel >> 10) & 0x1F; - - prevAvg = (((*prevPixel >> 0) & 0x1F) + ((*prevPixel >> 5) & 0x1F) + ((*prevPixel >> 10) & 0x1F)) / 3; - curAvg = (((*curPixel >> 0) & 0x1F) + ((*curPixel >> 5) & 0x1F) + ((*curPixel >> 10) & 0x1F)) / 3; - nextAvg = (((*nextPixel >> 0) & 0x1F) + ((*nextPixel >> 5) & 0x1F) + ((*nextPixel >> 10) & 0x1F)) / 3; - + red = GET_R(*curPixel); + green = GET_G(*curPixel); + blue = GET_B(*curPixel); + + prevAvg = (GET_R(*prevPixel) + GET_G(*prevPixel) + GET_B(*prevPixel)) / 3; + curAvg = (GET_R(*curPixel) + GET_G(*curPixel) + GET_B(*curPixel)) / 3; + nextAvg = (GET_R(*nextPixel) + GET_G(*nextPixel) + GET_B(*nextPixel)) / 3; + if (prevAvg == curAvg && nextAvg == curAvg) return *curPixel; @@ -802,8 +804,8 @@ void ConvertImageProcessingToGBA(struct ImageProcessingContext *context) dest = dest_ + ((i * width + j) << 4) + (k << 1); src = src_ + ((((i << 3) + k) << 3) * width) + (j << 3); - dest[0] = src[0] | (src[1] << 4) | (src[2] << 8) | (src[3] << 0xC); - dest[1] = src[4] | (src[5] << 4) | (src[6] << 8) | (src[7] << 0xC); + dest[0] = src[0] | (src[1] << 4) | (src[2] << 8) | (src[3] << 12); + dest[1] = src[4] | (src[5] << 4) | (src[6] << 8) | (src[7] << 12); } } } @@ -851,37 +853,37 @@ void ApplyImageProcessingQuantization(struct ImageProcessingContext *context) static void SetPresetPalette_PrimaryColors(void) { - gCanvasPalette[0] = RGB2(0, 0, 0); - gCanvasPalette[1] = RGB2(6, 6, 6); - gCanvasPalette[2] = RGB2(29, 29, 29); - gCanvasPalette[3] = RGB2(11, 11, 11); - gCanvasPalette[4] = RGB2(29, 6, 6); - gCanvasPalette[5] = RGB2(6, 29, 6); - gCanvasPalette[6] = RGB2(6, 6, 29); - gCanvasPalette[7] = RGB2(29, 29, 6); - gCanvasPalette[8] = RGB2(29, 6, 29); - gCanvasPalette[9] = RGB2(6, 29, 29); - gCanvasPalette[10] = RGB2(29, 11, 6); - gCanvasPalette[11] = RGB2(11, 29, 6); - gCanvasPalette[12] = RGB2(6, 11, 29); - gCanvasPalette[13] = RGB2(29, 6, 11); - gCanvasPalette[14] = RGB2(6, 29, 11); - gCanvasPalette[15] = RGB2(11, 6, 29); + gCanvasPalette[0] = RGB_BLACK; + gCanvasPalette[1] = RGB(6, 6, 6); + gCanvasPalette[2] = RGB(29, 29, 29); + gCanvasPalette[3] = RGB(11, 11, 11); + gCanvasPalette[4] = RGB(29, 6, 6); + gCanvasPalette[5] = RGB(6, 29, 6); + gCanvasPalette[6] = RGB(6, 6, 29); + gCanvasPalette[7] = RGB(29, 29, 6); + gCanvasPalette[8] = RGB(29, 6, 29); + gCanvasPalette[9] = RGB(6, 29, 29); + gCanvasPalette[10] = RGB(29, 11, 6); + gCanvasPalette[11] = RGB(11, 29, 6); + gCanvasPalette[12] = RGB(6, 11, 29); + gCanvasPalette[13] = RGB(29, 6, 11); + gCanvasPalette[14] = RGB(6, 29, 11); + gCanvasPalette[15] = RGB(11, 6, 29); } static void SetPresetPalette_BlackAndWhite(void) { - gCanvasPalette[0] = RGB2(0, 0, 0); - gCanvasPalette[1] = RGB2(0, 0, 0); - gCanvasPalette[2] = RGB2(31, 31, 31); + gCanvasPalette[0] = RGB_BLACK; + gCanvasPalette[1] = RGB_BLACK; + gCanvasPalette[2] = RGB_WHITE; } static void SetPresetPalette_GrayscaleSmall(void) { u8 i; - gCanvasPalette[0] = RGB2(0, 0, 0); - gCanvasPalette[1] = RGB2(0, 0, 0); + gCanvasPalette[0] = RGB_BLACK; + gCanvasPalette[1] = RGB_BLACK; for (i = 0; i < 14; i++) gCanvasPalette[i + 2] = RGB2(2 * (i + 2), 2 * (i + 2), 2 * (i + 2)); } @@ -890,7 +892,7 @@ static void SetPresetPalette_Grayscale(void) { u8 i; - gCanvasPalette[0] = RGB2(0, 0, 0); + gCanvasPalette[0] = RGB_BLACK; for (i = 0; i < 32; i++) gCanvasPalette[i + 1] = RGB2(i, i, i); } @@ -914,7 +916,7 @@ static void QuantizePalette_Standard(bool8 useLimitedPalette) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (*pixel & 0x8000) + if (IS_ALPHA(*pixel)) { *pixel = gCanvasPaletteStart; } @@ -982,7 +984,7 @@ static void QuantizePalette_BlackAndWhite(void) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (*pixel & 0x8000) + if (IS_ALPHA(*pixel)) { *pixel = gCanvasPaletteStart; } @@ -1013,7 +1015,7 @@ static void QuantizePalette_GrayscaleSmall(void) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (*pixel & 0x8000) + if (IS_ALPHA(*pixel)) *pixel = gCanvasPaletteStart; else *pixel = QuantizePixel_GrayscaleSmall(pixel) + gCanvasPaletteStart; @@ -1031,7 +1033,7 @@ static void QuantizePalette_Grayscale(void) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (*pixel & 0x8000) + if (IS_ALPHA(*pixel)) *pixel = gCanvasPaletteStart; else *pixel = QuantizePixel_Grayscale(pixel) + gCanvasPaletteStart; @@ -1049,7 +1051,7 @@ static void QuantizePalette_PrimaryColors(void) u16 *pixel = &pixelRow[gCanvasColumnStart]; for (i = 0; i < gCanvasColumnEnd; i++, pixel++) { - if (*pixel & 0x8000) + if (IS_ALPHA(*pixel)) *pixel = gCanvasPaletteStart; else *pixel = QuantizePixel_PrimaryColors(pixel) + gCanvasPaletteStart; @@ -1060,9 +1062,9 @@ static void QuantizePalette_PrimaryColors(void) // Quantizes the pixel's color channels to nearest multiple of 4, and clamps to [6, 30]. static u16 QuantizePixel_Standard(u16 *pixel) { - u16 red = *pixel & 0x1F; - u16 green = (*pixel >> 5) & 0x1F; - u16 blue = (*pixel >> 10) & 0x1F; + u16 red = GET_R(*pixel); + u16 green = GET_G(*pixel); + u16 blue = GET_B(*pixel); // Quantize color channels to muliples of 4, rounding up. if (red & 3) @@ -1091,10 +1093,10 @@ static u16 QuantizePixel_Standard(u16 *pixel) static u16 QuantizePixel_PrimaryColors(u16* color) { - u16 red = *color & 0x1F; - u16 green = (*color >> 5) & 0x1F; - u16 blue = (*color >> 10) & 0x1F; - + u16 red = GET_R(*color); + u16 green = GET_G(*color); + u16 blue = GET_B(*color); + if (red < 12 && green < 11 && blue < 11) return 1; @@ -1206,9 +1208,9 @@ static u16 QuantizePixel_PrimaryColors(u16* color) static u16 QuantizePixel_GrayscaleSmall(u16 *color) { - u16 red = *color & 0x1F; - u16 green = (*color >> 5) & 0x1F; - u16 blue = (*color >> 10) & 0x1F; + u16 red = GET_R(*color); + u16 green = GET_G(*color); + u16 blue = GET_B(*color); u16 average = ((red + green + blue) / 3) & 0x1E; if (average == 0) return 1; @@ -1218,9 +1220,9 @@ static u16 QuantizePixel_GrayscaleSmall(u16 *color) static u16 QuantizePixel_Grayscale(u16 *color) { - u16 red = *color & 0x1F; - u16 green = (*color >> 5) & 0x1F; - u16 blue = (*color >> 10) & 0x1F; + u16 red = GET_R(*color); + u16 green = GET_G(*color); + u16 blue = GET_B(*color); u16 average = (red + green + blue) / 3; return average + 1; } |