DXGL r914 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r913‎ | r914 | r915 >
Date:19:32, 13 April 2019
Author:admin
Status:new
Tags:
Comment:
Add YUY2/clones and YVYU formats as Blt source.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/fourcc.c (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -1111,8 +1111,10 @@
11121112 String_Append(fsrc, op_pixeluyvy);
11131113 break;
11141114 case 0x81:
 1115+ String_Append(fsrc, op_pixelyuyv);
11151116 break;
11161117 case 0x82:
 1118+ String_Append(fsrc, op_pixelyvyu);
11171119 break;
11181120 }
11191121 }
@@ -1164,6 +1166,16 @@
11651167 String_Append(fsrc, op_destout);
11661168 else String_Append(fsrc, op_destoutyuvrgb);
11671169 break;
 1170+ case 0x81:
 1171+ if ((desttype >= 0x80) && (desttype <= 0x83))
 1172+ String_Append(fsrc, op_destout);
 1173+ else String_Append(fsrc, op_destoutyuvrgb);
 1174+ break;
 1175+ case 0x82:
 1176+ if ((desttype >= 0x80) && (desttype <= 0x83))
 1177+ String_Append(fsrc, op_destout);
 1178+ else String_Append(fsrc, op_destoutyuvrgb);
 1179+ break;
11681180 case 0x83:
11691181 if ((desttype >= 0x80) && (desttype <= 0x83))
11701182 String_Append(fsrc, op_destout);
Index: ddraw/fourcc.c
@@ -25,6 +25,10 @@
2626 MAKEFOURCC('U','Y','V','Y'),
2727 MAKEFOURCC('U','Y','N','V'),
2828 MAKEFOURCC('Y','4','2','2'),
 29+ MAKEFOURCC('Y','U','Y','2'),
 30+ MAKEFOURCC('Y','U','Y','V'),
 31+ MAKEFOURCC('Y','U','N','V'),
 32+ MAKEFOURCC('Y','V','Y','U'),
2933 MAKEFOURCC('A','Y','U','V'),
3034 MAKEFOURCC('Y','8',' ',' '),
3135 MAKEFOURCC('Y','8','0','0'),
Index: ddraw/glTexture.cpp
@@ -1463,10 +1463,22 @@
14641464 case DXGLPIXELFORMAT_FOURCC_YUY2:
14651465 case DXGLPIXELFORMAT_FOURCC_YUYV:
14661466 case DXGLPIXELFORMAT_FOURCC_YUNV:
 1467+ if (This->renderer->ext->glver_major >= 3)
 1468+ {
 1469+ This->internalformats[0] = GL_RG8;
 1470+ This->format = GL_RG;
 1471+ }
 1472+ else
 1473+ {
 1474+ This->useconv = TRUE;
 1475+ This->convfunctionupload = 9;
 1476+ This->convfunctiondownload = 10;
 1477+ This->internalsize = 4;
 1478+ This->internalformats[0] = GL_RGBA8;
 1479+ This->format = GL_RGBA;
 1480+ }
14671481 This->blttype = 0x81;
1468 - This->internalformats[0] = GL_RGBA8;
1469 - This->format = GL_BGRA;
1470 - This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
 1482+ This->type = GL_UNSIGNED_BYTE;
14711483 if (!This->target) This->target = GL_TEXTURE_RECTANGLE;
14721484 This->colororder = 1;
14731485 This->colorsizes[0] = 255;
@@ -1477,13 +1489,25 @@
14781490 This->colorbits[1] = 8;
14791491 This->colorbits[2] = 8;
14801492 This->colorbits[3] = 8;
1481 - This->packsize = 2;
 1493+ This->packsize = 1;
