Esempio n. 1
0
        private static void EncodeRow(BitWriter bw, IEnumerable <IStaticEntity> rowTracks)
        {
            // Go through this row
            var row     = rowTracks.OfType <Track>().ToDictionary(x => x.Column, x => x.Direction);
            int lastCol = row.Keys.Max();

            TrackEncoding lastDir      = TrackEncoding.Blank;
            int           lastDirCount = 0;

            for (int c = 0; c <= lastCol; c++)
            {
                TrackEncoding currentDir = TrackEncoding.Blank;
                if (row.ContainsKey(c))
                {
                    currentDir = s_directionMap.Single(x => x.Value == row[c]).Key;
                }
                if (currentDir == lastDir)
                {
                    lastDirCount++;
                }
                else
                {
                    if (lastDirCount > 0)
                    {
                        WriteOutTrack(bw, lastDir, lastDirCount);
                    }
                    lastDirCount = 1;
                    lastDir      = currentDir;
                }
            }
            if (lastDirCount > 0)
            {
                WriteOutTrack(bw, lastDir, lastDirCount);
            }
        }
Esempio n. 2
0
 private static void WriteOutTrack(BitWriter bw, TrackEncoding direction, int count)
 {
     if (direction == TrackEncoding.Blank)
     {
         // Empty is 2, RepeatEmpty is 5 + 2, Only saves if we more than 3
         WriteMultiple(bw, count, 3, x => x.WriteEmpty());
     }
     else
     {
         // Track is 6, RepeatTrack is 5 + 6, Only saves if we more than 1
         WriteMultiple(bw, count, 1, x => x.WriteTrack(direction));
     }
 }
Esempio n. 3
0
 public void WriteTrack(TrackEncoding track)
 {
     Write(0, 1);
     Write4BitInt((int)track);
 }