public bool Compare(PSDLayer x, PSDLayer y) { return(Comparer <T> .Default.Compare(GetID(x), GetID(y)) == 0 && IsGroup(x) == IsGroup(y)); }
protected override string GetID(PSDLayer x) { return(x.name.ToLower()); }
protected virtual bool IsGroup(PSDLayer layer) { return(layer.isGroup); }
protected abstract T GetID(PSDLayer layer);
protected override int GetID(PSDLayer x) { return(x.layerID); }
protected override string GetID(PSDLayer x) { return(x.name); }
static (int width, int height) ExtractLayer(List <PSDLayer> extractedLayer, List <BitmapLayer> layers, bool importHiddenLayer, bool flatten, List <LayerExtractData> layerExtract, PSDImporter.FlattenLayerData[] previousFlatten, IPSDLayerMappingStrategy mappingStrategy, bool parentGroupVisible) { // parent is the previous element in extracedLayer int parentGroupIndex = extractedLayer.Count - 1; int maxWidth = 0, maxHeight = 0; int width = 0, height = 0; foreach (var l in layers) { bool layerVisible = l.Visible && parentGroupVisible; if (l.IsGroup) { var layer = new PSDLayer(l.Surface.color, parentGroupIndex, l.IsGroup, l.Name, 0, 0, l.LayerID, l.Visible); layer.flatten = previousFlatten.FirstOrDefault(x => mappingStrategy.Compare(x, l)) != null; layer.isImported = (importHiddenLayer || layerVisible) && !flatten && layer.flatten; int startIndex = extractedLayer.Count; extractedLayer.Add(layer); (width, height) = ExtractLayer(extractedLayer, l.ChildLayer, importHiddenLayer, flatten || layer.flatten, layerExtract, previousFlatten, mappingStrategy, layerVisible); int endIndex = extractedLayer.Count - 1; // If this group is to be flatten and there are flatten layers if (flatten == false && layer.flatten && startIndex < endIndex) { layerExtract.Add(new LayerExtractData() { start = startIndex, end = endIndex, width = width, height = height }); } } else { var surface = importHiddenLayer || l.Visible ? l.Surface.color : default; var layer = new PSDLayer(surface, parentGroupIndex, l.IsGroup, l.Name, l.Surface.width, l.Surface.height, l.LayerID, l.Visible); layer.isImported = (importHiddenLayer || layerVisible) && !flatten; extractedLayer.Add(layer); if (layer.isImported) { layerExtract.Add(new LayerExtractData() { start = extractedLayer.Count - 1, end = extractedLayer.Count - 1, width = l.Surface.width, height = l.Surface.height, }); } width = l.Surface.width; height = l.Surface.height; } if (maxWidth < width) { maxWidth = width; } if (maxHeight < height) { maxHeight = height; } } return(maxWidth, maxHeight); }