DXGL r508 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r507‎ | r508 | r509 >
Date:23:44, 31 August 2014
Author:admin
Status:new
Tags:
Comment:
Convert matrix.cpp and scalers.cpp from C++ to C.
Modified paths:
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/matrix.c (added) (history)
  • /ddraw/matrix.cpp (deleted) (history)
  • /ddraw/matrix.h (modified) (history)
  • /ddraw/scalers.c (added) (history)
  • /ddraw/scalers.cpp (deleted) (history)
  • /ddraw/scalers.h (modified) (history)

Diff [purge]

Index: ddraw/scalers.cpp
@@ -1,105 +0,0 @@
2 -// DXGL
3 -// Copyright (C) 2011 William Feely
4 -
5 -// This library is free software; you can redistribute it and/or
6 -// modify it under the terms of the GNU Lesser General Public
7 -// License as published by the Free Software Foundation; either
8 -// version 2.1 of the License, or (at your option) any later version.
9 -
10 -// This library is distributed in the hope that it will be useful,
11 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 -// Lesser General Public License for more details.
14 -
15 -// You should have received a copy of the GNU Lesser General Public
16 -// License along with this library; if not, write to the Free Software
17 -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 -
19 -#include "common.h"
20 -#include "scalers.h"
21 -#include <WinDef.h>
22 -
23 -
24 -void ScaleNearest8(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch)
25 -{
26 - BYTE *d = (BYTE *)dest;
27 - BYTE *s = (BYTE *)src;
28 - int rx = (int)((sw<<16)/dw)+1;
29 - int ry = (int)((sh<<16)/dh)+1;
30 - int x2,y2;
31 - for(int y = 0; y < dh; y++)
32 - {
33 - int b1 = y*outpitch;
34 - y2 = ((y*ry)>>16);
35 - int b2 = y2*inpitch;
36 - for(int x = 0; x < dw; x++)
37 - {
38 - x2 = ((x*rx)>>16);
39 - y2 = ((y*ry)>>16);
40 - d[b1+x] = s[b2+x2];
41 - }
42 - }
43 -}
44 -void ScaleNearest16(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch)
45 -{
46 - WORD *d = (WORD *)dest;
47 - WORD *s = (WORD *)src;
48 - int rx = (int)((sw<<16)/dw)+1;
49 - int ry = (int)((sh<<16)/dh)+1;
50 - int x2,y2;
51 - for(int y = 0; y < dh; y++)
52 - {
53 - int b1 = y*outpitch;
54 - y2 = ((y*ry)>>16);
55 - int b2 = y2*inpitch;
56 - for(int x = 0; x < dw; x++)
57 - {
58 - x2 = ((x*rx)>>16);
59 - y2 = ((y*ry)>>16);
60 - d[b1+x] = s[b2+x2];
61 - }
62 - }
63 -}
64 -void ScaleNearest24(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch)
65 -{
66 - RGBTRIPLE *d = (RGBTRIPLE *)dest;
67 - RGBTRIPLE *s = (RGBTRIPLE *)src;
68 - char *d8 = (char*)dest;
69 - char *s8 = (char*)src;
70 - int rx = (int)((sw<<16)/dw)+1;
71 - int ry = (int)((sh<<16)/dh)+1;
72 - int x2,y2;
73 - for(int y = 0; y < dh; y++)
74 - {
75 - d8 = (y*outpitch)+(char*)dest;
76 - y2 = ((y*ry)>>16);
77 - s8 = (y2*inpitch)+(char*)src;
78 - d = (RGBTRIPLE*)d8;
79 - s = (RGBTRIPLE*)s8;
80 - for(int x = 0; x < dw; x++)
81 - {
82 - x2 = ((x*rx)>>16);
83 - y2 = ((y*ry)>>16);
84 - d[x] = s[x2];
85 - }
86 - }
87 -}
88 -void ScaleNearest32(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch)
89 -{
90 - DWORD *d = (DWORD *)dest;
91 - DWORD *s = (DWORD *)src;
92 - int rx = (int)((sw<<16)/dw)+1;
93 - int ry = (int)((sh<<16)/dh)+1;
94 - int x2,y2;
95 - for(int y = 0; y < dh; y++)
96 - {
97 - int b1 = y*outpitch;
98 - y2 = ((y*ry)>>16);
99 - int b2 = y2*inpitch;
100 - for(int x = 0; x < dw; x++)
101 - {
102 - x2 = ((x*rx)>>16);
103 - d[b1+x] = s[b2+x2];
104 - }
105 - }
106 -}
Index: ddraw/matrix.cpp
@@ -1,200 +0,0 @@
2 -// DXGL
3 -// Copyright (C) 2012 William Feely
4 -
5 -// This library is free software; you can redistribute it and/or
6 -// modify it under the terms of the GNU Lesser General Public
7 -// License as published by the Free Software Foundation; either
8 -// version 2.1 of the License, or (at your option) any later version.
9 -
10 -// This library is distributed in the hope that it will be useful,
11 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 -// Lesser General Public License for more details.
14 -
15 -// You should have received a copy of the GNU Lesser General Public
16 -// License along with this library; if not, write to the Free Software
17 -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 -
19 -// Portions of this file are from the Mesa library, found in src/glu/sgi/libutil/project.c
20 -// project.c is licensed under the SGI Free Software License B, version 2.0.
21 -/*
22 - * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
23 - * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
24 - *
25 - * Permission is hereby granted, free of charge, to any person obtaining a
26 - * copy of this software and associated documentation files (the "Software"),
27 - * to deal in the Software without restriction, including without limitation
28 - * the rights to use, copy, modify, merge, publish, distribute, sublicense,
29 - * and/or sell copies of the Software, and to permit persons to whom the
30 - * Software is furnished to do so, subject to the following conditions:
31 - *
32 - * The above copyright notice including the dates of first publication and
33 - * either this permission notice or a reference to
34 - * http://oss.sgi.com/projects/FreeB/
35 - * shall be included in all copies or substantial portions of the Software.
36 - *
37 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
38 - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
40 - * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
41 - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
42 - * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 - * SOFTWARE.
44 - *
45 - * Except as contained in this notice, the name of Silicon Graphics, Inc.
46 - * shall not be used in advertising or otherwise to promote the sale, use or
47 - * other dealings in this Software without prior written authorization from
48 - * Silicon Graphics, Inc.
49 - */
50 -#include "common.h"
51 -#include "matrix.h"
52 -
53 -// From project.c:
54 -/*
55 -** Invert 4x4 matrix.
56 -** Contributed by David Moore (See Mesa bug #6748)
57 -*/
58 -// Converted to float
59 -int __gluInvertMatrixf(const GLfloat m[16], GLfloat invOut[16])
60 -{
61 - GLfloat inv[16], det;
62 - int i;
63 -
64 - inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15]
65 - + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10];
66 - inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15]
67 - - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10];
68 - inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15]
69 - + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9];
70 - inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14]
71 - - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9];
72 - inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15]
73 - - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10];
74 - inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15]
75 - + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10];
76 - inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15]
77 - - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9];
78 - inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14]
79 - + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9];
80 - inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15]
81 - + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6];
82 - inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15]
83 - - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6];
84 - inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15]
85 - + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5];
86 - inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14]
87 - - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5];
88 - inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11]
89 - - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6];
90 - inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11]
91 - + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6];
92 - inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11]
93 - - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5];
94 - inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10]
95 - + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5];
96 -
97 - det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12];
98 - if (det == 0)
99 - return GL_FALSE;
100 -
101 - det = 1.0f / det;
102 -
103 - for (i = 0; i < 16; i++)
104 - invOut[i] = inv[i] * det;
105 -
106 - return GL_TRUE;
107 -}
108 -
109 -void __gluMultMatricesf(const GLfloat a[16], const GLfloat b[16],
110 - GLfloat r[16])
111 -{
112 - int i, j;
113 - GLfloat out[16];
114 -
115 - for (i = 0; i < 4; i++) {
116 - for (j = 0; j < 4; j++) {
117 - out[i*4+j] =
118 - a[i*4+0]*b[0*4+j] +
119 - a[i*4+1]*b[1*4+j] +
120 - a[i*4+2]*b[2*4+j] +
121 - a[i*4+3]*b[3*4+j];
122 - }
123 - }
124 - memcpy(r, out, 16 * sizeof(GLfloat));
125 -}
126 -
127 -void __gluMakeIdentityf(GLfloat m[16])
128 -{
129 - m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
130 - m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
131 - m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
132 - m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
133 -}
134 -
135 -void __gluMultMatrixVecf(const GLfloat matrix[16], const GLfloat in[4], GLfloat out[4])
136 -{
137 - int i;
138 -
139 - for (i=0; i<4; i++) {
140 - out[i] =
141 - in[0] * matrix[0*4+i] +
142 - in[1] * matrix[1*4+i] +
143 - in[2] * matrix[2*4+i] +
144 - in[3] * matrix[3*4+i];
145 - }
146 -}
147 -
148 -
149 -// Portions of this file are from the Wine project, distributed under the
150 -// following license:
151 -/*
152 -* Copyright (c) 1998-2004 Lionel Ulmer
153 -* Copyright (c) 2002-2005 Christian Costa
154 -* Copyright (c) 2006-2009, 2011-2013 Stefan Dösinger
155 -* Copyright (c) 2008 Alexander Dorofeyev
156 -*
157 -* This library is free software; you can redistribute it and/or
158 -* modify it under the terms of the GNU Lesser General Public
159 -* License as published by the Free Software Foundation; either
160 -* version 2.1 of the License, or (at your option) any later version.
161 -*
162 -* This library is distributed in the hope that it will be useful,
163 -* but WITHOUT ANY WARRANTY; without even the implied warranty of
164 -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
165 -* Lesser General Public License for more details.
166 -*
167 -* You should have received a copy of the GNU Lesser General Public
168 -* License along with this library; if not, write to the Free Software
169 -* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
170 -*/
171 -
172 -void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1,
173 - const struct wined3d_matrix *src2)
174 -{
175 - struct wined3d_matrix temp;
176 -
177 - /* Now do the multiplication 'by hand'.
178 - I know that all this could be optimised, but this will be done later :-) */
179 - temp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
180 - temp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
181 - temp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
182 - temp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);
183 -
184 - temp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
185 - temp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
186 - temp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
187 - temp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);
188 -
189 - temp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
190 - temp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
191 - temp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
192 - temp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);
193 -
194 - temp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
195 - temp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
196 - temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
197 - temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
198 -
199 - /* And copy the new matrix in the good storage.. */
200 - memcpy(dest, &temp, 16 * sizeof(float));
201 -}
Index: ddraw/ddraw.vcxproj
@@ -364,7 +364,14 @@
365365 <ClCompile Include="glRenderer.cpp" />
366366 <ClCompile Include="glRenderWindow.cpp" />
367367 <ClCompile Include="glUtil.cpp" />
368 - <ClCompile Include="matrix.cpp" />
 368+ <ClCompile Include="matrix.c">
 369+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
 370+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
 371+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
 372+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
 373+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
 374+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
 375+ </ClCompile>
