private void Calculate(List <BitArray> unpackedImage, List <BitArray> previousUnpackedImage, PhotonLayer photonLayer) { islandRows = new List <BitArray>(); isLandsCount = 0; photonLayer.Clear(); for (int y = 0; y < unpackedImage.Count; y++) { BitArray currentRow = unpackedImage[y]; BitArray prevRow = previousUnpackedImage?[y]; if (currentRow != null) { int x = 0; while ((x = currentRow.NextSetBit(x)) >= 0) { if (prevRow == null || prevRow[x]) { photonLayer.Supported(x, y); } else { photonLayer.Island(x, y); } ++x; } } } photonLayer.Reduce(); isLandsCount = photonLayer.SetIslands(islandRows); }
private void UnknownPixels(List <BitArray> unpackedImage, PhotonLayer photonLayer) { photonLayer.Clear(); for (int y = 0; y < unpackedImage.Count; y++) { BitArray currentRow = unpackedImage[y]; if (currentRow != null) { int x = 0; while ((x = currentRow.NextSetBit(x)) >= 0) { photonLayer.Supported(x, y); ++x; } } } }
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(); }