DXGL r913 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r912‎ | r913 | r914 >
Date:19:11, 13 April 2019
Author:admin
Status:new
Tags:
Comment:
Add support (Blt source only, nearest-neighbor only) for UYVY and identical surface formats.
Add FOURCC codes for supported FOURCC formats.
Use RGB->YUV conversion in surfacegen.cpp
Store UYVY formats in GL_RG8 texture.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/colorconv.c (modified) (history)
  • /ddraw/colorconv.h (modified) (history)
  • /ddraw/fourcc.c (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -156,6 +156,9 @@
157157 vec2 index = vec2(((myindex.x*(255.0/256.0))+(0.5/256.0)),0.5);\n\
158158 pixel = ivec4(texture2D(srcpal, index)*vec4(colorsizedest)+.5);\n";
159159 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";
160163 static const char op_lumpixel[] = "pixel = ivec4(vec4(texture2D(srctex,gl_TexCoord[0].st).rrr,1.0)*vec4(colorsizedest)+.5);\n";
161164 static const char op_color[] = "pixel = fillcolor;\n";
162165 static const char op_dest[] = "dest = ivec4(texture2D(desttex,gl_TexCoord[1].st)*vec4(colorsizedest)+.5);\n";
@@ -197,12 +200,32 @@
198201 {\n\
199202 return vec4(vec3((bt601_coeff_inv * rgba.rgb) + yuv_offsets_inv),rgba.a);\n\
200203 }\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";
206228
 229+
207230 // ROP Operations
208231 static const char *op_ROP[256] = {
209232 "pixel = ivec4(0);\n",//00 BLACKNESS
@@ -890,6 +913,18 @@
891914 else String_Append(fsrc, version_110);
892915 }
893916 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+ }
894929 String_Append(fsrc, idheader);
895930 String_Append(fsrc, idstring);
896931
@@ -913,6 +948,9 @@
914949 case 0:
915950 default:
916951 break;
 952+ case 0x80:
 953+ case 0x81:
 954+ case 0x82:
917955 case 0x83:
918956 if ((srctype >= 0x80) && (srctype <= 0x83)) break;
919957 String_Append(fsrc, const_bt601_coeff_inv);
@@ -995,10 +1033,19 @@
9961034 case 0x21:
9971035 break;
9981036 case 0x80:
 1037+ String_Append(fsrc, func_readuyvy_nearest);
 1038+ if ((desttype >= 0x80) && (desttype <= 0x83)) break;
 1039+ String_Append(fsrc, func_yuvatorgba);
9991040 break;
10001041 case 0x81:
 1042+ String_Append(fsrc, func_readyuyv_nearest);
 1043+ if ((desttype >= 0x80) && (desttype <= 0x83)) break;
 1044+ String_Append(fsrc, func_yuvatorgba);
10011045 break;
10021046 case 0x82:
 1047+ String_Append(fsrc, func_readyvyu_nearest);
 1048+ if ((desttype >= 0x80) && (desttype <= 0x83)) break;
 1049+ String_Append(fsrc, func_yuvatorgba);
10031050 break;
10041051 case 0x83:
10051052 if ((desttype >= 0x80) && (desttype <= 0x83)) break;
@@ -1034,7 +1081,7 @@
10351082 if (id & DDBLT_COLORFILL) String_Append(fsrc, op_color);
10361083 else
10371084 {
1038 - switch (srctype2)
 1085+ switch (srctype)
10391086 {
10401087 case 0x00: // Classic RGB
10411088 case 0x83: // AYUV
@@ -1049,7 +1096,8 @@
10501097 case 0x11:
10511098 case 0x12:
10521099 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);
10541102 break;
10551103 case 0x18:
10561104 case 0x19:
@@ -1060,6 +1108,7 @@
10611109 case 0x21:
10621110 break;
10631111 case 0x80:
 1112+ String_Append(fsrc, op_pixeluyvy);
10641113 break;
10651114 case 0x81:
10661115 break;
@@ -1110,6 +1159,11 @@
11111160 break;
11121161 }
11131162 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;
11141168 case 0x83:
11151169 if ((desttype >= 0x80) && (desttype <= 0x83))
11161170 String_Append(fsrc, op_destout);
Index: ddraw/colorconv.c
@@ -30,8 +30,8 @@
3131 rgba8888torgba1555, // 6
3232 rgba4444torgba8888, // 7
3333 rgba8888torgba4444, // 8
34 - uyvytorgbx8888, // 9
35 - rgbx8888touyvy, // 10
 34+ unpackrg88, // 9
 35+ packrg88, // 10
3636 pal1topal8, // 11
3737 pal2topal8, // 12
3838 pal4topal8, // 13
@@ -270,30 +270,25 @@
271271 return ((DWORD)r << 16) | ((DWORD)g << 8) || (DWORD)b;
272272 }
273273
274 -void uyvytorgbx8888(size_t count, DWORD *dest, DWORD *src)
 274+void unpackrg88(size_t count, DWORD *dest, WORD *src)
275275 {
276276 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++)
280278 {
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];
290280 }
291281 }
292282
293 -void rgbx8888touyvy(size_t count, DWORD *dest, DWORD *src)
 283+void packrg88(size_t count, WORD* dest, DWORD* src)
