示例#1
0
        public static bool MakeSpecialIndicesUnique(this IPalette palette, out byte[] changed)
        {
            List <byte> clist = new List <byte>();

            foreach (byte b in UniqueIndices)
            {
                Color c = palette.Get(b);
                if (palette.Count(c) > 1) // include self
                {
                    int argb = c.ToArgb();
                    argb++;
                    palette.Set(b, Color.FromArgb(255, Color.FromArgb(argb)));
                    c = palette.Get(b);
                    while (palette.Count(c) > 1) // include self
                    {
                        argb++;
                        palette.Set(b, Color.FromArgb(255, Color.FromArgb(argb)));
                        c = palette.Get(b); // use the get function, since we have 15-bit and 18-bit colour that could produce the same results with different RGB values.
                    }
                    clist.Add(b);
                }
            }
            changed = clist.ToArray();
            return(changed.Length > 0);
        }
示例#2
0
 public void Import(IPalette source)
 {
     for (int i = 0; i < 256; i++)
     {
         Set(i, source.Get(i));
     }
 }
示例#3
0
        public static bool HasNonUniqueSpecialIndices(this IPalette palette, out byte[] affected)
        {
            List <byte> clist = new List <byte>();

            foreach (byte b in UniqueIndices)
            {
                Color c = palette.Get(b);
                if (palette.Count(c) > 1) // include self
                {
                    clist.Add(b);
                }
            }
            affected = clist.ToArray();
            return(affected.Length > 0);
        }
示例#4
0
        public Bitmap GetBitmap(Palette_18Bit basePalette, HousePaletteFile housePalette, bool includeFrame, bool makeTransparent, int houseIndex)
        {
            if (PaletteType == PaletteType.EMPTY_ENTRY)
            {
                // at least draw something so it does not error out.
                Bitmap empty = new Bitmap(1, 1);
                empty.MakeTransparent();
                return(empty);
            }

            Bitmap bmp = new Bitmap(ImageWidth, ImageHeight);

            if (BitsPerPixel == 8)
            {
                IPalette pal = (PaletteHandle == 0) ? (IPalette)basePalette.Clone() : Palette.Clone();
                if (houseIndex != -1)
                {
                    pal = housePalette.Merge(pal, houseIndex);
                }

                for (int x = 0; x < ImageWidth; x++)
                {
                    for (int y = 0; y < ImageHeight; y++)
                    {
                        int  pos   = x + y * ImageWidth;
                        byte data8 = ImageData[pos];

                        if (makeTransparent && data8 == 0)
                        {
                            bmp.SetPixel(x, y, Color.Transparent);
                        }
                        else if (makeTransparent && data8 == 1)
                        {
                            bmp.SetPixel(x, y, Color.FromArgb(128, 0, 0, 0));
                        }
                        else
                        {
                            bmp.SetPixel(x, y, pal.Get(data8));
                        }
                    }
                }
            }
            else if (BitsPerPixel == 16)
            {
                // doesn't care about palettes, as its image data is direct color
                for (int x = 0; x < ImageWidth; x++)
                {
                    for (int y = 0; y < ImageHeight; y++)
                    {
                        int    pos    = (x + y * ImageWidth) * 2;
                        ushort data16 = BitConverter.ToUInt16(ImageData, pos);
                        bmp.SetPixel(x, y, Palette_15Bit.ConvertColor(data16));
                    }
                }
            }
            else
            {
                throw new InvalidDataException("Unexpected bits per pixel! (Value = {0})".F(BitsPerPixel));
            }

            if (makeTransparent)
            {
                bmp.MakeTransparent(Palette.Get(0));
            }

            if (includeFrame)
            {
                Bitmap bmpFrame = new Bitmap(FrameWidth, FrameHeight);
                bmpFrame.MakeTransparent();
                Graphics g = Graphics.FromImage(bmpFrame);
                g.DrawImageUnscaled(bmp, new Point((FrameWidth - ImageWidth) / 2, (FrameHeight - ImageHeight) / 2));
                return(bmpFrame);
            }
            else
            {
                return(bmp);
            }
        }