コード例 #1
0
                    // whether the i-th bit is set.
                    private static bool Has(this bitmap bm, Sym i)
                    {
                        var n = uint(i) / 32L;
                        var r = uint(i) % 32L;

                        return(bm[n] & (1L << (int)(r)) != 0L);
                    }
コード例 #2
0
                    // set the i-th bit.
                    private static void Set(this bitmap bm, Sym i)
                    {
                        var n = uint(i) / 32L;
                        var r = uint(i) % 32L;

                        bm[n] |= 1L << (int)(r);
                    }
コード例 #3
0
        public void LoadBitmapTag(CacheBase Cache, CacheBase.IndexItem Tag)
        {
            exportAllImagesToolStripMenuItem.Visible = true;

            cache = Cache;
            tag   = Tag;

            bitm = DefinitionsManager.bitm(cache, tag);

            lstBitmaps.Items.Clear();
            var list = GetBitmapsByTag(cache, tag, PixelFormat.Format32bppArgb);

            for (int i = 0; i < list.Count; i++)
            {
                var submap = bitm.Bitmaps[i];
                lstBitmaps.Items.Add(new ListViewItem(new string[]
                {
                    i.ToString(),
                    submap.Width.ToString(),
                    submap.Height.ToString(),
                    submap.Type.ToString(),
                    submap.Format.ToString()
                })
                {
                    Tag = (list[i] == null) ? GetErrorImage() : list[i]
                });
            }

            lstBitmaps.FocusedItem = lstBitmaps.Items[0];
            lstBitmaps_SelectedIndexChanged(null, null);
        }
