OSDN Git Service

fixed snapshot, it now works when there are blank rows of chunks! + added to csproj
authorThe Grand Dog <alex.h@me.com>
Tue, 2 Jun 2020 13:32:24 +0000 (09:32 -0400)
committerThe Grand Dog <alex.h@me.com>
Tue, 2 Jun 2020 13:32:24 +0000 (09:32 -0400)
Automap/Automap.csproj
Automap/Subsystems/Snapshot.cs

index 68b2350..e458cbe 100644 (file)
     </None>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+               <Compile Include="Subsystems\Snapshot.cs" />
 </Project>
\ No newline at end of file
index c427813..305e446 100644 (file)
@@ -44,7 +44,7 @@ namespace Automap
                        ImageInfo info = new ImageInfo(Width * chunkSize, Height * chunkSize, 8, false);
                        PngWriter snapWriter = FileHelper.CreatePngWriter(path, info, true);
                        snapWriter.CompLevel = 5;
-                       snapWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman;
+                       snapWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Filtered;
 
                        var orderedList =
                                from ch in cols
@@ -52,12 +52,24 @@ namespace Automap
                                orderby g.Key
                                select g;
                        // that sorts things in ascending order so we can only create (chunkSize) lines at once
-                       int row = 0;
+                       int row = 0, lastPosY = 0, posY = 0;
                        foreach (var chunkGroup in orderedList)
                        {
-                               var posY = chunkGroup.Key - NorthEdge;
-                               var inGroup = (await ReadAllInGroup(chunkGroup)).ToArray();
                                // oh god here we go...
+                               posY = chunkGroup.Key - NorthEdge;
+                               var delta = posY - lastPosY;
+                               lastPosY = posY;
+
+                               // if there is more than 1 blank step then the gap needs to be filled.
+                               for (int i = 1; i < delta; i++)
+                               {
+                                       byte[] blankLine = new byte[info.BytesPerRow];
+                                       for (int j = 0; j < chunkSize; j++)
+                                               snapWriter.WriteRowByte(blankLine, row++);
+                               }
+
+                               var inGroup = (await ReadAllInGroup(chunkGroup)).ToArray();
+                               
                                for (int r = 0; r < chunkSize; r++)
                                {
                                        var line = new byte[info.BytesPerRow];
@@ -70,7 +82,14 @@ namespace Automap
                                }
                        }
                        snapWriter.ShouldCloseStream = true;
-
+                       try
+                       {
+                               snapWriter.End();
+                       }
+                       catch (Exception)
+                       {
+                               Console.WriteLine("Snapshot exception!");
+                       }
                        Console.WriteLine($"snapshot finished in {t.ElapsedMilliseconds}");
                }
 
@@ -96,7 +115,6 @@ namespace Automap
                                Console.WriteLine(e.Message);
                                return null;
                        } // do nothing on error
-
                }
        }
 }