Exemplo n.º 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;
            }
        }
Exemplo n.º 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 override BitmapUW LoadImageAt(int index, bool Alpha)
        {
            if (ImageFileDataLoaded == false)
            {
                if (!LoadImageFile())
                {
                    return(base.LoadImageAt(index));
                }
            }
            else
            {
                if (ImageCache[index] != null)
                {
                    return(ImageCache[index]);
                }
            }


            long imageOffset = Util.getValAtAddress(ImageFileData, (index * 4) + 3, 32);

            if (imageOffset >= ImageFileData.GetUpperBound(0))
            {//Image out of range
                return(base.LoadImageAt(index));
            }


            switch (Util.getValAtAddress(ImageFileData, imageOffset, 8)) //File type
            {
            case 0x4:                                                    //8 bit uncompressed
            {
                int BitMapWidth  = (int)Util.getValAtAddress(ImageFileData, imageOffset + 1, 8);
                int BitMapHeight = (int)Util.getValAtAddress(ImageFileData, imageOffset + 2, 8);
                imageOffset       = imageOffset + 5;
                ImageCache[index] = Image(this, ImageFileData, imageOffset, index, BitMapWidth, BitMapHeight, "name_goes_here", PaletteLoader.Palettes[PaletteNo], Alpha, BitmapUW.ImageTypes.EightBitUncompressed);
                return(ImageCache[index]);
            }

            case 0x8:    //4 bit run-length
            {
                char[] imgNibbles;
                int    auxPalIndex;

                int BitMapWidth  = (int)Util.getValAtAddress(ImageFileData, imageOffset + 1, 8);
                int BitMapHeight = (int)Util.getValAtAddress(ImageFileData, imageOffset + 2, 8);
                if (!useOverrideAuxPalIndex)
                {
                    auxPalIndex = (int)Util.getValAtAddress(ImageFileData, imageOffset + 3, 8);
                }
                else
                {
                    auxPalIndex = OverrideAuxPalIndex;
                }
                int datalen = (int)Util.getValAtAddress(ImageFileData, imageOffset + 4, 16);
                imgNibbles  = new char[Math.Max(BitMapWidth * BitMapHeight * 2, (datalen + 5) * 2)];
                imageOffset = imageOffset + 6;          //Start of raw data.
                copyNibbles(ImageFileData, ref imgNibbles, datalen, imageOffset);
                int[]  aux       = PaletteLoader.LoadAuxilaryPalIndices(main.basepath + AuxPalPath, auxPalIndex);
                char[] RawImg    = DecodeRLEBitmap(imgNibbles, datalen, BitMapWidth, BitMapHeight, 4);
                char[] OutputImg = ApplyAuxPal(RawImg, aux);
                ImageCache[index] = Image(this, OutputImg, 0, index, BitMapWidth, BitMapHeight, "name_goes_here", PaletteLoader.Palettes[PaletteNo], Alpha, BitmapUW.ImageTypes.FourBitRunLength);
                ImageCache[index].UncompressedData = RawImg;
                ImageCache[index].SetAuxPalRef(aux);
                ImageCache[index].AuxPalNo = auxPalIndex;
                return(ImageCache[index]);
            }

            case 0xA:    //4 bit uncompressed
            {
                char[] imgNibbles;
                int    auxPalIndex;
                int    datalen;
                int    BitMapWidth  = (int)Util.getValAtAddress(ImageFileData, imageOffset + 1, 8);
                int    BitMapHeight = (int)Util.getValAtAddress(ImageFileData, imageOffset + 2, 8);
                if (!useOverrideAuxPalIndex)
                {
                    auxPalIndex = (int)Util.getValAtAddress(ImageFileData, imageOffset + 3, 8);
                }
                else
                {
                    auxPalIndex = OverrideAuxPalIndex;
                }
                datalen     = (int)Util.getValAtAddress(ImageFileData, imageOffset + 4, 16);
                imgNibbles  = new char[Math.Max(BitMapWidth * BitMapHeight * 2, (5 + datalen) * 2)];
                imageOffset = imageOffset + 6;          //Start of raw data.
                copyNibbles(ImageFileData, ref imgNibbles, datalen, imageOffset);
                //Palette auxpal = PaletteLoader.LoadAuxilaryPal(main.basepath + AuxPalPath, PaletteLoader.Palettes[PaletteNo], auxPalIndex);
                int[]  aux       = PaletteLoader.LoadAuxilaryPalIndices(main.basepath + AuxPalPath, auxPalIndex);
                char[] OutputImg = ApplyAuxPal(imgNibbles, aux);
                ImageCache[index] = Image(this, OutputImg, 0, index, BitMapWidth, BitMapHeight, "name_goes_here", PaletteLoader.Palettes[PaletteNo], Alpha, BitmapUW.ImageTypes.FourBitUncompress);
                ImageCache[index].UncompressedData = OutputImg;
                ImageCache[index].SetAuxPalRef(aux);
                ImageCache[index].AuxPalNo   = auxPalIndex;
                ImageCache[index].FileOffset = imageOffset;
                return(ImageCache[index]);
            }

            //break;
            default:
            {
                int BitMapWidth  = (int)Util.getValAtAddress(ImageFileData, imageOffset + 1, 8);
                int BitMapHeight = (int)Util.getValAtAddress(ImageFileData, imageOffset + 2, 8);
                if (FileName.ToUpper().EndsWith("PANELS.GR"))
                {        //Check to see if the file is panels.gr
                    if (index >= 4)
                    {
                        return(base.LoadImageAt(0));
                    }                          //new Bitmap(2, 2);
                    BitMapWidth  = 83;         //getValAtAddress(textureFile, textureOffset + 1, 8);
                    BitMapHeight = 114;        // getValAtAddress(textureFile, textureOffset + 2, 8);
                    if (main.curgame == main.GAME_UW2)
                    {
                        BitMapWidth  = 79;
                        BitMapHeight = 112;
                    }
                    imageOffset       = Util.getValAtAddress(ImageFileData, (index * 4) + 3, 32);
                    ImageCache[index] = Image(this, ImageFileData, imageOffset, index, BitMapWidth, BitMapHeight, "name_goes_here", PaletteLoader.Palettes[PaletteNo], Alpha, BitmapUW.ImageTypes.EightBitUncompressed);
                    return(ImageCache[index]);
                }
                break;
            }
            }

            return(base.LoadImageAt(0));
        }