369376 <ClCompile Include="precomp.cpp">
370377 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">Create</PrecompiledHeader>
371378 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
@@ -373,7 +380,14 @@
374381 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">Create</PrecompiledHeader>
375382 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
376383 </ClCompile>
377 - <ClCompile Include="scalers.cpp" />
 384+ <ClCompile Include="scalers.c">
 385+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
 386+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
 387+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
 388+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
 389+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
 390+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
 391+ </ClCompile>
378392 <ClCompile Include="ShaderGen3D.cpp" />
379393 <ClCompile Include="ShaderGen2D.cpp" />
380394 <ClCompile Include="ShaderManager.cpp" />
Index: ddraw/ddraw.vcxproj.filters
@@ -160,9 +160,6 @@
161161 <ClCompile Include="precomp.cpp">
162162 <Filter>Source Files</Filter>
163163 </ClCompile>
164 - <ClCompile Include="scalers.cpp">
165 - <Filter>Source Files</Filter>
166 - </ClCompile>
167164 <ClCompile Include="glClassFactory.cpp">
168165 <Filter>Source Files</Filter>
169166 </ClCompile>
@@ -178,9 +175,6 @@
179176 <ClCompile Include="glRenderer.cpp">
180177 <Filter>Source Files</Filter>
181178 </ClCompile>
182 - <ClCompile Include="matrix.cpp">
183 - <Filter>Source Files</Filter>
184 - </ClCompile>
185179 <ClCompile Include="glRenderWindow.cpp">
186180 <Filter>Source Files</Filter>
187181 </ClCompile>
@@ -235,6 +229,12 @@
236230 <ClCompile Include="timer.c">
237231 <Filter>Source Files</Filter>
238232 </ClCompile>
 233+ <ClCompile Include="matrix.c">
 234+ <Filter>Source Files</Filter>
 235+ </ClCompile>
 236+ <ClCompile Include="scalers.c">
 237+ <Filter>Source Files</Filter>
 238+ </ClCompile>
