Skip to content
Permalink
Browse files

Fix all compile errors

Hopefully didn't break too much
  • Loading branch information...
UnknownShadow200 committed Oct 7, 2019
1 parent d7d73fa commit 80ee35fdced81f62c8ecd37cd0e293795214d846
Showing with 74 additions and 59 deletions.
  1. +12 −10 src/Bitmap.c
  2. +55 −41 src/Drawer2D.c
  3. +2 −3 src/EntityComponents.c
  4. +2 −4 src/Launcher.c
  5. +3 −1 src/Widgets.c
@@ -307,7 +307,7 @@ static Png_RowExpander Png_GetExpander(cc_uint8 col, cc_uint8 bitsPerSample) {
}

/* Sets alpha to 0 for any pixels in the bitmap whose RGB is same as col */
static void Png_ComputeTransparency(Bitmap* bmp, BitmapCol col) {
static void ComputeTransparency(Bitmap* bmp, BitmapCol col) {
BitmapCol trnsRGB = col & BITMAPCOL_RGB_MASK;
int x, y, width = bmp->Width, height = bmp->Height;

@@ -337,7 +337,7 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) {
cc_uint32 scanlineSize, scanlineBytes;

/* palette data */
BitmapCol transparentCol;
BitmapCol trnsCol;
BitmapCol palette[PNG_PALETTE];
cc_uint32 i;

@@ -359,7 +359,7 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) {
if (res) return res;
if (!Png_Detect(tmp, PNG_SIG_SIZE)) return PNG_ERR_INVALID_SIG;

transparentCol = BITMAPCOL_BLACK;
trnsCol = BITMAPCOL_BLACK;
for (i = 0; i < PNG_PALETTE; i++) { palette[i] = BITMAPCOL_BLACK; }

Inflate_MakeStream(&compStream, &inflate, stream);
@@ -410,9 +410,10 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) {
if (res) return res;

for (i = 0; i < dataSize; i += 3) {
palette[i / 3].R = tmp[i];
palette[i / 3].G = tmp[i + 1];
palette[i / 3].B = tmp[i + 2];
palette[i / 3] &= BITMAPCOL_A_MASK; /* set RGB to 0 */
palette[i / 3] |= tmp[i ] << BITMAPCOL_R_SHIFT;
palette[i / 3] |= tmp[i + 1] << BITMAPCOL_G_SHIFT;
palette[i / 3] |= tmp[i + 2] << BITMAPCOL_B_SHIFT;
}
} break;

@@ -423,23 +424,24 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) {
if (res) return res;

/* RGB is 16 bits big endian, ignore least significant 8 bits */
transparentCol = BitmapCol_Make(tmp[0], tmp[0], tmp[0], 0);
trnsCol = BitmapCol_Make(tmp[0], tmp[0], tmp[0], 0);
} else if (col == PNG_COL_INDEXED) {
if (dataSize > PNG_PALETTE) return PNG_ERR_TRANS_COUNT;
res = Stream_Read(stream, tmp, dataSize);
if (res) return res;

/* set alpha component of palette */
for (i = 0; i < dataSize; i++) {
palette[i].A = tmp[i];
palette[i] &= BITMAPCOL_RGB_MASK; /* set A to 0 */
palette[i] |= tmp[i] << PACKEDCOL_A_SHIFT;
}
} else if (col == PNG_COL_RGB) {
if (dataSize != 6) return PNG_ERR_TRANS_COUNT;
res = Stream_Read(stream, tmp, dataSize);
if (res) return res;

/* R,G,B is 16 bits big endian, ignore least significant 8 bits */
transparentCol = BitmapCol_Make(tmp[0], tmp[2], tmp[4], 0);
trnsCol = BitmapCol_Make(tmp[0], tmp[2], tmp[4], 0);
} else {
return PNG_ERR_TRANS_INVALID;
}
@@ -496,7 +498,7 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) {

case PNG_FourCC('I','E','N','D'): {
if (dataSize) return PNG_ERR_INVALID_END_SIZE;
if (!transparentCol.A) Png_ComputeTransparency(bmp, transparentCol);
if (!BitmapCol_A(trnsCol)) ComputeTransparency(bmp, trnsCol);
return bmp->Scan0 ? 0 : PNG_ERR_NO_DATA;
} break;

@@ -115,7 +115,7 @@ static void Drawer2D_CalculateTextWidths(void) {

/* Iterate through each pixel of the given character, on the current scanline */
for (xx = tileSize - 1; xx >= 0; xx--) {
if (!row[x + xx].A) continue;
if (!BitmapCol_A(row[x + xx])) continue;

/* Check if this is the pixel furthest to the right, for the current character */
tileWidths[i] = max(tileWidths[i], xx + 1);
@@ -172,7 +172,7 @@ bool Drawer2D_Clamp(Bitmap* bmp, int* x, int* y, int* width, int* height) {
void Gradient_Noise(Bitmap* bmp, BitmapCol col, int variation,
int x, int y, int width, int height) {
BitmapCol* dst;
int xx, yy, n;
int R, G, B, xx, yy, n;
float noise;
if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return;

@@ -184,14 +184,11 @@ void Gradient_Noise(Bitmap* bmp, BitmapCol col, int variation,
n = (n << 13) ^ n;
noise = 1.0f - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f;

n = col.B + (int)(noise * variation);
dst->B = Drawer2D_ClampPixel(n);
n = col.G + (int)(noise * variation);
dst->G = Drawer2D_ClampPixel(n);
n = col.R + (int)(noise * variation);
dst->R = Drawer2D_ClampPixel(n);
R = BitmapCol_R(col) + (int)(noise * variation); Drawer2D_ClampPixel(R);
G = BitmapCol_G(col) + (int)(noise * variation); Drawer2D_ClampPixel(G);
B = BitmapCol_B(col) + (int)(noise * variation); Drawer2D_ClampPixel(B);

dst->A = 255;
*dst = BitmapCol_Make(R, G, B, 255);
}
}
}
@@ -220,35 +217,35 @@ void Gradient_Vertical(Bitmap* bmp, BitmapCol a, BitmapCol b,
void Gradient_Blend(Bitmap* bmp, BitmapCol col, int blend,
int x, int y, int width, int height) {
BitmapCol* dst;
int xx, yy, t;
int R, G, B, xx, yy;
if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return;

/* Pre compute the alpha blended source colour */
col.R = (cc_uint8)(col.R * blend / 255);
col.G = (cc_uint8)(col.G * blend / 255);
col.B = (cc_uint8)(col.B * blend / 255);
/* TODO: Avoid shift when multiplying */
col = BitmapCol_Make(
BitmapCol_R(col) * blend / 255,
BitmapCol_G(col) * blend / 255,
BitmapCol_B(col) * blend / 255,
0);
blend = 255 - blend; /* inverse for existing pixels */

t = 0;
for (yy = 0; yy < height; yy++) {
dst = Bitmap_GetRow(bmp, y + yy) + x;

for (xx = 0; xx < width; xx++, dst++) {
t = col.B + (dst->B * blend) / 255;
dst->B = Drawer2D_ClampPixel(t);
t = col.G + (dst->G * blend) / 255;
dst->G = Drawer2D_ClampPixel(t);
t = col.R + (dst->R * blend) / 255;
dst->R = Drawer2D_ClampPixel(t);

dst->A = 255;
/* TODO: Not shift when multiplying */
R = BitmapCol_R(col) + (BitmapCol_R(*dst) * blend) / 255;
G = BitmapCol_G(col) + (BitmapCol_G(*dst) * blend) / 255;
B = BitmapCol_B(col) + (BitmapCol_B(*dst) * blend) / 255;

*dst = BitmapCol_Make(R, G, B, 255);
}
}
}

void Gradient_Tint(Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
int x, int y, int width, int height) {
BitmapCol* row;
BitmapCol* row, col;
cc_uint8 tint;
int xx, yy;
if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return;
@@ -258,9 +255,14 @@ void Gradient_Tint(Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
tint = (cc_uint8)Math_Lerp(tintA, tintB, (float)yy / height);

for (xx = 0; xx < width; xx++) {
row[xx].B = (row[xx].B * tint) / 255;
row[xx].G = (row[xx].G * tint) / 255;
row[xx].R = (row[xx].R * tint) / 255;
/* TODO: Not shift when multiplying */
col = BitmapCol_Make(
BitmapCol_R(row[xx]) * tint / 255,
BitmapCol_G(row[xx]) * tint / 255,
BitmapCol_B(row[xx]) * tint / 255,
0);

row[xx] = col | (row[xx] & BITMAPCOL_A_MASK);
}
}
}
@@ -344,7 +346,7 @@ void Drawer2D_Make2DTexture(struct Texture* tex, Bitmap* bmp, Size2D used) {

bool Drawer2D_ValidColCodeAt(const String* text, int i) {
if (i >= text->length) return false;
return Drawer2D_GetCol(text->buffer[i]).A > 0;
return BitmapCol_A(Drawer2D_GetCol(text->buffer[i])) != 0;
}

bool Drawer2D_IsEmptyText(const String* text) {
@@ -374,8 +376,13 @@ char Drawer2D_LastCol(const String* text, int start) {
bool Drawer2D_IsWhiteCol(char c) { return c == '\0' || c == 'f' || c == 'F'; }

/* Divides R/G/B by 4 */
#define SHADOW_MASK ((0x3F << BITMAPCOL_R_SHIFT) | (0x3F << BITMAPCOL_G_SHIFT) | (0x3F << BITMAPCOL_B_SHIFT))
CC_NOINLINE static BitmapCol Drawer2D_ShadowCol(BitmapCol c) {
c.R >>= 2; c.G >>= 2; c.B >>= 2; return c;
/* Initial layout: aaaa_aaaa|rrrr_rrrr|gggg_gggg|bbbb_bbbb */
/* Shift right 2: 00aa_aaaa|aarr_rrrr|rrgg_gggg|ggbb_bbbb */
/* And by 3f3f3f: 0000_0000|00rr_rrrr|00gg_gggg|00bb_bbbb */
/* Or by alpha : aaaa_aaaa|00rr_rrrr|00gg_gggg|00bb_bbbb */
return (c & BITMAPCOL_A_MASK) | ((c >> 2) & SHADOW_MASK);
}

/* TODO: Needs to account for DPI */
@@ -502,11 +509,14 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int
dstX = x + xx;
if ((unsigned)dstX >= (unsigned)bmp->Width) continue;

dst.B = src.B * col.B / 255;
dst.G = src.G * col.G / 255;
dst.R = src.R * col.R / 255;
dst.A = src.A;
dstRow[dstX] = dst;
/* TODO: Transparent text by multiplying by col.A */
/* TODO: Not shift when multiplying */
/* TODO: avoid BitmapCol_A shift */
dstRow[dstX] = BitmapCol_Make(
BitmapCol_R(src) * BitmapCol_R(col) / 255,
BitmapCol_G(src) * BitmapCol_G(col) / 255,
BitmapCol_B(src) * BitmapCol_B(col) / 255,
BitmapCol_A(src));
}
x += dstWidth + xPadding;
}
@@ -1068,7 +1078,7 @@ static int Font_SysTextWidth(struct DrawTextArgs* args) {
static void DrawGrayscaleGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y, BitmapCol col) {
cc_uint8* src;
BitmapCol* dst;
cc_uint8 intensity, invIntensity;
cc_uint8 I, invI; /* intensity */
int xx, yy;

for (yy = 0; yy < img->rows; yy++) {
@@ -1078,13 +1088,17 @@ static void DrawGrayscaleGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y, Bitmap

for (xx = 0; xx < img->width; xx++, src++, dst++) {
if ((unsigned)(x + xx) >= (unsigned)bmp->Width) continue;
intensity = *src; invIntensity = UInt8_MaxValue - intensity;

dst->B = ((col.B * intensity) >> 8) + ((dst->B * invIntensity) >> 8);
dst->G = ((col.G * intensity) >> 8) + ((dst->G * invIntensity) >> 8);
dst->R = ((col.R * intensity) >> 8) + ((dst->R * invIntensity) >> 8);
/*dst->A = ((col.A * intensity) >> 8) + ((dst->A * invIntensity) >> 8);*/
dst->A = intensity + ((dst->A * invIntensity) >> 8);
I = *src; invI = UInt8_MaxValue - I;

/* TODO: Support transparent text */
/* dst->A = ((col.A * intensity) >> 8) + ((dst->A * invIntensity) >> 8);*/
/* TODO: Not shift when multiplying */
*dst = BitmapCol_Make(
((BitmapCol_R(col) * I) >> 8) + ((BitmapCol_R(*dst) * invI) >> 8),
((BitmapCol_G(col) * I) >> 8) + ((BitmapCol_G(*dst) * invI) >> 8),
((BitmapCol_B(col) * I) >> 8) + ((BitmapCol_B(*dst) * invI) >> 8),
((BitmapCol_A(*dst) * invI) >> 8)
);
}
}
}
@@ -586,8 +586,7 @@ static bool ShadowComponent_GetBlocks(struct Entity* e, int x, int y, int z, str
#define sh_half (sh_size / 2)
static void ShadowComponent_MakeTex(void) {
cc_uint8 pixels[Bitmap_DataSize(sh_size, sh_size)];
BitmapCol inPix = BitmapCol_Make(0, 0, 0, 200);
BitmapCol outPix = BitmapCol_Make(0, 0, 0, 0);
BitmapCol col = BitmapCol_Make(0, 0, 0, 200);
Bitmap bmp;
cc_uint32 x, y;

@@ -599,7 +598,7 @@ static void ShadowComponent_MakeTex(void) {
double dist =
(sh_half - (x + 0.5)) * (sh_half - (x + 0.5)) +
(sh_half - (y + 0.5)) * (sh_half - (y + 0.5));
row[x] = dist < sh_half * sh_half ? inPix : outPix;
row[x] = dist < sh_half * sh_half ? col : 0;
}
}
ShadowComponent_ShadowTex = Gfx_CreateTexture(&bmp, false, false);
@@ -161,8 +161,6 @@ static void Launcher_Display(void) {
}

static void Launcher_Init(void) {
BitmapCol col = BitmapCol_Make(125, 125, 125, 255);

Event_RegisterVoid(&WindowEvents.Resized, NULL, Launcher_OnResize);
Event_RegisterVoid(&WindowEvents.StateChanged, NULL, Launcher_OnResize);
Event_RegisterVoid(&WindowEvents.Redraw, NULL, Launcher_ReqeustRedraw);
@@ -179,7 +177,7 @@ static void Launcher_Init(void) {
Drawer2D_MakeFont(&Launcher_TextFont, 14, FONT_STYLE_NORMAL);
Drawer2D_MakeFont(&Launcher_HintFont, 12, FONT_STYLE_ITALIC);

Drawer2D_Cols['g'] = col;
Drawer2D_Cols['g'] = BitmapCol_Make(125, 125, 125, 255);
Utils_EnsureDirectory("texpacks");
Utils_EnsureDirectory("audio");
}
@@ -342,7 +340,7 @@ void Launcher_LoadSkin(void) {
CC_NOINLINE static void Launcher_SetCol(const char* key, BitmapCol col) {
String value; char valueBuffer[8];
/* Component order might be different to BitmapCol */
PackedCol tmp = PackedCol_Make(col.R, col.G, col.B, 0);
PackedCol tmp = PackedCol_Make(BitmapCol_R(col), BitmapCol_G(col), BitmapCol_B(col), 0);

String_InitArray(value, valueBuffer);
PackedCol_ToHex(&value, tmp);
@@ -928,7 +928,9 @@ static void InputWidget_UpdateCaret(struct InputWidget* w) {

if (colCode) {
col = Drawer2D_GetCol(colCode);
w->caretCol = PackedCol_Make(col.R, col.G, col.B, col.A);
/* Component order might be different to BitmapCol */
w->caretCol = PackedCol_Make(BitmapCol_R(col), BitmapCol_G(col),
BitmapCol_B(col), BitmapCol_A(col));
} else {
w->caretCol = PackedCol_Scale(PACKEDCOL_WHITE, 0.8f);
}

0 comments on commit 80ee35f

Please sign in to comment.
You can’t perform that action at this time.