/// <summary>
        /// Loads the image at index.
        /// </summary>
        /// <returns>The <see cref="UnityEngine.Texture2D"/>.</returns>
        /// <param name="index">Index.</param>
        public virtual BitmapUW LoadImageAt(int index, bool Alpha)
        {
            BitmapUW newimg = new BitmapUW();

            newimg.image = new Bitmap(2, 2);
            return(newimg);
        }
Example #2
0
        public override BitmapUW LoadImageAt(int index, bool Alpha)
        {
            switch (main.curgame)
            {
            case main.GAME_UW2:
            {
                ImageCache[index] = extractUW2Bitmap(main.basepath + "\\DATA\\BYT.ARK", index, Alpha);
                return(ImageCache[index]);
            }

            default:
            {
                if (!DataLoaded)
                {
                    FileName = main.basepath + "\\data\\" + FilePaths[index];
                    LoadImageFile();
                    DataLoaded = true;
                }
                if (ImageCache == null)
                {
                    ImageCache = new BitmapUW[1];
                }

                ImageCache[0] = Image(this, ImageFileData, 0, 0, 320, 200, "name_goes_here", PaletteLoader.Palettes[PaletteIndices[index]], Alpha, BitmapUW.ImageTypes.Byt);
                return(ImageCache[0]);
            }
            }
        }
 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>
        /// Loads the image at index.
        /// </summary>
        /// <returns>The <see cref="UnityEngine.Texture2D"/>.</returns>
        /// <param name="index">Index.</param>
        public virtual BitmapUW LoadImageAt(int index)
        {
            BitmapUW newimg = new BitmapUW();

            newimg.image        = new Bitmap(2, 2);
            newimg.ImagePalette = PaletteLoader.Palettes[0];
            ImageCache[index]   = newimg;
            ImageCache[index].UncompressedData = new char[4];
            return(ImageCache[index]);
        }
        public TextureLoader()
        {
            ImageCache       = new BitmapUW[261];
            imageCacheLowRes = new Bitmap[261];

            MaskNE = new Bitmap(LOWRESSIZE, LOWRESSIZE);
            for (int x = 0; x < LOWRESSIZE; x++)
            {
                for (int y = 0; y < LOWRESSIZE; y++)
                {
                    if (x < y)
                    {
                        MaskNE.SetPixel(x, y, Color.White);
                    }
                }
            }

            MaskNW = new Bitmap(LOWRESSIZE, LOWRESSIZE);
            for (int x = 0; x < LOWRESSIZE; x++)
            {
                for (int y = 0; y < LOWRESSIZE; y++)
                {
                    if (LOWRESSIZE - x < y)
                    {
                        MaskNW.SetPixel(x, y, Color.White);
                    }
                }
            }


            MaskSW = new Bitmap(LOWRESSIZE, LOWRESSIZE);
            for (int x = 0; x < LOWRESSIZE; x++)
            {
                for (int y = 0; y < LOWRESSIZE; y++)
                {
                    if (x > y)
                    {
                        MaskSW.SetPixel(x, y, Color.White);
                    }
                }
            }

            MaskSE = new Bitmap(LOWRESSIZE, LOWRESSIZE);
            for (int x = 0; x < LOWRESSIZE; x++)
            {
                for (int y = 0; y < LOWRESSIZE; y++)
                {
                    if (LOWRESSIZE - x > y)
                    {
                        MaskSE.SetPixel(x, y, Color.White);
                    }
                }
            }
        }
 public bool LoadImageFile()
 {
     if (!Util.ReadStreamFile(FileName, out ImageFileData))
     {
         return(false);
     }
     else
     {
         NoOfImages          = (int)Util.getValAtAddress(ImageFileData, 1, 16);
         ImageCache          = new BitmapUW[NoOfImages];
         ImageFileDataLoaded = true;
         return(true);
     }
 }
        /// <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);
        }
