From f34ad259319b0bcf890603a86faf6a9a2eebb21b Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 25 Aug 2024 10:18:39 +0700 Subject: [PATCH] remove V_LinearToPatch It has a limitation: the maximum patch height is 256. Besides, the performance difference is not that big. --- src/v_fmt.c | 77 ++++------------------------------------------------- src/v_fmt.h | 3 --- 2 files changed, 5 insertions(+), 75 deletions(-) diff --git a/src/v_fmt.c b/src/v_fmt.c index bc709315..b87fd69e 100644 --- a/src/v_fmt.c +++ b/src/v_fmt.c @@ -111,7 +111,7 @@ patch_t *V_LinearToTransPatch(const byte *data, int width, int height, // If the current pixel is not transparent, add it to the current // post - if (data[offset] != color_key) + if (color_key == NO_COLOR_KEY || data[offset] != color_key) { // If we're not currently building a post, begin one and set its // offset @@ -239,7 +239,7 @@ patch_t *V_LinearToTransPatch(const byte *data, int width, int height, array_free(columns); - if (*output_size) + if (output_size) { *output_size = size; } @@ -248,64 +248,6 @@ patch_t *V_LinearToTransPatch(const byte *data, int width, int height, return (patch_t *)output; } -patch_t *V_LinearToPatch(byte *data, int width, int height, int *output_size, - int tag, void **user) -{ - size_t size = 0; - size += 4 * sizeof(int16_t); // 4 header shorts - size += width * sizeof(int32_t); // offsets table - size += width * (height + sizeof(column_t) + 3); // 2 pad bytes and cap - - byte *output = Z_Malloc(size, tag, user); - - byte *rover = output; - - // write header fields - PUTSHORT(rover, width); - PUTSHORT(rover, height); - // This is written to afterwards - PUTSHORT(rover, 0); - PUTSHORT(rover, 0); - - // set starting position of column offsets table, and skip over it - byte *col_offsets = rover; - rover += width * sizeof(int32_t); - - for (int x = 0; x < width; ++x) - { - // write column offset to offset table - PUTLONG(col_offsets, rover - output); - - // column_t topdelta - PUTBYTE(rover, 0); - // column_t length - PUTBYTE(rover, height); - - // pad byte - ++rover; - - byte *src = data + x; - for (int y = 0; y < height; ++y) - { - PUTBYTE(rover, *src); - src += width; - } - - // pad byte - ++rover; - - // Write 255 cap byte - PUTBYTE(rover, 0xff); - } - - if (*output_size) - { - *output_size = size; - } - - return (patch_t *)output; -} - static patch_t *DummyPatch(int lump, pu_tag tag) { int num = (W_CheckNumForName)("TNT1A0", ns_sprites); @@ -688,18 +630,9 @@ patch_t *V_CachePatchNum(int lump, pu_tag tag) Z_Free(buffer); - patch_t *patch; - if (png.color_key == NO_COLOR_KEY) - { - patch = V_LinearToPatch(png.image, png.width, png.height, - &lumpinfo[lump].fmt_size, tag, &lumpcache[lump]); - } - else - { - patch = V_LinearToTransPatch(png.image, png.width, png.height, - &lumpinfo[lump].fmt_size, png.color_key, - tag, &lumpcache[lump]); - } + patch_t *patch = V_LinearToTransPatch(png.image, png.width, png.height, + &lumpinfo[lump].fmt_size, + png.color_key, tag, &lumpcache[lump]); patch->leftoffset = leftoffset; patch->topoffset = topoffset; diff --git a/src/v_fmt.h b/src/v_fmt.h index f3ec4075..1125dc34 100644 --- a/src/v_fmt.h +++ b/src/v_fmt.h @@ -24,9 +24,6 @@ struct patch_s *V_LinearToTransPatch(const byte *data, int width, int height, int *output_size, int color_key, pu_tag tag, void **user); -struct patch_s *V_LinearToPatch(byte *data, int width, int height, - int *output_size, int tag, void **user); - struct patch_s *V_CachePatchNum(int lump, pu_tag tag); inline static struct patch_s *V_CachePatchName(const char *name, pu_tag tag)