Esempio n. 1
0
        void AsyncDraw(object sender, DoWorkEventArgs e)
        {
            stopwatch         = Stopwatch.StartNew();
            renderer.Rotation = previewRotation;

            if (bwRenderer.CancellationPending)
            {
                return;
            }

            renderer.ProgressChanged +=
                (progressSender, progressArgs) =>
                bwRenderer.ReportProgress(progressArgs.ProgressPercentage, progressArgs.UserState);
            IsoCatResult result = renderer.Draw(map);

            if (result.Canceled || bwRenderer.CancellationPending)
            {
                return;
            }

            Bitmap rawImage = result.Bitmap;

            if (rawImage != null)
            {
                previewImage = rawImage.Clone(result.CropRectangle, rawImage.PixelFormat);
            }
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Optimized);
        }
Esempio n. 2
0
        void AsyncDraw(object sender, DoWorkEventArgs e)
        {
            stopwatch         = Stopwatch.StartNew();
            renderer.Rotation = previewRotation;

            if (bwRenderer.CancellationPending)
            {
                return;
            }

            IsoCatResult result = renderer.Draw(map);

            if (result.Cancelled || bwRenderer.CancellationPending)
            {
                return;
            }

            Bitmap rawImage = result.Bitmap;

            if (rawImage != null)
            {
                previewImage = rawImage.Clone(result.CropRectangle, rawImage.PixelFormat);
            }
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Optimized);
        }
Esempio n. 3
0
        void RenderLoop()
        {
            renderer = MakeRenderer();
            using (MemoryStream ms = new MemoryStream()) {
                // loop terminates with the rest of the program (this is a background thread)
                while (true)
                {
                    // wait (block) until a map is available for drawing
                    RenderTask task = inQueue.WaitDequeue();
                    try {
                        // render the map
                        IsoCatResult result = renderer.Draw(task.Map);
                        task.Map = null;

                        // crop image (if needed)
                        Image image;
                        if (p.Uncropped)
                        {
                            image = result.Bitmap;
                        }
                        else
                        {
                            image = result.Bitmap.Clone(result.CropRectangle, result.Bitmap.PixelFormat);
                            result.Bitmap.Dispose();
                        }

                        // encode image
                        if (p.ExportFormat.Equals(ImageFormat.Jpeg))
                        {
                            EncoderParameters encoderParams = new EncoderParameters();
                            encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, p.JpegQuality);
                            image.Save(ms, p.ImageEncoder, encoderParams);
                        }
                        else if (p.ExportFormat.Equals(ImageFormat.Gif))
                        {
                            OctreeQuantizer q = new OctreeQuantizer(255, 8);
                            image = q.Quantize(image);
                            image.Save(ms, p.ExportFormat);
                        }
                        else
                        {
                            image.Save(ms, p.ExportFormat);
                        }
                        image.Dispose();

                        // store result as a byte[]
                        task.Result = ms.ToArray();
                    } catch (Exception ex) {
                        task.Exception = ex;
                    }

                    // send stack to the results queue
                    outQueue.Enqueue(task);
                    ms.SetLength(0);
                }
            }
        }
Esempio n. 4
0
        static bool RenderOneMap([NotNull] FileSystemInfo fileSystemInfo)
        {
            if (fileSystemInfo == null)
            {
                throw new ArgumentNullException("fileSystemInfo");
            }

            try {
                Map map;
                if (mapImporter != null)
                {
                    if (!mapImporter.ClaimsName(fileSystemInfo.FullName))
                    {
                        return(false);
                    }
                    Console.Write("Loading {0}... ", fileSystemInfo.Name);
                    map = mapImporter.Load(fileSystemInfo.FullName);
                }
                else
                {
                    Console.Write("Checking {0}... ", fileSystemInfo.Name);
                    map = MapUtility.Load(fileSystemInfo.FullName);
                }

                string targetFileName;
                if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    targetFileName = fileSystemInfo.Name + imageFileExtension;
                }
                else
                {
                    targetFileName = Path.GetFileNameWithoutExtension(fileSystemInfo.Name) + imageFileExtension;
                }

                string targetPath = Path.Combine(outputDirName, targetFileName);
                if (!overwrite && File.Exists(targetPath))
                {
                    Console.WriteLine();
                    if (!ShowYesNo("File \"{0}\" already exists. Overwrite?", targetFileName))
                    {
                        return(false);
                    }
                }
                Console.Write("Drawing... ");
                IsoCatResult result = renderer.Draw(map);
                Console.Write("Saving {0}... ", Path.GetFileName(targetFileName));
                if (uncropped)
                {
                    SaveImage(result.Bitmap, targetPath);
                }
                else
                {
                    SaveImage(result.Bitmap.Clone(result.CropRectangle, result.Bitmap.PixelFormat), targetPath);
                }
                Console.WriteLine("ok");
                return(true);
            } catch (NoMapConverterFoundException) {
                Console.WriteLine("skip");
                return(false);
            } catch (Exception ex) {
                Console.WriteLine("ERROR");
                Console.Error.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message);
                return(false);
            }
        }
Esempio n. 5
0
        static void RenderOneMap([NotNull] FileSystemInfo fileSystemInfo, [NotNull] string relativeName)
        {
            if (fileSystemInfo == null)
            {
                throw new ArgumentNullException("fileSystemInfo");
            }
            if (relativeName == null)
            {
                throw new ArgumentNullException("relativeName");
            }

            try {
                // if output directory was not given, save to same directory as the mapfile
                if (!outputDirGiven)
                {
                    outputDirName = Paths.GetDirectoryNameOrRoot(fileSystemInfo.FullName);
                }

                // load the mapfile
                Map map;
                if (mapImporter != null)
                {
                    if (!mapImporter.ClaimsName(fileSystemInfo.FullName))
                    {
                        return;
                    }
                    Console.Write("Loading {0}... ", relativeName);
                    map = mapImporter.Load(fileSystemInfo.FullName);
                }
                else
                {
                    Console.Write("Checking {0}... ", relativeName);
                    map = MapUtility.Load(fileSystemInfo.FullName, tryHard);
                }

                // select target image file name
                string targetFileName;
                if ((fileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    targetFileName = fileSystemInfo.Name + imageFileExtension;
                }
                else
                {
                    targetFileName = Path.GetFileNameWithoutExtension(fileSystemInfo.Name) + imageFileExtension;
                }

                // get full target image file name, check if it already exists
                string targetPath = Path.Combine(outputDirName, targetFileName);
                if (!overwrite && File.Exists(targetPath))
                {
                    Console.WriteLine();
                    if (!ShowYesNo("File \"{0}\" already exists. Overwrite?", targetFileName))
                    {
                        return;
                    }
                }

                // draw and save
                Console.Write("Drawing... ");
                IsoCatResult result = renderer.Draw(map);
                Console.Write("Saving {0}... ", Path.GetFileName(targetFileName));
                if (uncropped)
                {
                    SaveImage(result.Bitmap, targetPath);
                }
                else
                {
                    SaveImage(result.Bitmap.Clone(result.CropRectangle, result.Bitmap.PixelFormat), targetPath);
                }
                Console.WriteLine("ok");
            } catch (NoMapConverterFoundException) {
                Console.WriteLine("skip");
            } catch (Exception ex) {
                Console.WriteLine("ERROR");
                Console.Error.WriteLine("{0}: {1}", ex.GetType().Name, ex);
            }
        }