diff --git a/src/buttons_effects.c b/src/buttons_effects.c index 1ea9ec38..dcb336e9 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -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[] = { diff --git a/src/graph.c b/src/graph.c index 4dd24326..41989b11 100644 --- a/src/graph.c +++ b/src/graph.c @@ -3386,6 +3386,31 @@ done: } } +/// Paint a pixel with GBC constraints +/// +/// Same 4 color palette for all pixels in a 8x8 block. +static void Pixel_in_screen_gbc_with_opt_preview(word x,word y,byte color,int preview) +{ + word startx = x & ~7; + word starty = y & ~7; + word x2, y2; + byte palette; + + // first set the pixel + Pixel_in_screen_layered_with_opt_preview(x,y,color,preview); + palette = color & ~3; + // force all pixels of the block to the same palette + for (y2 = 0; y2 < 8; y2++) + { + for (x2 = 0; x2 < 8; x2++) + { + byte col = Read_pixel_from_current_layer(startx+x2, starty+y2); + if ((col & ~3) != palette) + Pixel_in_screen_layered_with_opt_preview(startx+x2, starty+y2, palette | (col & 3), preview); + } + } +} + /// Paint a pixel with C64 MultiColor constraints /// /// Only 4 colors in a 4x8 block, including the background color @@ -3558,7 +3583,6 @@ void Update_pixel_renderer(void) switch (Main.backups->Pages->Image_mode) { case IMAGE_MODE_C64FLI: //TODO - case IMAGE_MODE_GBC: // TODO case IMAGE_MODE_ANIMATION: // direct Pixel_in_current_screen_with_opt_preview = Pixel_in_screen_direct_with_opt_preview; @@ -3575,6 +3599,9 @@ void Update_pixel_renderer(void) case IMAGE_MODE_THOMSON: Pixel_in_current_screen_with_opt_preview = Pixel_in_screen_thomson_with_opt_preview; break; + case IMAGE_MODE_GBC: + Pixel_in_current_screen_with_opt_preview = Pixel_in_screen_gbc_with_opt_preview; + break; case IMAGE_MODE_C64HIRES: case IMAGE_MODE_ZX: Pixel_in_current_screen_with_opt_preview = Pixel_in_screen_zx_with_opt_preview; diff --git a/src/helpfile.h b/src/helpfile.h index 18b614d4..aea7154e 100644 --- a/src/helpfile.h +++ b/src/helpfile.h @@ -2,6 +2,7 @@ */ /* Grafx2 - The Ultimate 256-color bitmap paint program + Copyright 2018 Thomas Bernard Copyright 2008 Yves Rizoud Copyright 2009 Franck Charlet Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) @@ -1936,10 +1937,22 @@ static const T_Help_table helptable_effects[] = HELP_TEXT ("") HELP_TEXT ("") HELP_BOLD ("Block modes") - HELP_TEXT ("ZX Spectrum, Thomson MOTO, C64 multicolor,") - HELP_TEXT ("C64 HiRes are modes with block constraints.") - HELP_TEXT ("Only a limited different colors (generaly 2)") - HELP_TEXT ("are allowed in a pixel block.") + HELP_TEXT ("ZX Spectrum, Game Boy Color, Thomson MOTO,") + HELP_TEXT ("C64 MultiColor, C64 HiRes are modes with") + HELP_TEXT ("block constraints. Only a limited count of") + HELP_TEXT ("different colors (generaly 2) is allowed in") + HELP_TEXT ("a pixel block.") + HELP_TEXT ("") + HELP_BOLD ("Game Boy Color") + HELP_TEXT ("All pixels within a 8x8 block should be in") + HELP_TEXT ("same 4 colors palette. There are 8 palettes:") + HELP_TEXT ("colors #0-#3, #4-#7, ..., #28-#31.") + HELP_TEXT ("Advice: put common colors at the same") + HELP_TEXT (" position within the palettes. eg if") + HELP_TEXT (" you need a black background, set") + HELP_TEXT (" colors #0, #4, #8, etc. to black.") + HELP_TEXT ("Color #0 of each palette is transparent for") + HELP_TEXT ("Game Boy sprites.") HELP_TEXT ("") HELP_TEXT ("") HELP_BOLD ("Amstrad CPC Mode5")