Example #9
0
        public BitmapUW extractUW2Bitmap(string path, int index, bool Alpha)
        {
            char[] textureFile;          // Pointer to our buffered data (little endian format)
                                         //int i;
            long NoOfTextures;


            if (!Util.ReadStreamFile(path, out textureFile))
            {
                return(null);
            }
            // Get the size of the file in bytes

            NoOfTextures = Util.getValAtAddress(textureFile, 0, 8);
            if (ImageCache == null)
            {
                ImageCache = new BitmapUW[NoOfTextures + 1];
            }
            long textureOffset = (int)Util.getValAtAddress(textureFile, (index * 4) + 6, 32);

            if (textureOffset != 0)
            {
                int compressionFlag = (int)Util.getValAtAddress(textureFile, ((index * 4) + 6) + (NoOfTextures * 4), 32);
                int isCompressed    = (compressionFlag >> 1) & 0x01;
                if (isCompressed == 1)
                {
                    long datalen = 0;
                    return(Image(this, Util.unpackUW2(textureFile, textureOffset, ref datalen), 0, index, 320, 200, "namehere", PaletteLoader.Palettes[PaletteIndicesUW2[index]], Alpha, BitmapUW.ImageTypes.Byt));
                }
                else
                {
                    return(Image(this, textureFile, textureOffset, index, 320, 200, "name_goes_here", PaletteLoader.Palettes[PaletteIndicesUW2[index]], Alpha, BitmapUW.ImageTypes.Byt));
                }
            }
            return(null);
        }
        public static void setPixelAtLocation(BitmapUW currentimg, PictureBox img, int x, int y, int newpixel, int auxpixel)
        {
            if (currentimg.artdata == null)
            {
                return;
            }
            if (img.Image == null)
            {
                return;
            }
            currentimg.artdata.ImageCache[currentimg.ImageNo].image.SetPixel(x, y, currentimg.ImagePalette.ColorAtPixel((byte)newpixel, false));

            switch (main.CurrentImage.ImageType)
            {
            case BitmapUW.ImageTypes.Texture:
            {
                TextureLoader texdata = (TextureLoader)currentimg.artdata;
                switch (main.curgame)
                {
                case main.GAME_UW1:
                {
                    if (currentimg.ImageNo < 210)
                    {
                        texdata.texturebufferW[currentimg.FileOffset + y * 64 + x] = (char)newpixel;
                    }
                    else
                    {
                        texdata.texturebufferF[currentimg.FileOffset + y * 32 + x] = (char)newpixel;
                    }
                    currentimg.artdata.Modified = true;
                    break;
                }

                case main.GAME_UW2:
                {
                    texdata.texturebufferT[currentimg.FileOffset + y * 64 + x] = (char)newpixel;
                    currentimg.artdata.Modified = true;
                    break;
                }
                }
                break;
            }

            case BitmapUW.ImageTypes.Byt:
            {
                switch (main.curgame)
                {
                case main.GAME_UW1:
                {
                    BytLoader byt = (BytLoader)currentimg.artdata;
                    byt.ImageFileData[currentimg.FileOffset + y * (currentimg.image.Width) + x] = (char)newpixel;
                    currentimg.artdata.Modified = true;
                    break;
                }
                }
                break;
            }

            case BitmapUW.ImageTypes.EightBitUncompressed:
            {
                GRLoader gr = (GRLoader)currentimg.artdata;
                gr.ImageFileData[currentimg.FileOffset + y * (currentimg.image.Width) + x] = (char)newpixel;
                currentimg.artdata.Modified = true;
                break;
            }

            case BitmapUW.ImageTypes.FourBitUncompress:
            {
                GRLoader gr            = (GRLoader)currentimg.artdata;
                int      Offset        = y * (currentimg.image.Width) + x;
                long     NibbleAddress = currentimg.FileOffset + (Offset / 2);
                int      HiOrLow       = Offset % 2;
                if (HiOrLow == 1)
                {        //low nibble
                    gr.ImageFileData[NibbleAddress] = (char)(gr.ImageFileData[NibbleAddress] & 0xF0);
                    gr.ImageFileData[NibbleAddress] = (char)(gr.ImageFileData[NibbleAddress] | ((char)auxpixel & 0xf));
                }
                else
                {
                    gr.ImageFileData[NibbleAddress] = (char)(gr.ImageFileData[NibbleAddress] & 0x0F);
                    gr.ImageFileData[NibbleAddress] = (char)(gr.ImageFileData[NibbleAddress] | ((char)(auxpixel << 4) & 0xf0));
                }

                currentimg.artdata.Modified = true;
                break;
            }

            //case BitmapUW.ImageTypes.FourBitRunLength:
            //    {
            //GRLoader gr = (GRLoader)currentimg.artdata;
            //currentimg.UncompressedData[y * (currentimg.image.Width) + x] = (char)auxpixel;
            //currentimg.artdata.Modified = true;
            //        break;
            //    }
            default:
            {
                return;
                // img.Image = main.CurrentImage.image;
                //break;
            }
            }
            currentimg.Modified = true;
            main.CurrentImage   = currentimg.artdata.ImageCache[currentimg.ImageNo];
            img.Image           = main.CurrentImage.image;
        }
Example #11
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();
            }
        }