diff options
author | Andrey Nazarov <skuller@skuller.net> | 2013-10-24 21:43:25 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2013-10-24 21:43:25 +0400 |
commit | c0689324a0bf72c8b00af40c83d2e3d5dd188d8e (patch) | |
tree | 2b62123fba587c53118375211653ce433b4693d6 /src | |
parent | c9129395e9b4fc76ff501dabacbea5d088d2dfcc (diff) |
Remove OpenGL viewport aligment restrictions.
Instead, take GL_PACK_ALIGNMENT into account when making screenshots.
This would allow fullscreen resolutions like 1366x768 without black bars.
Diffstat (limited to 'src')
-rw-r--r-- | src/refresh/gl/main.c | 4 | ||||
-rw-r--r-- | src/refresh/gl/state.c | 9 | ||||
-rw-r--r-- | src/refresh/images.c | 33 | ||||
-rw-r--r-- | src/refresh/sw/main.c | 3 |
4 files changed, 30 insertions, 19 deletions
diff --git a/src/refresh/gl/main.c b/src/refresh/gl/main.c index e2b0233..8effa80 100644 --- a/src/refresh/gl/main.c +++ b/src/refresh/gl/main.c @@ -1107,8 +1107,8 @@ R_ModeChanged */ void R_ModeChanged(int width, int height, int flags, int rowbytes, void *pixels) { - r_config.width = width & ~7; - r_config.height = height & ~1; + r_config.width = width; + r_config.height = height; r_config.flags = flags; } diff --git a/src/refresh/gl/state.c b/src/refresh/gl/state.c index ac7baf0..19b2f6b 100644 --- a/src/refresh/gl/state.c +++ b/src/refresh/gl/state.c @@ -422,17 +422,22 @@ void GL_SetDefaultState(void) } // for screenshots -byte *IMG_ReadPixels(qboolean reverse, int *width, int *height) +byte *IMG_ReadPixels(qboolean reverse, int *width, int *height, int *rowbytes) { + int align = 4; + int pitch; byte *pixels; - pixels = FS_AllocTempMem(r_config.width * r_config.height * 3); + qglGetIntegerv(GL_PACK_ALIGNMENT, &align); + pitch = (r_config.width * 3 + align - 1) & ~(align - 1); + pixels = FS_AllocTempMem(pitch * r_config.height); qglReadPixels(0, 0, r_config.width, r_config.height, reverse ? GL_BGR : GL_RGB, GL_UNSIGNED_BYTE, pixels); *width = r_config.width; *height = r_config.height; + *rowbytes = pitch; return pixels; } diff --git a/src/refresh/images.c b/src/refresh/images.c index 8ee4774..9e37f69 100644 --- a/src/refresh/images.c +++ b/src/refresh/images.c @@ -46,7 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define IMG_SAVE(x) \ static qerror_t IMG_Save##x(qhandle_t f, const char *filename, \ - const byte *pic, int width, int height, int param) + const byte *pic, int width, int height, int row_stride, int param) /* ==================================================================== @@ -602,9 +602,9 @@ IMG_LOAD(TGA) IMG_SAVE(TGA) { - size_t len; byte header[TARGA_HEADER_SIZE]; ssize_t ret; + int i; memset(&header, 0, sizeof(header)); header[ 2] = 2; // uncompressed type @@ -619,10 +619,18 @@ IMG_SAVE(TGA) return ret; } - len = width * height * 3; - ret = FS_Write(pic, len, f); - if (ret < 0) { - return ret; + if (row_stride == width * 3) { + ret = FS_Write(pic, width * height * 3, f); + if (ret < 0) { + return ret; + } + } else { + for (i = 0; i < height; i++) { + ret = FS_Write(pic + i * row_stride, width * 3, f); + if (ret < 0) { + return ret; + } + } } return Q_ERR_SUCCESS; @@ -887,7 +895,6 @@ IMG_SAVE(JPG) struct jpeg_compress_struct cinfo; struct my_error_mgr jerr; JSAMPARRAY row_pointers; - int row_stride; qerror_t ret; int i; @@ -916,7 +923,6 @@ IMG_SAVE(JPG) jpeg_start_compress(&cinfo, TRUE); row_pointers = FS_AllocTempMem(sizeof(JSAMPROW) * height); - row_stride = width * 3; // JSAMPLEs per row in image_buffer for (i = 0; i < height; i++) { row_pointers[i] = (JSAMPROW)(pic + (height - i - 1) * row_stride); @@ -1131,7 +1137,7 @@ IMG_SAVE(PNG) png_structp png_ptr; png_infop info_ptr; png_bytepp row_pointers; - int i, row_stride; + int i; my_png_error my_err; qerror_t ret; @@ -1164,7 +1170,6 @@ IMG_SAVE(PNG) png_set_compression_level(png_ptr, clamp(param, 0, 9)); row_pointers = FS_AllocTempMem(sizeof(png_bytep) * height); - row_stride = width * 3; for (i = 0; i < height; i++) { row_pointers[i] = (png_bytep)pic + (height - i - 1) * row_stride; @@ -1241,22 +1246,22 @@ static qhandle_t create_screenshot(char *buffer, size_t size, } static void make_screenshot(const char *name, const char *ext, - qerror_t (*save)(qhandle_t, const char *, const byte *, int, int, int), + qerror_t (*save)(qhandle_t, const char *, const byte *, int, int, int, int), qboolean reverse, int param) { char buffer[MAX_OSPATH]; byte *pixels; qerror_t ret; qhandle_t f; - int w, h; + int w, h, rowbytes; f = create_screenshot(buffer, sizeof(buffer), name, ext); if (!f) { return; } - pixels = IMG_ReadPixels(reverse, &w, &h); - ret = save(f, buffer, pixels, w, h, param); + pixels = IMG_ReadPixels(reverse, &w, &h, &rowbytes); + ret = save(f, buffer, pixels, w, h, rowbytes, param); FS_FreeTempMem(pixels); FS_FCloseFile(f); diff --git a/src/refresh/sw/main.c b/src/refresh/sw/main.c index cb8f251..a15df2b 100644 --- a/src/refresh/sw/main.c +++ b/src/refresh/sw/main.c @@ -765,7 +765,7 @@ static void R_EdgeDrawing(void) //======================================================================= -byte *IMG_ReadPixels(qboolean reverse, int *width, int *height) +byte *IMG_ReadPixels(qboolean reverse, int *width, int *height, int *rowbytes) { byte *pixels; byte *src, *dst; @@ -798,6 +798,7 @@ byte *IMG_ReadPixels(qboolean reverse, int *width, int *height) *width = vid.width; *height = vid.height; + *rowbytes = vid.width * 3; return pixels; } |