1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
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 for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16
17 #include "port.h"
18 #include "libs/platform.h"
19
20 #if defined(MMX_ASM)
21
22 #include "libs/graphics/sdl/sdl_common.h"
23 #include "types.h"
24 #include "scalers.h"
25 #include "scaleint.h"
26 #include "2xscalers.h"
27 #include "2xscalers_mmx.h"
28
29 // MMX name for all functions
30 #undef SCALE_
31 #define SCALE_(name) Scale ## _MMX_ ## name
32
33 // Tell them which opcodes we want to support
34 #undef USE_MOVNTQ
35 #undef USE_PREFETCH
36 #undef USE_PSADBW
37 // And Bring in inline asm functions
38 #include "scalemmx.h"
39
40
41 // Scaler function lookup table
42 //
43 const Scale_FuncDef_t
44 Scale_MMX_Functions[] =
45 {
46 {TFB_GFXFLAGS_SCALE_BILINEAR, Scale_MMX_BilinearFilter},
47 {TFB_GFXFLAGS_SCALE_BIADAPT, Scale_BiAdaptFilter},
48 {TFB_GFXFLAGS_SCALE_BIADAPTADV, Scale_MMX_BiAdaptAdvFilter},
49 {TFB_GFXFLAGS_SCALE_TRISCAN, Scale_MMX_TriScanFilter},
50 {TFB_GFXFLAGS_SCALE_HQXX, Scale_MMX_HqFilter},
51 // Default
52 {0, Scale_MMX_Nearest}
53 };
54
55 // MMX transformation multipliers
56 Uint64 mmx_888to555_mult;
57 Uint64 mmx_Y_mult;
58 Uint64 mmx_U_mult;
59 Uint64 mmx_V_mult;
60 // Uint64 mmx_YUV_threshold = 0x00300706; original hq2x threshold
61 //Uint64 mmx_YUV_threshold = 0x0030100e;
62 Uint64 mmx_YUV_threshold = 0x0040120c;
63
64 void
Scale_MMX_PrepPlatform(const SDL_PixelFormat * fmt)65 Scale_MMX_PrepPlatform (const SDL_PixelFormat* fmt)
66 {
67 // prepare the channel-shuffle multiplier
68 mmx_888to555_mult = ((Uint64)0x0400) << (fmt->Rshift * 2)
69 | ((Uint64)0x0020) << (fmt->Gshift * 2)
70 | ((Uint64)0x0001) << (fmt->Bshift * 2);
71
72 // prepare the RGB->YUV multipliers
73 mmx_Y_mult = ((Uint64)(uint16)YUV_matrix[YUV_XFORM_R][YUV_XFORM_Y])
74 << (fmt->Rshift * 2)
75 | ((Uint64)(uint16)YUV_matrix[YUV_XFORM_G][YUV_XFORM_Y])
76 << (fmt->Gshift * 2)
77 | ((Uint64)(uint16)YUV_matrix[YUV_XFORM_B][YUV_XFORM_Y])
78 << (fmt->Bshift * 2);
79
80 mmx_U_mult = ((Uint64)(uint16)YUV_matrix[YUV_XFORM_R][YUV_XFORM_U])
81 << (fmt->Rshift * 2)
82 | ((Uint64)(uint16)YUV_matrix[YUV_XFORM_G][YUV_XFORM_U])
83 << (fmt->Gshift * 2)
84 | ((Uint64)(uint16)YUV_matrix[YUV_XFORM_B][YUV_XFORM_U])
85 << (fmt->Bshift * 2);
86
87 mmx_V_mult = ((Uint64)(uint16)YUV_matrix[YUV_XFORM_R][YUV_XFORM_V])
88 << (fmt->Rshift * 2)
89 | ((Uint64)(uint16)YUV_matrix[YUV_XFORM_G][YUV_XFORM_V])
90 << (fmt->Gshift * 2)
91 | ((Uint64)(uint16)YUV_matrix[YUV_XFORM_B][YUV_XFORM_V])
92 << (fmt->Bshift * 2);
93
94 mmx_YUV_threshold = (SCALE_DIFFYUV_TY << 16) | (SCALE_DIFFYUV_TU << 8)
95 | SCALE_DIFFYUV_TV;
96 }
97
98
99 // Nearest Neighbor scaling to 2x
100 // void Scale_MMX_Nearest (SDL_Surface *src,
101 // SDL_Surface *dst, SDL_Rect *r)
102
103 #include "nearest2x.c"
104
105
106 // Bilinear scaling to 2x
107 // void Scale_MMX_BilinearFilter (SDL_Surface *src,
108 // SDL_Surface *dst, SDL_Rect *r)
109
110 #include "bilinear2x.c"
111
112
113 // Advanced Biadapt scaling to 2x
114 // void Scale_MMX_BiAdaptAdvFilter (SDL_Surface *src,
115 // SDL_Surface *dst, SDL_Rect *r)
116
117 #include "biadv2x.c"
118
119
120 // Triscan scaling to 2x
121 // derivative of 'scale2x' -- scale2x.sf.net
122 // void Scale_MMX_TriScanFilter (SDL_Surface *src,
123 // SDL_Surface *dst, SDL_Rect *r)
124
125 #include "triscan2x.c"
126
127 // Hq2x scaling
128 // (adapted from 'hq2x' by Maxim Stepin -- www.hiend3d.com/hq2x.html)
129 // void Scale_MMX_HqFilter (SDL_Surface *src,
130 // SDL_Surface *dst, SDL_Rect *r)
131
132 #include "hq2x.c"
133
134
135 #endif /* MMX_ASM */
136
137