Esempio n. 1
0
        public static List <PhotonFileLayer> ReadLayers(PhotonFileHeader photonFileHeader, byte[] fileContent, int margin, Action <string> reportProgress)
        {
            var photonLayer = new PhotonLayer(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());

            var layers = new List <PhotonFileLayer>();

            int antiAliasLevel = 1;

            if (photonFileHeader.GetVersion() > 1)
            {
                antiAliasLevel = photonFileHeader.GetAntiAliasingLevel();
            }

            int layerCount = photonFileHeader.GetNumberOfLayers();

            var start = photonFileHeader.GetLayersDefinitionOffsetAddress();
            var ds    = new BinaryReader(new MemoryStream(fileContent, start, fileContent.Length - start));

            {
                var layerMap = new Dictionary <int, PhotonFileLayer>();
                for (int i = 0; i < layerCount; i++)
                {
                    reportProgress?.Invoke("Reading photon file layer " + (i + 1) + "/" + photonFileHeader.GetNumberOfLayers());

                    var layer = new PhotonFileLayer(ds)
                    {
                        photonFileHeader = photonFileHeader
                    };
                    layer.imageData = ArraysEmulation.CopyOfRange(fileContent, layer.dataAddress, layer.dataAddress + layer.dataSize);
                    layers.Add(layer);
                    layerMap[i] = layer;
                }

                if (antiAliasLevel > 1)
                {
                    for (int a = 0; a < (antiAliasLevel - 1); a++)
                    {
                        for (int i = 0; i < layerCount; i++)
                        {
                            reportProgress?.Invoke("Reading photon file AA " + (2 + a) + "/" + antiAliasLevel + " layer " + (i + 1) + "/" + photonFileHeader.GetNumberOfLayers());

                            var layer = new PhotonFileLayer(ds)
                            {
                                photonFileHeader = photonFileHeader
                            };
                            layer.imageData = ArraysEmulation.CopyOfRange(fileContent, layer.dataAddress, layer.dataAddress + layer.dataSize);

                            layerMap[i].AddAntiAliasLayer(layer);
                        }
                    }
                }
            }

            photonLayer.UnLink();

            return(layers);
        }
Esempio n. 2
0
        public static void CalculateLayers(PhotonFileHeader photonFileHeader, List <PhotonFileLayer> layers, int margin, Action <string> reportProgress)
        {
            var             photonLayer           = new PhotonLayer(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());
            List <BitArray> previousUnpackedImage = null;

            for (int i = 0; i < layers.Count; i++)
            {
                var layer = layers[i];

                List <BitArray> unpackedImage = layer.UnpackImage(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());

                reportProgress?.Invoke("Calculating photon file layer " + i + "/" + photonFileHeader.GetNumberOfLayers());

                if (margin > 0)
                {
                    layer.extendsMargin = layer.CheckMargin(unpackedImage, margin);
                }

                layer.UnknownPixels(unpackedImage, photonLayer);

                layer.Calculate(unpackedImage, previousUnpackedImage, photonLayer);

                if (previousUnpackedImage != null)
                {
                    previousUnpackedImage.Clear();
                }
                previousUnpackedImage = unpackedImage;

                layer.packedLayerImage = photonLayer.PackLayerImage();
                layer.isCalculated     = true;

                if (photonFileHeader.GetVersion() > 1)
                {
                    foreach (var aaFileLayer in layer.antiAliasLayers)
                    {
                        List <BitArray> aaUnpackedImage = aaFileLayer.UnpackImage(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());
                        var             aaPhotonLayer   = new PhotonLayer(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());
                        aaFileLayer.UnknownPixels(aaUnpackedImage, aaPhotonLayer);
                        aaFileLayer.packedLayerImage = aaPhotonLayer.PackLayerImage();
                        aaFileLayer.isCalculated     = false;
                    }
                }
            }
            photonLayer.UnLink();
        }
Esempio n. 3
0
        private PhotonFile ReadFile(byte[] file, Action <string> reportProgress)
        {
            reportProgress?.Invoke("Reading Photon file header information...");
            var photonFileHeader = new PhotonFileHeader(file);

            iFileHeader = photonFileHeader;

            reportProgress?.Invoke("Reading photon large preview image information...");
            previewOne = new PhotonFilePreview(photonFileHeader.GetPreviewOneOffsetAddress(), file);
            reportProgress?.Invoke("Reading photon small preview image information...");
            previewTwo = new PhotonFilePreview(photonFileHeader.GetPreviewTwoOffsetAddress(), file);
            if (photonFileHeader.GetVersion() > 1)
            {
                reportProgress?.Invoke("Reading Print parameters information...");
                photonFileHeader.ReadParameters(file);
            }
            reportProgress?.Invoke("Reading photon layers information...");
            layers = PhotonFileLayer.ReadLayers(photonFileHeader, file, margin, reportProgress);
            ResetMarginAndIslandInfo();

            return(this);
        }