/// <summary>
        /// Adds a mapping from the given RGB color to the given ARGB color.
        /// </summary>
        /// <param name="source">The source RGB color.</param>
        /// <param name="destination">The destination ARGB color.</param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="source"/> and <paramref name="destination"/> colors are
        /// identical, and thus this mapping is trivial.</exception>
        public void AddMapping(RgbColor source, ArgbColor destination)
        {
            if (source.ToArgb() == destination.ToArgb())
                throw new ArgumentException(
                    "source and destination colors are identical. Trivial mappings may not be explicitly defined.");

            map.Add(source, destination);
        }
Example #2
0
 /// <summary>
 /// Builds the color mapping by adding all colors in the given table, and also resolving lookups according to the given alpha map.
 /// </summary>
 /// <param name="colorTable">The colors that should be added to the current lookup mapping.</param>
 /// <param name="alphaMap">The alpha mapping that specifies new ARGB colors that should replace any given RGB colors in the color
 /// table.</param>
 private void BuildColorMap(ArgbColor[] colorTable, AlphaRemappingTable alphaMap)
 {
     foreach (ArgbColor sourceArgbColor in colorTable)
     {
         if (sourceArgbColor.A == 255)
         {
             RgbColor sourceRgbColor = (RgbColor)sourceArgbColor;
             Color    sourceColor    = Color.FromArgb(sourceRgbColor.ToArgb());
             if (!colorMappingTable.ContainsKey(sourceColor))
             {
                 if (!alphaMap.TryGetMapping(sourceRgbColor, out ArgbColor desiredArgbColor))
                 {
                     desiredArgbColor = sourceArgbColor;
                 }
                 colorMappingTable.Add(sourceColor, Color.FromArgb(desiredArgbColor.ToArgb()));
             }
         }
     }
 }