summaryrefslogtreecommitdiff
path: root/retrace/d3d9state_images.cpp
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2012-12-11 17:50:50 +0000
committerJosé Fonseca <jfonseca@vmware.com>2012-12-11 17:50:50 +0000
commit3747d74bb1630cbe6d006252543a97460ef8b3ba (patch)
treeff305e6d2086199af0a1dd2f85495bec240e93de /retrace/d3d9state_images.cpp
parentf3fe75cfc6b9f5936fbc601542ec14aba129e20f (diff)
d3d9state: Upack D3DFMT_R5G6B5 too.
Quite common.
Diffstat (limited to 'retrace/d3d9state_images.cpp')
-rw-r--r--retrace/d3d9state_images.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/retrace/d3d9state_images.cpp b/retrace/d3d9state_images.cpp
index 81f7f7f0..c21573cd 100644
--- a/retrace/d3d9state_images.cpp
+++ b/retrace/d3d9state_images.cpp
@@ -25,6 +25,7 @@
#include <assert.h>
+#include <stdint.h>
#include "image.hpp"
#include "json.hpp"
@@ -53,7 +54,9 @@ getRenderTargetImage(IDirect3DDevice9 *pDevice,
hr = pRenderTarget->GetDesc(&Desc);
assert(SUCCEEDED(hr));
- if (Desc.Format != D3DFMT_X8R8G8B8 && Desc.Format != D3DFMT_A8R8G8B8) {
+ if (Desc.Format != D3DFMT_X8R8G8B8 &&
+ Desc.Format != D3DFMT_A8R8G8B8 &&
+ Desc.Format != D3DFMT_R5G6B5) {
std::cerr << "warning: unsupported D3DFORMAT " << Desc.Format << "\n";
goto no_staging;
}
@@ -81,11 +84,22 @@ getRenderTargetImage(IDirect3DDevice9 *pDevice,
dst = image->start();
src = (const unsigned char *)LockedRect.pBits;
for (unsigned y = 0; y < Desc.Height; ++y) {
- for (unsigned x = 0; x < Desc.Width; ++x) {
- dst[3*x + 0] = src[4*x + 2];
- dst[3*x + 1] = src[4*x + 1];
- dst[3*x + 2] = src[4*x + 0];
+ if (Desc.Format == D3DFMT_R5G6B5) {
+ for (unsigned x = 0; x < Desc.Width; ++x) {
+ uint32_t pixel = ((const uint16_t *)src)[x];
+ dst[3*x + 0] = (( pixel & 0x1f) * (2*0xff) + 0x1f) / (2*0x1f);
+ dst[3*x + 1] = (((pixel >> 5) & 0x3f) * (2*0xff) + 0x3f) / (2*0x3f);
+ dst[3*x + 2] = (( pixel >> 11 ) * (2*0xff) + 0x1f) / (2*0x1f);
+ dst[3*x + 3] = 0xff;
+ }
+ } else {
+ for (unsigned x = 0; x < Desc.Width; ++x) {
+ dst[3*x + 0] = src[4*x + 2];
+ dst[3*x + 1] = src[4*x + 1];
+ dst[3*x + 2] = src[4*x + 0];
+ }
}
+
src += LockedRect.Pitch;
dst += image->stride();
}