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); }
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(); }
public void AdjustLayerSettings() { for (int i = 0; i < layers.Count; i++) { PhotonFileLayer layer = layers[i]; if (i < iFileHeader.GetBottomLayers()) { layer.SetLayerExposure(iFileHeader.GetBottomExposureTimeSeconds()); } else { layer.SetLayerExposure(iFileHeader.GetNormalExposure()); } layer.SetLayerOffTimeSeconds(iFileHeader.GetOffTimeSeconds()); } }
private int Fixit(Action <string> reportProgress, PhotonLayer layer, PhotonFileLayer fileLayer, int loops) { int changed = layer.Fixlayer(); if (changed > 0) { layer.Reduce(); fileLayer.UpdateLayerIslands(layer); reportProgress?.Invoke(", " + changed + " pixels changed"); if (loops > 0) { changed += Fixit(reportProgress, layer, fileLayer, loops - 1); } } return(changed); }
public bool RemoveAllIslands(Action <string> reportProgress) { bool layersFixed = false; reportProgress?.Invoke("Removing islands from " + islandLayers.Count + " layers...<br>"); PhotonLayer layer = null; foreach (var layerNo in islandLayers) { PhotonFileLayer fileLayer = layers[layerNo]; if (layer == null) { layer = fileLayer.GetLayer(); } else { fileLayer.GetUpdateLayer(layer); } reportProgress?.Invoke("Removing islands from layer " + layerNo); int removed = layer.RemoveIslands(); if (removed == 0) { reportProgress?.Invoke(", but nothing could be done."); } else { reportProgress?.Invoke(", " + removed + " islands removed"); fileLayer.SaveLayer(layer); Calculate(layerNo); if (layerNo < GetLayerCount() - 1) { Calculate(layerNo + 1); } layersFixed = true; } reportProgress?.Invoke("<br>"); } FindIslands(); return(layersFixed); }
public bool FixLayers(Action <string> reportProgress) { bool layersFixed = false; PhotonLayer layer = null; foreach (int layerNo in islandLayers) { reportProgress?.Invoke("Checking layer " + layerNo); // Unpack the layer data to the layer utility class PhotonFileLayer fileLayer = layers[layerNo]; if (layer == null) { layer = fileLayer.GetLayer(); } else { fileLayer.GetUpdateLayer(layer); } int changed = Fixit(reportProgress, layer, fileLayer, 10); if (changed == 0) { reportProgress?.Invoke(", but nothing could be done."); } else { fileLayer.SaveLayer(layer); Calculate(layerNo); if (layerNo < GetLayerCount() - 1) { Calculate(layerNo + 1); } layersFixed = true; } reportProgress?.Invoke("<br>"); } FindIslands(); return(layersFixed); }
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); }
public void UnLink() { while (layers.Count > 0) { PhotonFileLayer layer = layers[0]; layers.RemoveAt(0); layer.UnLink(); } if (islandLayers != null) { islandLayers.Clear(); } if (marginLayers != null) { marginLayers.Clear(); } iFileHeader.UnLink(); iFileHeader = null; previewOne.UnLink(); previewOne = null; previewTwo.UnLink(); previewTwo = null; }
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(); }
private void FindIslands() { if (islandLayers != null) { islandLayers.Clear(); islandList = new StringBuilder(); islandLayerCount = 0; if (layers != null) { for (int i = 0; i < iFileHeader.GetNumberOfLayers(); i++) { PhotonFileLayer layer = layers[i]; if (layer.GetIsLandsCount() > 0) { if (islandLayerCount < 11) { if (islandLayerCount == 10) { islandList.Append(", ..."); } else { if (islandList.Length > 0) { islandList.Append(", "); } islandList.Append(i); } } islandLayerCount++; islandLayers.Add(i); } } } } }
private void AddAntiAliasLayer(PhotonFileLayer layer) { antiAliasLayers.Add(layer); }
public void CalculateAaLayers(Action <string> reportProgress, PhotonAaMatrix photonAaMatrix) { PhotonFileLayer.CalculateAALayers((PhotonFileHeader)iFileHeader, layers, photonAaMatrix, reportProgress); }
public void Calculate(int layerNo) { PhotonFileLayer.CalculateLayers((PhotonFileHeader)iFileHeader, layers, margin, layerNo); ResetMarginAndIslandInfo(); }
public void Calculate(Action <string> reportProgress) { PhotonFileLayer.CalculateLayers((PhotonFileHeader)iFileHeader, layers, margin, reportProgress); ResetMarginAndIslandInfo(); }
private void WriteFile(BinaryWriter writer) { int antiAliasLevel = iFileHeader.GetAALevels(); int headerPos = 0; int previewOnePos = headerPos + iFileHeader.GetByteSize(); int previewTwoPos = previewOnePos + previewOne.GetByteSize(); int layerDefinitionPos = previewTwoPos + previewTwo.GetByteSize(); int parametersPos = 0; int machineInfoPos = 0; if (iFileHeader.GetVersion() > 1) { parametersPos = layerDefinitionPos; if (((PhotonFileHeader)iFileHeader).photonFileMachineInfo.GetByteSize() > 0) { machineInfoPos = parametersPos + ((PhotonFileHeader)iFileHeader).photonFilePrintParameters.GetByteSize(); layerDefinitionPos = machineInfoPos + ((PhotonFileHeader)iFileHeader).photonFileMachineInfo.GetByteSize(); } else { layerDefinitionPos = parametersPos + ((PhotonFileHeader)iFileHeader).photonFilePrintParameters.GetByteSize(); } } int dataPosition = layerDefinitionPos + (PhotonFileLayer.GetByteSize() * iFileHeader.GetNumberOfLayers() * antiAliasLevel); ((PhotonFileHeader)iFileHeader).Save(writer, previewOnePos, previewTwoPos, layerDefinitionPos, parametersPos, machineInfoPos); previewOne.Save(writer, previewOnePos); previewTwo.Save(writer, previewTwoPos); if (iFileHeader.GetVersion() > 1) { ((PhotonFileHeader)iFileHeader).photonFilePrintParameters.Save(writer); ((PhotonFileHeader)iFileHeader).photonFileMachineInfo.Save(writer, machineInfoPos); } // Optimize order for speed read on photon for (int i = 0; i < iFileHeader.GetNumberOfLayers(); i++) { PhotonFileLayer layer = layers[i]; dataPosition = layer.SavePos(dataPosition); if (antiAliasLevel > 1) { for (int a = 0; a < (antiAliasLevel - 1); a++) { dataPosition = layer.GetAntiAlias(a).SavePos(dataPosition); } } } // Order for backward compatibility with photon/cbddlp version 1 for (int i = 0; i < iFileHeader.GetNumberOfLayers(); i++) { layers[i].Save(writer); } if (antiAliasLevel > 1) { for (int a = 0; a < (antiAliasLevel - 1); a++) { for (int i = 0; i < iFileHeader.GetNumberOfLayers(); i++) { layers[i].GetAntiAlias(a).Save(writer); } } } // Optimize order for speed read on photon for (int i = 0; i < iFileHeader.GetNumberOfLayers(); i++) { PhotonFileLayer layer = layers[i]; layer.SaveData(writer); if (antiAliasLevel > 1) { for (int a = 0; a < (antiAliasLevel - 1); a++) { layer.GetAntiAlias(a).SaveData(writer); } } } }