| Index: ddraw/colorconv.c |
| — | — | @@ -0,0 +1,187 @@ |
| | 2 | +// DXGL
|
| | 3 | +// Copyright (C) 2018 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 "colorconv.h"
|
| | 21 | +
|
| | 22 | +__inline unsigned int _1to8(unsigned int input)
|
| | 23 | +{
|
| | 24 | + return input * 255;
|
| | 25 | +}
|
| | 26 | +
|
| | 27 | +__inline unsigned int _2to8(unsigned int input)
|
| | 28 | +{
|
| | 29 | + return input * 85;
|
| | 30 | +}
|
| | 31 | +
|
| | 32 | +__inline unsigned int _3to8(unsigned int input)
|
| | 33 | +{
|
| | 34 | + return (input * 146 + 1) >> 2;
|
| | 35 | +}
|
| | 36 | +
|
| | 37 | +__inline unsigned int _4to8(unsigned int input)
|
| | 38 | +{
|
| | 39 | + return input * 17;
|
| | 40 | +}
|
| | 41 | +
|
| | 42 | +__inline unsigned int _5to8(unsigned int input)
|
| | 43 | +{
|
| | 44 | + return (input * 527 + 23) >> 6;
|
| | 45 | +}
|
| | 46 | +
|
| | 47 | +__inline unsigned int _6to8(unsigned int input)
|
| | 48 | +{
|
| | 49 | + return (input * 259 + 33) >> 6;
|
| | 50 | +}
|
| | 51 | +
|
| | 52 | +void rgba8332torgba8888(size_t count, DWORD *dest, WORD *src)
|
| | 53 | +{
|
| | 54 | + size_t i;
|
| | 55 | + WORD in;
|
| | 56 | + for (i = 0; i < count; i++)
|
| | 57 | + {
|
| | 58 | + in = src[i];
|
| | 59 | + dest[i] = ((in & 0xFF00) << 16) | (_3to8((in & 0xE0) >> 5) << 16) |
|
| | 60 | + (_3to8((in & 0x1C) >> 2) << 8) | _2to8(in & 0x3);
|
| | 61 | + }
|
| | 62 | +}
|
| | 63 | +
|
| | 64 | +void rgba8888torgba8332(size_t count, WORD *dest, DWORD *src)
|
| | 65 | +{
|
| | 66 | + size_t i;
|
| | 67 | + DWORD in;
|
| | 68 | + for (i = 0; i < count; i++)
|
| | 69 | + {
|
| | 70 | + in = src[i];
|
| | 71 | + dest[i] = ((in & 0xFF000000) >> 16) | ((in & 0xE00000) >> 16) |
|
| | 72 | + ((in & 0xE000) >> 11) | ((in & 0xC0) >> 6);
|
| | 73 | + }
|
| | 74 | +}
|
| | 75 | +
|
| | 76 | +void rgb565torgba8888(size_t count, DWORD *dest, WORD *src)
|
| | 77 | +{
|
| | 78 | + size_t i;
|
| | 79 | + DWORD in;
|
| | 80 | + for (i = 0; i < count; i++)
|
| | 81 | + {
|
| | 82 | + in = src[i];
|
| | 83 | + dest[i] = 0xFF000000 | (_5to8((in & 0xF800) >> 11) << 16) |
|
| | 84 | + (_6to8((in & 0x7E0) >> 5) << 8) | _5to8(in & 0x1F);
|
| | 85 | + }
|
| | 86 | +}
|
| | 87 | +
|
| | 88 | +void rgb565torgbx8888(size_t count, DWORD *dest, WORD *src)
|
| | 89 | +{
|
| | 90 | + size_t i;
|
| | 91 | + DWORD in;
|
| | 92 | + for (i = 0; i < count; i++)
|
| | 93 | + {
|
| | 94 | + in = src[i];
|
| | 95 | + dest[i] = (_5to8((in & 0xF800) >> 11) << 16) |
|
| | 96 | + (_6to8((in & 0x7E0) >> 5) << 8) | _5to8(in & 0x1F);
|
| | 97 | + }
|
| | 98 | +}
|
| | 99 | +
|
| | 100 | +void rgbx8888torgb565(size_t count, WORD *dest, DWORD *src)
|
| | 101 | +{
|
| | 102 | + size_t i;
|
| | 103 | + DWORD in;
|
| | 104 | + for (i = 0; i < count; i++)
|
| | 105 | + {
|
| | 106 | + in = src[i];
|
| | 107 | + dest[i] = ((in & 0xF80000) >> 8) | ((in & 0xFC00) >> 5)
|
| | 108 | + | ((in & 0xF8) >> 3);
|
| | 109 | + }
|
| | 110 | +}
|
| | 111 | +
|
| | 112 | +void rgba1555torgba8888(size_t count, DWORD *dest, WORD *src)
|
| | 113 | +{
|
| | 114 | + size_t i;
|
| | 115 | + DWORD in;
|
| | 116 | + for (i = 0; i < count; i++)
|
| | 117 | + {
|
| | 118 | + in = src[i];
|
| | 119 | + dest[i] = (_1to8((in & 0x8000) >> 15) << 24) | (_5to8((in & 0x7C00) >> 10) << 16) |
|
| | 120 | + (_5to8((in & 0x3E0) >> 5) << 8) | _5to8(in & 0x1F);
|
| | 121 | + }
|
| | 122 | +}
|
| | 123 | +
|
| | 124 | +void rgba8888torgba1555(size_t count, WORD *dest, DWORD *src)
|
| | 125 | +{
|
| | 126 | + size_t i;
|
| | 127 | + DWORD in;
|
| | 128 | + for (i = 0; i < count; i++)
|
| | 129 | + {
|
| | 130 | + in = src[i];
|
| | 131 | + dest[i] = ((in & 0x80000000) >> 16) | ((in & 0xF80000) >> 9) |
|
| | 132 | + ((in & 0xF800) >> 6) | ((in & 0xF8) >> 3);
|
| | 133 | + }
|
| | 134 | +}
|
| | 135 | +
|
| | 136 | +void rgba4444torgba8888(size_t count, DWORD *dest, WORD *src)
|
| | 137 | +{
|
| | 138 | + size_t i;
|
| | 139 | + DWORD in;
|
| | 140 | + for (i = 0; i < count; i++)
|
| | 141 | + {
|
| | 142 | + in = src[i];
|
| | 143 | + dest[i] = (_4to8((in & 0xF000) >> 12) << 24) | (_4to8((in & 0xF00) >> 8) << 16) |
|
| | 144 | + (_4to8((in & 0xF0) >> 4) << 8) | _4to8(in & 0xF);
|
| | 145 | + }
|
| | 146 | +}
|
| | 147 | +
|
| | 148 | +void rgba8888torgba4444(size_t count, WORD *dest, DWORD *src)
|
| | 149 | +{
|
| | 150 | + size_t i;
|
| | 151 | + DWORD in;
|
| | 152 | + for (i = 0; i < count; i++)
|
| | 153 | + {
|
| | 154 | + in = src[i];
|
| | 155 | + dest[i] = ((in & 0xF0000000) >> 16) | ((in & 0xF00000) >> 12) |
|
| | 156 | + ((in & 0xF000) >> 8) | ((in & 0xF0) >> 4);
|
| | 157 | + }
|
| | 158 | +}
|
| | 159 | +
|
| | 160 | +__inline DWORD yuvtorgb(DWORD y, DWORD u, DWORD v)
|
| | 161 | +{
|
| | 162 | + float r, g, b;
|
| | 163 | + r = y + 1.402f * v;
|
| | 164 | + g = y - 0.344f * u - 0.714f * v;
|
| | 165 | + b = y + 1.772f * u;
|
| | 166 | + if (r > 255.0f) r = 255.0f;
|
| | 167 | + if (r < 0.0f) r = 0.0f;
|
| | 168 | + return ((DWORD)r << 16) | ((DWORD)g << 8) || (DWORD)b;
|
| | 169 | +}
|
| | 170 | +
|
| | 171 | +void uyvytorgbx8888(size_t count, DWORD *dest, DWORD *src)
|
| | 172 | +{
|
| | 173 | + size_t i;
|
| | 174 | + DWORD in;
|
| | 175 | + DWORD y, u, v;
|
| | 176 | + for (i = 0; i < (count << 1); i++)
|
| | 177 | + {
|
| | 178 | + in = src[i];
|
| | 179 | + // first pixel
|
| | 180 | + y = (src[i] >> 8) & 0xFF;
|
| | 181 | + u = src[i] & 0xFF;
|
| | 182 | + v = (src[i] >> 16) & 0xFF;
|
| | 183 | + dest[i << 1] = yuvtorgb(y, u, v);
|
| | 184 | + // second pixel
|
| | 185 | + y = (src[i] >> 24) & 0xFF;
|
| | 186 | + dest[(i << 1)+1] = yuvtorgb(y, u, v);
|
| | 187 | + }
|
| | 188 | +} |
| \ No newline at end of file |
| Index: ddraw/colorconv.h |
| — | — | @@ -0,0 +1,34 @@ |
| | 2 | +// DXGL
|
| | 3 | +// Copyright (C) 2018 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 | +#pragma once
|
| | 20 | +#ifndef __COLORCONV_H
|
| | 21 | +#define __COLORCONV_H
|
| | 22 | +
|
| | 23 | +#ifdef __cplusplus
|
| | 24 | +extern "C" {
|
| | 25 | +#endif
|
| | 26 | +
|
| | 27 | +void rgba8332torgba8888(size_t count, DWORD *dest, WORD *src);
|
| | 28 | +void rgba8888torgba8332(size_t count, WORD *dest, DWORD *src);
|
| | 29 | +void rgb565torgba8888(size_t count, DWORD *dest, WORD *src);
|
| | 30 | +
|
| | 31 | +#ifdef __cplusplus
|
| | 32 | +}
|
| | 33 | +#endif
|
| | 34 | +
|
| | 35 | +#endif //__COLORCONV_H |
| \ No newline at end of file |
| Index: ddraw/ddraw.vcxproj |
| — | — | @@ -315,6 +315,7 @@ |
| 316 | 316 | <None Include="include\d3dvec.inl" />
|
| 317 | 317 | </ItemGroup>
|
| 318 | 318 | <ItemGroup>
|
| | 319 | + <ClInclude Include="colorconv.h" />
|
| 319 | 320 | <ClInclude Include="common.h" />
|
| 320 | 321 | <ClInclude Include="const.h" />
|
| 321 | 322 | <ClInclude Include="ddraw.h" />
|
| — | — | @@ -360,6 +361,15 @@ |
| 361 | 362 | <ClInclude Include="util.h" />
|
| 362 | 363 | </ItemGroup>
|
| 363 | 364 | <ItemGroup>
|
| | 365 | + <ClCompile Include="colorconv.c">
|
| | 366 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
| | 367 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| | 368 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug VS2017|Win32'">NotUsing</PrecompiledHeader>
|
| | 369 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| | 370 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
| | 371 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release VS2017|Win32'">NotUsing</PrecompiledHeader>
|
| | 372 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
|
| | 373 | + </ClCompile>
|
| 364 | 374 | <ClCompile Include="const.c">
|
| 365 | 375 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
| 366 | 376 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug VS2017|Win32'">NotUsing</PrecompiledHeader>
|
| Index: ddraw/ddraw.vcxproj.filters |
| — | — | @@ -158,6 +158,9 @@ |
| 159 | 159 | <ClInclude Include="struct_command.h">
|
| 160 | 160 | <Filter>Header Files</Filter>
|
| 161 | 161 | </ClInclude>
|
| | 162 | + <ClInclude Include="colorconv.h">
|
| | 163 | + <Filter>Header Files</Filter>
|
| | 164 | + </ClInclude>
|
| 162 | 165 | </ItemGroup>
|
| 163 | 166 | <ItemGroup>
|
| 164 | 167 | <ClCompile Include="ddraw.cpp">
|
| — | — | @@ -265,6 +268,9 @@ |
| 266 | 269 | <ClCompile Include="const.c">
|
| 267 | 270 | <Filter>Source Files</Filter>
|
| 268 | 271 | </ClCompile>
|
| | 272 | + <ClCompile Include="colorconv.c">
|
| | 273 | + <Filter>Source Files</Filter>
|
| | 274 | + </ClCompile>
|
| 269 | 275 | </ItemGroup>
|
| 270 | 276 | <ItemGroup>
|
| 271 | 277 | <ResourceCompile Include="ddraw.rc">
|
| Index: ddraw/glTexture.cpp |
| — | — | @@ -135,6 +135,7 @@ |
| 136 | 136 | if (!newtexture) return DDERR_OUTOFMEMORY;
|
| 137 | 137 | ZeroMemory(newtexture, sizeof(glTexture));
|
| 138 | 138 | memcpy(&newtexture->levels[0].ddsd, ddsd, sizeof(DDSURFACEDESC2));
|
| | 139 | + newtexture->useconv = FALSE;
|
| 139 | 140 | if (bigwidth)
|
| 140 | 141 | {
|
| 141 | 142 | newtexture->bigwidth = bigwidth;
|
| — | — | @@ -815,6 +816,8 @@ |
| 816 | 817 | This->colorbits[3] = 0;
|
| 817 | 818 | break;
|
| 818 | 819 | case 7: // 16-bit RGBA8332
|
| | 820 | + //This->useconv = TRUE;
|
| | 821 | + //This->convfunction = 0;
|
| 819 | 822 | FIXME("Unusual texture format RGBA8332 not supported");
|
| 820 | 823 | This->colororder = 1;
|
| 821 | 824 | This->colorsizes[0] = 7;
|
| Index: ddraw/struct.h |
| — | — | @@ -311,6 +311,8 @@ |
| 312 | 312 | GLenum format;
|
| 313 | 313 | GLenum type;
|
| 314 | 314 | BOOL zhasstencil;
|
| | 315 | + BOOL useconv;
|
| | 316 | + int convfunction;
|
| 315 | 317 | struct glTexture *palette;
|
| 316 | 318 | struct glTexture *stencil;
|
| 317 | 319 | struct glTexture *dummycolor;
|
| Index: dxglcfg/dxgltest.cpp |
| — | — | @@ -223,7 +223,8 @@ |
| 224 | 224 | {7, 7, 0, 0, TRUE, 60.0, TRUE, TRUE, TRUE, _T("Texture Stage shaders (Interactive, DX7)")},
|
| 225 | 225 | {7, 7, 0, 0, TRUE, 60.0, TRUE, TRUE, TRUE, _T("Vertex shaders (Interactive, DX7)")},
|
| 226 | 226 | {1, 7, 0, 1, TRUE, 60.0, FALSE, FALSE, FALSE, _T("SetCursorPos Test")},
|
| 227 | | - {1, 7, 0, 1, TRUE, 60.0, FALSE, FALSE, FALSE, _T("Blt Background, Raster operation Blt sprites")}
|
| | 227 | + {1, 7, 0, 1, TRUE, 60.0, FALSE, FALSE, FALSE, _T("Blt Background, Raster operation Blt sprites")},
|
| | 228 | + {7, 7, 1, 1, FALSE, 0.0, TRUE, TRUE, FALSE, _T("Surface/Texture format test")}
|
| 228 | 229 | };
|
| 229 | 230 | const int END_TESTS = __LINE__ - 4;
|
| 230 | 231 | const int numtests = END_TESTS - START_TESTS;
|
| Index: dxglcfg/tests.cpp |
| — | — | @@ -46,7 +46,7 @@ |
| 47 | 47 | static HWND hWnd;
|
| 48 | 48 | static int testnum;
|
| 49 | 49 | static unsigned int randnum;
|
| 50 | | -static int testtypes[] = {0,1,0,1,0,1,0,0,2,1,0,0,0,0,0,0,0,0};
|
| | 50 | +static int testtypes[] = {0,1,0,1,0,1,0,0,-1,1,0,0,0,0,0,0,0,0,2};
|
| 51 | 51 | static DWORD counter;
|
| 52 | 52 | static DWORD hotspotx,hotspoty;
|
| 53 | 53 |
|
| — | — | @@ -278,7 +278,30 @@ |
| 279 | 279 | PostQuitMessage(0);
|
| 280 | 280 | break;
|
| 281 | 281 | case WM_KEYDOWN:
|
| 282 | | - if(wParam == VK_ESCAPE) DestroyWindow(hWnd);
|
| | 282 | + if (wParam == VK_ESCAPE)
|
| | 283 | + {
|
| | 284 | + DestroyWindow(hWnd);
|
| | 285 | + break;
|
| | 286 | + }
|
| | 287 | + if (testtypes[testnum] == 2)
|
| | 288 | + {
|
| | 289 | + if (testnum == 18)
|
| | 290 | + {
|
| | 291 | + switch (wParam)
|
| | 292 | + {
|
| | 293 | + case VK_SPACE:
|
| | 294 | + break;
|
| | 295 | + case VK_UP:
|
| | 296 | + break;
|
| | 297 | + case VK_DOWN:
|
| | 298 | + break;
|
| | 299 | + case VK_LEFT:
|
| | 300 | + break;
|
| | 301 | + case VK_RIGHT:
|
| | 302 | + break;
|
| | 303 | + }
|
| | 304 | + }
|
| | 305 | + }
|
| 283 | 306 | break;
|
| 284 | 307 | case WM_APP:
|
| 285 | 308 | RunTestTimed(testnum);
|