239239 </ItemGroup>
240240 <ItemGroup>
241241 <ResourceCompile Include="ddraw.rc">
Index: ddraw/matrix.c
@@ -0,0 +1,200 @@
 2+// DXGL
 3+// Copyright (C) 2012 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+// Portions of this file are from the Mesa library, found in src/glu/sgi/libutil/project.c
 20+// project.c is licensed under the SGI Free Software License B, version 2.0.
 21+/*
 22+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
 23+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
 24+ *
 25+ * Permission is hereby granted, free of charge, to any person obtaining a
 26+ * copy of this software and associated documentation files (the "Software"),
 27+ * to deal in the Software without restriction, including without limitation
 28+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 29+ * and/or sell copies of the Software, and to permit persons to whom the
 30+ * Software is furnished to do so, subject to the following conditions:
 31+ *
 32+ * The above copyright notice including the dates of first publication and
 33+ * either this permission notice or a reference to
 34+ * http://oss.sgi.com/projects/FreeB/
 35+ * shall be included in all copies or substantial portions of the Software.
 36+ *
 37+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 38+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 39+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 40+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 41+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 42+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 43+ * SOFTWARE.
 44+ *
 45+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
 46+ * shall not be used in advertising or otherwise to promote the sale, use or
 47+ * other dealings in this Software without prior written authorization from
 48+ * Silicon Graphics, Inc.
 49+ */
 50+#include "common.h"
 51+#include "matrix.h"
 52+
 53+// From project.c:
 54+/*
 55+** Invert 4x4 matrix.
 56+** Contributed by David Moore (See Mesa bug #6748)
 57+*/
 58+// Converted to float
 59+int __gluInvertMatrixf(const GLfloat m[16], GLfloat invOut[16])
 60+{
 61+ GLfloat inv[16], det;
 62+ int i;
 63+
 64+ inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15]
 65+ + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10];
 66+ inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15]
 67+ - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10];
 68+ inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15]
 69+ + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9];
 70+ inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14]
 71+ - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9];
 72+ inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15]
 73+ - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10];
 74+ inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15]
 75+ + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10];
 76+ inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15]
 77+ - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9];
 78+ inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14]
 79+ + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9];
 80+ inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15]
 81+ + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6];
 82+ inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15]
 83+ - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6];
 84+ inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15]
 85+ + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5];
 86+ inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14]
 87+ - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5];
 88+ inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11]
 89+ - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6];
 90+ inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11]
 91+ + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6];
 92+ inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11]
 93+ - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5];
 94+ inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10]
 95+ + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5];
 96+
 97+ det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12];
 98+ if (det == 0)
 99+ return GL_FALSE;
 100+
 101+ det = 1.0f / det;
 102+
 103+ for (i = 0; i < 16; i++)
 104+ invOut[i] = inv[i] * det;
 105+
 106+ return GL_TRUE;
 107+}
 108+
 109+void __gluMultMatricesf(const GLfloat a[16], const GLfloat b[16],
 110+ GLfloat r[16])
 111+{
 112+ int i, j;
 113+ GLfloat out[16];
 114+
 115+ for (i = 0; i < 4; i++) {
 116+ for (j = 0; j < 4; j++) {
 117+ out[i*4+j] =
 118+ a[i*4+0]*b[0*4+j] +
 119+ a[i*4+1]*b[1*4+j] +
 120+ a[i*4+2]*b[2*4+j] +
 121+ a[i*4+3]*b[3*4+j];
 122+ }
 123+ }
 124+ memcpy(r, out, 16 * sizeof(GLfloat));
 125+}
 126+
 127+void __gluMakeIdentityf(GLfloat m[16])
 128+{
 129+ m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
 130+ m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
 131+ m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
 132+ m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
 133+}
 134+
 135+void __gluMultMatrixVecf(const GLfloat matrix[16], const GLfloat in[4], GLfloat out[4])
 136+{
 137+ int i;
 138+
 139+ for (i=0; i<4; i++) {
 140+ out[i] =
 141+ in[0] * matrix[0*4+i] +
 142+ in[1] * matrix[1*4+i] +
 143+ in[2] * matrix[2*4+i] +
 144+ in[3] * matrix[3*4+i];
 145+ }
 146+}
 147+
 148+
 149+// Portions of this file are from the Wine project, distributed under the
 150+// following license:
 151+/*
 152+* Copyright (c) 1998-2004 Lionel Ulmer
 153+* Copyright (c) 2002-2005 Christian Costa
 154+* Copyright (c) 2006-2009, 2011-2013 Stefan Dösinger
 155+* Copyright (c) 2008 Alexander Dorofeyev
 156+*
 157+* This library is free software; you can redistribute it and/or
 158+* modify it under the terms of the GNU Lesser General Public
 159+* License as published by the Free Software Foundation; either
 160+* version 2.1 of the License, or (at your option) any later version.
 161+*
 162+* This library is distributed in the hope that it will be useful,
 163+* but WITHOUT ANY WARRANTY; without even the implied warranty of
 164+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 165+* Lesser General Public License for more details.
 166+*
 167+* You should have received a copy of the GNU Lesser General Public
 168+* License along with this library; if not, write to the Free Software
 169+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 170+*/
 171+
 172+void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1,
 173+ const struct wined3d_matrix *src2)
 174+{
 175+ struct wined3d_matrix temp;
 176+
 177+ /* Now do the multiplication 'by hand'.
 178+ I know that all this could be optimised, but this will be done later :-) */
 179+ temp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
 180+ temp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
 181+ temp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
 182+ temp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);
 183+
 184+ temp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
 185+ temp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
 186+ temp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
 187+ temp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);
 188+
 189+ temp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
 190+ temp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
 191+ temp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
 192+ temp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);
 193+
 194+ temp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
 195+ temp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
 196+ temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
 197+ temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
 198+
 199+ /* And copy the new matrix in the good storage.. */
 200+ memcpy(dest, &temp, 16 * sizeof(float));
 201+}
