From 6291bcb84c5a9bc2ab8a749a167d6918c69e40c5 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 16 Jul 2023 23:24:02 +0300 Subject: [PATCH] Add 32 bit colors in DrawStretchRaw (#45) Sync with https://github.com/yquake2/yquake2/commit/146e5615af0ade1f37b8f38a4987b1785f54d5a4 --- src/common/header/ref_api.h | 9 ++-- src/vk/header/local.h | 2 +- src/vk/vk_draw.c | 82 ++++++++++++++++++++++--------------- 3 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/common/header/ref_api.h b/src/common/header/ref_api.h index d79adcc..680ab4d 100644 --- a/src/common/header/ref_api.h +++ b/src/common/header/ref_api.h @@ -197,8 +197,11 @@ typedef struct void (EXPORT *DrawFill) (int x, int y, int w, int h, int c); void (EXPORT *DrawFadeScreen) (void); - // Draw images for cinematic rendering (which can have a different palette). Note that calls - void (EXPORT *DrawStretchRaw) (int x, int y, int w, int h, int cols, int rows, byte *data); + /* + * Draw images for cinematic rendering (which can have a different palette if bits equals to 8). + * Note that calls + */ + void (EXPORT *DrawStretchRaw) (int x, int y, int w, int h, int cols, int rows, const byte *data, int bits); /* ** video mode and refresh state management entry points @@ -278,7 +281,7 @@ void Draw_CharScaled(int x, int y, int num, float scale); void Draw_TileClear(int x, int y, int w, int h, char *name); void Draw_Fill(int x, int y, int w, int h, int c); void Draw_FadeScreen(void); -void Draw_StretchRaw(int x, int y, int w, int h, int cols, int rows, byte *data); +void Draw_StretchRaw(int x, int y, int w, int h, int cols, int rows, const byte *data, int bits); //int R_Init(void *hinstance, void *hWnd); //void R_Shutdown(void); void R_SetPalette(const unsigned char *palette); diff --git a/src/vk/header/local.h b/src/vk/header/local.h index 40454d0..ab309ba 100644 --- a/src/vk/header/local.h +++ b/src/vk/header/local.h @@ -231,7 +231,7 @@ void RE_Draw_CharScaled (int x, int y, int num, float scale); void RE_Draw_TileClear (int x, int y, int w, int h, char *name); void RE_Draw_Fill (int x, int y, int w, int h, int c); void RE_Draw_FadeScreen (void); -void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data); +void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *data, int bits); qboolean RE_EndWorldRenderpass( void ); diff --git a/src/vk/vk_draw.c b/src/vk/vk_draw.c index 063b248..9f7d16d 100644 --- a/src/vk/vk_draw.c +++ b/src/vk/vk_draw.c @@ -260,7 +260,7 @@ RE_Draw_StretchRaw static int vk_rawTexture_height; static int vk_rawTexture_width; -void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data) +void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *data, int bits) { int i, j; @@ -272,53 +272,66 @@ void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *d if (!vk_frameStarted) return; - if (r_retexturing->value) + if (bits == 32) { - // triple scaling - if (cols < (vid.width / 3) || rows < (vid.height / 3)) + raw_image32 = malloc(cols * rows * sizeof(unsigned)); + if (!raw_image32) { - image_scaled = malloc(cols * rows * 9); - - scale3x(data, image_scaled, cols, rows); - - cols = cols * 3; - rows = rows * 3; + return; } - else - // double scaling - { - image_scaled = malloc(cols * rows * 4); - scale2x(data, image_scaled, cols, rows); - - cols = cols * 2; - rows = rows * 2; - } + memcpy(raw_image32, data, cols * rows * sizeof(unsigned)); } else { - image_scaled = data; - } - - raw_image32 = malloc(cols * rows * sizeof(unsigned)); - - source = image_scaled; - dest = raw_image32; - for (i = 0; i < rows; ++i) - { - int rowOffset = i * cols; - for (j = 0; j < cols; ++j) + if (r_retexturing->value) { - byte palIdx = source[rowOffset + j]; - dest[rowOffset + j] = r_rawpalette[palIdx]; + // triple scaling + if (cols < (vid.width / 3) || rows < (vid.height / 3)) + { + image_scaled = malloc(cols * rows * 9); + + scale3x(data, image_scaled, cols, rows); + + cols = cols * 3; + rows = rows * 3; + } + else + // double scaling + { + image_scaled = malloc(cols * rows * 4); + + scale2x(data, image_scaled, cols, rows); + + cols = cols * 2; + rows = rows * 2; + } + } + else + { + image_scaled = (byte *)data; + } + + raw_image32 = malloc(cols * rows * sizeof(unsigned)); + + source = image_scaled; + dest = raw_image32; + for (i = 0; i < rows; ++i) + { + int rowOffset = i * cols; + for (j = 0; j < cols; ++j) + { + byte palIdx = source[rowOffset + j]; + dest[rowOffset + j] = r_rawpalette[palIdx]; + } } } if (r_retexturing->value) { - free(image_scaled); - int scaled_size = cols * rows; + + free(image_scaled); SmoothColorImage(raw_image32, scaled_size, (scaled_size) >> 7); } @@ -351,6 +364,7 @@ void RE_Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *d QVk_DebugSetObjectName((uint64_t)vk_rawTexture.resource.memory, VK_OBJECT_TYPE_DEVICE_MEMORY, "Memory: raw texture"); } + free(raw_image32); float imgTransform[] = { (float)x / vid.width, (float)y / vid.height,