From 268887f4565cbe2978b5b14c6110b83f64c0d704 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 6 Feb 2018 12:52:07 +0100 Subject: [PATCH] Load_IFF() use CAMG to set EHB palette Fixes loading of Cougar_Sanasmatron.iff Some ILBM have 64 colors in palette for EHB images. That's OK when the 32 extra colors are valid (half bright ones) but some have garbage in the CMAP --- src/fileformats.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/fileformats.c b/src/fileformats.c index 27c0fbb6..52367fb9 100644 --- a/src/fileformats.c +++ b/src/fileformats.c @@ -587,6 +587,18 @@ static void PBM_Decode(T_IO_Context * context, FILE * file, byte compression, wo } } +static void IFF_Set_EHB_Palette(T_IO_Context * context) +{ + int i, j; // 32 colors in the palette. + for (i=0; i<32; i++) // The next 32 colors are the same with values divided by 2 + { + j=i+32; + context->Palette[j].R=context->Palette[i].R>>1; + context->Palette[j].G=context->Palette[i].G>>1; + context->Palette[j].B=context->Palette[i].B>>1; + } +} + void Load_IFF(T_IO_Context * context) { FILE * IFF_file; @@ -884,17 +896,8 @@ void Load_IFF(T_IO_Context * context) memset(context->Palette,0,sizeof(T_Palette)); if (Read_bytes(IFF_file,context->Palette,3*nb_colors)) { - if ((nb_colors==32) && (header.BitPlanes==6)) - { // This is a Extra Half-Brite (EHB) 64 color image. - int i, j; // 32 colors in the palette. - for (i=0; i<32; i++) // The next 32 colors are the same with values divided by 2 - { - j=i+32; - context->Palette[j].R=context->Palette[i].R>>1; - context->Palette[j].G=context->Palette[i].G>>1; - context->Palette[j].B=context->Palette[i].B>>1; - } - } + if (((nb_colors==32) || (AmigaViewModes & 0x80)) && (header.BitPlanes==6)) + IFF_Set_EHB_Palette(context); // This is a Extra Half-Brite (EHB) 64 color image. section_size -= 3*nb_colors; while(section_size > 0) // Read padding bytes @@ -949,6 +952,8 @@ void Load_IFF(T_IO_Context * context) Image_HAM = header.BitPlanes; bpp = 3 * (header.BitPlanes - 2); } + if ((AmigaViewModes & 0x80) && (header.BitPlanes == 6)) // This is a Extra Half-Brite (EHB) 64 color image. + IFF_Set_EHB_Palette(context); // Set the palette in case CAMG is after CMAP } else if (memcmp(section, "DPPV", 4) == 0) // DPaint II ILBM perspective chunk {