Index: ddraw/matrix.h
@@ -50,6 +50,10 @@
5151 #ifndef _MATRIX_H
5252 #define _MATRIX_H
5353
 54+#ifdef __cplusplus
 55+extern "C" {
 56+#endif
 57+
5458 int __gluInvertMatrixf(const GLfloat m[16], GLfloat invOut[16]);
5559 void __gluMultMatricesf(const GLfloat a[16], const GLfloat b[16],
5660 GLfloat r[16]);
@@ -97,4 +101,8 @@
98102 void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1,
99103 const struct wined3d_matrix *src2);
100104
 105+#ifdef __cplusplus
 106+}
 107+#endif
 108+
101109 #endif //_MATRIX_H
\ No newline at end of file
Index: ddraw/scalers.c
@@ -0,0 +1,112 @@
 2+// DXGL
 3+// Copyright (C) 2011 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#include "common.h"
 20+#include "scalers.h"
 21+#include <WinDef.h>
 22+
 23+
 24+void ScaleNearest8(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch)
 25+{
 26+ BYTE *d = (BYTE *)dest;
 27+ BYTE *s = (BYTE *)src;
 28+ int rx = (int)((sw<<16)/dw)+1;
 29+ int ry = (int)((sh<<16)/dh)+1;
 30+ int x,y;
 31+ int x2,y2;
 32+ int b1,b2;
 33+ for(y = 0; y < dh; y++)
 34+ {
 35+ b1 = y*outpitch;
 36+ y2 = ((y*ry)>>16);
 37+ b2 = y2*inpitch;
 38+ for(x = 0; x < dw; x++)
 39+ {
 40+ x2 = ((x*rx)>>16);
 41+ y2 = ((y*ry)>>16);
 42+ d[b1+x] = s[b2+x2];
 43+ }
 44+ }
 45+}
 46+void ScaleNearest16(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch)
 47+{
 48+ WORD *d = (WORD *)dest;
 49+ WORD *s = (WORD *)src;
 50+ int rx = (int)((sw<<16)/dw)+1;
 51+ int ry = (int)((sh<<16)/dh)+1;
 52+ int x,y;
 53+ int x2,y2;
 54+ int b1,b2;
 55+ for(y = 0; y < dh; y++)
 56+ {
 57+ b1 = y*outpitch;
 58+ y2 = ((y*ry)>>16);
 59+ b2 = y2*inpitch;
 60+ for(x = 0; x < dw; x++)
 61+ {
 62+ x2 = ((x*rx)>>16);
 63+ y2 = ((y*ry)>>16);
 64+ d[b1+x] = s[b2+x2];
 65+ }
 66+ }
 67+}
 68+void ScaleNearest24(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch)
 69+{
 70+ RGBTRIPLE *d = (RGBTRIPLE *)dest;
 71+ RGBTRIPLE *s = (RGBTRIPLE *)src;
 72+ char *d8 = (char*)dest;
 73+ char *s8 = (char*)src;
 74+ int rx = (int)((sw<<16)/dw)+1;
 75+ int ry = (int)((sh<<16)/dh)+1;
 76+ int x,y;
 77+ int x2,y2;
 78+ for(y = 0; y < dh; y++)
 79+ {
 80+ d8 = (y*outpitch)+(char*)dest;
 81+ y2 = ((y*ry)>>16);
 82+ s8 = (y2*inpitch)+(char*)src;
 83+ d = (RGBTRIPLE*)d8;
 84+ s = (RGBTRIPLE*)s8;
 85+ for(x = 0; x < dw; x++)
 86+ {
 87+ x2 = ((x*rx)>>16);
 88+ y2 = ((y*ry)>>16);
 89+ d[x] = s[x2];
 90+ }
 91+ }
 92+}
 93+void ScaleNearest32(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch)
 94+{
 95+ DWORD *d = (DWORD *)dest;
 96+ DWORD *s = (DWORD *)src;
 97+ int rx = (int)((sw<<16)/dw)+1;
 98+ int ry = (int)((sh<<16)/dh)+1;
 99+ int x,y;
 100+ int x2,y2;
 101+ int b1,b2;
 102+ for(y = 0; y < dh; y++)
 103+ {
 104+ b1 = y*outpitch;
 105+ y2 = ((y*ry)>>16);
 106+ b2 = y2*inpitch;
 107+ for(x = 0; x < dw; x++)
 108+ {
 109+ x2 = ((x*rx)>>16);
 110+ d[b1+x] = s[b2+x2];
 111+ }
 112+ }
 113+}
Index: ddraw/scalers.h
@@ -19,10 +19,17 @@
2020 #ifndef _SCALERS_H
2121 #define _SCALERS_H
2222
 23+#ifdef __cplusplus
 24+extern "C" {
 25+#endif
 26+
2327 void ScaleNearest8(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch);
2428 void ScaleNearest16(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch);
2529 void ScaleNearest24(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch);
2630 void ScaleNearest32(void *dest, void *src, int dw, int dh, int sw, int sh, int inpitch, int outpitch);
2731
 32+#ifdef __cplusplus
 33+}
 34+#endif
2835
2936 #endif //_SCALERS_H
\ No newline at end of file