Explorar o código

First working version of xBRZ upscaler

Ivan Savenko hai 1 ano
pai
achega
fa65b0019c

+ 5 - 0
client/CMakeLists.txt

@@ -172,6 +172,8 @@ set(client_SRCS
 	windows/settings/BattleOptionsTab.cpp
 	windows/settings/AdventureOptionsTab.cpp
 
+	xBRZ/xbrz.cpp
+
 	ArtifactsUIController.cpp
 	CGameInfo.cpp
 	CMT.cpp
@@ -380,6 +382,9 @@ set(client_HEADERS
 	windows/settings/BattleOptionsTab.h
 	windows/settings/AdventureOptionsTab.h
 
+	xBRZ/xbrz.h
+	xBRZ/xbrz_tools.h
+
 	ArtifactsUIController.h
 	CGameInfo.h
 	CMT.h

+ 28 - 0
client/renderSDL/SDL_Extensions.cpp

@@ -15,6 +15,7 @@
 #include "../render/Graphics.h"
 #include "../render/Colors.h"
 #include "../CMT.h"
+#include "../xBRZ/xbrz.h"
 
 #include "../../lib/GameConstants.h"
 
@@ -630,6 +631,9 @@ SDL_Surface * CSDL_Ext::scaleSurface(SDL_Surface * surf, int width, int height)
 	if(!surf || !width || !height)
 		return nullptr;
 
+	if (surf->w * 2 == width && surf->h * 2 == height)
+		return scaleSurfaceIntegerFactor(surf, 2);
+
 	SDL_Surface * intermediate = SDL_ConvertSurface(surf, screen->format, 0);
 	SDL_Surface * ret = newSurface(Point(width, height), intermediate);
 
@@ -643,6 +647,30 @@ SDL_Surface * CSDL_Ext::scaleSurface(SDL_Surface * surf, int width, int height)
 	return ret;
 }
 
+SDL_Surface * CSDL_Ext::scaleSurfaceIntegerFactor(SDL_Surface * surf, int factor)
+{
+	if(surf == nullptr || factor == 0)
+		return nullptr;
+
+	int newWidth = surf->w * factor;
+	int newHight = surf->h * factor;
+
+	SDL_Surface * intermediate = SDL_ConvertSurface(surf, screen->format, 0);
+	SDL_Surface * ret = newSurface(Point(newWidth, newHight), intermediate);
+
+	assert(intermediate->pitch == intermediate->w * 4);
+	assert(ret->pitch == ret->w * 4);
+
+	const uint32_t * srcPixels = static_cast<const uint32_t*>(intermediate->pixels);
+	uint32_t * dstPixels = static_cast<uint32_t*>(ret->pixels);
+
+	xbrz::scale(factor, srcPixels, dstPixels, intermediate->w, intermediate->h, xbrz::ColorFormat::ARGB);
+
+	SDL_FreeSurface(intermediate);
+
+	return ret;
+}
+
 void CSDL_Ext::blitSurface(SDL_Surface * src, const Rect & srcRectInput, SDL_Surface * dst, const Point & dstPoint)
 {
 	SDL_Rect srcRect = CSDL_Ext::toSDL(srcRectInput);

+ 1 - 0
client/renderSDL/SDL_Extensions.h

@@ -92,6 +92,7 @@ using TColorPutterAlpha = void (*)(uint8_t *&, const uint8_t &, const uint8_t &,
 
 	// bilinear filtering. Always returns rgba surface
 	SDL_Surface * scaleSurface(SDL_Surface * surf, int width, int height);
+	SDL_Surface * scaleSurfaceIntegerFactor(SDL_Surface * surf, int factor);
 
 	template<int bpp>
 	void convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect);