Split out the floodfile code into its own file.

This commit is contained in:
Bill Currie 2011-12-23 19:01:31 +09:00
parent 6fe9557dae
commit 59ef1eae9d
4 changed files with 113 additions and 75 deletions

View File

@ -462,6 +462,7 @@ void Mod_LoadAlias2Model (model_t *mod, void *buffer,
void Mod_LoadSpriteModel (model_t *mod, void *buffer); void Mod_LoadSpriteModel (model_t *mod, void *buffer);
void Mod_LoadSprite2Model (model_t *mod, void *buffer); void Mod_LoadSprite2Model (model_t *mod, void *buffer);
void Mod_SubdivideSurface (msurface_t *fa); void Mod_SubdivideSurface (msurface_t *fa);
void Mod_FloodFillSkin (byte * skin, int skinwidth, int skinheight);
void Mod_Print (void); void Mod_Print (void);

View File

@ -24,8 +24,8 @@ endif
noinst_LTLIBRARIES= $(gl) $(glsl) $(sw) noinst_LTLIBRARIES= $(gl) $(glsl) $(sw)
alias_src= model_alias.c alias_src= model_alias.c
gl_src= gl_mesh.c gl_model_alias.c gl_src= gl_mesh.c gl_model_alias.c mod_flood.c
glsl_src= glsl_mesh.c glsl_model_alias.c glsl_src= glsl_mesh.c glsl_model_alias.c mod_flood.c
sw_src= sw_model_alias.c sw_src= sw_model_alias.c
libalias_gl_la_SOURCES= $(gl_src) $(alias_src) libalias_gl_la_SOURCES= $(gl_src) $(alias_src)

View File

@ -55,79 +55,6 @@ static __attribute__ ((used)) const char rcsid[] =
VISIBLE byte player_8bit_texels[640 * 400]; VISIBLE byte player_8bit_texels[640 * 400];
// a pose is a single set of vertexes. a frame may be
// an animating sequence of poses
typedef struct {
short x, y;
} floodfill_t;
// 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) { \
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]; \
}
/*
Mod_FloodFillSkin
Fill background pixels so mipmapping doesn't have halos - Ed
*/
static void
Mod_FloodFillSkin (byte * skin, int skinwidth, int skinheight)
{
byte fillcolor = *skin; // assume this is the pixel to fill
floodfill_t fifo[FLOODFILL_FIFO_SIZE];
int filledcolor = -1, inpt = 0, outpt = 0;
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;
}
}
// can't fill to filled color or transparent color (used as visited marker)
if ((fillcolor == filledcolor) || (fillcolor == 255)) {
Sys_MaskPrintf (SYS_GLT, "not filling skin from %d to %d\n",
fillcolor, filledcolor);
return;
}
fifo[inpt].x = 0, fifo[inpt].y = 0;
inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;
while (outpt != inpt) {
int x = fifo[outpt].x, y = fifo[outpt].y, 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);
skin[x + skinwidth * y] = fdc;
}
}
void * void *
Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc) maliasskindesc_t *skindesc)

View File

@ -0,0 +1,110 @@
/*
mod_flood.c
Flood fill a skin texture.
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
// models are the only shared resource between a client and server running
// on the same machine.
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include "QF/model.h"
#include "QF/sys.h"
#include "QF/vid.h"
// a pose is a single set of vertexes. a frame may be
// an animating sequence of poses
typedef struct {
short x, y;
} floodfill_t;
// 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) { \
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]; \
}
/*
Mod_FloodFillSkin
Fill background pixels so mipmapping doesn't have halos - Ed
*/
VISIBLE void
Mod_FloodFillSkin (byte * skin, int skinwidth, int skinheight)
{
byte fillcolor = *skin; // assume this is the pixel to fill
floodfill_t fifo[FLOODFILL_FIFO_SIZE];
int filledcolor = -1, inpt = 0, outpt = 0;
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;
}
}
// can't fill to filled color or transparent color (used as visited marker)
if ((fillcolor == filledcolor) || (fillcolor == 255)) {
Sys_MaskPrintf (SYS_GLT, "not filling skin from %d to %d\n",
fillcolor, filledcolor);
return;
}
fifo[inpt].x = 0, fifo[inpt].y = 0;
inpt = (inpt + 1) & FLOODFILL_FIFO_MASK;
while (outpt != inpt) {
int x = fifo[outpt].x, y = fifo[outpt].y, 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);
skin[x + skinwidth * y] = fdc;
}
}