Exemplo n.º 1
0
        public BitmapInjectionForm(HaloMap.Map.Map Map, string Filename, ParsedBitmap ParsedBitm, int NumDDS)
        {
            InitializeComponent();

            this.bitm     = ParsedBitm;
            this.filename = Filename;
            this.map      = Map;

            // Load the DDS info & picture
            loadDDSInfo(filename, this.bitm);

            // Get the filename variable from the path / filename combo
            filename = filename.Substring(filename.LastIndexOf('\\') + 1);

            // Populate Bitmap Injection box with number of bitmaps in current selection
            for (int i = 0; i < NumDDS; i++)
            {
                lbInjectionBitmap.Items.Add("Bitmap #" + i.ToString());
            }

            #region inject_Form
            this.Text = "Inject " + filename + " to...";
            if (lbInjectionBitmap.Items.Count > 0)
            {
                lbInjectionBitmap.SelectedIndex = 0;
            }

            #endregion
        }
Exemplo n.º 2
0
        public ProcessedBitmap GetNumberFromProcessedImage(ParsedBitmap image, Location location, Rectangle cropLocation)
        {
            ProcessedBitmap processed = new ProcessedBitmap(imageProcessor);

            processed = processed.Process(image, location, cropLocation);
            try
            {
                processed.NumberReadFromImage = ReadImageText(processed.Image);
            }
            catch (NotSupportedException) {
                processed = processed.Process(image, location, cropLocation, BinarizationThreshold.Heavy);
                processed.NumberReadFromImage = ReadImageText(processed.Image);
            }
            return(processed);;
        }
