Game Boy Color constraints support

This commit is contained in:
Thomas Bernard
2018-11-29 10:07:20 +01:00
parent 14f7eb1ba4
commit 8d7c37cc5f
3 changed files with 91 additions and 27 deletions

View File

@@ -180,6 +180,7 @@ static int Check_block_constraints(enum IMAGE_MODES mode)
int x, y, x2, y2;
int block_width = 8, block_height = 8, max_colors = 2; // default values
int error_count = 0;
byte errcol = 17;
switch (mode)
{
@@ -193,6 +194,10 @@ static int Check_block_constraints(enum IMAGE_MODES mode)
block_width = 4;
max_colors = 3; // 3 + background color
break;
case IMAGE_MODE_GBC:
max_colors = 4;
errcol = 33;
break;
default:
return -1; // unsupported mode
}
@@ -210,11 +215,24 @@ static int Check_block_constraints(enum IMAGE_MODES mode)
{
int i;
byte col = Main.backups->Pages->Image[0].Pixels[x+x2 + (y+y2)*Main.image_width];
if (mode == IMAGE_MODE_GBC)
{
if (count == 0)
c[count++] = col;
else if ((col & ~3) != (c[0] & ~3)) // compare palettes
{
if (Main.backups->Pages->Nb_layers < 2)
Add_layer(Main.backups, 1);
Main.backups->Pages->Image[1].Pixels[x+x2 + (y+y2)*Main.image_width] = errcol;
error_count++;
}
continue;
}
if (col > 15) // forbidden color !
{
if (Main.backups->Pages->Nb_layers < 2)
Add_layer(Main.backups, 1);
Main.backups->Pages->Image[1].Pixels[x+x2 + (y+y2)*Main.image_width] = 17;
Main.backups->Pages->Image[1].Pixels[x+x2 + (y+y2)*Main.image_width] = errcol;
error_count++;
continue;
}
@@ -239,7 +257,7 @@ static int Check_block_constraints(enum IMAGE_MODES mode)
GFX2_Log(GFX2_INFO, "Check_block_constraints() intensity error at (%d,%d) color=%d (other color=%d)\n", x+x2, y+y2, col, c[0]);
if (Main.backups->Pages->Nb_layers < 2)
Add_layer(Main.backups, 1);
Main.backups->Pages->Image[1].Pixels[x+x2 + (y+y2)*Main.image_width] = 17;
Main.backups->Pages->Image[1].Pixels[x+x2 + (y+y2)*Main.image_width] = errcol;
error_count++;
continue;
}
@@ -250,7 +268,7 @@ static int Check_block_constraints(enum IMAGE_MODES mode)
GFX2_Log(GFX2_INFO, "Check_block_constraints() constraint error at (%d,%d)\n", x+x2, y+y2);
if (Main.backups->Pages->Nb_layers < 2)
Add_layer(Main.backups, 1);
Main.backups->Pages->Image[1].Pixels[x+x2 + (y+y2)*Main.image_width] = 17;
Main.backups->Pages->Image[1].Pixels[x+x2 + (y+y2)*Main.image_width] = errcol;
error_count++;
}
else
@@ -341,7 +359,7 @@ void Button_Constraint_menu(void)
int grid;
} modes[] = {
{IMAGE_MODE_ZX, "ZX Spectrum", "2 colors per 8x8 block", 1}, // 256x192
//{IMAGE_MODE_GBC, "Game Boy Color"},
{IMAGE_MODE_GBC, "Game Boy Color","4 colors per 8x8 block", 1}, // 160x144 to 256x256
{IMAGE_MODE_THOMSON, "40col (MO/TO)", "2 colors per 8x1 block", 1}, // 320x200
{IMAGE_MODE_EGX, "EGX (CPC)", "Alternate Mode0/Mode1 ", 0}, // 320x200
{IMAGE_MODE_EGX2, "EGX2 (CPC)", "Alternate Mode1/Mode2 ", 0}, // 640x200
@@ -394,6 +412,8 @@ void Button_Constraint_menu(void)
}
else if (clicked_button == 3)
{
if (Selected_Constraint_Mode == IMAGE_MODE_GBC)
set_palette = 1; // activate palette back when switching from GBC
Selected_Constraint_Mode = Window_attribute2;
for (i = 0; i < sizeof(modes)/sizeof(modes[0]) ; i++)
if (Selected_Constraint_Mode == modes[i].mode)
@@ -401,32 +421,24 @@ void Button_Constraint_menu(void)
set_grid = modes[i].grid;
Hide_cursor();
Print_in_window(10, 21+18, modes[i].summary, MC_Dark, MC_Light);
Print_in_window(10+3, 87+3, set_grid?"X":" ", MC_Black, MC_Light);
Display_cursor();
break;
}
if (Selected_Constraint_Mode == IMAGE_MODE_GBC)
set_palette = 0;
}
else if (clicked_button == 4)
{
// palette
else if (clicked_button == 4) // palette
set_palette = !set_palette;
else if (clicked_button == 5) // picture size
set_pic_size = !set_pic_size;
else if (clicked_button == 6) // enable grid
set_grid = !set_grid;
if (clicked_button > 0) // refresh buttons
{
Hide_cursor();
Print_in_window(10+3, 51+3, set_palette?"X":" ", MC_Black, MC_Light);
Display_cursor();
}
else if (clicked_button == 5)
{
// picture size
set_pic_size = !set_pic_size;
Hide_cursor();
Print_in_window(10+3, 69+3, set_pic_size?"X":" ", MC_Black, MC_Light);
Display_cursor();
}
else if (clicked_button == 6)
{
// enable grid
set_grid = !set_grid;
Hide_cursor();
Print_in_window(10+3, 87+3, set_grid?"X":" ", MC_Black, MC_Light);
Display_cursor();
}
@@ -447,6 +459,10 @@ void Button_Constraint_menu(void)
Resize_image(256, 192);
End_of_modification();
break;
case IMAGE_MODE_GBC:
Resize_image(160, 144);
End_of_modification();
break;
case IMAGE_MODE_MODE5:
Resize_image(288, 256);
End_of_modification();
@@ -479,6 +495,7 @@ void Button_Constraint_menu(void)
switch (Selected_Constraint_Mode)
{
case IMAGE_MODE_ZX:
case IMAGE_MODE_GBC:
case IMAGE_MODE_C64HIRES:
Snap_width = 8;
Snap_height = 8;
@@ -517,6 +534,13 @@ void Button_Constraint_menu(void)
Fore_color = 7;
Back_color = 0;
break;
case IMAGE_MODE_GBC: // 32 colors among 32768
memset(Main.palette + 32, 0, sizeof(T_Components) * (256 - 32));
Main.palette[33].R = 255; // for color clashes
First_color_in_palette = 0;
Fore_color = 3;
Back_color = 0;
break;
case IMAGE_MODE_THOMSON:
{
static const T_MultipleChoice moto_choices[] = {