Example #1
0
        /**<summary>Returns a palette image loaded from the specified bitmap image.</summary>*/
        public static PaletteImage FromImage(Bitmap image, Palette palette)
        {
            PaletteImage paletteImage = new PaletteImage(image.Size);

            for (int x = 0; x < image.Width; x++)
            {
                for (int y = 0; y < image.Height; y++)
                {
                    Color imageColor    = image.GetPixel(x, y);
                    int   minDelta      = GetColorDelta(imageColor, palette.Colors[0]);
                    int   minDeltaIndex = 0;
                    for (int i = 10; i < palette.NumColors; i++)
                    {
                        int delta = GetColorDelta(imageColor, palette.Colors[i]);
                        if (delta < minDelta)
                        {
                            minDelta      = delta;
                            minDeltaIndex = i;
                        }
                    }
                    paletteImage.pixels[x, y] = (byte)minDeltaIndex;
                }
            }

            return(paletteImage);
        }
Example #2
0
        //=========== DRAWING ============
        #region Drawing

        /**<summary>Draws the terrain to the specified palette image.</summary>*/
        public void Draw(PaletteImage p, Point point, int darkness)
        {
            point.X -= 32 + ((Origin.X - Origin.Y) * 32);
            point.Y -= 15 + ((Origin.X + Origin.Y) * 16);
            for (int x1 = 0; x1 < Size.Width; x1++)
            {
                for (int y1 = 0; y1 < Size.Height; y1++)
                {
                    if (Slope != -1 &&
                        ((Slope == 0 && x1 < Origin.X - 0) || (Slope == 2 && x1 > Origin.X + 2) ||
                         (Slope == 1 && y1 < Origin.Y - 1) || (Slope == 3 && y1 > Origin.Y + 1)))
                    {
                        LandTiles[0].DrawWithOffset(p, point.X + ((x1 - y1) * 32), point.Y + ((x1 + y1 - 1) * 16),
                                                    darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                                    );
                    }
                    else if (Slope == -1 ||
                             (Slope % 2 == 0 && (x1 < Origin.X - 0 || x1 > Origin.X + 2)) ||
                             (Slope % 2 == 1 && (y1 < Origin.Y - 1 || y1 > Origin.Y + 1)))
                    {
                        /*(Slope % 2 == 0 && (x1 < Origin.X - 0 || x1 > Origin.X + 2)) ||
                        *  (Slope % 2 == 1 && (y1 < Origin.Y - 1 || y1 > Origin.Y + 1))) {*/
                        LandTiles[0].DrawWithOffset(p, point.X + ((x1 - y1) * 32), point.Y + ((x1 + y1) * 16),
                                                    darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                                    );
                    }
                    else if (Slope == 0 && x1 == Origin.X + 2)
                    {
                        LandTiles[1].DrawWithOffset(p, point.X + ((x1 - y1) * 32), point.Y + ((x1 + y1) * 16),
                                                    darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                                    );
                    }
                    else if (Slope == 1 && y1 == Origin.Y + 1)
                    {
                        LandTiles[2].DrawWithOffset(p, point.X + ((x1 - y1) * 32), point.Y + ((x1 + y1) * 16),
                                                    darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                                    );
                    }
                    else if (Slope == 2 && x1 == Origin.X - 0)
                    {
                        LandTiles[3].DrawWithOffset(p, point.X + ((x1 - y1) * 32), point.Y + ((x1 + y1) * 16),
                                                    darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                                    );
                    }
                    else if (Slope == 3 && y1 == Origin.Y - 1)
                    {
                        LandTiles[4].DrawWithOffset(p, point.X + ((x1 - y1) * 32), point.Y + ((x1 + y1) * 16),
                                                    darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                                    );
                    }
                }
            }
        }
Example #3
0
 /**<summary>Draws the palette image into the specified palette image.</summary>*/
 public void Draw(PaletteImage p, Point point, int darkness, bool glass, RemapColors remap1 = RemapColors.None, RemapColors remap2 = RemapColors.None, RemapColors remap3 = RemapColors.None)
 {
     for (int x1 = 0; x1 < Width; x1++)
     {
         for (int y1 = 0; y1 < Height; y1++)
         {
             if (x1 + point.X >= 0 && y1 + point.Y >= 0 && x1 + point.X < p.Width && y1 + point.Y < p.Height)
             {
                 p.pixels[x1 + point.X, y1 + point.Y] = GetColorIndexRemapped(pixels[x1, y1], p.pixels[x1 + point.X, y1 + point.Y], darkness, glass, remap1, remap2, remap3);
             }
         }
     }
 }
