shithub: cstory

Download patch

ref: e864f7e1421e661a83d53462b78308257221cae1
parent: c9b681299c15e1ba437bbf2b0e29ea6d01fa1e73
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Mar 11 10:38:11 EDT 2019

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.

--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -170,7 +170,7 @@
 		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 @@
 	{
 		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 @@
 										*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 @@
 	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 @@
 	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));
 
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -1815,7 +1815,7 @@
 
 							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)
 								{
@@ -1822,8 +1822,6 @@
 									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 @@
 							{
 								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 @@
 						{
 							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;
 							}
 						}
 					}