14821494 break;
14831495 case DXGLPIXELFORMAT_FOURCC_YVYU:
 1496+ if (This->renderer->ext->glver_major >= 3)
 1497+ {
 1498+ This->internalformats[0] = GL_RG8;
 1499+ This->format = GL_RG;
 1500+ }
 1501+ else
 1502+ {
 1503+ This->useconv = TRUE;
 1504+ This->convfunctionupload = 9;
 1505+ This->convfunctiondownload = 10;
 1506+ This->internalsize = 4;
 1507+ This->internalformats[0] = GL_RGBA8;
 1508+ This->format = GL_RGBA;
 1509+ }
14841510 This->blttype = 0x82;
1485 - This->internalformats[0] = GL_RGBA8;
1486 - This->format = GL_BGRA;
1487 - This->type = GL_UNSIGNED_INT_8_8_8_8_REV;
 1511+ This->type = GL_UNSIGNED_BYTE;
14881512 if (!This->target) This->target = GL_TEXTURE_RECTANGLE;
14891513 This->colororder = 1;
14901514 This->colorsizes[0] = 255;
@@ -1494,7 +1518,7 @@
14951519 This->colorbits[1] = 8;
14961520 This->colorbits[2] = 8;
14971521 This->colorbits[3] = 8;
1498 - This->packsize = 2;
 1522+ This->packsize = 1;
14991523 break;
15001524 case DXGLPIXELFORMAT_FOURCC_RGBG:
15011525 This->blttype = 0x9E;
Index: dxglcfg/surfacegen.cpp
@@ -216,6 +216,30 @@
217217 else return (u | (y << 8));
218218 }
219219
 220+unsigned short EncodeYUYV(unsigned long value, DWORD x)
 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+ if (x % 2) return (y | (v << 8));
 229+ else return (y | (u << 8));
 230+}
 231+
 232+unsigned short EncodeYVYU(unsigned long value, DWORD x)
 233+{
 234+ short r = (value >> 16) & 0xff;
 235+ short g = (value >> 8) & 0xff;
 236+ short b = value & 0xff;
 237+ unsigned char y = ((66 * r + 129 * g + 25 * b + 128) >> 8) + 16;
 238+ unsigned char u = ((-38 * r - 74 * g + 112 * b + 128) >> 8) + 128;
 239+ unsigned char v = ((112 * r - 94 * g - 18 * b + 128) >> 8) + 128;
 240+ if (x % 2) return (y | (u << 8));
 241+ else return (y | (v << 8));
 242+}
 243+
220244 unsigned long EncodeAYUV(unsigned long value)
221245 {
222246 short r = (value >> 16) & 0xff;
@@ -327,6 +351,26 @@
328352 }
329353 }
330354 break;
 355+ case MAKEFOURCC('Y', 'U', 'Y', '2'):
 356+ case MAKEFOURCC('Y', 'U', 'Y', 'V'):
 357+ case MAKEFOURCC('Y', 'U', 'N', 'V'):
 358+ for (y = 0; y < ddsd.dwHeight; y++)
 359+ {
 360+ for (x = 0; x < ddsd.dwWidth; x++)
 361+ {
 362+ buffer16[x + ((ddsd.lPitch / 2) * y)] = EncodeYUYV((unsigned long)((x / (ddsd.dwWidth / 4096.)) + 4096 * floor((y / (ddsd.dwHeight / 4096.)))), x);
 363+ }
 364+ }
 365+ break;
 366+ case MAKEFOURCC('Y', 'V', 'Y', 'U'):
 367+ for (y = 0; y < ddsd.dwHeight; y++)
 368+ {
 369+ for (x = 0; x < ddsd.dwWidth; x++)
 370+ {
 371+ buffer16[x + ((ddsd.lPitch / 2) * y)] = EncodeYVYU((unsigned long)((x / (ddsd.dwWidth / 4096.)) + 4096 * floor((y / (ddsd.dwHeight / 4096.)))), x);
 372+ }
 373+ }
 374+ break;
331375 default:
332376 for (y = 0; y < ddsd.dwHeight; y++)
333377 {