Bladeren bron

* Handle alpha layer in floodfill (but don't make it conditionnal to the algorithm)

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2678 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
jylam 16 jaren geleden
bovenliggende
commit
baa61a9f6d
3 gewijzigde bestanden met toevoegingen van 14 en 11 verwijderingen
  1. +1
    -1
      examples/floodfill.c
  2. +12
    -9
      pipi/fill/floodfill.c
  3. +1
    -1
      pipi/pipi.h

+ 1
- 1
examples/floodfill.c Bestand weergeven

@@ -30,7 +30,7 @@ int main(int argc, char *argv[])

newimg = pipi_copy(img);
pipi_free(img);
ret = pipi_flood_fill(newimg, atoi(argv[2]), atoi(argv[3]), 1, 0, 0);
ret = pipi_flood_fill(newimg, atoi(argv[2]), atoi(argv[3]), 1, 0, 0, 1);

if(!ret) pipi_save(newimg, dstname);



+ 12
- 9
pipi/fill/floodfill.c Bestand weergeven

@@ -35,8 +35,8 @@ static void pipi_flood_fill_stack_scanline_u32(pipi_pixels_t *dstp,
uint32_t new, uint32_t old);
static void pipi_flood_fill_stack_scanline_float(pipi_pixels_t *dstp,
int x, int y,
float nr, float ng, float nb,
float or, float og, float ob);
float nr, float ng, float nb, float na,
float or, float og, float ob, float oa);
static int pop (int *x,int *y, int h);
static int push(int x, int y, int h);
static void clear_stack(int h);
@@ -63,7 +63,7 @@ static int validate_pixel_f(float r1, float g1, float b1,
/* Public function */
int pipi_flood_fill(pipi_image_t *src,
int px, int py,
float r, float g, float b)
float r, float g, float b, float a)
{
pipi_image_t *dst = src;
pipi_pixels_t *dstp;
@@ -80,7 +80,7 @@ int pipi_flood_fill(pipi_image_t *src,

if(src->last_modified == PIPI_PIXELS_RGBA32) {
uint32_t *dstdata;
unsigned char nr, ng, nb;
unsigned char nr, ng, nb, na;

/* Get ARGB32 pointer */
dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA32);
@@ -89,15 +89,16 @@ int pipi_flood_fill(pipi_image_t *src,
nr = r*255.0f;
ng = g*255.0f;
nb = b*255.0f;
na = a*255.0f;

dstp->w = w;
dstp->h = h;
pipi_flood_fill_stack_scanline_u32(dstp, px, py, (nr<<16)|(ng<<8)|(nb), dstdata[px+py*w]);
pipi_flood_fill_stack_scanline_u32(dstp, px, py, (na<<24)|(nr<<16)|(ng<<8)|(nb), dstdata[px+py*w]);

} else {
int gray = (dst->last_modified == PIPI_PIXELS_Y_F);
float *dstdata;
float or, og, ob;
float or, og, ob, oa;

dstp = gray ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)
: pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
@@ -107,11 +108,12 @@ int pipi_flood_fill(pipi_image_t *src,
or = dstdata[(px+py*w)*4];
og = dstdata[(px+py*w)*4 + 1];
ob = dstdata[(px+py*w)*4 + 2];
oa = dstdata[(px+py*w)*4 + 3];

dstp->w = w;
dstp->h = h;

pipi_flood_fill_stack_scanline_float(dstp, px, py, r, g, b, or, og, ob);
pipi_flood_fill_stack_scanline_float(dstp, px, py, r, g, b, a, or, og, ob, oa);
}

return 0;
@@ -177,8 +179,8 @@ void pipi_flood_fill_stack_scanline_u32(pipi_pixels_t *dstp,
/* Float version. Much slower, but supports HDR and (soon antialiasing) */
static void pipi_flood_fill_stack_scanline_float(pipi_pixels_t *dstp,
int x, int y,
float nr, float ng, float nb,
float or, float og, float ob)
float nr, float ng, float nb, float na,
float or, float og, float ob, float oa)
{
if((nr==or) && (ng==og) && (nb==ob)) return;

@@ -214,6 +216,7 @@ static void pipi_flood_fill_stack_scanline_float(pipi_pixels_t *dstp,
cur_line[x*4] = nr;
cur_line[x*4 + 1] = ng;
cur_line[x*4 + 2] = nb;
cur_line[x*4 + 3] = na;

if(!left && x > 0 && validate_pixel_f(cur_line[xm1],
cur_line[xm1 + 1],


+ 1
- 1
pipi/pipi.h Bestand weergeven

@@ -83,7 +83,7 @@ extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *,
float, float, float, float);

extern int pipi_flood_fill(pipi_image_t *,
int, int, float, float, float);
int, int, float, float, float, float);

extern pipi_image_t *pipi_dither_floydsteinberg(pipi_image_t *, pipi_scan_t);
extern pipi_image_t *pipi_dither_ordered(pipi_image_t *);


Laden…
Annuleren
Opslaan