Exemplo n.º 3
0
        private async Task <List <Data> > ProcessSingleImageFromUrl(string url, DateRange dateRange)
        {
            List <Data> linksData = new List <Data>();

            if (url is null || dateRange is null)
            {
                return(linksData);
            }

            ParsedBitmap parsed = await webService.DownloadImage(url);

            ProcessedBitmap processed = ocrService.GetNumberFromProcessedImage(parsed, Location.Chilliwack, map[Location.Chilliwack]);

            linksData.Add(Data.Convert(processed, dateRange));
            return(linksData);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BitmapControl"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public BitmapControl(Map map)
        {
            InitializeComponent();
            this.map = map;

            map.OpenMap(MapTypes.Internal);

            pm = new ParsedBitmap(ref map.SelectedMeta, map);

            for (int x = 0; x < pm.Properties.Length; x++)
            {
                TreeNode tn = new TreeNode("Bitmap #" + x);
                tn.Tag = "BITMAP";

                for (int i = 0; i < map.SelectedMeta.raw.rawChunks.Count; i++)
                {
                    int count = pm.Properties[x].mipMapCount;
                    BitmapRawDataChunk bmRaw = (BitmapRawDataChunk)map.SelectedMeta.raw.rawChunks[i];
                    if (bmRaw.inchunk == x)
                    {
                        TreeNode chunknode = new TreeNode("Chunk #" + bmRaw.num);
                        chunknode.Tag = "CHUNK";

                        int chunkWidth = pm.Properties[x].width >> bmRaw.num;
                        int mipcount   = 0;
                        while (chunkWidth > 1 && count > 0)
                        {
                            TreeNode mipnode = new TreeNode("Mipmap #" + (mipcount++));
                            mipnode.Tag = "MIPMAP";
                            chunknode.Nodes.Add(mipnode);
                            chunkWidth >>= 1;
                            count--;
                        }

                        tn.Nodes.Add(chunknode);
                    }
                }

                treeView1.Nodes.Add(tn);
            }

            map.CloseMap();

            DisplayBitmap(0, 0, 0);
        }
Exemplo n.º 5
0
        public Bitmap DDSRead(DDS inp)
        {
            inp.stream.Position = inp.streamOffset;
            byte[] b = new byte[inp.streamSize - inp.streamOffset];
            inp.stream.Read(b, 0, b.Length);

            Bitmap bm = ParsedBitmap.DecodeBitm(b,
                                                inp.Height,
                                                inp.Width,
                                                inp.Depth,
                                                inp.BitsPerPixel,
                                                inp.
                                                inp.FormatName,
                                                inp.Swizzle,
                                                0,      // mapnumber only matters for lightmaps
                                                0,      // vcindex only matters for lightmaps
                                                0);     // ident only matters for lightmaps

            return(bm);
        }
Exemplo n.º 6
0
        /// <summary>
        /// The tree view 1_ after select.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode.Level == 2)
            {
                currBitm   = treeView1.SelectedNode.Parent.Parent.Index;
                currChunk  = treeView1.SelectedNode.Parent.Index;
                currMipMap = treeView1.SelectedNode.Index;
            }
            else if (treeView1.SelectedNode.Level == 1)
            {
                currBitm   = treeView1.SelectedNode.Parent.Index;
                currChunk  = treeView1.SelectedNode.Index;
                currMipMap = 0;
            }
            else
            {
                currBitm   = treeView1.SelectedNode.Index;
                currChunk  = 0;
                currMipMap = 0;
            }

            DisplayBitmap(currBitm, currChunk, currMipMap);

            object o = ((Form)this.TopLevelControl).ActiveMdiChild;

            if (o is MapForm)
            {
                MapForm      mf   = (MapForm)o;
                Meta         meta = map.SelectedMeta;
                ParsedBitmap pm   = new ParsedBitmap(ref meta, map);

                Bitmap b = pm.FindChunkAndDecode(currBitm, currChunk, currMipMap, ref meta, map, 0, 0);
                mf.pictureBox    = (Bitmap)pictureBox1.Image.Clone();
                mf.statusBarText = (Math.Max(pm.Properties[currBitm].width >> currChunk >> currMipMap, 1)).ToString().PadLeft(4) + " X " +
                                   (Math.Max(pm.Properties[currBitm].height >> currChunk >> currMipMap, 1)).ToString().PadRight(4) + "X " +
                                   (Math.Max(pm.Properties[currBitm].depth >> currChunk >> currMipMap, 1)).ToString().PadRight(4) + " " +
                                   ("(" + pm.Properties[currBitm].typename.ToString().Remove(0, 10) + ") ").PadRight(10) +
                                   pm.Properties[currBitm].formatname.ToString().Remove(0, 12).PadRight(10) + " - Swizzle:" +
                                   pm.Properties[0].swizzle + "- Location: " + meta.raw.rawChunks[0].rawLocation;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// The h 2 shader info.
        /// </summary>
        /// <param name="TagIndex">The TagIndex.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void H2ShaderInfo(int TagIndex, Map map)
        {
            bool alreadyOpen = true;

            if (!(map.isOpen && map.openMapType == MapTypes.Internal))
            {
                map.OpenMap(MapTypes.Internal);
                alreadyOpen = false;
            }

            this.TagIndex = TagIndex;
            if (this.TagIndex == -1)
            {
                return;
            }

            this.shaderName            = map.FileNames.Name[this.TagIndex];
            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 4;
            int tempstem = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

            if (tempstem != -1)
            {
                if (map.FileNames.Name[tempstem].IndexOf("alphatest") != -1)
                {
                    this.Alpha = AlphaType.AlphaTest;
                }
                else if (map.FileNames.Name[tempstem].IndexOf("alpha") != -1)
                {
                    this.Alpha = AlphaType.AlphaBlend;
                }
                else if (map.FileNames.Name[tempstem].IndexOf("water") != -1)
                {
                    this.Alpha = AlphaType.AlphaBlend;
                }
                else
                {
                    this.Alpha = AlphaType.None;
                }
            }
            else
            {
                this.Alpha = AlphaType.None;
            }

            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 12;
            int tempc2 = map.BR.ReadInt32();
            int tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            if (tempc2 != 0)
            {
                map.BR.BaseStream.Position = tempr2 + 4;
                int tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                if (tempcrap != -1)
                {
                    Meta tempmeta = new Meta(map);
                    tempmeta.ReadMetaFromMap(tempcrap, false);
                    ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                    this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                    this.MainName   = map.FileNames.Name[tempcrap];
                    this.levels     = pm.Properties[0].mipMapCount;
                }
            }

            //map.OpenMap(MapTypes.Internal);
            map.BR.BaseStream.Position = map.MetaInfo.Offset[this.TagIndex] + 32;
            tempc2 = map.BR.ReadInt32();
            tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            map.BR.BaseStream.Position = tempr2 + 24;
            int fuckr = map.BR.ReadInt32();

            if (fuckr != 0)
            {
                fuckr -= map.SecondaryMagic;
                map.BR.BaseStream.Position = fuckr;
                this.primarydetailuscale   = map.BR.ReadSingle();
                this.primarydetailvscale   = map.BR.ReadSingle();
                this.primarydetailwscale   = map.BR.ReadSingle();
                map.BR.ReadSingle();
                this.secondarydetailuscale = map.BR.ReadSingle();
                this.secondarydetailvscale = map.BR.ReadSingle();
                this.secondarydetailwscale = map.BR.ReadSingle();
            }

            map.BR.BaseStream.Position = tempr2 + 4;
            tempc2 = map.BR.ReadInt32();
            tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            /*
             *
             * for (int x = 0; x < tempc2; x++)
             * {
             *  map.BR.BaseStream.Position = tempr2 + (x * 12);
             *  int tempcrap = map.Functions.Meta.FindMetaByID(map.BR.ReadInt32(), map);
             *  if (tempcrap == -1) { continue; }
             *  Meta tempmeta = new Meta(map);
             *  tempmeta.ReadMetaFromMap(tempcrap, map, false);
             *  Raw.ParsedBitmap pm = new Raw.ParsedBitmap(ref tempmeta, map);
             *  Bitmaps.Add(pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0));
             * BitmapNames.Add(map.FileNames.Name[tempcrap]);
             * }
             *
             */
            // map.BR.BaseStream.Position = tempr + 20;
            // tempc2 = map.BR.ReadInt32();
            // tempr2 = map.BR.ReadInt32() - map.SecondaryMagic;

            // tempc2 = tempc;
            // tempr2 = tempr;
            if (tempc2 != 0)
            {
                map.BR.BaseStream.Position = tempr2;
                int tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());

                if (tempcrap != -1)
                {
                    int test = map.FileNames.Name[tempcrap].IndexOf("reflection_maps");
                    if (map.FileNames.Name[tempcrap].IndexOf("_bump") != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                        //  this.BumpMapBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.BumpMapName = map.FileNames.Name[tempcrap];
                    }
                    else if (map.FileNames.Name[tempcrap].IndexOf("_cube_map") != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                        //  this.CubeMapBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.CubeMapName = map.FileNames.Name[tempcrap];
                    }
                    else if (map.FileNames.Name[tempcrap].IndexOf("default_") == -1 && this.MainBitmap == null &&
                             test == -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);

                        // Try to load LOD2-MIP3 if that fails, load LOD2-MIP0, otherwise LOD0-MIP0
                        this.MainBitmap = pm.FindChunkAndDecode(0, 2, 3, ref tempmeta, map, 0, 0);
                        if (this.MainBitmap == null)
                        {
                            this.MainBitmap = pm.FindChunkAndDecode(0, 2, 0, ref tempmeta, map, 0, 0);
                            if (this.MainBitmap == null)
                            {
                                this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                            }
                        }

                        this.MainName = map.FileNames.Name[tempcrap];
                        this.levels   = pm.Properties[0].mipMapCount;
                    }
                    else if (test != -1)
                    {
                        map.BR.BaseStream.Position += 8;
                        tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);

                        // this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map);
                        // this.MainName = map.FileNames.Name[tempcrap];
                    }
                }

                map.BR.BaseStream.Position = tempr2 + 24;
                tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                if (tempcrap != -1 && this.MainBitmap == null)
                {
                    Meta tempmeta = new Meta(map);
                    tempmeta.ReadMetaFromMap(tempcrap, false);
                    ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                    this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                    this.MainName   = map.FileNames.Name[tempcrap];
                    this.levels     = pm.Properties[0].mipMapCount;
                }
                else if (this.MainBitmap == null)
                {
                    map.BR.BaseStream.Position = tempr2 + 12;
                    tempcrap = map.Functions.ForMeta.FindMetaByID(map.BR.ReadInt32());
                    if (tempcrap != -1)
                    {
                        Meta tempmeta = new Meta(map);
                        tempmeta.ReadMetaFromMap(tempcrap, false);
                        ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);
                        this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                        this.MainName   = map.FileNames.Name[tempcrap];
                        this.levels     = pm.Properties[0].mipMapCount;
                    }
                }
            }

            if (!alreadyOpen)
            {
                map.CloseMap();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// The ce shader info.
        /// </summary>
        /// <param name="TagIndex">The TagIndex.</param>
        /// <param name="map">The map.</param>
        /// <remarks></remarks>
        public void CEShaderInfo(int TagIndex, Map map)
        {
            this.TagIndex = TagIndex;
            if (this.TagIndex == -1)
            {
                return;
            }

            this.shaderName = map.FileNames.Name[this.TagIndex];

            map.OpenMap(MapTypes.Internal);
            int mainid          = 0;
            int primarydetail   = -1;
            int secondarydetail = -1;
            int micro           = -1;

            switch (map.MetaInfo.TagType[TagIndex])
            {
            case "schi":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 228;
                mainid = map.BR.ReadInt32();
                break;

            case "soso":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 176;
                mainid = map.BR.ReadInt32();
                break;

            case "sgla":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 356;
                mainid = map.BR.ReadInt32();
                break;

            case "scex":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 900;
                mainid = map.BR.ReadInt32();
                break;

            case "senv":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 148;
                mainid = map.BR.ReadInt32();
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 180;
                this.primarydetailuscale   = map.BR.ReadSingle();
                this.primarydetailvscale   = this.primarydetailuscale;
                this.primarydetailwscale   = 1;
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 196;
                primarydetail = map.BR.ReadInt32();

                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 200;
                this.secondarydetailuscale = map.BR.ReadSingle();
                this.secondarydetailvscale = this.secondarydetailuscale;
                this.secondarydetailwscale = 1;
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 216;
                secondarydetail            = map.BR.ReadInt32();

                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 248;
                this.microdetailuscale     = map.BR.ReadSingle();
                this.microdetailvscale     = this.secondarydetailuscale;
                this.microdetailwscale     = 1;
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 264;
                micro = map.BR.ReadInt32();

                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 40;
                byte alphatest = map.BR.ReadByte();
                int  test      = alphatest & 1;
                if (test != 0)
                {
                    this.Alpha = AlphaType.AlphaTest;
                }

                break;

            case "swat":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 88;
                mainid = map.BR.ReadInt32();
                break;

            case "smet":
                map.BR.BaseStream.Position = map.MetaInfo.Offset[TagIndex] + 88;
                mainid = map.BR.ReadInt32();
                break;
            }

            map.CloseMap();

            mainid          = map.Functions.ForMeta.FindMetaByID(mainid);
            primarydetail   = map.Functions.ForMeta.FindMetaByID(primarydetail);
            secondarydetail = map.Functions.ForMeta.FindMetaByID(secondarydetail);
            micro           = map.Functions.ForMeta.FindMetaByID(micro);
            if (mainid == -1)
            {
                return;
            }

            if (map.MetaInfo.external[mainid])
            {
                map.OpenMap(MapTypes.Bitmaps);
            }
            else
            {
                map.OpenMap(MapTypes.Internal);
            }

            Meta tempmeta = new Meta(map);

            tempmeta.ReadMetaFromMap(mainid, false);

            map.CloseMap();
            ParsedBitmap pm = new ParsedBitmap(ref tempmeta, map);

            // Attempt to load LOD2, if that fails, load LOD0
            try
            {
                this.MainBitmap = pm.FindChunkAndDecode(0, 2, 0, ref tempmeta, map, 0, 0);
            }
            catch
            {
                this.MainBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
            }
            this.MainName = map.FileNames.Name[mainid];

            if (primarydetail != -1)
            {
                if (map.MetaInfo.external[primarydetail])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(primarydetail, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.primarydetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.primarydetailName   = map.FileNames.Name[primarydetail];
            }

            if (secondarydetail != -1)
            {
                if (map.MetaInfo.external[secondarydetail])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(secondarydetail, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.secondarydetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.secondarydetailName   = map.FileNames.Name[secondarydetail];
            }

            if (micro != -1)
            {
                if (map.MetaInfo.external[micro])
                {
                    map.OpenMap(MapTypes.Bitmaps);
                }
                else
                {
                    map.OpenMap(MapTypes.Internal);
                }

                tempmeta = new Meta(map);
                tempmeta.ReadMetaFromMap(micro, false);

                map.CloseMap();
                pm = new ParsedBitmap(ref tempmeta, map);
                this.microdetailBitmap = pm.FindChunkAndDecode(0, 0, 0, ref tempmeta, map, 0, 0);
                this.microdetailName   = map.FileNames.Name[micro];
            }
        }
Exemplo n.º 9
0
        public void loadDDSInfo(string filename, ParsedBitmap pb)
        {
            FileStream   fs = new FileStream(filename, FileMode.Open);
            BinaryReader br = new BinaryReader(fs);

            dds.ReadStruct(ref br);

            // Determine Format Type
            ParsedBitmap.BitmapType bitmapType = ParsedBitmap.BitmapType.BITM_TYPE_2D;
            if (((int)DDS.DDSEnum.DDSCAPS2_VOLUME & dds.ddsd.ddsCaps.caps2) > 0)
            {
                bitmapType = ParsedBitmap.BitmapType.BITM_TYPE_3D;
            }
            else if (((int)DDS.DDSEnum.DDSCAPS2_CUBEMAP & dds.ddsd.ddsCaps.caps2) > 0)
            {
                bitmapType = ParsedBitmap.BitmapType.BITM_TYPE_CUBEMAP;
            }


            // Used to display external (file) bitmap to be injected
            int tempsize = dds.ddsd.width * dds.ddsd.height;

            switch (dds.ddsd.ddfPixelFormat.FourCC)
            {
            case "DXT1":
                tempsize /= 2;
                break;

            case "DXT2":
            case "DXT3":
            case "DXT4":
            case "DXT5":

                // tempsize /= 1;
                break;

            // for non-compressed
            default:
                tempsize *= dds.ddsd.ddfPixelFormat.RGBBitCount >> 3;
                break;
            }

            int widthPad = 0;

            if (dds.ddsd.width % 16 != 0)
            {
                widthPad = 16 - dds.ddsd.width % 16;
            }

            int byteStep = dds.ddsd.ddfPixelFormat.RGBBitCount / 8;

            /*
             * int totalSize = tempsize + (dds.ddsd.height * widthPad * byteStep);
             * if (bitmapType == ParsedBitmap.BitmapType.BITM_TYPE_CUBEMAP)
             *  totalSize *= 6;
             * byte[] guh = new byte[totalSize];
             */
            byte[] guh = new byte[br.BaseStream.Length - br.BaseStream.Position]; // + (widthPad * dds.ddsd.height * byteStep)];
            br.BaseStream.Read(guh, 0, guh.Length);

            // Determine DDS Format
            ParsedBitmap.BitmapFormat bmf = DDS.getBitmapFormat(dds);

            // G8B8 same as A8Y8 (found as A8Y8), but adjusted to 128 as center
            if (bmf == ParsedBitmap.BitmapFormat.BITM_FORMAT_A8Y8 &&
                pb.Properties[0].formatname == ParsedBitmap.BitmapFormat.BITM_FORMAT_G8B8)
            {
                for (int ii = 0; ii < guh.Length; ii++)
                {
                    guh[ii] += 128;
                }

                bmf = ParsedBitmap.BitmapFormat.BITM_FORMAT_G8B8;
            }

            pbSourceDDS.Image = ParsedBitmap.DecodeBitm(
                guh,
                dds.ddsd.height,
                dds.ddsd.width,
                dds.ddsd.depth,
                dds.ddsd.ddfPixelFormat.RGBBitCount,
                bitmapType,
                bmf,
                false,
                null,
                -1,
                -1);

            br.Close();
            fs.Close();

            #region Fill the source info box with the DDS information
            this.lbSourceDDS.Items.Add("Aspect : " + dds.ddsd.width + "x" + dds.ddsd.height);
            this.lbSourceDDS.Items.Add("w/ Pad : " + (dds.ddsd.width + widthPad) + "x" + dds.ddsd.height);
            int    bpp    = 32;
            string format = string.Empty;
            switch (dds.ddsd.ddfPixelFormat.FourCC)
            {
            case "DXT1":
                format = "DXT1";
                break;

            case "DXT2":
            case "DXT3":
                format = "DXT2AND3";
                break;

            case "DXT4":
            case "DXT5":
                format = "DXT4AND5";
                break;

            default:
                bpp = dds.ddsd.ddfPixelFormat.RGBBitCount;
                int aCount = 0;
                int rCount = 0;
                int gCount = 0;
                int bCount = 0;

                for (int i = 0; i < bpp; i++)
                {
                    // # of alpha bits
                    if ((dds.ddsd.ddfPixelFormat.RGBAlphaBitMask & (1 << i)) != 0)
                    {
                        aCount++;
                    }

                    // # of red bits
                    if ((dds.ddsd.ddfPixelFormat.RBitMask & (1 << i)) != 0)
                    {
                        rCount++;
                    }

                    // # of green bits
                    if ((dds.ddsd.ddfPixelFormat.GBitMask & (1 << i)) != 0)
                    {
                        gCount++;
                    }

                    // # of blue bits
                    if ((dds.ddsd.ddfPixelFormat.BBitMask & (1 << i)) != 0)
                    {
                        bCount++;
                    }
                }

                if ((aCount > 0) && ((dds.ddsd.ddfPixelFormat.Flags & 0x03) > 0))
                {
                    format += "A" + aCount;
                }
                else if (bpp - (rCount + gCount + bCount) > 0)
                {
                    format += "X" + (bpp - (rCount + gCount + bCount));
                }

                if (rCount > 0)
                {
                    format += "R" + rCount;
                }

                if (gCount > 0)
                {
                    format += "G" + gCount;
                }

                if (bCount > 0)
                {
                    format += "B" + bCount;
                }

                break;
            }
            lbSourceDDS.Items.Add("BPP    : " + bpp);
            lbSourceDDS.Items.Add("Type   : " + bitmapType.ToString().Substring(10));
            lbSourceDDS.Items.Add("Format : " + format); // remove "BITMAP_FORMAT_"
            lbSourceDDS.Items.Add("# Mips : " + Math.Max(dds.ddsd.MipMapCount - 1, 0));
            #endregion
        }
Exemplo n.º 10
0
        private void loadSkin()
        {
            animation    = new List <animationData>();
            bitmapBlocks = new List <bitmapData>();
            textBlocks   = new List <textBlockData>();
            BinaryReader br  = new BinaryReader(meta.MS);
            BinaryReader br2 = br;

            #region Animation Frames reflexive
            br2 = br;
            br.BaseStream.Position = 20;
            int animationCount  = br.ReadInt32();
            int animationOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int animationTag = map.Functions.ForMeta.FindMetaByOffset(animationOffset);
            if (animationCount > 0 && animationTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(animationTag, meta.Map, false, true);
                br2              = new BinaryReader(newMeta.MS);
                animationOffset -= newMeta.offset;
            }
            else
            {
                animationOffset -= meta.offset;
            }

            for (int list = 0; list < animationCount; list++)
            {
                animationData ad = new animationData(list, meta);
                ad.offset = animationOffset + list * 16;
                ad.Read(br2);
                this.animation.Add(ad);
            }
            #endregion

            #region Text blocks reflexive
            br2 = br;
            br.BaseStream.Position = 28;
            int textBlockCount  = br.ReadInt32();
            int textBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int textBlockTag = map.Functions.ForMeta.FindMetaByOffset(textBlockOffset);
            if (textBlockCount > 0 && textBlockTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(textBlockTag, map, false, true);
                br2              = new BinaryReader(newMeta.MS);
                textBlockOffset -= newMeta.offset;
            }
            else
            {
                textBlockOffset -= meta.offset;
            }

            for (int list = 0; list < textBlockCount; list++)
            {
                textBlockData tbd = new textBlockData(list);
                tbd.offset = textBlockOffset + list * 44;
                tbd.Read(br2);
                this.textBlocks.Add(tbd);
            }
            #endregion

            #region Bitmap block reflexive
            br.BaseStream.Position = 36;
            int bitmapBlockCount  = br.ReadInt32();
            int bitmapBlockOffset = br.ReadInt32() - map.SecondaryMagic;

            // Handles reflexives in other tags (pointers)
            int bitmBlockTag = map.Functions.ForMeta.FindMetaByOffset(bitmapBlockOffset);
            if (bitmapBlockCount > 0 && bitmBlockTag != meta.TagIndex)
            {
                Meta newMeta = Map.GetMetaFromTagIndex(bitmBlockTag, map, false, true);
                br2 = new BinaryReader(newMeta.MS);
                bitmapBlockOffset -= newMeta.offset;
            }
            else
            {
                bitmapBlockOffset -= meta.offset;
            }

            // Always add 3 in case of using sub bitmaps
            for (int list = 0; list < bitmapBlockCount; list++)
            {
                bitmapData bd = new bitmapData(list);
                bd.offset = bitmapBlockOffset + list * 56;
                bd.Read(br2);
                int bitmID = map.Functions.ForMeta.FindMetaByID(bd.bitmIdent);
                if (bitmID != -1)
                {
                    bd.meta = Map.GetMetaFromTagIndex(bitmID, map, false, false);
                    ParsedBitmap pm = new ParsedBitmap(ref bd.meta, map);
                    bd.link = pm.FindChunkAndDecode(0, 0, 0, ref bd.meta, map, 0, 0);
                    this.bitmapBlocks.Add(bd);

                    if (pm.Properties.Length > 1)
                    {
                        bd      = (bitmapData)bd.Clone();
                        bd.link = pm.FindChunkAndDecode(1, 0, 0, ref bd.meta, map, 0, 0);
                    }
                    this.bitmapBlocks.Add(bd);

                    if (pm.Properties.Length > 2)
                    {
                        bd      = (bitmapData)bd.Clone();
                        bd.link = pm.FindChunkAndDecode(2, 0, 0, ref bd.meta, map, 0, 0);
                    }
                    this.bitmapBlocks.Add(bd);
                }
            }
            #endregion

            isLoaded = true;
        }