Takes a screenshot of the frontbuffer and puts it into the passed bitmap handle
| 3195 | |
| 3196 | // Takes a screenshot of the frontbuffer and puts it into the passed bitmap handle |
| 3197 | void d3d_Screenshot(int bm_handle) { |
| 3198 | uint16_t *dest_data; |
| 3199 | int i, t; |
| 3200 | DDSURFACEDESC2 surf_desc; |
| 3201 | HRESULT ddrval; |
| 3202 | int bitdepth; |
| 3203 | |
| 3204 | ASSERT((bm_w(bm_handle, 0)) == D3D_state.screen_width); |
| 3205 | ASSERT((bm_h(bm_handle, 0)) == D3D_state.screen_height); |
| 3206 | |
| 3207 | DDPIXELFORMAT ddpf; |
| 3208 | // do 8bit or 16bit copy depending on surface type |
| 3209 | ddpf.dwSize = sizeof(ddpf); |
| 3210 | ddrval = lpFrontBuffer->GetPixelFormat(&ddpf); |
| 3211 | if (ddrval != DD_OK) |
| 3212 | return; |
| 3213 | |
| 3214 | bitdepth = ddpf.dwRGBBitCount; |
| 3215 | |
| 3216 | dest_data = bm_data(bm_handle, 0); |
| 3217 | |
| 3218 | memset(&surf_desc, 0, sizeof(DDSURFACEDESC2)); |
| 3219 | surf_desc.dwSize = sizeof(DDSURFACEDESC2); |
| 3220 | surf_desc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); |
| 3221 | |
| 3222 | ddrval = lpFrontBuffer->Lock(NULL, &surf_desc, DDLOCK_WAIT, NULL); |
| 3223 | |
| 3224 | if (ddrval == DD_OK) { |
| 3225 | int w = D3D_state.screen_width, h = D3D_state.screen_height; |
| 3226 | |
| 3227 | if (bitdepth == 16 || bitdepth == 15) { |
| 3228 | int shorts_per_row = surf_desc.lPitch / 2; |
| 3229 | bool bit15 = (ddpf.dwGBitMask == 0x03e0) ? true : false; |
| 3230 | |
| 3231 | uint16_t pix; |
| 3232 | |
| 3233 | uint16_t *rptr; |
| 3234 | rptr = (uint16_t *)surf_desc.lpSurface; |
| 3235 | |
| 3236 | // Go through and read our pixels |
| 3237 | |
| 3238 | if (bit15 == false) { |
| 3239 | // Do 16bit |
| 3240 | for (i = 0; i < h; i++) { |
| 3241 | for (t = 0; t < w; t++) { |
| 3242 | pix = rptr[i * shorts_per_row + t]; |
| 3243 | |
| 3244 | int r = (pix >> 11 & 0x1f) << 3; |
| 3245 | int g = (pix >> 5 & 0x3f) << 2; |
| 3246 | int b = (pix & 0x1f) << 3; |
| 3247 | |
| 3248 | r = std::min(255, (float)r * 1.4f); |
| 3249 | g = std::min(255, (float)g * 1.4f); |
| 3250 | b = std::min(255, (float)b * 1.4f); |
| 3251 | |
| 3252 | pix = GR_RGB16(r, g, b); |
| 3253 | |
| 3254 | dest_data[i * w + t] = OPAQUE_FLAG | pix; |