294284 {
295 -
 285+ size_t i;
 286+ for (i = 0; i < count; i++)
 287+ {
 288+ dest[i] = src[i] & 0xFFFF;
 289+ }
296290 }
297291
 292+
298293 void bpp24tobpp32(size_t count, DWORD *dest, BYTE *src)
299294 {
300295 size_t i;
Index: ddraw/colorconv.h
@@ -41,8 +41,8 @@
4242 void rgba8888torgba1555(size_t count, WORD *dest, DWORD *src);
4343 void rgba4444torgba8888(size_t count, DWORD *dest, WORD *src);
4444 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);
4747 void bpp24tobpp32(size_t count, DWORD *dest, BYTE *src);
4848 void bpp32tobpp24(size_t count, BYTE *dest, DWORD *src);
4949
Index: ddraw/fourcc.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2018 William Feely
 3+// Copyright (C) 2018-2019 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -21,7 +21,15 @@
2222
2323 static const int START_FOURCC = __LINE__;
2424 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',' ')
2634 };
2735 static const int END_FOURCC = __LINE__ - 4;
2836
Index: ddraw/glRenderer.cpp
@@ -3431,10 +3431,20 @@
34323432 This->bltvertices[0].x = This->bltvertices[2].x = (GLfloat)destrect.right;
34333433 This->bltvertices[0].y = This->bltvertices[1].y = (GLfloat)ddsd.dwHeight - (GLfloat)destrect.top;
34343434 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+ }
34393449 if ((cmd->bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->flags & DDBLT_DDFX))
34403450 {
34413451 if (cmd->bltfx.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT)
@@ -3677,10 +3687,20 @@
36783688 glUtil_SetTexture(This->util, 8, texture);
36793689 This->ext->glUniform1i(This->shaders->shaders[progtype].tex0, 8);
36803690 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+ }
36853705 This->bltvertices[1].x = This->bltvertices[3].x = (float)x1;
36863706 This->bltvertices[0].x = This->bltvertices[2].x = (float)x2;
36873707 This->bltvertices[0].y = This->bltvertices[1].y = (float)y1;
Index: ddraw/glTexture.cpp
@@ -1432,10 +1432,22 @@
14331433 case DXGLPIXELFORMAT_FOURCC_UYVY:
14341434 case DXGLPIXELFORMAT_FOURCC_UYNV:
14351435 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+ }
14361450 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;
14401452 if (!This->target) This->target = GL_TEXTURE_RECTANGLE;
14411453 This->colororder = 1;
14421454 This->colorsizes[0] = 255;
@@ -1443,10 +1455,10 @@
14441456 This->colorsizes[2] = 255;
14451457 This->colorsizes[3] = 255;
14461458 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;
14511463 break;
14521464 case DXGLPIXELFORMAT_FOURCC_YUY2:
14531465 case DXGLPIXELFORMAT_FOURCC_YUYV:
@@ -1462,9 +1474,9 @@
14631475 This->colorsizes[2] = 255;
14641476 This->colorsizes[3] = 255;
14651477 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;
14691481 This->packsize = 2;
14701482 break;
14711483 case DXGLPIXELFORMAT_FOURCC_YVYU:
@@ -1479,9 +1491,9 @@
14801492 This->colorsizes[2] = 255;
14811493 This->colorsizes[3] = 255;
14821494 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;
14861498 This->packsize = 2;
14871499 break;
14881500 case DXGLPIXELFORMAT_FOURCC_RGBG:
@@ -1496,9 +1508,9 @@
14971509 This->colorsizes[2] = 255;
14981510 This->colorsizes[3] = 255;
14991511 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;
15031515 This->packsize = 2;
15041516 break;
15051517 case DXGLPIXELFORMAT_FOURCC_GRGB:
@@ -1513,9 +1525,9 @@
15141526 This->colorsizes[2] = 255;
15151527 This->colorsizes[3] = 255;
15161528 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;
15201532 This->packsize = 2;
15211533 break;
15221534 case DXGLPIXELFORMAT_FOURCC_AYUV: // 32-bit AYUV
Index: dxglcfg/surfacegen.cpp
@@ -204,6 +204,29 @@
205205 else return FALSE;
206206 }
207207
 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+
208231 void DrawPalette(DDSURFACEDESC2 ddsd, unsigned char *buffer) // Palette test
209232 {
210233 DWORD x,y;
@@ -268,7 +291,7 @@
269292 }
270293 }
271294 else if(((ddsd.ddpfPixelFormat.dwRBitMask | ddsd.ddpfPixelFormat.dwGBitMask |
272 - ddsd.ddpfPixelFormat.dwBBitMask) == 0xFFFF) || (ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC))
 295+ ddsd.ddpfPixelFormat.dwBBitMask) == 0xFFFF))
273296 {
274297 for(y = 0; y < ddsd.dwHeight; y++)
275298 {
@@ -289,6 +312,33 @@
290313 }
291314 }
292315 }
 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+ }
293343 else
294344 {
295345 for(y = 0; y < ddsd.dwHeight; y++)
@@ -333,6 +383,31 @@
334384 }
335385 }
336386 }
 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+ }
337412 else
338413 {
339414 for (y = 0; y < ddsd.dwHeight; y++)