Exemplo 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);
        }
Exemplo n.º 2
0
 public void UnLink()
 {
     imageData        = null;
     packedLayerImage = null;
     if (islandRows != null)
     {
         islandRows.Clear();
     }
     photonFileHeader = null;
 }
Exemplo n.º 3
0
        public PhotonFileLayer(PhotonFileLayer photonFileLayer, PhotonFileHeader photonFileHeader)
        {
            layerPositionZ      = photonFileLayer.layerPositionZ;
            layerExposure       = photonFileLayer.layerExposure;
            layerOffTimeSeconds = photonFileLayer.layerOffTimeSeconds;
            dataAddress         = photonFileLayer.dataAddress;
            dataAddress         = photonFileLayer.dataSize;

            this.photonFileHeader = photonFileHeader;

            // Dont copy data, we are building new AA layers anyway
            //this.imageData = copy();
            //this.packedLayerImage = copy();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public static void CalculateLayers(PhotonFileHeader photonFileHeader, List <PhotonFileLayer> layers, int margin, int layerIndex)
        {
            var             photonLayer           = new PhotonLayer(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());
            List <BitArray> previousUnpackedImage = null;

            if (layerIndex > 0)
            {
                previousUnpackedImage = layers[layerIndex - 1].UnpackImage(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());
            }

            for (int i = 0; i < 2; i++)
            {
                PhotonFileLayer layer         = layers[layerIndex + i];
                List <BitArray> unpackedImage = layer.UnpackImage(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());

                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;

                i++;
            }
            photonLayer.UnLink();
        }
Exemplo n.º 7
0
        public static void CalculateAALayers(PhotonFileHeader photonFileHeader, List <PhotonFileLayer> layers, PhotonAaMatrix photonAaMatrix, Action <string> reportProgress)
        {
            var photonLayer = new PhotonLayer(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());

            int[,] source = new int[photonFileHeader.GetResolutionY(), photonFileHeader.GetResolutionX()];

            int i = 0;

            foreach (var layer in layers)
            {
                List <BitArray> unpackedImage = layer.UnpackImage(photonFileHeader.GetResolutionX(), photonFileHeader.GetResolutionY());

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

                for (int y = 0; y < photonFileHeader.GetResolutionY(); y++)
                {
                    for (int x = 0; x < photonFileHeader.GetResolutionX(); x++)
                    {
                        source[y, x] = 0;
                    }
                }

                for (int y = 0; y < unpackedImage.Count; y++)
                {
                    BitArray currentRow = unpackedImage[y];
                    if (currentRow != null)
                    {
                        for (int x = 0; x < currentRow.Length; x++)
                        {
                            if (currentRow[x])
                            {
                                source[y, x] = 255;
                            }
                        }
                    }
                }

                // Calc
                int[,] target = photonAaMatrix.Calc(source);

                int aaTresholdDiff = 255 / photonFileHeader.GetAntiAliasingLevel();
                int aaTreshold     = 0;
                foreach (var aaFileLayer in layer.antiAliasLayers)
                {
                    photonLayer.Clear();
                    aaTreshold += aaTresholdDiff;

                    for (int y = 0; y < photonFileHeader.GetResolutionY(); y++)
                    {
                        for (int x = 0; x < photonFileHeader.GetResolutionX(); x++)
                        {
                            if (target[y, x] >= aaTreshold)
                            {
                                photonLayer.Supported(x, y);
                            }
                        }
                    }

                    aaFileLayer.SaveLayer(photonLayer);
                }

                i++;
            }
            photonLayer.UnLink();
        }