Esempio n. 1
0
        internal static void GeneratePostImageResizes(Settings settings, PostRepository postRepository)
        {
            var size         = settings.ItemImageSize;
            var maximumLevel = DeepZoomImage.DetermineMaximumLevel(size);

            var workingPath      = Path.GetFullPath(WorkingFolderName);
            var imageFormat      = settings.PostImageEncoding;
            var extension        = imageFormat.ToString().ToLower();
            var fileNameIdFormat = settings.FileNameIdFormat;

            foreach (var postId in postRepository.RetrievePostIds())
            {
                var relativeBinnedImagePath   = Post.ComputeBinnedPath(postId, extension, fileNameIdFormat);
                var absoluteBinnedImagePath   = Path.Combine(workingPath, relativeBinnedImagePath);
                var relativeBinnedImageFolder = Post.ComputeBinnedPath(postId, null, fileNameIdFormat) + "_files";
                var absoluteBinnedImageFolder = Path.Combine(workingPath, relativeBinnedImageFolder);
                Directory.CreateDirectory(absoluteBinnedImageFolder);
                using (var inputStream =
                           new FileStream(absoluteBinnedImagePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var sourceBitmap = new Bitmap(inputStream))
                    {
                        GeneratePostImageResizes(sourceBitmap, size, maximumLevel, (level, resizedBitmap) =>
                        {
                            var levelImageName = "{0}.{1}".FormatInvariant(level, extension);
                            var levelImagePath = Path.Combine(absoluteBinnedImageFolder, levelImageName);
                            using (var outputStream =
                                       new FileStream(levelImagePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                            {
                                resizedBitmap.Save(outputStream, imageFormat);
                            }
                        }
                                                 );
                    }
            }
        }
Esempio n. 2
0
        internal void GeneratePostImageResizes(PostRepository postRepository)
        {
            var dzi = new DeepZoomImage(_settings);

            var workingPath      = _settings.AbsoluteWorkingFolder;
            var imageFormat      = _settings.PostImageEncoding;
            var extension        = imageFormat.GetName();
            var fileNameIdFormat = _settings.FileNameIdFormat;

            foreach (var postId in postRepository.RetrievePostIds())
            {
                var relativeBinnedImagePath   = Post.ComputeBinnedPath(postId, extension, fileNameIdFormat);
                var absoluteBinnedImagePath   = Path.Combine(workingPath, relativeBinnedImagePath);
                var relativeBinnedImageFolder = Post.ComputeBinnedPath(postId, null, fileNameIdFormat) + "_files";
                var absoluteBinnedImageFolder = Path.Combine(workingPath, relativeBinnedImageFolder);
                Directory.CreateDirectory(absoluteBinnedImageFolder);
                using (var inputStream = absoluteBinnedImagePath.CreateReadStream())
                    using (var sourceBitmap = new Bitmap(inputStream))
                    {
                        dzi.GeneratePostImageResizes(sourceBitmap, (level, resizedBitmap) =>
                        {
                            var levelImageName = "{0}.{1}".FormatInvariant(level, extension);
                            var levelImagePath = Path.Combine(absoluteBinnedImageFolder, levelImageName);
                            using (var outputStream = levelImagePath.CreateReadStream())
                            {
                                resizedBitmap.Save(outputStream, imageFormat);
                            }
                        }
                                                     );
                    }
            }
        }
Esempio n. 3
0
        internal static void GenerateImageManifests(Settings settings, PostRepository postRepository)
        {
            var outputPath       = Path.GetFullPath(OutputFolderName);
            var fileNameIdFormat = settings.FileNameIdFormat;
            var imageNode        = GenerateImageManifest(settings.TileSize, settings.TileOverlap,
                                                         settings.PostImageEncoding.ToString().ToLower(),
                                                         settings.ItemImageSize.Width, settings.ItemImageSize.Height);

            var sb = new StringBuilder();

            using (var writer = XmlWriter.Create(sb, WriterSettings))
            {
                Debug.Assert(writer != null);
                imageNode.WriteTo(writer);
            }
            var imageManifest = sb.ToString();

            foreach (var postId in postRepository.RetrievePostIds())
            {
                var relativeBinnedImageManifestPath = Post.ComputeBinnedPath(postId, "dzi", fileNameIdFormat);
                var absoluteBinnedImageManifestPath = Path.Combine(outputPath, relativeBinnedImageManifestPath);
                Directory.CreateDirectory(Path.GetDirectoryName(absoluteBinnedImageManifestPath));
                File.WriteAllText(absoluteBinnedImageManifestPath, imageManifest, Encoding.UTF8);
            }
        }
        internal XElement CreateImageCollectionItemNode(int mortonNumber, int id, string relativePathToRoot)
        {
            #region <I N="0" Id="351" Source="../../../0/0351.dzi" />
            var itemNode = new XElement(ItemNodeName);
            // "N" is "The number of the item (Morton Number) where it appears in the tiles."
            itemNode.SetAttributeValue("N", mortonNumber);
            itemNode.SetAttributeValue("Id", id);
            var relativeDziSubPath = Post.ComputeBinnedPath(id, "dzi", _settings.FileNameIdFormat);
            var relativeDziPath    = Path.Combine(relativePathToRoot, relativeDziSubPath);
            itemNode.SetAttributeValue("Source", relativeDziPath);
            #endregion

            return(itemNode);
        }
        internal IEnumerable <Bitmap> OpenLevelImages(IEnumerable <int> postIds, int level)
        {
            var levelName     = Convert.ToString(level, 10);
            var inputFileName = Path.ChangeExtension(DeepZoomImage.TileZeroZero, _imageFormatName);

            foreach (var postId in postIds)
            {
                var relativeFolder          = Post.ComputeBinnedPath(postId, null, _settings.FileNameIdFormat) + "_files";
                var relativeLevelFolder     = relativeFolder.CombinePath(levelName, inputFileName);
                var absoluteSourceImagePath = Path.Combine(_settings.AbsoluteOutputFolder, relativeLevelFolder);
                using (var bitmap = new Bitmap(absoluteSourceImagePath))
                {
                    yield return(bitmap);
                }
            }
        }
        public void PivotizeTag(Tag tag, IEnumerable <int> postIds)
        {
            var relativeBinnedCxmlPath = tag.ComputeBinnedPath(".cxml");
            var absoluteBinnedCxmlPath = Path.Combine(_settings.AbsoluteOutputFolder, relativeBinnedCxmlPath);

            Directory.CreateDirectory(Path.GetDirectoryName(absoluteBinnedCxmlPath));
            using (var outputStream = absoluteBinnedCxmlPath.CreateWriteStream())
            {
                var streamReaders = postIds.Map(postId =>
                {
                    var relativeBinnedXmlPath = Post.ComputeBinnedPath(postId, ".xml", _settings.FileNameIdFormat);
                    var absoluteBinnedXmlPath = Path.Combine(_settings.AbsoluteWorkingFolder, relativeBinnedXmlPath);
                    var sr = new StreamReader(absoluteBinnedXmlPath);
                    return(sr);
                }
                                                );
                PivotizeTag(tag, streamReaders, outputStream);
            }
        }
Esempio n. 7
0
        internal static void SlicePostImage(int postId, Size size, int maximumLevel, string extension, string fileNameIdFormat, ImageFormat imageFormat, int tileSize, int tileOverlap)
        {
            var workingPath = Path.GetFullPath(WorkingFolderName);
            var outputPath  = Path.GetFullPath(OutputFolderName);
            var relativeBinnedImageFolder       = Post.ComputeBinnedPath(postId, null, fileNameIdFormat) + "_files";
            var absoluteBinnedImageFolder       = Path.Combine(workingPath, relativeBinnedImageFolder);
            var absoluteBinnedOutputImageFolder = Path.Combine(outputPath, relativeBinnedImageFolder);

            for (var level = maximumLevel; level >= 0; level--)
            {
                var levelName           = Convert.ToString(level, 10);
                var targetSize          = DeepZoomImage.ComputeLevelSize(size, level);
                var tileFiles           = new List <Stream> ();
                var inputLevelImageFile = Path.ChangeExtension(levelName, extension);
                var inputLevelImagePath = Path.Combine(absoluteBinnedImageFolder, inputLevelImageFile);
                var outputLevelFolder   = Path.Combine(absoluteBinnedOutputImageFolder, levelName);
                Directory.CreateDirectory(outputLevelFolder);

                var tiles = DeepZoomImage.ComputeTiles(targetSize, tileSize, tileOverlap);
                using (var inputStream =
                           new FileStream(inputLevelImagePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var levelBitmap = new Bitmap(inputStream))
                    {
                        DeepZoomImage.Slice(levelBitmap, tiles, imageFormat, tileName =>
                        {
                            var tileFileName = Path.ChangeExtension(tileName, extension);
                            var tilePath     = Path.Combine(outputLevelFolder, tileFileName);
                            var stream       =
                                new FileStream(tilePath, FileMode.Create, FileAccess.Write, FileShare.Read);
                            tileFiles.Add(stream);
                            return(stream);
                        }
                                            );
                    }
                foreach (var stream in tileFiles)
                {
                    stream.Close();
                }
            }
        }
Esempio n. 8
0
        internal static void PivotizeTag(PostRepository postRepository, Tag tag, Settings settings)
        {
            var workingPath            = Path.GetFullPath(WorkingFolderName);
            var outputPath             = Path.GetFullPath(OutputFolderName);
            var relativeBinnedCxmlPath = tag.ComputeBinnedPath(".cxml");
            var absoluteBinnedCxmlPath = Path.Combine(outputPath, relativeBinnedCxmlPath);

            Directory.CreateDirectory(Path.GetDirectoryName(absoluteBinnedCxmlPath));
            using (var outputStream
                       = new FileStream(absoluteBinnedCxmlPath, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                var postIds       = postRepository.RetrievePostIds(tag.Id);
                var streamReaders = postIds.Map(postId =>
                {
                    var relativeBinnedXmlPath = Post.ComputeBinnedPath(postId, ".xml", settings.FileNameIdFormat);
                    var absoluteBinnedXmlPath = Path.Combine(workingPath, relativeBinnedXmlPath);
                    var sr = new StreamReader(absoluteBinnedXmlPath);
                    return(sr);
                }
                                                );
                PivotizeTag(tag, streamReaders, outputStream, settings.SiteDomain);
            }
        }
Esempio n. 9
0
        internal void GenerateImageManifests(PostRepository postRepository)
        {
            var fileNameIdFormat = _settings.FileNameIdFormat;
            var imageNode        = _settings.GenerateImageManifest();

            var sb = new StringBuilder();

            using (var writer = XmlWriter.Create(sb, _settings.XmlWriterSettings))
            {
                Debug.Assert(writer != null);
                imageNode.WriteTo(writer);
            }
            var imageManifest = sb.ToString();

            foreach (var postId in postRepository.RetrievePostIds())
            {
                var relativeBinnedImageManifestPath = Post.ComputeBinnedPath(postId, "dzi", fileNameIdFormat);
                var absoluteBinnedImageManifestPath =
                    Path.Combine(_settings.AbsoluteOutputFolder, relativeBinnedImageManifestPath);
                Directory.CreateDirectory(Path.GetDirectoryName(absoluteBinnedImageManifestPath));
                File.WriteAllText(absoluteBinnedImageManifestPath, imageManifest, Encoding.UTF8);
            }
        }
Esempio n. 10
0
        public void SlicePostImage(int postId)
        {
            var extension = _settings.PostImageEncoding.GetName();
            var relativeBinnedImageFolder       = Post.ComputeBinnedPath(postId, null, _settings.FileNameIdFormat) + "_files";
            var absoluteBinnedImageFolder       = Path.Combine(_settings.AbsoluteWorkingFolder, relativeBinnedImageFolder);
            var absoluteBinnedOutputImageFolder = Path.Combine(_settings.AbsoluteOutputFolder, relativeBinnedImageFolder);

            for (var level = _maximumLevel; level >= 0; level--)
            {
                var levelName           = Convert.ToString(level, 10);
                var targetSize          = ComputeLevelSize(level);
                var tileFiles           = new List <Stream> ();
                var inputLevelImageFile = Path.ChangeExtension(levelName, extension);
                var inputLevelImagePath = Path.Combine(absoluteBinnedImageFolder, inputLevelImageFile);
                var outputLevelFolder   = Path.Combine(absoluteBinnedOutputImageFolder, levelName);
                Directory.CreateDirectory(outputLevelFolder);

                var tiles = ComputeTiles(targetSize);
                using (var inputStream = inputLevelImagePath.CreateReadStream())
                    using (var levelBitmap = new Bitmap(inputStream))
                    {
                        Slice(levelBitmap, tiles, tileName =>
                        {
                            var tileFileName = Path.ChangeExtension(tileName, extension);
                            var tilePath     = Path.Combine(outputLevelFolder, tileFileName);
                            var stream       = tilePath.CreateWriteStream();
                            tileFiles.Add(stream);
                            return(stream);
                        }
                              );
                    }
                foreach (var stream in tileFiles)
                {
                    stream.Close();
                }
            }
        }