1 // Copyright (c) 2012- PPSSPP Project.
2 
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
6 
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU General Public License 2.0 for more details.
11 
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14 
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17 
18 #pragma once
19 
20 #include "Common/CommonTypes.h"
21 #include "Common/MemoryUtil.h"
22 
23 #include <vector>
24 
25 static const int MIN_TEXSCALE_LINES_PER_THREAD = 4;
26 
27 class TextureScalerCommon {
28 public:
29 	TextureScalerCommon();
30 	~TextureScalerCommon();
31 
32 	void ScaleAlways(u32 *out, u32 *src, u32 &dstFmt, int &width, int &height, int factor);
33 	bool Scale(u32 *&data, u32 &dstfmt, int &width, int &height, int factor);
34 	bool ScaleInto(u32 *out, u32 *src, u32 &dstfmt, int &width, int &height, int factor);
35 
36 	enum { XBRZ = 0, HYBRID = 1, BICUBIC = 2, HYBRID_BICUBIC = 3 };
37 
38 protected:
39 	virtual void ConvertTo8888(u32 format, u32 *source, u32 *&dest, int width, int height) = 0;
40 	virtual int BytesPerPixel(u32 format) = 0;
41 	virtual u32 Get8888Format() = 0;
42 
43 	void ScaleXBRZ(int factor, u32* source, u32* dest, int width, int height);
44 	void ScaleBilinear(int factor, u32* source, u32* dest, int width, int height);
45 	void ScaleBicubicBSpline(int factor, u32* source, u32* dest, int width, int height);
46 	void ScaleBicubicMitchell(int factor, u32* source, u32* dest, int width, int height);
47 	void ScaleHybrid(int factor, u32* source, u32* dest, int width, int height, bool bicubic = false);
48 
49 	void DePosterize(u32* source, u32* dest, int width, int height);
50 
51 	bool IsEmptyOrFlat(u32* data, int pixels, int fmt);
52 
53 	// depending on the factor and texture sizes, these can get pretty large
54 	// maximum is (100 MB total for a 512 by 512 texture with scaling factor 5 and hybrid scaling)
55 	// of course, scaling factor 5 is totally silly anyway
56 	SimpleBuf<u32> bufInput, bufDeposter, bufOutput, bufTmp1, bufTmp2, bufTmp3;
57 };
58