コード例 #4
0
        /// <summary>
        /// Gets an image from a bitmap tag.
        /// </summary>
        /// <param name="Cache">The CacheFile containing the bitmap tag.</param>
        /// <param name="bitm">The bitmap tag.</param>
        /// <param name="Index">The index of the BitmapData chunk to use.</param>
        /// <param name="Alpha">Whether to include the alpha channel in the image.</param>
        /// <returns>The image from the bitmap tag as a Bitmap.</returns>
        public static Bitmap GetBitmapByTag(CacheBase Cache, bitmap bitm, int Index, PixelFormat PF)
        {
            try
            {
                var submap = bitm.Bitmaps[Index];

                byte[] raw;
                if (Cache.Version <= DefinitionSet.Halo2Vista)
                {
                    raw = Cache.GetRawFromID(submap.PixelsOffset, submap.RawSize);
                }
                else
                {
                    if (bitm.RawChunkBs.Count > 0)
                    {
                        int    rawID  = bitm.RawChunkBs[submap.InterleavedIndex].RawID;
                        byte[] buffer = Cache.GetRawFromID(rawID);
                        raw = new byte[submap.RawSize];
                        Array.Copy(buffer, submap.Index2 * submap.RawSize, raw, 0, submap.RawSize);
                    }
                    else
                    {
                        int rawID = bitm.RawChunkAs[Index].RawID;
                        raw = Cache.GetRawFromID(rawID, submap.RawSize);
                    }
                }

                int vHeight = submap.VirtualHeight;
                int vWidth  = submap.VirtualWidth;

                if (submap.Type == TextureType.CubeMap)
                {
                    return(DXTDecoder.DecodeCubeMap(raw, submap, PF, Cache.Version));
                }

                raw = DXTDecoder.DecodeBitmap(raw, submap, Cache.Version);

                Bitmap     bitmap2          = new Bitmap(submap.Width, submap.Height, PF);
                Rectangle  rect             = new Rectangle(0, 0, submap.Width, submap.Height);
                BitmapData bitmapdata       = bitmap2.LockBits(rect, ImageLockMode.WriteOnly, PF);
                byte[]     destinationArray = new byte[(submap.Width * submap.Height) * 4];

                for (int j = 0; j < submap.Height; j++)
                {
                    Array.Copy(raw, j * vWidth * 4, destinationArray, j * submap.Width * 4, submap.Width * 4);
                }

                Marshal.Copy(destinationArray, 0, bitmapdata.Scan0, destinationArray.Length);
                bitmap2.UnlockBits(bitmapdata);

                return(bitmap2);
            }
            catch
            {
                return(null);
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets all images from the a bitmap tag.
        /// </summary>
        /// <param name="Cache">The CacheFile containing the bitmap tag.</param>
        /// <param name="bitm">The bitmap tag.</param>
        /// <param name="Alpha">Whether to include the alpha channels in the images.</param>
        /// <returns>A List containing each image as a Bitmap.</returns>
        public static List <Bitmap> GetBitmapsByTag(CacheBase Cache, bitmap bitm, PixelFormat PF)
        {
            List <Bitmap> list = new List <Bitmap>();

            for (int i = 0; i < bitm.Bitmaps.Count; i++)
            {
                list.Add(GetBitmapByTag(Cache, bitm, i, PF));
            }

            return(list);
        }
コード例 #6
0
        /// <summary>
        /// Saves all images from a bitmap tag to disk.
        /// </summary>
        /// <param name="Filename">The full path and filename of the first bitmap to save. All subsequent images will be named accordingly.</param>
        /// <param name="Cache">The CacheFile containing the bitmap tag.</param>
        /// <param name="Tag">The bitmap tag.</param>
        /// <param name="Format">The format to save the images in.</param>
        /// <param name="Alpha">Whether to include the alpha channel in the images. Only applies when saving in TIF format.</param>
        public static void SaveAllImages(string Filename, CacheBase Cache, bitmap bitm, BitmapFormat Format, bool Alpha)
        {
            string ext;

            switch (Format)
            {
            case BitmapFormat.TIF:
                ext = ".tif";
                break;

            case BitmapFormat.PNG:
                ext = ".png";
                break;

            case BitmapFormat.DDS:
                ext = ".dds";
                break;

            case BitmapFormat.RAW:
                ext = ".bin";
                break;

            default:
                throw new InvalidOperationException("Invalid BitmapFormat received.");
            }

            if (Filename.EndsWith(ext))
            {
                Filename = Filename.Substring(0, Filename.LastIndexOf('.'));
            }

            for (int i = 0; i < bitm.Bitmaps.Count; i++)
            {
                SaveImage(((i == 0) ? Filename + ext : Filename + " [" + i.ToString() + "]" + ext), Cache, bitm, i, Format, Alpha);
            }
        }
コード例 #7
0
        /// <summary>
        /// Saves an image from a bitmap tag to disk.
        /// </summary>
        /// <param name="Filename">The full path and filename to save to.</param>
        /// <param name="Cache">The CacheFile containing the bitmap tag.</param>
        /// <param name="Tag">The bitmap tag.</param>
        /// <param name="Index">The index of the BitmapData chunk to use.</param>
        /// <param name="Format">The format to save the image in.</param>
        /// <param name="Alpha">Whether to include the alpha channel in the image. Only applies when saving in TIF format.</param>
        public static void SaveImage(string Filename, CacheBase Cache, bitmap bitm, int Index, BitmapFormat Format, bool Alpha)
        {
            var submap = bitm.Bitmaps[Index];

            byte[] raw;

            if (Cache.Version <= DefinitionSet.Halo2Vista)
            {
                raw = Cache.GetRawFromID(submap.PixelsOffset, submap.RawSize);
            }
            else
            {
                if (bitm.RawChunkBs.Count > 0)
                {
                    int    rawID  = bitm.RawChunkBs[submap.InterleavedIndex].RawID;
                    byte[] buffer = Cache.GetRawFromID(rawID);
                    raw = new byte[submap.RawSize];
                    Array.Copy(buffer, submap.Index2 * submap.RawSize, raw, 0, submap.RawSize);
                }
                else
                {
                    int rawID = bitm.RawChunkAs[Index].RawID;
                    raw = Cache.GetRawFromID(rawID, submap.RawSize);
                }
            }

            int vHeight = submap.VirtualHeight;
            int vWidth  = submap.VirtualWidth;

            if (Format == BitmapFormat.TIF || Format == BitmapFormat.PNG)
            {
                string      ext     = (Format == BitmapFormat.TIF) ? ".tif" : ".png";
                int         pLength = (Format == BitmapFormat.TIF) ? 4 : 4;
                ImageFormat IF      = (Format == BitmapFormat.TIF) ? ImageFormat.Tiff : ImageFormat.Png;

                if (!Filename.EndsWith(ext))
                {
                    Filename += ext;
                }

                if (submap.Type == TextureType.CubeMap)
                {
                    var img = DXTDecoder.DecodeCubeMap(raw, submap, Alpha ? PixelFormat.Format32bppArgb : PixelFormat.Format32bppRgb, Cache.Version);
                    if (!Directory.GetParent(Filename).Exists)
                    {
                        Directory.GetParent(Filename).Create();
                    }
                    img.Save(Filename, ImageFormat.Tiff);
                    return;
                }

                raw = DXTDecoder.DecodeBitmap(raw, submap, Cache.Version);

                PixelFormat PF = (Alpha) ? PixelFormat.Format32bppArgb : PixelFormat.Format32bppRgb;

                Bitmap     bitmap2          = new Bitmap(submap.Width, submap.Height, PF);
                Rectangle  rect             = new Rectangle(0, 0, submap.Width, submap.Height);
                BitmapData bitmapdata       = bitmap2.LockBits(rect, ImageLockMode.WriteOnly, PF);
                byte[]     destinationArray = new byte[(submap.Width * submap.Height) * pLength];

                for (int j = 0; j < submap.Height; j++)
                {
                    Array.Copy(raw, j * vWidth * pLength, destinationArray, j * submap.Width * pLength, submap.Width * pLength);
                }

                Marshal.Copy(destinationArray, 0, bitmapdata.Scan0, destinationArray.Length);
                bitmap2.UnlockBits(bitmapdata);

                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }

                bitmap2.Save(Filename, IF);
            }
            else if (Format == BitmapFormat.DDS)
            {
                if (!Filename.EndsWith(".dds"))
                {
                    Filename += ".dds";
                }

                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }

                var fs = new FileStream(Filename, FileMode.Create, FileAccess.Write);
                var bw = new BinaryWriter(fs);

                if (submap.Flags.Values[3])
                {
                    raw = DXTDecoder.ConvertToLinearTexture(raw, vWidth, vHeight, submap.Format);
                }

                if (submap.Format != TextureFormat.A8R8G8B8)
                {
                    for (int i = 0; i < raw.Length; i += 2)
                    {
                        Array.Reverse(raw, i, 2);
                    }
                }
                else
                {
                    for (int i = 0; i < (raw.Length); i += 4)
                    {
                        Array.Reverse(raw, i, 4);
                    }
                }

                new DDS(submap).Write(bw);
                bw.Write(raw);

                bw.Close();
                bw.Dispose();
            }
            else if (Format == BitmapFormat.RAW)
            {
                if (!Filename.EndsWith(".bin"))
                {
                    Filename += ".bin";
                }

                if (!Directory.GetParent(Filename).Exists)
                {
                    Directory.GetParent(Filename).Create();
                }

                File.WriteAllBytes(Filename, raw);
            }
            else
            {
                throw new InvalidOperationException("Invalid BitmapFormat received.");
            }
        }
