GRIM: implement scaling for screenshot and add filtering
This commit is contained in:
parent
29d224bde7
commit
cea5828be3
2 changed files with 40 additions and 34 deletions
|
@ -1213,24 +1213,25 @@ Bitmap *GfxOpenGL::getScreenshot(int w, int h) {
|
||||||
Graphics::PixelBuffer src(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), _screenWidth * _screenHeight, DisposeAfterUse::YES);
|
Graphics::PixelBuffer src(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), _screenWidth * _screenHeight, DisposeAfterUse::YES);
|
||||||
glReadPixels(0, 0, _screenWidth, _screenHeight, GL_RGBA, GL_UNSIGNED_BYTE, src.getRawBuffer());
|
glReadPixels(0, 0, _screenWidth, _screenHeight, GL_RGBA, GL_UNSIGNED_BYTE, src.getRawBuffer());
|
||||||
|
|
||||||
int step = 0;
|
int i1 = (_screenWidth * w - 1) / _screenWidth + 1;
|
||||||
for (int y = 0; y <= 479; y++) {
|
int j1 = (_screenHeight * h - 1) / _screenHeight + 1;
|
||||||
for (int x = 0; x <= 639; x++) {
|
|
||||||
uint8 r, g, b;
|
|
||||||
src.getRGBAt(y * 640 + x, r, g, b);
|
|
||||||
uint32 color = (r + g + b) / 3;
|
|
||||||
src.setPixelAt(step++, color, color, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float step_x = (float)_screenWidth / w;
|
for (int j = 0; j < j1; j++) {
|
||||||
float step_y = (float)_screenHeight / h;
|
for (int i = 0; i < i1; i++) {
|
||||||
step = 0;
|
int x0 = i * _screenWidth / w;
|
||||||
uint8 r, g, b;
|
int x1 = ((i + 1) * _screenWidth - 1) / w + 1;
|
||||||
for (float y = 479; y >= 0; y -= step_y) {
|
int y0 = j * _screenHeight / h;
|
||||||
for (float x = 0; x < 639; x += step_x) {
|
int y1 = ((j + 1) * _screenHeight - 1) / h + 1;
|
||||||
src.getRGBAt((int)y * _screenWidth + (int)x, r, g, b);
|
uint32 color = 0;
|
||||||
buffer.setPixelAt(step++, r, g, b);
|
for (int y = y0; y < y1; y++) {
|
||||||
|
for (int x = x0; x < x1; x++) {
|
||||||
|
uint8 lr, lg, lb;
|
||||||
|
src.getRGBAt(y * _screenWidth + x, lr, lg, lb);
|
||||||
|
color += (lr + lg + lb) / 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
color /= (x1 - x0) * (y1 - y0);
|
||||||
|
buffer.setPixelAt((h - j - 1) * w + i, color, color, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1275,6 +1276,10 @@ void GfxOpenGL::dimScreen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GfxOpenGL::dimRegion(int x, int yReal, int w, int h, float level) {
|
void GfxOpenGL::dimRegion(int x, int yReal, int w, int h, float level) {
|
||||||
|
x = (int)(x * _scaleW);
|
||||||
|
yReal = (int)(yReal *_scaleH);
|
||||||
|
w = (int)(w * _scaleW);
|
||||||
|
h = (int)(h * _scaleH);
|
||||||
uint32 *data = new uint32[w * h];
|
uint32 *data = new uint32[w * h];
|
||||||
int y = _screenHeight - yReal;
|
int y = _screenHeight - yReal;
|
||||||
|
|
||||||
|
|
|
@ -1040,24 +1040,25 @@ void GfxTinyGL::drawEmergString(int x, int y, const char *text, const Color &fgC
|
||||||
Bitmap *GfxTinyGL::getScreenshot(int w, int h) {
|
Bitmap *GfxTinyGL::getScreenshot(int w, int h) {
|
||||||
Graphics::PixelBuffer buffer = Graphics::PixelBuffer::createBuffer<565>(w * h, DisposeAfterUse::YES);
|
Graphics::PixelBuffer buffer = Graphics::PixelBuffer::createBuffer<565>(w * h, DisposeAfterUse::YES);
|
||||||
|
|
||||||
int step = 0;
|
int i1 = (_screenWidth * w - 1) / _screenWidth + 1;
|
||||||
for (int y = 0; y < _gameHeight; y++) {
|
int j1 = (_screenHeight * h - 1) / _screenHeight + 1;
|
||||||
for (int x = 0; x < _gameWidth; x++) {
|
|
||||||
uint8 r, g, b;
|
|
||||||
_zb->pbuf.getRGBAt(y * _gameWidth + x, r, g, b);
|
|
||||||
uint32 color = (r + g + b) / 3;
|
|
||||||
_zb->pbuf.setPixelAt(step++, color, color,color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float step_x = 640.0f / w;
|
for (int j = 0; j < j1; j++) {
|
||||||
float step_y = 480.0f / h;
|
for (int i = 0; i < i1; i++) {
|
||||||
step = 0;
|
int x0 = i * _screenWidth / w;
|
||||||
for (float y = 0; y <= _gameHeight; y += step_y) {
|
int x1 = ((i + 1) * _screenWidth - 1) / w + 1;
|
||||||
for (float x = 0; x <= _gameWidth; x += step_x) {
|
int y0 = j * _screenHeight / h;
|
||||||
uint8 r, g, b;
|
int y1 = ((j + 1) * _screenHeight - 1) / h + 1;
|
||||||
_zb->pbuf.getRGBAt((int)y * _gameWidth + (int)x, r, g, b);
|
uint32 color = 0;
|
||||||
buffer.setPixelAt(step++, r, g, b);
|
for (int y = y0; y < y1; y++) {
|
||||||
|
for (int x = x0; x < x1; x++) {
|
||||||
|
uint8 lr, lg, lb;
|
||||||
|
_zb->pbuf.getRGBAt(y * _screenWidth + x, lr, lg, lb);
|
||||||
|
color += (lr + lg + lb) / 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
color /= (x1 - x0) * (y1 - y0);
|
||||||
|
buffer.setPixelAt(j * w + i, color, color, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue