Exemple #1
0
        private void BtnImport_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                Bitmap  jr       = (Bitmap)Bitmap.FromFile(openFileDialog1.FileName);
                Palette FinalPal = CurrentImage.GetFinalPallette();
                if ((jr.Width != CurrentImage.image.Width) || (jr.Height != CurrentImage.image.Height))
                {
                    jr = ArtLoader.Resize(jr, CurrentImage.image.Width, CurrentImage.image.Height);
                }

                for (int x = 0; x < jr.Width; x++)
                {
                    for (int y = 0; y < jr.Height; y++)
                    {
                        int nearest = PaletteLoader.GetNearestColour(jr.GetPixel(x, y), FinalPal);
                        //Get nearest palette to color
                        ArtUI.setPixelAtLocation(CurrentImage, ImgOut, x, y, nearest, nearest);
                    }
                }
                ImgOut.Image = CurrentImage.image;
            }
        }
Exemple #2
0
        /// <summary>
        /// Load events. Calls the file selection dialog.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void main_Load(object sender, EventArgs e)
        {
            FrmSelect frm = new FrmSelect();

            frm.ShowDialog();
            PaletteLoader.LoadPalettes(main.basepath + "\\data\\pals.dat");
            PicPalette.Image = ArtLoader.Palette(PaletteLoader.Palettes[0]).image;
            PopulateTextureTree();
        }
 public Bitmap LowResAt(int index)
 {
     if (imageCacheLowRes[index] == null)
     {
         BitmapUW tmp = LoadImageAt(index);
         tmp.image.RotateFlip(RotateFlipType.RotateNoneFlipY);
         imageCacheLowRes[index] = ArtLoader.Resize(tmp.image, LOWRESSIZE, LOWRESSIZE);
     }
     return(imageCacheLowRes[index]);
 }
        /// <summary>
        /// Returns a palette as an image.
        /// </summary>
        /// <returns>The to image.</returns>
        /// <param name="PalIndex">Pal index.</param>
        public static Bitmap PaletteToImage(int PalIndex)
        {
            int height = 1;
            int width  = 256;

            char[] imgData = new char[height * width];
            for (int i = 0; i < imgData.GetUpperBound(0); i++)
            {
                imgData[i] = (char)i;
            }
            BitmapUW output = ArtLoader.Image(null, imgData, 0, 0, width, height, "name here", Palettes[PalIndex], true, BitmapUW.ImageTypes.Palette);

            return(output.image);
        }
        /// <summary>
        /// Generates the image from the specified data buffer position and also use the xfer look up table
        /// </summary>
        /// <param name="databuffer">Databuffer.</param>
        /// <param name="dataOffSet">Data off set.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="imageName">Image name.</param>
        /// <param name="pal">Pal.</param>
        /// <param name="Alpha">If set to <c>true</c> alpha.</param>
        public static BitmapUW Image(ArtLoader instance, char[] databuffer, long dataOffSet, int index, int width, int height, string imageName, Palette pal, bool Alpha, bool useXFER, BitmapUW.ImageTypes imgType)
        {
            BitmapUW imgUW = new BitmapUW();

            imgUW.artdata      = instance;
            imgUW.FileOffset   = dataOffSet;
            imgUW.ImageType    = imgType;
            imgUW.ImagePalette = pal;
            imgUW.ImageNo      = index;
            if (instance != null)
            {
                instance.ImageType = imgType;
            }
            Bitmap image = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            Byte[] imageColors = new Byte[width * height * 4];

            long counter = 0;

            for (int iRow = 0; iRow < height; iRow++)
            {
                for (int j = (iRow * width); j < (iRow * width) + width; j++)
                {
                    byte  pixel = (byte)Util.getValAtAddress(databuffer, dataOffSet + (long)j, 8);
                    Color col   = pal.ColorAtPixel(pixel, Alpha);
                    //imageColors[counter++] = pal.ColorAtPixel(pixel, Alpha);
                    imageColors[counter++] = col.B;
                    imageColors[counter++] = col.G;
                    imageColors[counter++] = col.R;
                    imageColors[counter++] = col.A;
                    //image.SetPixel(j- (iRow * width), iRow, pal.ColorAtPixel(pixel, Alpha));
                }
            }
            //image.filterMode = FilterMode.Point;
            // image.SetPixels32(imageColors);
            //image.Apply();
            //return image;
            imgUW.image = CopyDataToBitmap(imageColors, width, height);
            return(imgUW);
        }
