From d7d73fa526a162516731f5ecaca96f2dca6c35c7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 7 Oct 2019 14:56:16 +1100 Subject: [PATCH] less compile errors --- src/Bitmap.c | 6 ++++-- src/Block.c | 8 ++++---- src/Drawer2D.c | 25 +++++++++++++------------ src/Entity.c | 2 +- src/Graphics.c | 18 +++++++++--------- src/LScreens.c | 2 +- src/LWidgets.c | 10 +++++----- src/Launcher.c | 4 ++-- src/PackedCol.c | 1 + src/TexturePack.c | 18 ++++++++++-------- src/Utils.c | 4 +++- src/Widgets.c | 6 +++--- 12 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/Bitmap.c b/src/Bitmap.c index b55759bd6..1d1ea4152 100644 --- a/src/Bitmap.c +++ b/src/Bitmap.c @@ -565,11 +565,13 @@ static void Png_MakeRow(const BitmapCol* src, cc_uint8* dst, int lineLen, bool a if (alpha) { for (; dst < end; src++, dst += 4) { - dst[0] = src->R; dst[1] = src->G; dst[2] = src->B; dst[3] = src->A; + dst[0] = BitmapCol_R(*src); dst[1] = BitmapCol_G(*src); + dst[2] = BitmapCol_B(*src); dst[3] = BitmapCol_A(*src); } } else { for (; dst < end; src++, dst += 3) { - dst[0] = src->R; dst[1] = src->G; dst[2] = src->B; + dst[0] = BitmapCol_R(*src); dst[1] = BitmapCol_G(*src); + dst[2] = BitmapCol_B(*src); } } } diff --git a/src/Block.c b/src/Block.c index 8960fde2c..818e6cf8b 100644 --- a/src/Block.c +++ b/src/Block.c @@ -352,7 +352,7 @@ static float Block_GetSpriteBB_MinX(int size, int tileX, int tileY, const Bitmap for (x = 0; x < size; x++) { for (y = 0; y < size; y++) { row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size); - if (row[x].A) { return (float)x / size; } + if (BitmapCol_A(row[x])) { return (float)x / size; } } } return 1.0f; @@ -365,7 +365,7 @@ static float Block_GetSpriteBB_MinY(int size, int tileX, int tileY, const Bitmap for (y = size - 1; y >= 0; y--) { row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size); for (x = 0; x < size; x++) { - if (row[x].A) { return 1.0f - (float)(y + 1) / size; } + if (BitmapCol_A(row[x])) { return 1.0f - (float)(y + 1) / size; } } } return 1.0f; @@ -378,7 +378,7 @@ static float Block_GetSpriteBB_MaxX(int size, int tileX, int tileY, const Bitmap for (x = size - 1; x >= 0; x--) { for (y = 0; y < size; y++) { row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size); - if (row[x].A) { return (float)(x + 1) / size; } + if (BitmapCol_A(row[x])) { return (float)(x + 1) / size; } } } return 0.0f; @@ -391,7 +391,7 @@ static float Block_GetSpriteBB_MaxY(int size, int tileX, int tileY, const Bitmap for (y = 0; y < size; y++) { row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size); for (x = 0; x < size; x++) { - if (row[x].A) { return 1.0f - (float)y / size; } + if (BitmapCol_A(row[x])) { return 1.0f - (float)y / size; } } } return 0.0f; diff --git a/src/Drawer2D.c b/src/Drawer2D.c index e813b04d9..81659fb65 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -202,15 +202,16 @@ void Gradient_Vertical(Bitmap* bmp, BitmapCol a, BitmapCol b, int xx, yy; float t; if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return; - col.A = 255; for (yy = 0; yy < height; yy++) { row = Bitmap_GetRow(bmp, y + yy) + x; t = (float)yy / (height - 1); /* so last row has colour of b */ - col.B = (cc_uint8)Math_Lerp(a.B, b.B, t); - col.G = (cc_uint8)Math_Lerp(a.G, b.G, t); - col.R = (cc_uint8)Math_Lerp(a.R, b.R, t); + col = BitmapCol_Make( + Math_Lerp(BitmapCol_R(a), BitmapCol_R(b), t), + Math_Lerp(BitmapCol_G(a), BitmapCol_G(b), t), + Math_Lerp(BitmapCol_B(a), BitmapCol_B(b), t), + 255); for (xx = 0; xx < width; xx++) { row[xx] = col; } } @@ -496,7 +497,7 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int for (xx = 0; xx < dstWidth; xx++) { fontX = srcX + xx * srcWidth / dstWidth; src = srcRow[fontX]; - if (!src.A) continue; + if (!BitmapCol_A(src)) continue; dstX = x + xx; if ((unsigned)dstX >= (unsigned)bmp->Width) continue; @@ -671,10 +672,11 @@ void Drawer2D_DrawClippedText(Bitmap* bmp, struct DrawTextArgs* args, int x, int *---------------------------------------------------Drawer2D component----------------------------------------------------* *#########################################################################################################################*/ static void Drawer2D_HexEncodedCol(int i, int hex, cc_uint8 lo, cc_uint8 hi) { - Drawer2D_Cols[i].R = (cc_uint8)(lo * ((hex >> 2) & 1) + hi * (hex >> 3)); - Drawer2D_Cols[i].G = (cc_uint8)(lo * ((hex >> 1) & 1) + hi * (hex >> 3)); - Drawer2D_Cols[i].B = (cc_uint8)(lo * ((hex >> 0) & 1) + hi * (hex >> 3)); - Drawer2D_Cols[i].A = 255; + Drawer2D_Cols[i] = BitmapCol_Make( + lo * ((hex >> 2) & 1) + hi * (hex >> 3), + lo * ((hex >> 1) & 1) + hi * (hex >> 3), + lo * ((hex >> 0) & 1) + hi * (hex >> 3), + 255); } static void Drawer2D_Reset(void) { @@ -1102,10 +1104,9 @@ static void DrawBlackWhiteGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y, Bitma if ((unsigned)(x + xx) >= (unsigned)bmp->Width) continue; intensity = src[xx >> 3]; + /* TODO: transparent text (don't set A to 255) */ if (intensity & (1 << (7 - (xx & 7)))) { - dst->B = col.B; dst->G = col.G; dst->R = col.R; - /*dst->A = col.A*/ - dst->A = 255; + *dst = col | BitmapCol_A_Bits(255); } } } diff --git a/src/Entity.c b/src/Entity.c index a1c43e0a8..34f0788c5 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -396,7 +396,7 @@ static void Entity_ClearHat(Bitmap* bmp, cc_uint8 skinType) { for (y = 0; y < sizeY; y++) { BitmapCol* row = Bitmap_GetRow(bmp, y) + sizeX; for (x = 0; x < sizeX; x++) { - if (row[x].A != 255) return; + if (BitmapCol_A(row[x]) != 255) return; } } diff --git a/src/Graphics.c b/src/Graphics.c index 433d670a4..6cdbe643f 100644 --- a/src/Graphics.c +++ b/src/Graphics.c @@ -206,25 +206,25 @@ static BitmapCol AverageCol(BitmapCol p1, BitmapCol p2) { cc_uint32 a1, a2, aSum; cc_uint32 b1, g1, r1; cc_uint32 b2, g2, r2; - BitmapCol ave; - a1 = p1.A; a2 = p2.A; + a1 = BitmapCol_A(p1); a2 = BitmapCol_A(p2); aSum = (a1 + a2); aSum = aSum > 0 ? aSum : 1; /* avoid divide by 0 below */ /* Convert RGB to pre-multiplied form */ - b1 = p1.B * a1; g1 = p1.G * a1; r1 = p1.R * a1; - b2 = p2.B * a2; g2 = p2.G * a2; r2 = p2.R * a2; + /* TODO: Don't shift when multiplying/averaging */ + r1 = BitmapCol_R(p1) * a1; g1 = BitmapCol_G(p1) * a1; b1 = BitmapCol_B(p1) * a1; + r2 = BitmapCol_R(p2) * a2; g2 = BitmapCol_G(p2) * a2; b2 = BitmapCol_B(p2) * a2; /* https://stackoverflow.com/a/347376 */ /* We need to convert RGB back from the pre-multiplied average into normal form */ /* ((r1 + r2) / 2) / ((a1 + a2) / 2) */ /* but we just cancel out the / 2 */ - ave.B = (b1 + b2) / aSum; - ave.G = (g1 + g2) / aSum; - ave.R = (r1 + r2) / aSum; - ave.A = aSum >> 1; - return ave; + return BitmapCol_Make( + (r1 + r2) / aSum, + (g1 + g2) / aSum, + (b1 + b2) / aSum, + aSum >> 1); } /* Generates the next mipmaps level bitmap for the given bitmap. */ diff --git a/src/LScreens.c b/src/LScreens.c index cbc6c503c..401eabb69 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -368,7 +368,7 @@ static void ColoursScreen_TextChanged(struct LInput* w) { if (!Convert_ParseUInt8(&s->iptColours[index + 1].Text, &g)) return; if (!Convert_ParseUInt8(&s->iptColours[index + 2].Text, &b)) return; - col->R = r; col->G = g; col->B = b; + *col = BitmapCol_Make(r, g, b, 255); Launcher_SaveSkin(); Launcher_Redraw(); } diff --git a/src/LWidgets.c b/src/LWidgets.c index e48610aea..48bb7f8b8 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -50,10 +50,10 @@ void LWidget_Redraw(void* widget) { *#########################################################################################################################*/ static BitmapCol LButton_Expand(BitmapCol a, int amount) { int r, g, b; - r = a.R + amount; Math_Clamp(r, 0, 255); a.R = r; - g = a.G + amount; Math_Clamp(g, 0, 255); a.G = g; - b = a.B + amount; Math_Clamp(b, 0, 255); a.B = b; - return a; + r = BitmapCol_R(a) + amount; Math_Clamp(r, 0, 255); + g = BitmapCol_G(a) + amount; Math_Clamp(g, 0, 255); + b = BitmapCol_B(a) + amount; Math_Clamp(b, 0, 255); + return BitmapCol_Make(r, g, b, 255); } static void LButton_DrawBackground(struct LButton* w) { @@ -818,7 +818,7 @@ static void LTable_DrawRowsBackground(struct LTable* w) { /* hit the end of the table */ if (height < 0) break; - if (col.A) { + if (col) { Drawer2D_Clear(&Launcher_Framebuffer, col, w->X, y, w->Width, height); } else { diff --git a/src/Launcher.c b/src/Launcher.c index 4a03bcdc9..6ea941001 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -325,10 +325,10 @@ void Launcher_ResetSkin(void) { CC_NOINLINE static void Launcher_GetCol(const char* key, BitmapCol* col) { cc_uint8 rgb[3]; String value; - if (!Options_UNSAFE_Get(key, &value)) return; + if (!Options_UNSAFE_Get(key, &value)) return; if (!PackedCol_TryParseHex(&value, rgb)) return; - col->R = rgb[0]; col->G = rgb[1]; col->B = rgb[2]; + *col = BitmapCol_Make(rgb[0], rgb[1], rgb[2], 255); } void Launcher_LoadSkin(void) { diff --git a/src/PackedCol.c b/src/PackedCol.c index 347996394..64d83880f 100644 --- a/src/PackedCol.c +++ b/src/PackedCol.c @@ -19,6 +19,7 @@ PackedCol PackedCol_Tint(PackedCol a, PackedCol b) { cc_uint32 R = PackedCol_R(a) * PackedCol_R(b) / 255; cc_uint32 G = PackedCol_G(a) * PackedCol_G(b) / 255; cc_uint32 B = PackedCol_B(a) * PackedCol_B(b) / 255; + /* TODO: don't shift when multiplying */ return (a & PACKEDCOL_A_MASK) | (R << PACKEDCOL_R_SHIFT) | (G << PACKEDCOL_G_SHIFT) | (B << PACKEDCOL_B_SHIFT); } diff --git a/src/TexturePack.c b/src/TexturePack.c index 217d39c9f..b5a58ca02 100644 --- a/src/TexturePack.c +++ b/src/TexturePack.c @@ -86,10 +86,11 @@ static void LavaAnimation_Tick(BitmapCol* ptr, int size) { col = 2.0f * L_soupHeat[i]; Math_Clamp(col, 0.0f, 1.0f); - ptr->R = (cc_uint8)(col * 100.0f + 155.0f); - ptr->G = (cc_uint8)(col * col * 255.0f); - ptr->B = (cc_uint8)(col * col * col * col * 128.0f); - ptr->A = 255; + *ptr = BitmapCol_Make( + col * 100.0f + 155.0f, + col * col * 255.0f, + col * col * col * col * 128.0f, + 255); ptr++; i++; } @@ -137,10 +138,11 @@ static void WaterAnimation_Tick(BitmapCol* ptr, int size) { Math_Clamp(col, 0.0f, 1.0f); col = col * col; - ptr->R = (cc_uint8)(32.0f + col * 32.0f); - ptr->G = (cc_uint8)(50.0f + col * 64.0f); - ptr->A = (cc_uint8)(146.0f + col * 50.0f); - ptr->B = 255; + *ptr = BitmapCol_Make( + 32.0f + col * 32.0f, + 50.0f + col * 64.0f, + 255, + 146.0f + col * 50.0f); ptr++; i++; } diff --git a/src/Utils.c b/src/Utils.c index 81d0801f4..62c13971e 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -73,13 +73,15 @@ static bool Utils_IsAllBlack(const Bitmap* bmp, int x1, int y1, int width, int h } cc_uint8 Utils_CalcSkinType(const Bitmap* bmp) { + BitmapCol col; int scale; if (bmp->Width == bmp->Height * 2) return SKIN_64x32; if (bmp->Width != bmp->Height) return SKIN_INVALID; scale = bmp->Width / 64; /* Minecraft alex skins have this particular pixel with alpha of 0 */ - if (Bitmap_GetPixel(bmp, 54 * scale, 20 * scale).A < 128) return SKIN_64x64_SLIM; + col = Bitmap_GetPixel(bmp, 54 * scale, 20 * scale); + if (BitmapCol_A(col) < 128) return SKIN_64x64_SLIM; return Utils_IsAllBlack(bmp, 54 * scale, 20 * scale, 2 * scale, 12 * scale) && Utils_IsAllBlack(bmp, 50 * scale, 16 * scale, 2 * scale, 4 * scale) ? SKIN_64x64_SLIM : SKIN_64x64; diff --git a/src/Widgets.c b/src/Widgets.c index f14c4b377..6a9f46aa5 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -1018,7 +1018,7 @@ static bool InputWidget_CheckCol(struct InputWidget* w, int index) { code = w->text.buffer[index]; col = w->text.buffer[index + 1]; - return (code == '%' || code == '&') && Drawer2D_GetCol(col).A; + return (code == '%' || code == '&') && BitmapCol_A(Drawer2D_GetCol(col)); } static void InputWidget_BackspaceKey(struct InputWidget* w) { @@ -2468,8 +2468,8 @@ static void SpecialInputWidget_UpdateColString(struct SpecialInputWidget* w) { String_InitArray(w->colString, w->_colBuffer); for (i = 0; i < DRAWER2D_MAX_COLS; i++) { - if (i >= 'A' && i <= 'F') continue; - if (!Drawer2D_Cols[i].A) continue; + if (i >= 'A' && i <= 'F') continue; + if (!BitmapCol_A(Drawer2D_Cols[i])) continue; String_Append(&w->colString, '&'); String_Append(&w->colString, (char)i); String_Append(&w->colString, '%'); String_Append(&w->colString, (char)i);