Index: ddraw/ShaderGen2D.cpp |
— | — | @@ -156,6 +156,9 @@ |
157 | 157 | vec2 index = vec2(((myindex.x*(255.0/256.0))+(0.5/256.0)),0.5);\n\
|
158 | 158 | pixel = ivec4(texture2D(srcpal, index)*vec4(colorsizedest)+.5);\n";
|
159 | 159 | static const char op_pixelmul256[] = "pixel = ivec4(vec4(256.0)*texture2D(srctex,gl_TexCoord[0].st)*vec4(colorsizedest)+.5);\n";
|
| 160 | +static const char op_pixeluyvy[] = "pixel = ivec4(readuyvy(srctex)*vec4(colorsizedest)+.5);\n";
|
| 161 | +static const char op_pixelyuyv[] = "pixel = ivec4(readyuyv(srctex)*vec4(colorsizedest)+.5);\n";
|
| 162 | +static const char op_pixelyvyu[] = "pixel = ivec4(readyvyu(srctex)*vec4(colorsizedest)+.5);\n";
|
160 | 163 | static const char op_lumpixel[] = "pixel = ivec4(vec4(texture2D(srctex,gl_TexCoord[0].st).rrr,1.0)*vec4(colorsizedest)+.5);\n";
|
161 | 164 | static const char op_color[] = "pixel = fillcolor;\n";
|
162 | 165 | static const char op_dest[] = "dest = ivec4(texture2D(desttex,gl_TexCoord[1].st)*vec4(colorsizedest)+.5);\n";
|
— | — | @@ -197,12 +200,32 @@ |
198 | 201 | {\n\
|
199 | 202 | return vec4(vec3((bt601_coeff_inv * rgba.rgb) + yuv_offsets_inv),rgba.a);\n\
|
200 | 203 | }\n\n";
|
201 | | -static const char func_readrgbg[] = "";
|
202 | | -static const char func_readgrgb[] = "";
|
203 | | -static const char func_readuyvy[] = "";
|
204 | | -static const char func_readyuyv[] = "";
|
205 | | -static const char func_readyvyu[] = "";
|
| 204 | +static const char func_readuyvy_nearest[] =
|
| 205 | +"vec4 readuyvy(sampler2DRect texture)\n\
|
| 206 | +{\n\
|
| 207 | + float x = floor(gl_TexCoord[0].s);\n\
|
| 208 | + float y = floor(gl_TexCoord[0].t);\n\
|
| 209 | + float x2 = floor(gl_TexCoord[0].s/2.0)*2.0;\n\
|
| 210 | + return vec4(texture2DRect(texture,vec2(x,y)).g,texture2DRect(texture,vec2(x2,y)).r,texture2DRect(texture,vec2(x2+1.0,y)).r,1.0);\n\
|
| 211 | +}\n\n";
|
| 212 | +static const char func_readyuyv_nearest[] =
|
| 213 | +"vec4 readyuyv(sampler2DRect texture)\n\
|
| 214 | +{\n\
|
| 215 | + float x = floor(gl_TexCoord[0].s);\n\
|
| 216 | + float y = floor(gl_TexCoord[0].t);\n\
|
| 217 | + float x2 = floor(gl_TexCoord[0].s/2.0)*2.0;\n\
|
| 218 | + return vec4(texture2DRect(texture,vec2(x,y)).r,texture2DRect(texture,vec2(x2,y)).g,texture2DRect(texture,vec2(x2+1.0,y)).g,1.0);\n\
|
| 219 | +}\n\n";
|
| 220 | +static const char func_readyvyu_nearest[] =
|
| 221 | +"vec4 readyvyu(sampler2DRect texture)\n\
|
| 222 | +{\n\
|
| 223 | + float x = floor(gl_TexCoord[0].s);\n\
|
| 224 | + float y = floor(gl_TexCoord[0].t);\n\
|
| 225 | + float x2 = floor(gl_TexCoord[0].s/2.0)*2.0;\n\
|
| 226 | + return vec4(texture2DRect(texture,vec2(x,y)).r,texture2DRect(texture,vec2(x2+1.0,y)).g,texture2DRect(texture,vec2(x2,y)).g,1.0);\n\
|
| 227 | +}\n\n";
|
206 | 228 |
|
| 229 | +
|
207 | 230 | // ROP Operations
|
208 | 231 | static const char *op_ROP[256] = {
|
209 | 232 | "pixel = ivec4(0);\n",//00 BLACKNESS
|
— | — | @@ -890,6 +913,18 @@ |
891 | 914 | else String_Append(fsrc, version_110);
|
892 | 915 | }
|
893 | 916 | else String_Append(fsrc, version_110);
|
| 917 | + switch (srctype)
|
| 918 | + {
|
| 919 | + default:
|
| 920 | + break;
|
| 921 | + case 0x20:
|
| 922 | + case 0x21:
|
| 923 | + case 0x80:
|
| 924 | + case 0x81:
|
| 925 | + case 0x82:
|
| 926 | + String_Append(fsrc, ext_texrect);
|
| 927 | + break;
|
| 928 | + }
|
894 | 929 | String_Append(fsrc, idheader);
|
895 | 930 | String_Append(fsrc, idstring);
|
896 | 931 |
|
— | — | @@ -913,6 +948,9 @@ |
914 | 949 | case 0:
|
915 | 950 | default:
|
916 | 951 | break;
|
| 952 | + case 0x80:
|
| 953 | + case 0x81:
|
| 954 | + case 0x82:
|
917 | 955 | case 0x83:
|
918 | 956 | if ((srctype >= 0x80) && (srctype <= 0x83)) break;
|
919 | 957 | String_Append(fsrc, const_bt601_coeff_inv);
|
— | — | @@ -995,10 +1033,19 @@ |
996 | 1034 | case 0x21:
|
997 | 1035 | break;
|
998 | 1036 | case 0x80:
|
| 1037 | + String_Append(fsrc, func_readuyvy_nearest);
|
| 1038 | + if ((desttype >= 0x80) && (desttype <= 0x83)) break;
|
| 1039 | + String_Append(fsrc, func_yuvatorgba);
|
999 | 1040 | break;
|
1000 | 1041 | case 0x81:
|
| 1042 | + String_Append(fsrc, func_readyuyv_nearest);
|
| 1043 | + if ((desttype >= 0x80) && (desttype <= 0x83)) break;
|
| 1044 | + String_Append(fsrc, func_yuvatorgba);
|
1001 | 1045 | break;
|
1002 | 1046 | case 0x82:
|
| 1047 | + String_Append(fsrc, func_readyvyu_nearest);
|
| 1048 | + if ((desttype >= 0x80) && (desttype <= 0x83)) break;
|
| 1049 | + String_Append(fsrc, func_yuvatorgba);
|
1003 | 1050 | break;
|
1004 | 1051 | case 0x83:
|
1005 | 1052 | if ((desttype >= 0x80) && (desttype <= 0x83)) break;
|
— | — | @@ -1034,7 +1081,7 @@ |
1035 | 1082 | if (id & DDBLT_COLORFILL) String_Append(fsrc, op_color);
|
1036 | 1083 | else
|
1037 | 1084 | {
|
1038 | | - switch (srctype2)
|
| 1085 | + switch (srctype)
|
1039 | 1086 | {
|
1040 | 1087 | case 0x00: // Classic RGB
|
1041 | 1088 | case 0x83: // AYUV
|
— | — | @@ -1049,7 +1096,8 @@ |
1050 | 1097 | case 0x11:
|
1051 | 1098 | case 0x12:
|
1052 | 1099 | case 0x13:
|
1053 | | - String_Append(fsrc, op_palpixel);
|
| 1100 | + if((desttype >= 0x10) && (desttype <= 0x13)) String_Append(fsrc, op_pixel);
|
| 1101 | + else String_Append(fsrc, op_palpixel);
|
1054 | 1102 | break;
|
1055 | 1103 | case 0x18:
|
1056 | 1104 | case 0x19:
|
— | — | @@ -1060,6 +1108,7 @@ |
1061 | 1109 | case 0x21:
|
1062 | 1110 | break;
|
1063 | 1111 | case 0x80:
|
| 1112 | + String_Append(fsrc, op_pixeluyvy);
|
1064 | 1113 | break;
|
1065 | 1114 | case 0x81:
|
1066 | 1115 | break;
|
— | — | @@ -1110,6 +1159,11 @@ |
1111 | 1160 | break;
|
1112 | 1161 | }
|
1113 | 1162 | break;
|
| 1163 | + case 0x80:
|
| 1164 | + if ((desttype >= 0x80) && (desttype <= 0x83))
|
| 1165 | + String_Append(fsrc, op_destout);
|
| 1166 | + else String_Append(fsrc, op_destoutyuvrgb);
|
| 1167 | + break;
|
1114 | 1168 | case 0x83:
|
1115 | 1169 | if ((desttype >= 0x80) && (desttype <= 0x83))
|
1116 | 1170 | String_Append(fsrc, op_destout);
|
Index: ddraw/colorconv.c |
— | — | @@ -30,8 +30,8 @@ |
31 | 31 | rgba8888torgba1555, // 6
|
32 | 32 | rgba4444torgba8888, // 7
|
33 | 33 | rgba8888torgba4444, // 8
|
34 | | - uyvytorgbx8888, // 9
|
35 | | - rgbx8888touyvy, // 10
|
| 34 | + unpackrg88, // 9
|
| 35 | + packrg88, // 10
|
36 | 36 | pal1topal8, // 11
|
37 | 37 | pal2topal8, // 12
|
38 | 38 | pal4topal8, // 13
|
— | — | @@ -270,30 +270,25 @@ |
271 | 271 | return ((DWORD)r << 16) | ((DWORD)g << 8) || (DWORD)b;
|
272 | 272 | }
|
273 | 273 |
|
274 | | -void uyvytorgbx8888(size_t count, DWORD *dest, DWORD *src)
|
| 274 | +void unpackrg88(size_t count, DWORD *dest, WORD *src)
|
275 | 275 | {
|
276 | 276 | size_t i;
|
277 | | - DWORD in;
|
278 | | - DWORD y, u, v;
|
279 | | - for (i = 0; i < (count << 1); i++)
|
| 277 | + for (i = 0; i < count; i++)
|
280 | 278 | {
|
281 | | - in = src[i];
|
282 | | - // first pixel
|
283 | | - y = (src[i] >> 8) & 0xFF;
|
284 | | - u = src[i] & 0xFF;
|
285 | | - v = (src[i] >> 16) & 0xFF;
|
286 | | - dest[i << 1] = yuvtorgb(y, u, v);
|
287 | | - // second pixel
|
288 | | - y = (src[i] >> 24) & 0xFF;
|
289 | | - dest[(i << 1)+1] = yuvtorgb(y, u, v);
|
| 279 | + dest[i] = src[i];
|
290 | 280 | }
|
291 | 281 | }
|
292 | 282 |
|
293 | | -void rgbx8888touyvy(size_t count, DWORD *dest, DWORD *src)
|
| 283 | +void packrg88(size_t count, WORD* dest, DWORD* src)
|
294 | 284 | {
|
295 | | -
|
| 285 | + size_t i;
|
| 286 | + for (i = 0; i < count; i++)
|
| 287 | + {
|
| 288 | + dest[i] = src[i] & 0xFFFF;
|
| 289 | + }
|
296 | 290 | }
|
297 | 291 |
|
| 292 | +
|
298 | 293 | void bpp24tobpp32(size_t count, DWORD *dest, BYTE *src)
|
299 | 294 | {
|
300 | 295 | size_t i;
|
Index: ddraw/colorconv.h |
— | — | @@ -41,8 +41,8 @@ |
42 | 42 | void rgba8888torgba1555(size_t count, WORD *dest, DWORD *src);
|
43 | 43 | void rgba4444torgba8888(size_t count, DWORD *dest, WORD *src);
|
44 | 44 | void rgba8888torgba4444(size_t count, WORD *dest, DWORD *src);
|
45 | | -void uyvytorgbx8888(size_t count, DWORD *dest, DWORD *src);
|
46 | | -void rgbx8888touyvy(size_t count, DWORD *dest, DWORD *src);
|
| 45 | +void unpackrg88(size_t count, DWORD *dest, WORD *src);
|
| 46 | +void packrg88(size_t count, WORD *dest, DWORD *src);
|
47 | 47 | void bpp24tobpp32(size_t count, DWORD *dest, BYTE *src);
|
48 | 48 | void bpp32tobpp24(size_t count, BYTE *dest, DWORD *src);
|
49 | 49 |
|
Index: ddraw/fourcc.c |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2018 William Feely
|
| 3 | +// Copyright (C) 2018-2019 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -21,7 +21,15 @@ |
22 | 22 |
|
23 | 23 | static const int START_FOURCC = __LINE__;
|
24 | 24 | const DWORD dxglfourcc[] =
|
25 | | -{ 0 // TODO: Add FourCC codes and remove placeholder
|
| 25 | +{
|
| 26 | + MAKEFOURCC('U','Y','V','Y'),
|
| 27 | + MAKEFOURCC('U','Y','N','V'),
|
| 28 | + MAKEFOURCC('Y','4','2','2'),
|
| 29 | + MAKEFOURCC('A','Y','U','V'),
|
| 30 | + MAKEFOURCC('Y','8',' ',' '),
|
| 31 | + MAKEFOURCC('Y','8','0','0'),
|
| 32 | + MAKEFOURCC('G','R','E','Y'),
|
| 33 | + MAKEFOURCC('Y','1','6',' ')
|
26 | 34 | };
|
27 | 35 | static const int END_FOURCC = __LINE__ - 4;
|
28 | 36 |
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -3431,10 +3431,20 @@ |
3432 | 3432 | This->bltvertices[0].x = This->bltvertices[2].x = (GLfloat)destrect.right;
|
3433 | 3433 | This->bltvertices[0].y = This->bltvertices[1].y = (GLfloat)ddsd.dwHeight - (GLfloat)destrect.top;
|
3434 | 3434 | This->bltvertices[2].y = This->bltvertices[3].y = (GLfloat)ddsd.dwHeight - (GLfloat)destrect.bottom;
|
3435 | | - This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)ddsdSrc.dwWidth;
|
3436 | | - This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right / (GLfloat)ddsdSrc.dwWidth;
|
3437 | | - This->bltvertices[0].t = This->bltvertices[1].t = (GLfloat)srcrect.top / (GLfloat)ddsdSrc.dwHeight;
|
3438 | | - This->bltvertices[2].t = This->bltvertices[3].t = (GLfloat)srcrect.bottom / (GLfloat)ddsdSrc.dwHeight;
|
| 3435 | + if (cmd->src && (cmd->src->target == GL_TEXTURE_RECTANGLE))
|
| 3436 | + {
|
| 3437 | + This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left;
|
| 3438 | + This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right;
|
| 3439 | + This->bltvertices[0].t = This->bltvertices[1].t = (GLfloat)srcrect.top;
|
| 3440 | + This->bltvertices[2].t = This->bltvertices[3].t = (GLfloat)srcrect.bottom;
|
| 3441 | + }
|
| 3442 | + else
|
| 3443 | + {
|
| 3444 | + This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)ddsdSrc.dwWidth;
|
| 3445 | + This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right / (GLfloat)ddsdSrc.dwWidth;
|
| 3446 | + This->bltvertices[0].t = This->bltvertices[1].t = (GLfloat)srcrect.top / (GLfloat)ddsdSrc.dwHeight;
|
| 3447 | + This->bltvertices[2].t = This->bltvertices[3].t = (GLfloat)srcrect.bottom / (GLfloat)ddsdSrc.dwHeight;
|
| 3448 | + }
|
3439 | 3449 | if ((cmd->bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->flags & DDBLT_DDFX))
|
3440 | 3450 | {
|
3441 | 3451 | if (cmd->bltfx.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT)
|
— | — | @@ -3677,10 +3687,20 @@ |
3678 | 3688 | glUtil_SetTexture(This->util, 8, texture);
|
3679 | 3689 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0, 8);
|
3680 | 3690 | This->ext->glUniform4f(This->shaders->shaders[progtype].view, view[0], view[1], view[2], view[3]);
|
3681 | | - This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)texture->levels[0].ddsd.dwWidth;
|
3682 | | - This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right / (GLfloat)texture->levels[0].ddsd.dwWidth;
|
3683 | | - This->bltvertices[0].t = This->bltvertices[1].t = (GLfloat)srcrect.top / (GLfloat)texture->levels[0].ddsd.dwHeight;
|
3684 | | - This->bltvertices[2].t = This->bltvertices[3].t = (GLfloat)srcrect.bottom / (GLfloat)texture->levels[0].ddsd.dwHeight;
|
| 3691 | + if (texture->target == GL_TEXTURE_RECTANGLE)
|
| 3692 | + {
|
| 3693 | + This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left;
|
| 3694 | + This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right;
|
| 3695 | + This->bltvertices[0].t = This->bltvertices[1].t = (GLfloat)srcrect.top;
|
| 3696 | + This->bltvertices[2].t = This->bltvertices[3].t = (GLfloat)srcrect.bottom;
|
| 3697 | + }
|
| 3698 | + else
|
| 3699 | + {
|
| 3700 | + This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)texture->levels[0].ddsd.dwWidth;
|
| 3701 | + This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right / (GLfloat)texture->levels[0].ddsd.dwWidth;
|
| 3702 | + This->bltvertices[0].t = This->bltvertices[1].t = (GLfloat)srcrect.top / (GLfloat)texture->levels[0].ddsd.dwHeight;
|
| 3703 | + This->bltvertices[2].t = This->bltvertices[3].t = (GLfloat)srcrect.bottom / (GLfloat)texture->levels[0].ddsd.dwHeight;
|
| 3704 | + }
|
3685 | 3705 | This->bltvertices[1].x = This->bltvertices[3].x = (float)x1;
|
3686 | 3706 | This->bltvertices[0].x = This->bltvertices[2].x = (float)x2;
|
3687 | 3707 | This->bltvertices[0].y = This->bltvertices[1].y = (float)y1;
|
Index: ddraw/glTexture.cpp |
— | — | @@ -1432,10 +1432,22 @@ |
1433 | 1433 | case DXGLPIXELFORMAT_FOURCC_UYVY:
|
1434 | 1434 | case DXGLPIXELFORMAT_FOURCC_UYNV:
|
1435 | 1435 | case DXGLPIXELFORMAT_FOURCC_Y422:
|
| 1436 | + if (This->renderer->ext->glver_major >= 3)
|
| 1437 | + {
|
| 1438 | + This->internalformats[0] = GL_RG8;
|
| 1439 | + This->format = GL_RG;
|
| 1440 | + }
|
| 1441 | + else
|
| 1442 | + {
|
| 1443 | + This->useconv = TRUE;
|
| 1444 | + This->convfunctionupload = 9;
|
| 1445 | + This->convfunctiondownload = 10;
|
| 1446 | + This->internalsize = 4;
|
| 1447 | + This->internalformats[0] = GL_RGBA8;
|
| 1448 | + This->format = GL_RGBA;
|
| 1449 | + }
|
1436 | 1450 | This->blttype = 0x80;
|
1437 | | - This->internalformats[0] = GL_RGBA8;
|
1438 | | - This->format = GL_BGRA;
|
1439 | | - This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| 1451 | + This->type = GL_UNSIGNED_BYTE;
|
1440 | 1452 | if (!This->target) This->target = GL_TEXTURE_RECTANGLE;
|
1441 | 1453 | This->colororder = 1;
|
1442 | 1454 | This->colorsizes[0] = 255;
|
— | — | @@ -1443,10 +1455,10 @@ |
1444 | 1456 | This->colorsizes[2] = 255;
|
1445 | 1457 | This->colorsizes[3] = 255;
|
1446 | 1458 | This->colorbits[0] = 8;
|
1447 | | - This->colorbits[0] = 8;
|
1448 | | - This->colorbits[0] = 8;
|
1449 | | - This->colorbits[0] = 8;
|
1450 | | - This->packsize = 2;
|
| 1459 | + This->colorbits[1] = 8;
|
| 1460 | + This->colorbits[2] = 8;
|
| 1461 | + This->colorbits[3] = 8;
|
| 1462 | + This->packsize = 1;
|
1451 | 1463 | break;
|
1452 | 1464 | case DXGLPIXELFORMAT_FOURCC_YUY2:
|
1453 | 1465 | case DXGLPIXELFORMAT_FOURCC_YUYV:
|
— | — | @@ -1462,9 +1474,9 @@ |
1463 | 1475 | This->colorsizes[2] = 255;
|
1464 | 1476 | This->colorsizes[3] = 255;
|
1465 | 1477 | This->colorbits[0] = 8;
|
1466 | | - This->colorbits[0] = 8;
|
1467 | | - This->colorbits[0] = 8;
|
1468 | | - This->colorbits[0] = 8;
|
| 1478 | + This->colorbits[1] = 8;
|
| 1479 | + This->colorbits[2] = 8;
|
| 1480 | + This->colorbits[3] = 8;
|
1469 | 1481 | This->packsize = 2;
|
1470 | 1482 | break;
|
1471 | 1483 | case DXGLPIXELFORMAT_FOURCC_YVYU:
|
— | — | @@ -1479,9 +1491,9 @@ |
1480 | 1492 | This->colorsizes[2] = 255;
|
1481 | 1493 | This->colorsizes[3] = 255;
|
1482 | 1494 | This->colorbits[0] = 8;
|
1483 | | - This->colorbits[0] = 8;
|
1484 | | - This->colorbits[0] = 8;
|
1485 | | - This->colorbits[0] = 8;
|
| 1495 | + This->colorbits[1] = 8;
|
| 1496 | + This->colorbits[2] = 8;
|
| 1497 | + This->colorbits[3] = 8;
|
1486 | 1498 | This->packsize = 2;
|
1487 | 1499 | break;
|
1488 | 1500 | case DXGLPIXELFORMAT_FOURCC_RGBG:
|
— | — | @@ -1496,9 +1508,9 @@ |
1497 | 1509 | This->colorsizes[2] = 255;
|
1498 | 1510 | This->colorsizes[3] = 255;
|
1499 | 1511 | This->colorbits[0] = 8;
|
1500 | | - This->colorbits[0] = 8;
|
1501 | | - This->colorbits[0] = 8;
|
1502 | | - This->colorbits[0] = 8;
|
| 1512 | + This->colorbits[1] = 8;
|
| 1513 | + This->colorbits[2] = 8;
|
| 1514 | + This->colorbits[3] = 8;
|
1503 | 1515 | This->packsize = 2;
|
1504 | 1516 | break;
|
1505 | 1517 | case DXGLPIXELFORMAT_FOURCC_GRGB:
|
— | — | @@ -1513,9 +1525,9 @@ |
1514 | 1526 | This->colorsizes[2] = 255;
|
1515 | 1527 | This->colorsizes[3] = 255;
|
1516 | 1528 | This->colorbits[0] = 8;
|
1517 | | - This->colorbits[0] = 8;
|
1518 | | - This->colorbits[0] = 8;
|
1519 | | - This->colorbits[0] = 8;
|
| 1529 | + This->colorbits[1] = 8;
|
| 1530 | + This->colorbits[2] = 8;
|
| 1531 | + This->colorbits[3] = 8;
|
1520 | 1532 | This->packsize = 2;
|
1521 | 1533 | break;
|
1522 | 1534 | case DXGLPIXELFORMAT_FOURCC_AYUV: // 32-bit AYUV
|
Index: dxglcfg/surfacegen.cpp |
— | — | @@ -204,6 +204,29 @@ |
205 | 205 | else return FALSE;
|
206 | 206 | }
|
207 | 207 |
|
| 208 | +unsigned short EncodeUYVY(unsigned long value, DWORD x)
|
| 209 | +{
|
| 210 | + short r = (value >> 16) & 0xff;
|
| 211 | + short g = (value >> 8) & 0xff;
|
| 212 | + short b = value & 0xff;
|
| 213 | + unsigned char y = ((66 * r + 129 * g + 25 * b + 128) >> 8) + 16;
|
| 214 | + unsigned char u = ((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128;
|
| 215 | + unsigned char v = ((112 * r - 94 * g - 18 * b + 128) >> 8) + 128;
|
| 216 | + if (x % 2) return (v | (y << 8));
|
| 217 | + else return (u | (y << 8));
|
| 218 | +}
|
| 219 | +
|
| 220 | +unsigned long EncodeAYUV(unsigned long value)
|
| 221 | +{
|
| 222 | + short r = (value >> 16) & 0xff;
|
| 223 | + short g = (value >> 8) & 0xff;
|
| 224 | + short b = value & 0xff;
|
| 225 | + unsigned char y = ((66 * r + 129 * g + 25 * b + 128) >> 8) + 16;
|
| 226 | + unsigned char u = ((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128;
|
| 227 | + unsigned char v = ((112 * r - 94 * g - 18 * b + 128) >> 8) + 128;
|
| 228 | + return (v | (u << 8) | (y << 16) | (value & 0xFF000000));
|
| 229 | +}
|
| 230 | +
|
208 | 231 | void DrawPalette(DDSURFACEDESC2 ddsd, unsigned char *buffer) // Palette test
|
209 | 232 | {
|
210 | 233 | DWORD x,y;
|
— | — | @@ -268,7 +291,7 @@ |
269 | 292 | }
|
270 | 293 | }
|
271 | 294 | else if(((ddsd.ddpfPixelFormat.dwRBitMask | ddsd.ddpfPixelFormat.dwGBitMask |
|
272 | | - ddsd.ddpfPixelFormat.dwBBitMask) == 0xFFFF) || (ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC))
|
| 295 | + ddsd.ddpfPixelFormat.dwBBitMask) == 0xFFFF))
|
273 | 296 | {
|
274 | 297 | for(y = 0; y < ddsd.dwHeight; y++)
|
275 | 298 | {
|
— | — | @@ -289,6 +312,33 @@ |
290 | 313 | }
|
291 | 314 | }
|
292 | 315 | }
|
| 316 | + else if (ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC)
|
| 317 | + {
|
| 318 | + switch (ddsd.ddpfPixelFormat.dwFourCC)
|
| 319 | + {
|
| 320 | + case MAKEFOURCC('U', 'Y', 'V', 'Y'):
|
| 321 | + case MAKEFOURCC('U', 'Y', 'N', 'V'):
|
| 322 | + case MAKEFOURCC('Y', '4', '2', '2'):
|
| 323 | + for (y = 0; y < ddsd.dwHeight; y++)
|
| 324 | + {
|
| 325 | + for (x = 0; x < ddsd.dwWidth; x++)
|
| 326 | + {
|
| 327 | + buffer16[x + ((ddsd.lPitch / 2) * y)] = EncodeUYVY((unsigned long)((x / (ddsd.dwWidth / 4096.)) + 4096 * floor((y / (ddsd.dwHeight / 4096.)))), x);
|
| 328 | + }
|
| 329 | + }
|
| 330 | + break;
|
| 331 | + default:
|
| 332 | + for (y = 0; y < ddsd.dwHeight; y++)
|
| 333 | + {
|
| 334 | + for (x = 0; x < ddsd.dwWidth; x++)
|
| 335 | + {
|
| 336 | + buffer16[x + ((ddsd.lPitch / 2) * y)] = (unsigned short)((x / (ddsd.dwWidth / 256.)) + 256 * floor((y / (ddsd.dwHeight / 256.))));
|
| 337 | + }
|
| 338 | + }
|
| 339 | + break;
|
| 340 | + }
|
| 341 | +
|
| 342 | + }
|
293 | 343 | else
|
294 | 344 | {
|
295 | 345 | for(y = 0; y < ddsd.dwHeight; y++)
|
— | — | @@ -333,6 +383,31 @@ |
334 | 384 | }
|
335 | 385 | }
|
336 | 386 | }
|
| 387 | + else if ((ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC))
|
| 388 | + {
|
| 389 | + switch (ddsd.ddpfPixelFormat.dwFourCC)
|
| 390 | + {
|
| 391 | + case MAKEFOURCC('A','Y','U','V'):
|
| 392 | + for (y = 0; y < ddsd.dwHeight; y++)
|
| 393 | + {
|
| 394 | + for (x = 0; x < ddsd.dwWidth; x++)
|
| 395 | + {
|
| 396 | + buffer32[x + ((ddsd.lPitch / 4) * y)] = EncodeAYUV((unsigned long)((x / (ddsd.dwWidth / 4096.)) + 4096 * floor((y / (ddsd.dwHeight / 4096.)))));
|
| 397 | + }
|
| 398 | + }
|
| 399 | + break;
|
| 400 | + break;
|
| 401 | + default:
|
| 402 | + for (y = 0; y < ddsd.dwHeight; y++)
|
| 403 | + {
|
| 404 | + for (x = 0; x < ddsd.dwWidth; x++)
|
| 405 | + {
|
| 406 | + buffer32[x + ((ddsd.lPitch / 4) * y)] = (unsigned long)((x / (ddsd.dwWidth / 4096.)) + 4096 * floor((y / (ddsd.dwHeight / 4096.))));
|
| 407 | + }
|
| 408 | + }
|
| 409 | + break;
|
| 410 | + }
|
| 411 | + }
|
337 | 412 | else
|
338 | 413 | {
|
339 | 414 | for (y = 0; y < ddsd.dwHeight; y++)
|