mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-23 23:16:31 +00:00
Apply thumbnail resampling fix to opengl.
See CL fb4ec5c7e32905b4bc1c7a66a1074e1e8f8e59c8 for full description.
This commit is contained in:
committed by
Baldur Karlsson
parent
6182c005b9
commit
ee2cac1a74
@@ -2190,41 +2190,31 @@ WrappedOpenGL::BackbufferImage *WrappedOpenGL::SaveBackbufferImage()
|
||||
GL.glPixelStorei(eGL_PACK_ALIGNMENT, prevPackAlignment);
|
||||
|
||||
// scale down if necessary using simple point sampling
|
||||
uint16_t resample_width = RDCMIN(maxSize, thwidth);
|
||||
resample_width &= ~3; // JPEG encoder gives shear distortion if width is not divisible by 4.
|
||||
if(thwidth != resample_width)
|
||||
thwidth = RDCMIN(maxSize, uint16_t(dat.initParams.width));
|
||||
// TODO(akharlamov): why does OpenGL align to 4 when Vulkan and DX11 align to 8?
|
||||
thwidth &= ~0x3; // align down to multiple of 4
|
||||
thheight = uint16_t(thwidth * dat.initParams.height / dat.initParams.width);
|
||||
|
||||
byte *src = thpixels;
|
||||
byte *dst = thpixels = new byte[3U * thwidth * thheight];
|
||||
|
||||
for(uint32_t y = 0; y < thheight; y++)
|
||||
{
|
||||
float widthf = float(thwidth);
|
||||
float heightf = float(thheight);
|
||||
|
||||
float aspect = widthf / heightf;
|
||||
|
||||
// clamp dimensions to a width of resample_width
|
||||
thwidth = resample_width;
|
||||
thheight = uint16_t(float(thwidth) / aspect);
|
||||
|
||||
byte *src = thpixels;
|
||||
byte *dst = thpixels = new byte[3U * thwidth * thheight];
|
||||
|
||||
for(uint32_t y = 0; y < thheight; y++)
|
||||
for(uint32_t x = 0; x < thwidth; x++)
|
||||
{
|
||||
for(uint32_t x = 0; x < thwidth; x++)
|
||||
{
|
||||
float xf = float(x) / float(thwidth);
|
||||
float yf = float(y) / float(thheight);
|
||||
uint32_t xSource = x * dat.initParams.width / thwidth;
|
||||
uint32_t ySource = y * dat.initParams.height / thheight;
|
||||
|
||||
byte *pixelsrc =
|
||||
&src[3 * uint32_t(xf * widthf) + dat.initParams.width * 3 * uint32_t(yf * heightf)];
|
||||
byte *pixelsrc = &src[3 * xSource + dat.initParams.width * 3 * ySource];
|
||||
|
||||
memcpy(dst, pixelsrc, 3);
|
||||
memcpy(dst, pixelsrc, 3);
|
||||
|
||||
dst += 3;
|
||||
}
|
||||
dst += 3;
|
||||
}
|
||||
|
||||
// src is the raw unscaled pixels, which is no longer needed
|
||||
SAFE_DELETE_ARRAY(src);
|
||||
}
|
||||
|
||||
// src is the raw unscaled pixels, which is no longer needed
|
||||
SAFE_DELETE_ARRAY(src);
|
||||
}
|
||||
|
||||
byte *jpgbuf = NULL;
|
||||
|
||||
Reference in New Issue
Block a user