Example #4
0
        /**<summary>Draws the palette image into the specified palette image using the image entry's offset.</summary>*/
        public void DrawWithOffset(PaletteImage p, int x, int y, int darkness, bool glass, RemapColors remap1 = RemapColors.None, RemapColors remap2 = RemapColors.None, RemapColors remap3 = RemapColors.None)
        {
            x += this.entry.XOffset;
            y += this.entry.YOffset;

            for (int x1 = 0; x1 < Width; x1++)
            {
                for (int y1 = 0; y1 < Height; y1++)
                {
                    if (x1 + x >= 0 && y1 + y >= 0 && x1 + x < p.Width && y1 + y < p.Height)
                    {
                        p.pixels[x1 + x, y1 + y] = GetColorIndexRemapped(pixels[x1, y1], p.pixels[x1 + x, y1 + y], darkness, glass, remap1, remap2, remap3);
                    }
                }
            }
        }
 /**<summary>Draws the palette into the specified palette image.</summary>*/
 public void Draw(PaletteImage p, Point point, Size colorSize)
 {
     for (int i = 0; i < colors.Length; i++)
     {
         int x2 = ((i + entry.XOffset) % 16) * colorSize.Width;
         int y2 = ((i + entry.XOffset) / 16) * colorSize.Height;
         for (int x1 = 0; x1 < colorSize.Width; x1++)
         {
             for (int y1 = 0; y1 < colorSize.Height; y1++)
             {
                 if (point.X + x1 + x2 >= 0 && point.Y + y1 + y2 >= 0 && point.X + x1 + x2 < p.Width && point.Y + y1 + y2 < p.Height)
                 {
                     p.pixels[point.X + x1 + x2, point.Y + y1 + y2] = (byte)(i + entry.XOffset);
                 }
             }
         }
     }
 }
Example #6
0
 /**<summary>Draws the palette into the specified palette image.</summary>*/
 public void Draw(PaletteImage p, int x, int y, int colorWidth, int colorHeight)
 {
     for (int i = 0; i < colors.Length; i++)
     {
         int x2 = ((i + entry.XOffset) % 16) * colorWidth;
         int y2 = ((i + entry.XOffset) / 16) * colorHeight;
         for (int x1 = 0; x1 < colorWidth; x1++)
         {
             for (int y1 = 0; y1 < colorHeight; y1++)
             {
                 if (x + x1 + x2 >= 0 && y + y1 + y2 >= 0 && x + x1 + x2 < p.Width && y + y1 + y2 < p.Height)
                 {
                     p.pixels[x + x1 + x2, y + y1 + y2] = (byte)(i + entry.XOffset);
                 }
             }
         }
     }
 }
Example #7
0
 /**<summary>Draws the terrain to the specified palette image.</summary>*/
 public void Draw(PaletteImage p, int x, int y, int darkness)
 {
     x -= 32 + ((Origin.X - Origin.Y) * 32);
     y -= 15 + ((Origin.X + Origin.Y) * 16);
     for (int x1 = 0; x1 < Size.Width; x1++)
     {
         for (int y1 = 0; y1 < Size.Height; y1++)
         {
             if (Slope == -1 ||
                 (Slope % 2 == 0 && x1 < Origin.X - 1 && x1 > Origin.X + 1) ||
                 (Slope % 2 == 1 && y1 < Origin.Y - 1 && y1 > Origin.Y + 1))
             {
                 LandTiles[0].DrawWithOffset(p, x + ((x1 - y1) * 32), y + ((x1 + y1) * 16),
                                             darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                             );
             }
             else if (Slope == 0 && x1 == Origin.X + 1)
             {
                 LandTiles[1].DrawWithOffset(p, x + ((x1 - y1) * 32), y + ((x1 + y1) * 16),
                                             darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                             );
             }
             else if (Slope == 1 && y1 == Origin.Y + 1)
             {
                 LandTiles[2].DrawWithOffset(p, x + ((x1 - y1) * 32), y + ((x1 + y1) * 16),
                                             darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                             );
             }
             else if (Slope == 2 && x1 == Origin.X - 1)
             {
                 LandTiles[3].DrawWithOffset(p, x + ((x1 - y1) * 32), y + ((x1 + y1) * 16),
                                             darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                             );
             }
             else if (Slope == 3 && y1 == Origin.Y - 1)
             {
                 LandTiles[4].DrawWithOffset(p, x + ((x1 - y1) * 32), y + ((x1 + y1) * 16),
                                             darkness, false, RemapColors.None, RemapColors.None, RemapColors.None
                                             );
             }
         }
     }
 }
 /**<summary>Draws the palette into the specified palette image.</summary>*/
 public void Draw(PaletteImage p, int x, int y, int colorWidth, int colorHeight)
 {
     Draw(p, new Point(x, y), new Size(colorWidth, colorHeight));
 }
 /**<summary>Draws the terrain to the specified palette image.</summary>*/
 public void Draw(PaletteImage p, int x, int y, int darkness)
 {
     Draw(p, new Point(x, y), darkness);
 }
Example #10
0
 /**<summary>Draws the palette image into the specified palette image using the image entry's offset.</summary>*/
 public void DrawWithOffset(PaletteImage p, int x, int y, int darkness, bool glass, RemapColors remap1 = RemapColors.None, RemapColors remap2 = RemapColors.None, RemapColors remap3 = RemapColors.None)
 {
     DrawWithOffset(p, new Point(x, y), darkness, glass, remap1, remap2, remap3);
 }