Fix part of issue 433: Safety colors (after image load) are now only added when not already present in palette, and in reverse order so that in the very common case of 0=black, the white is added in slot 255 (Now it's more consistent with 'backspace' in palette which forcibly adds these colors in unused slots at the end)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1775 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
		
							parent
							
								
									80e0b17be8
								
							
						
					
					
						commit
						c266b38e05
					
				@ -685,14 +685,35 @@ void Load_image(T_IO_Context *context)
 | 
			
		||||
      memset(color_usage,0,sizeof(color_usage));
 | 
			
		||||
      if (Count_used_colors(color_usage)<252)
 | 
			
		||||
      {
 | 
			
		||||
        int gui_index=0;
 | 
			
		||||
        int c;
 | 
			
		||||
        for (c=255; c>=0 && gui_index<4; c--)
 | 
			
		||||
        int gui_index;
 | 
			
		||||
        // From white to black
 | 
			
		||||
        for (gui_index=3; gui_index>=0; gui_index--)
 | 
			
		||||
        {
 | 
			
		||||
          if (color_usage[c]==0)
 | 
			
		||||
          int c;
 | 
			
		||||
          T_Components gui_color;
 | 
			
		||||
          
 | 
			
		||||
          gui_color=*Favorite_GUI_color(gui_index);
 | 
			
		||||
          // Try find a very close match (ignore last 2 bits)
 | 
			
		||||
          for (c=255; c>=0; c--)
 | 
			
		||||
          {
 | 
			
		||||
            context->Palette[c]=*Favorite_GUI_color(gui_index);
 | 
			
		||||
            gui_index++;
 | 
			
		||||
            if ((context->Palette[c].R|3) == (gui_color.R|3)
 | 
			
		||||
             && (context->Palette[c].G|3) == (gui_color.G|3) 
 | 
			
		||||
             && (context->Palette[c].B|3) == (gui_color.B|3) )
 | 
			
		||||
             break;
 | 
			
		||||
          }
 | 
			
		||||
          if (c<0) // Not found
 | 
			
		||||
          {
 | 
			
		||||
            // Find an unused slot at end of palette
 | 
			
		||||
            for (c=255; c>=0; c--)
 | 
			
		||||
            {
 | 
			
		||||
              if (color_usage[c]==0)
 | 
			
		||||
              {
 | 
			
		||||
                context->Palette[c]=gui_color;
 | 
			
		||||
                // Tag as a used color
 | 
			
		||||
                color_usage[c]=1;
 | 
			
		||||
                break;
 | 
			
		||||
              }
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user