Reuse FloodFillSkin from gl3 in vk

This commit is contained in:
Denis Pauk 2020-03-14 13:41:14 +02:00 committed by Yamagi
parent b249362d0f
commit 8bfb422ab2

View file

@ -951,7 +951,7 @@ IMAGE FLOOD FILLING
/*
=================
Mod_FloodFillSkin
FloodFillSkin
Fill background pixels so mipmapping doesn't have haloes
=================
@ -959,45 +959,50 @@ Fill background pixels so mipmapping doesn't have haloes
typedef struct
{
short x, y;
short x, y;
} floodfill_t;
// must be a power of 2
/* must be a power of 2 */
#define FLOODFILL_FIFO_SIZE 0x1000
#define FLOODFILL_FIFO_MASK (FLOODFILL_FIFO_SIZE - 1)
#define FLOODFILL_STEP( off, dx, dy ) \
{ \
if (pos[off] == fillcolor) \
#define FLOODFILL_STEP(off, dx, dy) \
{ \
pos[off] = 255; \
fifo[inpt].x = x + (dx), fifo[inpt].y = y + (dy); \
inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; \
} \
else if (pos[off] != 255) fdc = pos[off]; \
}
static void R_FloodFillSkin( byte *skin, int skinwidth, int skinheight )
{
byte fillcolor = *skin; // assume this is the pixel to fill
floodfill_t fifo[FLOODFILL_FIFO_SIZE];
int inpt = 0, outpt = 0;
int filledcolor = -1;
int i;
if (filledcolor == -1)
{
filledcolor = 0;
// attempt to find opaque black
for (i = 0; i < 256; ++i)
if (d_8to24table[i] == (255 << 0)) // alpha 1.0
{
filledcolor = i;
break;
}
if (pos[off] == fillcolor) \
{ \
pos[off] = 255; \
fifo[inpt].x = x + (dx), fifo[inpt].y = y + (dy); \
inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; \
} \
else if (pos[off] != 255) \
{ \
fdc = pos[off]; \
} \
}
// can't fill to filled color or to transparent color (used as visited marker)
/*
* Fill background pixels so mipmapping doesn't have haloes
*/
static void
FloodFillSkin(byte *skin, int skinwidth, int skinheight)
{
byte fillcolor = *skin; /* assume this is the pixel to fill */
floodfill_t fifo[FLOODFILL_FIFO_SIZE];
int inpt = 0, outpt = 0;
int filledcolor = 0;
int i;
/* attempt to find opaque black */
for (i = 0; i < 256; ++i)
{
if (LittleLong(d_8to24table[i]) == (255 << 0)) /* alpha 1.0 */
{
filledcolor = i;
break;
}
}
/* can't fill to filled color or to transparent color (used as visited marker) */
if ((fillcolor == filledcolor) || (fillcolor == 255))
{
return;
@ -1008,16 +1013,32 @@ static void R_FloodFillSkin( byte *skin, int skinwidth, int skinheight )
while (outpt != inpt)
{
int x = fifo[outpt].x, y = fifo[outpt].y;
int fdc = filledcolor;
byte *pos = &skin[x + skinwidth * y];
int x = fifo[outpt].x, y = fifo[outpt].y;
int fdc = filledcolor;
byte *pos = &skin[x + skinwidth * y];
outpt = (outpt + 1) & FLOODFILL_FIFO_MASK;
if (x > 0) FLOODFILL_STEP( -1, -1, 0 );
if (x < skinwidth - 1) FLOODFILL_STEP( 1, 1, 0 );
if (y > 0) FLOODFILL_STEP( -skinwidth, 0, -1 );
if (y < skinheight - 1) FLOODFILL_STEP( skinwidth, 0, 1 );
if (x > 0)
{
FLOODFILL_STEP(-1, -1, 0);
}
if (x < skinwidth - 1)
{
FLOODFILL_STEP(1, 1, 0);
}
if (y > 0)
{
FLOODFILL_STEP(-skinwidth, 0, -1);
}
if (y < skinheight - 1)
{
FLOODFILL_STEP(skinwidth, 0, 1);
}
skin[x + skinwidth * y] = fdc;
}
}
@ -1237,7 +1258,7 @@ image_t *Vk_LoadPic (char *name, byte *pic, int width, int height, imagetype_t t
image->type = type;
if (type == it_skin && bits == 8)
R_FloodFillSkin(pic, width, height);
FloodFillSkin(pic, width, height);
// load little pics into the scrap
if (image->type == it_pic && bits == 8