From 41e25d2204efd7484900487f67599ff1b67daa33 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sun, 9 Jun 2019 02:03:13 +0200 Subject: [PATCH] Save_IFF(): save CAMG chunk and detect EHB Extra Half Bright see http://pulkomandy.tk/projects/GrafX2/ticket/134 --- src/fileformats.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/fileformats.c b/src/fileformats.c index f67d3a1e..f39bd704 100644 --- a/src/fileformats.c +++ b/src/fileformats.c @@ -2296,6 +2296,7 @@ void Save_IFF(T_IO_Context * context) int palette_entries; byte bit_depth; long body_offset = -1; + int is_ehb = 0; // Extra half-bright if (context->Format == FORMAT_LBM) { @@ -2310,13 +2311,26 @@ void Save_IFF(T_IO_Context * context) bit_depth++; temp_byte>>=1; } while (temp_byte); - GFX2_Log(GFX2_DEBUG, "Saving ILBM with bit_depth = %d\n", bit_depth); + if (bit_depth == 6) + { + for (i = 0; i < 32; i++) + { + if ( (context->Palette[i].R >> 5) != (context->Palette[i+32].R >> 4) + || (context->Palette[i].G >> 5) != (context->Palette[i+32].G >> 4) + || (context->Palette[i].B >> 5) != (context->Palette[i+32].B >> 4)) + break; + } + if (i == 32) is_ehb = 1; + } + GFX2_Log(GFX2_DEBUG, "Saving ILBM with bit_depth = %d %s\n", bit_depth, + is_ehb ? "(Extra Half-Bright)" : ""); + palette_entries = 1 << (bit_depth - is_ehb); } else // FORMAT_PBM { - bit_depth=8; + bit_depth = 8; + palette_entries = 256; } - palette_entries = 1<Format == FORMAT_LBM) + { + dword ViewMode = 0; // HIRES=0x8000 LACE=0x4 HAM=0x800 HALFBRITE=0x80 + if (is_ehb) ViewMode |= 0x80; + if (context->Width > 400) + { + ViewMode |= 0x8000; + if (context->Width > 800) + ViewMode |= 0x20; // Super High-Res + } + if (context->Height > 300) ViewMode |= 0x4; + Write_bytes(IFF_file, "CAMG", 4); + Write_dword_be(IFF_file, 4); // Section size + Write_dword_be(IFF_file, ViewMode); + } + Write_bytes(IFF_file,"CMAP",4); Write_dword_be(IFF_file,palette_entries*3);