ZX: also apply brightness constraint
There may only be one brightness per cell: either two light, or two dark colors.
This commit is contained in:
parent
f2b04e08d0
commit
1d2cfc2a8d
60
src/graph.c
60
src/graph.c
@ -3134,35 +3134,56 @@ void Pixel_in_screen_zx(word x,word y,byte color)
|
||||
uint8_t c1, c2;
|
||||
|
||||
// The color we are going to replace
|
||||
c1 = *(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width);
|
||||
c1 = *(Main_backups->Pages->Image[Main_current_layer].Pixels
|
||||
+ x + y * Main_image_width);
|
||||
|
||||
if (c1 == color)
|
||||
return;
|
||||
|
||||
// find if there is another color in the cell
|
||||
for (x2 = 0; x2 < 8; x2++)
|
||||
for (y2 = 0; y2 < 8; y2++)
|
||||
{
|
||||
c2 = *(Main_backups->Pages->Image[Main_current_layer].Pixels + (x2+start)+(y2+starty)*Main_image_width);
|
||||
c2 = *(Main_backups->Pages->Image[Main_current_layer].Pixels
|
||||
+ (x2 + start) + (y2 + starty) * Main_image_width);
|
||||
// Pixel is already of the color we are going to add, it is no problem
|
||||
if (c2 == color)
|
||||
continue;
|
||||
// We have found another color, which is the one we will keep from the cell
|
||||
if (c2 != c1)
|
||||
goto done;
|
||||
}
|
||||
done:
|
||||
|
||||
if (c2 == c1 || c2 == color)
|
||||
if ((c2 == c1 || c2 == color))
|
||||
{
|
||||
// There was only one color, so we can add a second one.
|
||||
// There was only one color, so we can add a second one
|
||||
|
||||
// First make sure we have a single brightness
|
||||
if ((c2 & 8) != (color & 8))
|
||||
{
|
||||
for (x2 = 0; x2 < 8; x2++)
|
||||
for (y2 = 0; y2 < 8; y2++)
|
||||
{
|
||||
Pixel_in_screen_layered(x2+start,y2+starty,c2 ^ 8);
|
||||
}
|
||||
}
|
||||
|
||||
Pixel_in_screen_layered(x,y,color);
|
||||
return;
|
||||
}
|
||||
|
||||
// Now replace all pixels which are of color c1, with color c2
|
||||
for (x2 = 0; x2 < 8; x2++)
|
||||
for (y2 = 0; y2 < 8; y2++)
|
||||
{
|
||||
c2 = *(Main_backups->Pages->Image[Main_current_layer].Pixels + (x2+start)+(y2+starty)*Main_image_width);
|
||||
c2 = *(Main_backups->Pages->Image[Main_current_layer].Pixels
|
||||
+ (x2 + start) + (y2 + starty) * Main_image_width);
|
||||
if (c2 == c1) {
|
||||
Pixel_in_screen_layered(x2+start,y2+starty,color);
|
||||
} else {
|
||||
// Force the brightness bit
|
||||
Pixel_in_screen_layered(x2+start,y2+starty,(c2 & ~8) | (color & 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3175,7 +3196,8 @@ void Pixel_in_screen_zx_with_preview(word x,word y,byte color)
|
||||
uint8_t c1, c2;
|
||||
|
||||
// The color we are going to replace
|
||||
c1 = *(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width);
|
||||
c1 = *(Main_backups->Pages->Image[Main_current_layer].Pixels
|
||||
+ x + y * Main_image_width);
|
||||
|
||||
// Pixel is already of the wanted color: nothing to do
|
||||
if (c1 == color)
|
||||
@ -3185,7 +3207,8 @@ void Pixel_in_screen_zx_with_preview(word x,word y,byte color)
|
||||
for (x2 = 0; x2 < 8; x2++)
|
||||
for (y2 = 0; y2 < 8; y2++)
|
||||
{
|
||||
c2 = *(Main_backups->Pages->Image[Main_current_layer].Pixels + (x2+start)+(y2+starty)*Main_image_width);
|
||||
c2 = *(Main_backups->Pages->Image[Main_current_layer].Pixels
|
||||
+ (x2 + start) + (y2 + starty) * Main_image_width);
|
||||
// Pixel is already of the color we are going to add, it is no problem
|
||||
if (c2 == color)
|
||||
continue;
|
||||
@ -3195,20 +3218,35 @@ void Pixel_in_screen_zx_with_preview(word x,word y,byte color)
|
||||
}
|
||||
done:
|
||||
|
||||
if (c2 == c1 || c2 == color)
|
||||
if ((c2 == c1 || c2 == color))
|
||||
{
|
||||
// There was only one color, so we can add a second one.
|
||||
// There was only one color, so we can add a second one
|
||||
|
||||
// First make sure we have a single brightness
|
||||
if ((c2 & 8) != (color & 8))
|
||||
{
|
||||
for (x2 = 0; x2 < 8; x2++)
|
||||
for (y2 = 0; y2 < 8; y2++)
|
||||
{
|
||||
Pixel_in_screen_layered_with_preview(x2+start,y2+starty,c2 ^ 8);
|
||||
}
|
||||
}
|
||||
|
||||
Pixel_in_screen_layered_with_preview(x,y,color);
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace all C1 with C2
|
||||
// Replace all C1 with color
|
||||
for (x2 = 0; x2 < 8; x2++)
|
||||
for (y2 = 0; y2 < 8; y2++)
|
||||
{
|
||||
c2 = *(Main_backups->Pages->Image[Main_current_layer].Pixels + (x2+start)+(y2+starty)*Main_image_width);
|
||||
c2 = *(Main_backups->Pages->Image[Main_current_layer].Pixels
|
||||
+ (x2 + start) + (y2 + starty) * Main_image_width);
|
||||
if (c2 == c1) {
|
||||
Pixel_in_screen_layered_with_preview(x2+start,y2+starty,color);
|
||||
} else {
|
||||
// Force the brightness bit
|
||||
Pixel_in_screen_layered_with_preview(x2+start,y2+starty,(c2 & ~8) | (color & 8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user