fix segfault in check_pixel
This commit is contained in:
parent
9e61f3b192
commit
2d7b714c20
16
crystal.c
16
crystal.c
|
@ -54,7 +54,7 @@ int main(void)
|
|||
|
||||
unsigned char generate_color()
|
||||
{
|
||||
unsigned char clr = rand() % colors;
|
||||
unsigned char clr = rand() % colors + colors;
|
||||
|
||||
clr*=(unsigned char)lround( (256/colors) );
|
||||
|
||||
|
@ -191,6 +191,13 @@ void process(unsigned int id, unsigned int step)
|
|||
|
||||
int check_pixel(unsigned int x, unsigned int y)
|
||||
{
|
||||
printf("Checking (%u|%u)\n", x, y);
|
||||
if(x>=WIDTH || y>=HEIGHT)
|
||||
{
|
||||
fprintf(stderr, "coords (%d|%d) exceed image size %d×%d.\n", x, y, WIDTH, HEIGHT);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* as the image will be grayscaled, it works to check only one layer */
|
||||
/* this implies the background colour is 0 */
|
||||
if(image[y][x][0]!=0)
|
||||
|
@ -202,12 +209,7 @@ int check_pixel(unsigned int x, unsigned int y)
|
|||
|
||||
int paint_pixel(unsigned int x, unsigned int y, unsigned char clr)
|
||||
{
|
||||
if(x>WIDTH || y>HEIGHT)
|
||||
{
|
||||
fprintf(stderr, "coords (%d|%d) exceed image size %d×%d.\n", x, y, WIDTH, HEIGHT);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("paint_pixel called\n");
|
||||
if(check_pixel(x, y)) return 1;
|
||||
|
||||
image[y][x][0]=clr;
|
||||
|
|
Loading…
Reference in New Issue