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));
        }
示例#2
0
    public override Texture2D LoadImageAt(int index, bool Alpha)
    {
        if (ImageFileDataLoaded == false)
        {
            if (!LoadImageFile())
            {
                return(base.LoadImageAt(index));
            }
        }
        else
        {
            if (ImageCache[index] != null)
            {
                return(ImageCache[index]);
            }
        }


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

        if (imageOffset >= ImageFileData.GetUpperBound(0))
        {                //Image out of range
            return(base.LoadImageAt(index));
        }
        int     BitMapWidth  = (int)DataLoader.getValAtAddress(ImageFileData, imageOffset + 1, 8);
        int     BitMapHeight = (int)DataLoader.getValAtAddress(ImageFileData, imageOffset + 2, 8);
        int     datalen;
        Palette auxpal;
        int     auxPalIndex;

        char[] imgNibbles;
        char[] outputImg;


        switch (DataLoader.getValAtAddress(ImageFileData, imageOffset, 8)) //File type
        {
        case 0x4:                                                          //8 bit uncompressed
        {
            imageOffset       = imageOffset + 5;
            ImageCache[index] = Image(ImageFileData, imageOffset, BitMapWidth, BitMapHeight, "name_goes_here", GameWorldController.instance.palLoader.Palettes[PaletteNo], Alpha);
            return(ImageCache[index]);
        }

        case 0x8:        //4 bit run-length
        {
            if (!useOverrideAuxPalIndex)
            {
                auxPalIndex = (int)DataLoader.getValAtAddress(ImageFileData, imageOffset + 3, 8);
            }
            else
            {
                auxPalIndex = OverrideAuxPalIndex;
            }
            datalen     = (int)DataLoader.getValAtAddress(ImageFileData, imageOffset + 4, 16);
            imgNibbles  = new char[Mathf.Max(BitMapWidth * BitMapHeight * 2, (datalen + 5) * 2)];
            imageOffset = imageOffset + 6;                              //Start of raw data.
            copyNibbles(ImageFileData, ref imgNibbles, datalen, imageOffset);
            auxpal    = PaletteLoader.LoadAuxilaryPal(Loader.BasePath + AuxPalPath, GameWorldController.instance.palLoader.Palettes[PaletteNo], auxPalIndex);
            outputImg = DecodeRLEBitmap(imgNibbles, datalen, BitMapWidth, BitMapHeight, 4);
            //rawOut.texture= Image(outputImg,0, BitMapWidth, BitMapHeight,"name_goes_here",auxpal,true);
            ImageCache[index] = Image(outputImg, 0, BitMapWidth, BitMapHeight, "name_goes_here", auxpal, Alpha);
            return(ImageCache[index]);
        }

        case 0xA:        //4 bit uncompressed//Same as above???
        {
            if (!useOverrideAuxPalIndex)
            {
                auxPalIndex = (int)DataLoader.getValAtAddress(ImageFileData, imageOffset + 3, 8);
            }
            else
            {
                auxPalIndex = OverrideAuxPalIndex;
            }
            datalen     = (int)DataLoader.getValAtAddress(ImageFileData, imageOffset + 4, 16);
            imgNibbles  = new char[Mathf.Max(BitMapWidth * BitMapHeight * 2, (5 + datalen) * 2)];
            imageOffset = imageOffset + 6;                              //Start of raw data.
            copyNibbles(ImageFileData, ref imgNibbles, datalen, imageOffset);
            auxpal            = PaletteLoader.LoadAuxilaryPal(BasePath + AuxPalPath, GameWorldController.instance.palLoader.Palettes[PaletteNo], auxPalIndex);
            ImageCache[index] = Image(imgNibbles, 0, BitMapWidth, BitMapHeight, "name_goes_here", auxpal, Alpha);
            return(ImageCache[index]);
        }

        //break;
        default:
            //Check to see if the file is panels.gr
            if (pathGR[FileToLoad].ToUpper().EndsWith("PANELS.GR"))
            {
                BitMapWidth  = 83;                         //getValAtAddress(textureFile, textureOffset + 1, 8);
                BitMapHeight = 114;                        // getValAtAddress(textureFile, textureOffset + 2, 8);
                if (_RES == "UW2")
                {
                    BitMapWidth  = 79;
                    BitMapHeight = 112;
                }
                imageOffset       = DataLoader.getValAtAddress(ImageFileData, (index * 4) + 3, 32);
                ImageCache[index] = Image(ImageFileData, imageOffset, BitMapWidth, BitMapHeight, "name_goes_here", GameWorldController.instance.palLoader.Palettes[PaletteNo], Alpha);
                return(ImageCache[index]);
            }
            break;
        }

        return(new Texture2D(2, 2));
    }