Esempio n. 1
0
        void SwapChannels(int a, int b, int c)
        {
            var selections = PaletteImage.GetSelectedIndices();

            foreach (var selectedIndex in selections)
            {
                var paletteEntry = PaletteImage.Palette[selectedIndex];
                PaletteImage.Palette[selectedIndex] = new byte[] { paletteEntry[a], paletteEntry[b], paletteEntry[c], byte.MaxValue };
            }
            PaletteImage.Update(selections);
        }
Esempio n. 2
0
        private void PaletteImageMouseMove(object sender, MouseEventArgs e)
        {
            if (!(sender as Control).ClientRectangle.Contains(e.Location))
            {
                return;
            }
            PaletteImage paletteImage  = sender as PaletteImage;
            int          selectedColor = paletteImage.getSelectedColor(e);

            if (e.Button != MouseButtons.None && paletteImage.NumberOfSelectedColors > 0)
            {
                paletteImage.Moved(sender, e);
                ButtonNearestColors.Enabled = (paletteImage == RemappingPalette && paletteImage.NumberOfSelectedColors > 0);
            }
            else
            {
                PaletteImage otherPaletteImage          = GetOtherPalette(paletteImage);
                int[]        otherPaletteSelectedColors = otherPaletteImage.GetSelectedIndices();
                if (otherPaletteSelectedColors.Length > 0)
                {
                    SetMatchingSelectedColorsBasedOnOtherPaletteImage(paletteImage, selectedColor, ref otherPaletteSelectedColors);
                    paletteImage.Update(PaletteImage.AllPaletteColors);
                    paletteImage.SetSelected(otherPaletteSelectedColors, true); //visual change only, to be undone below
                    foreach (var selected in otherPaletteSelectedColors)
                    {
                        paletteImage.ColorsSelected[selected] = false;
                    }
                }
            }

            Text = "Remap Image Palette \u2013 " + selectedColor;
        }
Esempio n. 3
0
        /*internal bool ShowForm(Palette palette, J2TFile tileset)
         * {
         *  //CreateImageFromTileset(tileset);
         *  ShowDialog();
         *  return Result;
         * }*/
        internal bool ShowForm(Palette palette, Bitmap bitmap, ref byte[] colorRemappings, Color imageBackgroundColor)
        {
            //CreateImageFromTileset(tileset);

            if (colorRemappings == null)
            {
                for (uint i = 0; i < Palette.PaletteSize; ++i)
                {
                    ColorRemappings[i] = (byte)i;
                }
            }
            else
            {
                colorRemappings.CopyTo(ColorRemappings, 0);
            }

            LevelPalette.Palette    = palette;
            LevelPalette.Palette[0] = Palette.Convert(imageBackgroundColor);
            for (int i = 0; i < Palette.PaletteSize; ++i)
            {
                RemappingPalette.Palette[i] = LevelPalette.Palette[ColorRemappings[i]];
            }
            ImageWorkingPalette = bitmap.Palette;
            PaletteImage original = new PaletteImage(5, 0, true, false);

            for (uint i = 0; i < Palette.PaletteSize; ++i)
            {
                original.Palette.Colors[i]     = Palette.Convert(ImageWorkingPalette.Entries[i]);
                ImageWorkingPalette.Entries[i] = Palette.Convert(LevelPalette.Palette.Colors[ColorRemappings[i]]);
            }
            OriginalPalette.CopyFrom(original.Palette);
            bitmap.Palette = ImageWorkingPalette;

            pictureBox1.Image = bitmap;
            pictureBox1.Size  = bitmap.Size;
            Width            -= (320 - pictureBox1.Width);

            original.Location    = new Point(label1.Location.X, label1.Location.Y + 16);
            original.MouseMove  += PaletteImageMouseMove;
            original.MouseLeave += PaletteImageMouseLeave;
            Controls.Add(original);

            LevelPalette.Location    = new Point(label3.Left, panel1.Top);
            LevelPalette.MouseMove  += PaletteImageMouseMove;
            LevelPalette.MouseLeave += PaletteImageMouseLeave;
            LevelPalette.MouseDown  += PaletteImageMouseDown;
            Controls.Add(LevelPalette);

            RemappingPalette.Location    = new Point(label4.Left, label4.Location.Y + 16);
            RemappingPalette.MouseMove  += PaletteImageMouseMove;
            RemappingPalette.MouseLeave += PaletteImageMouseLeave;
            RemappingPalette.MouseDown  += PaletteImageMouseDown;
            Controls.Add(RemappingPalette);

            var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);

            ImageIndices = new byte[data.Width * data.Height];
            for (int y = 0; y < bitmap.Height; ++y)
            {
                Marshal.Copy(new IntPtr((int)data.Scan0 + data.Stride * y), ImageIndices, bitmap.Width * y, bitmap.Width);
            }
            bitmap.UnlockBits(data);

            for (uint i = 0; i < Palette.PaletteSize; ++i)
            {
                original.ColorDisabled[i] = RemappingPalette.ColorDisabled[i] = i == 0 || !ImageIndices.Contains((byte)i);
            }
            for (int i = 0; i < 10; ++i)
            {
                LevelPalette.ColorDisabled[i] = LevelPalette.ColorDisabled[Palette.PaletteSize - 10 + i] = true; //transparency, and default windows colors
            }
            original.Update(PaletteImage.AllPaletteColors);
            LevelPalette.Update(PaletteImage.AllPaletteColors);
            RemappingPalette.Update(PaletteImage.AllPaletteColors);

            ShowDialog();

            if (Result)
            {
                colorRemappings = ColorRemappings;
            }
            return(Result);
        }