コード例 #8
0
 foreach (var(bitmap, pts) in frames)
コード例 #9
0
ファイル: loader_LoaderStruct.cs プロジェクト: zjmit/go2cs
 public Loader(map <ptr <oReader>, Sym> start = default, slice <objIdx> objs = default, Sym max = default, Sym extStart = default, slice <nameVer> extSyms = default, slice <Sym> builtinSyms = default, long ocache = default, array <map <@string, Sym> > symsByName = default, map <nameVer, Sym> extStaticSyms = default, map <Sym, Sym> overwrite = default, map <@string, ptr <oReader> > objByPkg = default, slice <ptr <sym.Symbol> > Syms = default, long anonVersion = default, bitmap Reachable = default, slice <Sym> Reachparent = default, slice <sym.Reloc> relocBatch = default, uint flags = default, long strictDupMsgs = default)
 {
     this.start         = start;
     this.objs          = objs;
     this.max           = max;
     this.extStart      = extStart;
     this.extSyms       = extSyms;
     this.builtinSyms   = builtinSyms;
     this.ocache        = ocache;
     this.symsByName    = symsByName;
     this.extStaticSyms = extStaticSyms;
     this.overwrite     = overwrite;
     this.objByPkg      = objByPkg;
     this.Syms          = Syms;
     this.anonVersion   = anonVersion;
     this.Reachable     = Reachable;
     this.Reachparent   = Reachparent;
     this.relocBatch    = relocBatch;
     this.flags         = flags;
     this.strictDupMsgs = strictDupMsgs;
 }
コード例 #10
0
ファイル: AnalizadorImagenes.cs プロジェクト: Arthyom/C-Xmpls
 public AnalizadorImagenes(bitmap ImagenColor, bitmap ImagenGray)
 {
 }
コード例 #11
0
ファイル: Class731.cs プロジェクト: newchild/Project-DayZero
 Class731 class = Class731.smethod_5(bitmap);