clipped_getpixel

This commit is contained in:
Albert Cahalan 2004-12-07 00:58:50 +00:00
parent 4dda614a98
commit df3c31531d
2 changed files with 35 additions and 18 deletions

View file

@ -8,6 +8,9 @@ http://www.newbreedsoftware.com/tuxpaint/
2004.December.5 (0.9.15) 2004.December.5 (0.9.15)
* New clipped_getpixel function. It works on 3 sides so far. :-(
Albert Cahalan <albert@users.sf.net>
* New smudge tool! * New smudge tool!
Albert Cahalan <albert@users.sf.net> Albert Cahalan <albert@users.sf.net>

View file

@ -764,15 +764,18 @@ static void loadarbitrary(SDL_Surface * surfs[], SDL_Surface * altsurfs[],
#endif #endif
static SDL_Surface * thumbnail(SDL_Surface * src, int max_x, int max_y, static SDL_Surface * thumbnail(SDL_Surface * src, int max_x, int max_y,
int keep_aspect); int keep_aspect);
static Uint32 getpixel(SDL_Surface * surface, int x, int y); static Uint32 getpixel(SDL_Surface * surface, int x, int y);
static void putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel); static void putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel);
static Uint32 clipped_getpixel(SDL_Surface * surface, int x, int y);
static void clipped_putpixel(SDL_Surface * dest, int x, int y, Uint32 c);
static void debug(const char * const str); static void debug(const char * const str);
static void do_undo(void); static void do_undo(void);
static void do_redo(void); static void do_redo(void);
static void render_brush(void); static void render_brush(void);
static void playsound(int chan, int s, int override); static void playsound(int chan, int s, int override);
static void line_xor(int x1, int y1, int x2, int y2); static void line_xor(int x1, int y1, int x2, int y2);
static void clipped_putpixel(SDL_Surface * dest, int x, int y, Uint32 c);
static void rect_xor(int x1, int y1, int x2, int y2); static void rect_xor(int x1, int y1, int x2, int y2);
static void update_stamp_xor(void); static void update_stamp_xor(void);
static void stamp_xor(int x1, int y1); static void stamp_xor(int x1, int y1);
@ -4167,7 +4170,6 @@ static void blit_magic(int x, int y, int button_down)
unsigned i = 32*32; unsigned i = 32*32;
double rate = button_down ? 0.5 : 0.0; double rate = button_down ? 0.5 : 0.0;
SDL_LockSurface(last);
SDL_LockSurface(canvas); SDL_LockSurface(canvas);
while (i--) while (i--)
@ -4179,17 +4181,15 @@ static void blit_magic(int x, int y, int button_down)
continue; continue;
// it is on the circle, so grab it // it is on the circle, so grab it
//SDL_GetRGB(getpixel(last, x+ix-16, y+iy-16), last->format, &r, &g, &b); SDL_GetRGB(clipped_getpixel(canvas, x+ix-16, y+iy-16), last->format, &r, &g, &b);
SDL_GetRGB(getpixel(canvas, x+ix-16, y+iy-16), last->format, &r, &g, &b);
state[ix][iy][0] = rate*state[ix][iy][0] + (1.0-rate)*sRGB_to_linear_table[r]; state[ix][iy][0] = rate*state[ix][iy][0] + (1.0-rate)*sRGB_to_linear_table[r];
state[ix][iy][1] = rate*state[ix][iy][1] + (1.0-rate)*sRGB_to_linear_table[g]; state[ix][iy][1] = rate*state[ix][iy][1] + (1.0-rate)*sRGB_to_linear_table[g];
state[ix][iy][2] = rate*state[ix][iy][2] + (1.0-rate)*sRGB_to_linear_table[b]; state[ix][iy][2] = rate*state[ix][iy][2] + (1.0-rate)*sRGB_to_linear_table[b];
// opacity 100% --> new data not blended w/ existing data // opacity 100% --> new data not blended w/ existing data
putpixel(canvas, x+ix-16, y+iy-16, SDL_MapRGB(canvas->format, linear_to_sRGB(state[ix][iy][0]), linear_to_sRGB(state[ix][iy][1]), linear_to_sRGB(state[ix][iy][2]))); clipped_putpixel(canvas, x+ix-16, y+iy-16, SDL_MapRGB(canvas->format, linear_to_sRGB(state[ix][iy][0]), linear_to_sRGB(state[ix][iy][1]), linear_to_sRGB(state[ix][iy][2])));
} }
SDL_UnlockSurface(canvas); SDL_UnlockSurface(canvas);
SDL_UnlockSurface(last);
} }
else if (cur_magic == MAGIC_NEGATIVE) else if (cur_magic == MAGIC_NEGATIVE)
{ {
@ -7923,6 +7923,20 @@ static Uint32 getpixel(SDL_Surface * surface, int x, int y)
} }
static Uint32 clipped_getpixel(SDL_Surface * src, int x, int y)
{
if (x < 96)
x = 96;
if (x >= WINDOW_WIDTH - 96)
x = WINDOW_WIDTH - 96 - 1;
if (y < 0)
y = 0;
if (y >= 48 * 7 + 40 + HEIGHTOFFSET)
y = 48 * 7 + 40 + HEIGHTOFFSET - 1;
return getpixel(src, x, y);
}
/* Draw a single pixel into the surface: */ /* Draw a single pixel into the surface: */
static void putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel) static void putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel)
@ -7982,6 +7996,18 @@ static void putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel)
} }
} }
/* Should really clip at the line level, but oh well... */
static void clipped_putpixel(SDL_Surface * dest, int x, int y, Uint32 c)
{
if (x >= 96 && x < (WINDOW_WIDTH - 96) &&
y >= 0 && y < (48 * 7 + 40 + HEIGHTOFFSET))
{
putpixel(dest, x, y, c);
}
}
/* Show debugging stuff: */ /* Show debugging stuff: */
@ -8292,18 +8318,6 @@ static void line_xor(int x1, int y1, int x2, int y2)
} }
/* Should really clip at the line level, but oh well... */
static void clipped_putpixel(SDL_Surface * dest, int x, int y, Uint32 c)
{
if (x >= 96 && x < (WINDOW_WIDTH - 96) &&
y >= 0 && y < (48 * 7 + 40 + HEIGHTOFFSET))
{
putpixel(dest, x, y, c);
}
}
/* Draw a XOR rectangle: */ /* Draw a XOR rectangle: */
static void rect_xor(int x1, int y1, int x2, int y2) static void rect_xor(int x1, int y1, int x2, int y2)