Exemple #6
0
        /// <summary>
        /// Handles selection of an art file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeArt_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode node = TreeArt.SelectedNode;

            BtnRepack4Bit.Enabled = false;
            if (node.Parent != null)
            {
                string partext = node.Parent.Text.ToUpper();
                switch (partext)
                {
                case "TEXTURES":
                case "WALL TEXTURES":
                case "FLOOR TEXTURES":
                {        //loading a texture
                    int index;
                    if (node.Tag == null)
                    {
                        return;
                    }
                    if (int.TryParse(node.Tag.ToString(), out index))
                    {
                        CurrentImage = tex.LoadImageAt(index);
                    }
                    break;
                }

                case "GRAPHIC RESOURCES":
                {
                    int index;
                    if (node.Tag == null)
                    {
                        return;
                    }
                    if (int.TryParse(node.Tag.ToString(), out index))
                    {
                        if (grfile[index] == null)
                        {        //Load the gr file and populate the tree.
                            grfile[index] = new GRLoader(main.basepath + "\\data\\" + node.Text);
                            for (int i = 0; i <= grfile[index].ImageCache.GetUpperBound(0); i++)
                            {
                                TreeNode img = node.Nodes.Add(i.ToString());
                                img.Tag = i;
                            }
                        }
                    }
                    break;
                }

                case "BITMAP RESOURCES":
                {
                    int index;
                    if (node.Tag == null)
                    {
                        return;
                    }
                    if (int.TryParse(node.Tag.ToString(), out index))
                    {
                        if (bytfile[index] == null)
                        {
                            bytfile[index] = new BytLoader();
                        }
                        CurrentImage = bytfile[index].LoadImageAt(index);
                    }
                    break;
                }

                case "BYT.ARK":
                {
                    int index;
                    if (node.Tag == null)
                    {
                        return;
                    }
                    if (int.TryParse(node.Tag.ToString(), out index))
                    {
                        if (bytfile[0] == null)
                        {
                            bytfile[0] = new BytLoader();
                        }
                        CurrentImage = bytfile[0].LoadImageAt(index);
                    }
                    break;
                }

                default:
                    if (partext.ToUpper().Contains(".GR"))
                    {
                        int parentindex;
                        if (node.Parent.Tag == null)
                        {
                            return;
                        }
                        if (int.TryParse(node.Parent.Tag.ToString(), out parentindex))
                        {
                            int index;
                            if (node.Tag == null)
                            {
                                return;
                            }
                            if (int.TryParse(node.Tag.ToString(), out index))
                            {
                                //load the gr file
                                CurrentImage = grfile[parentindex].LoadImageAt(index);
                                switch (CurrentImage.ImageType)
                                {
                                case BitmapUW.ImageTypes.FourBitRunLength:
                                case BitmapUW.ImageTypes.FourBitUncompress:
                                    BtnRepack4Bit.Enabled = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                }
            }
            if (CurrentImage != null)
            {
                ImgOut.Image         = CurrentImage.image;
                PicPalette.Image     = ArtLoader.Palette(CurrentImage.ImagePalette, CurrentImage.PaletteRef).image;
                ImgOut.Width         = CurrentImage.image.Width * (int)NumZoom.Value;
                ImgOut.Height        = CurrentImage.image.Height * (int)NumZoom.Value;
                LblImageDetails.Text = CurrentImage.image.Height + "x" + CurrentImage.image.Width + "\n" + CurrentImage.ImageType.ToString();
            }
        }
 /// <summary>
 /// Generates the image from the specified data buffer position
 /// </summary>
 /// <param name="databuffer">Databuffer.</param>
 /// <param name="dataOffSet">Data off set.</param>
 /// <param name="width">Width.</param>
 /// <param name="height">Height.</param>
 /// <param name="imageName">Image name.</param>
 /// <param name="pal">Pal.</param>
 /// <param name="Alpha">If set to <c>true</c> alpha.</param>
 public static BitmapUW Image(ArtLoader instance, char[] databuffer, long dataOffSet, int index, int width, int height, string imageName, Palette pal, bool Alpha, BitmapUW.ImageTypes imgType)
 {
     return(Image(instance, databuffer, dataOffSet, index, width, height, imageName, pal, Alpha, false, imgType));
 }