コード例 #1
0
        public void SerializeIsoMapPack5(IniFile.IniSection isoMapPack5)
        {
            int cells       = (Width * 2 - 1) * Height;
            int lzoPackSize = cells * 11 + 4;             // last 4 bytes contains a lzo pack header saying no more data is left

            var  isoMapPack  = new byte[lzoPackSize];
            var  isoMapPack2 = new byte[lzoPackSize];
            long di          = 0;

            foreach (var tile in this.isoTiles)
            {
                var bs = tile.ToMapPack5Entry().ToArray();
                Array.Copy(bs, 0, isoMapPack, di, 11);
                di += 11;
            }

            var    compressed   = Format5.Encode(isoMapPack, 5);
            string compressed64 = Convert.ToBase64String(compressed);

            int i   = 1;
            int idx = 0;

            isoMapPack5.Clear();
            while (idx < compressed64.Length)
            {
                int adv = Math.Min(74, compressed64.Length - idx);
                isoMapPack5.SetValue(i++.ToString(), compressed64.Substring(idx, adv));
                idx += adv;
            }
        }
コード例 #2
0
    private byte[] GetEncoded(List <Tile> tileSet)
    {
        byte[] isoMapPack = new byte[tileSet.Count * 11 + 4];

        long byteIndex = 0;

        foreach (Tile tile in tileSet)
        {
            byte[] tileInBytes = tile.GetTileForMapPack();
            Array.Copy(tileInBytes, 0, isoMapPack, byteIndex, 11);
            byteIndex += 11;
        }

        return(Format5.Encode(isoMapPack, 5));
    }
コード例 #3
0
ファイル: TileLayer.cs プロジェクト: zzattack/ccmaps-net
        private byte[] GetEncoded(List <IsoTile> tileSetParam)
        {
            // A tile is of 11 bytes. Last 4 bytes of padding is used for termination
            byte[] isoMapPack = new byte[tileSetParam.Count * 11 + 4];

            long di = 0;

            foreach (var tile in tileSetParam)
            {
                var bs = tile.ToMapPack5Entry().ToArray();
                Array.Copy(bs, 0, isoMapPack, di, 11);
                di += 11;
            }

            return(Format5.Encode(isoMapPack, 5));
        }
コード例 #4
0
        public static unsafe void InjectThumb(Bitmap preview, IniFile map)
        {
            BitmapData bmd = preview.LockBits(new Rectangle(0, 0, preview.Width, preview.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            byte[] image = new byte[preview.Width * preview.Height * 3];
            int    idx   = 0;

            // invert rgb->bgr
            for (int y = 0; y < bmd.Height; y++)
            {
                byte *p = (byte *)bmd.Scan0 + bmd.Stride * y;
                for (int x = 0; x < bmd.Width; x++)
                {
                    byte r = *p++;
                    byte g = *p++;
                    byte b = *p++;

                    image[idx++] = b;
                    image[idx++] = g;
                    image[idx++] = r;
                }
            }

            // encode
            byte[] image_compressed = Format5.Encode(image, 5);

            // base64 encode
            string image_base64 = Convert.ToBase64String(image_compressed, Base64FormattingOptions.None);

            // now overwrite [Preview] and [PreviewPack], inserting them directly after [Basic] if not yet existing
            map.GetOrCreateSection("Preview").SetValue("Size", string.Format("0,0,{0},{1}", preview.Width, preview.Height));

            var section = map.GetOrCreateSection("PreviewPack", "Preview");

            section.Clear();
            section.Index = 0;

            int rowNum = 1;

            for (int i = 0; i < image_base64.Length; i += 70)
            {
                section.SetValue(rowNum++.ToString(CultureInfo.InvariantCulture), image_base64.Substring(i, Math.Min(70, image_base64.Length - i)));
            }
        }
コード例 #5
0
    private void UpdateOverlaySections()
    {
        MapSection overlaySection     = GetSection("OverlayPack");
        MapSection overlayDataSection = GetSection("OverlayDataPack");

        if (overlaySection != null && overlayDataSection != null)
        {
            byte[] overlayPack     = new byte[1 << 18];
            byte[] overlayDataPack = new byte[1 << 18];

            for (int i = 0; i < 262144; i++)
            {
                overlayPack[i]     = 0xFF;
                overlayDataPack[i] = 0;
            }

            if (overlays != null && overlays.Count > 0)
            {
                foreach (Overlay entry in overlays)
                {
                    int location = (entry.MapY * 512) + entry.MapX;
                    overlayPack[location]     = (byte)entry.OverlayIndex;
                    overlayDataPack[location] = (byte)entry.OverlayFrame;
                }
            }

            string oPackEncoded     = Convert.ToBase64String(Format5.Encode(overlayPack, 80), Base64FormattingOptions.None);
            string oDataPackEncoded = Convert.ToBase64String(Format5.Encode(overlayDataPack, 80), Base64FormattingOptions.None);

            overlaySection.Entries.Clear();
            overlayDataSection.Entries.Clear();

            for (int i = 0, j = 1; i < oPackEncoded.Length; i += 70)
            {
                overlaySection.Entries.Add(j++.ToString(CultureInfo.InvariantCulture), oPackEncoded.Substring(i, Math.Min(70, oPackEncoded.Length - i)));
            }

            for (int i = 0, j = 1; i < oDataPackEncoded.Length; i += 70)
            {
                overlayDataSection.Entries.Add(j++.ToString(CultureInfo.InvariantCulture), oDataPackEncoded.Substring(i, Math.Min(70, oDataPackEncoded.Length - i)));
            }
        }
    }