Example #1
0
        private void WriteColor(Color color, MimTileBlendType blendType, Stream ioStream)
        {
            if (ColorsHelper.IsBlack(color))
            {
                ioStream.Seek(3, SeekOrigin.Current);
                return;
            }

            if ((int)blendType < 4)
            {
                Color oldColor = ColorsHelper.ReadColor(ioStream, _buff3);
                color = BlendColor(color, oldColor, blendType);
                ioStream.Seek(-3, SeekOrigin.Current);
            }

            ColorsHelper.WriteBgr(ioStream, color);
        }
Example #2
0
        private static Color BlendColor(Color newColor, Color oldColor, MimTileBlendType blendType)
        {
            byte nr = newColor.R;
            byte ng = newColor.G;
            byte nb = newColor.B;

            byte or = oldColor.R;
            byte og = oldColor.G;
            byte ob = oldColor.B;

            switch (blendType)
            {
            case MimTileBlendType.Average:
                return(Color.FromArgb(255,
                                      (byte)Math.Min(255, ((nr + or) / 2)),
                                      (byte)Math.Min(255, ((ng + og) / 2)),
                                      (byte)Math.Min(255, ((nb + ob) / 2))));

            case MimTileBlendType.Add:
                return(Color.FromArgb(255,
                                      (byte)Math.Min(255, (nr + or)),
                                      (byte)Math.Min(255, (ng + og)),
                                      (byte)Math.Min(255, (nb + ob))));

            case MimTileBlendType.Sub:
                return(Color.FromArgb(255,
                                      (byte)Math.Min(255, (nr - or)),
                                      (byte)Math.Min(255, (ng - og)),
                                      (byte)Math.Min(255, (nb - ob))));

            case MimTileBlendType.Mul25:
                return(Color.FromArgb(255,
                                      (byte)Math.Min(255, (0.25 * nr + or)),
                                      (byte)Math.Min(255, (0.25 * ng + og)),
                                      (byte)Math.Min(255, (0.25 * nb + ob))));

            default:
                throw new NotSupportedException();
            }
        }