Removed the alpha channel from the surfaces

It's not needed here, where we use a colour-key instead. The enhanced
branch will need it though.
This commit is contained in:
Clownacy 2019-03-11 14:38:11 +00:00
parent c9b681299c
commit e864f7e142
2 changed files with 11 additions and 18 deletions

View file

@ -170,7 +170,7 @@ BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no)
else
{
//Create surface
surf[surf_no].surface = SDL_CreateRGBSurfaceWithFormat(0, bxsize * magnification, bysize * magnification, 0, SDL_PIXELFORMAT_RGBA32);
surf[surf_no].surface = SDL_CreateRGBSurfaceWithFormat(0, bxsize * magnification, bysize * magnification, 0, SDL_PIXELFORMAT_RGB24);
SDL_SetSurfaceBlendMode(surf[surf_no].surface, SDL_BLENDMODE_NONE);
if (surf[surf_no].surface == NULL)
@ -208,7 +208,7 @@ static void FlushSurface(Surface_Ids surf_no)
{
for (int w = 0; w < surf[surf_no].surface->w; ++w)
{
unsigned char *src_pixel = (unsigned char*)surf[surf_no].surface->pixels + (h * surf[surf_no].surface->pitch) + (w * 4);
unsigned char *src_pixel = (unsigned char*)surf[surf_no].surface->pixels + (h * surf[surf_no].surface->pitch) + (w * 3);
unsigned char *dst_pixel = (unsigned char*)raw_pixels + (h * pitch) + (w * 4);
dst_pixel[0] = src_pixel[0];
@ -285,14 +285,13 @@ static bool LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, bool create_surface)
*dst_ptr++ = src_ptr[0];
*dst_ptr++ = src_ptr[1];
*dst_ptr++ = src_ptr[2];
*dst_ptr++ = src_ptr[3];
}
src_ptr += 4;
src_ptr += 3;
}
for (int i = 1; i < magnification; ++i)
memcpy(dst_row + i * surf[surf_no].surface->pitch, dst_row, surf[surf_no].surface->w * 4);
memcpy(dst_row + i * surf[surf_no].surface->pitch, dst_row, surf[surf_no].surface->w * 3);
}
SDL_FreeSurface(converted_surface);
@ -412,9 +411,9 @@ void BackupSurface(Surface_Ids surf_no, RECT *rect)
SDL_GetRendererOutputSize(gRenderer, &w, &h);
//Get texture of what's currently rendered on screen
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, SDL_PIXELFORMAT_RGBA32);
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, SDL_PIXELFORMAT_RGB24);
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGBA32, surface->pixels, surface->pitch);
SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGB24, surface->pixels, surface->pitch);
//Get rects
SDL_Rect frameRect = RectToSDLRectScaled(rect);
@ -605,8 +604,8 @@ void PutText(int x, int y, const char *text, uint32_t color)
int surface_width, surface_height;
SDL_GetRendererOutputSize(gRenderer, &surface_width, &surface_height);
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, surface_width, surface_height, 0, SDL_PIXELFORMAT_RGBA32);
SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGBA32, surface->pixels, surface->pitch);
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, surface_width, surface_height, 0, SDL_PIXELFORMAT_RGB24);
SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_RGB24, surface->pixels, surface->pitch);
DrawText(gFont, surface, x * magnification, y * magnification, color, text, strlen(text));

View file

@ -1815,15 +1815,13 @@ void DrawText(FontObject *font_object, SDL_Surface *surface, int x, int y, unsig
if (font_pixel[0] || font_pixel[1] || font_pixel[2])
{
unsigned char *surface_pixel = (unsigned char*)surface->pixels + (letter_y + iy) * surface->pitch + (letter_x + ix) * 4;
unsigned char *surface_pixel = (unsigned char*)surface->pixels + (letter_y + iy) * surface->pitch + (letter_x + ix) * 3;
for (unsigned int j = 0; j < 3; ++j)
{
const double alpha = pow((font_pixel[j] / 255.0), 1.0 / 1.8); // Gamma correction
surface_pixel[j] = (unsigned char)((colours[j] * alpha) + (surface_pixel[j] * (1.0 - alpha))); // Alpha blending
}
surface_pixel[3] = 0xFF;
}
}
}
@ -1841,12 +1839,10 @@ void DrawText(FontObject *font_object, SDL_Surface *surface, int x, int y, unsig
{
const double alpha = pow((double)font_pixel / (converted.num_grays - 1), 1.0 / 1.8); // Gamma-corrected
unsigned char *surface_pixel = (unsigned char*)surface->pixels + (letter_y + iy) * surface->pitch + (letter_x + ix) * 4;
unsigned char *surface_pixel = (unsigned char*)surface->pixels + (letter_y + iy) * surface->pitch + (letter_x + ix) * 3;
for (unsigned int j = 0; j < 3; ++j)
surface_pixel[j] = (unsigned char)((colours[j] * alpha) + (surface_pixel[j] * (1.0 - alpha))); // Alpha blending
surface_pixel[3] = 0xFF;
}
}
}
@ -1860,12 +1856,10 @@ void DrawText(FontObject *font_object, SDL_Surface *surface, int x, int y, unsig
{
if (converted.buffer[iy * converted.pitch + ix])
{
unsigned char *surface_pixel = (unsigned char*)surface->pixels + (letter_y + iy) * surface->pitch + (letter_x + ix) * 4;
unsigned char *surface_pixel = (unsigned char*)surface->pixels + (letter_y + iy) * surface->pitch + (letter_x + ix) * 3;
for (unsigned int j = 0; j < 3; ++j)
surface_pixel[j] = colours[j];
surface_pixel[3] = 0xFF;
}
}
}