protected override void ReadValue(PsdReader reader, object userData, out PsdLayer[] value) { PsdDocument document = userData as PsdDocument; int layerCount = Math.Abs((int)reader.ReadInt16()); PsdLayer[] layers = new PsdLayer[layerCount]; for (int i = 0; i < layerCount; i++) { layers[i] = new PsdLayer(reader, document); } foreach (var item in layers) { item.ReadChannels(reader); } layers = Initialize(null, layers); foreach (var item in layers.SelectMany(item => item.Descendants()).Reverse()) { item.ComputeBounds(); } value = layers; }
public static void ImportMap(string mapFile, string tileFile) { var psdFile = new PsdFile(mapFile, Encoding.UTF8); var document = new PsdDocument(psdFile); var width = document.width; var height = document.height; if (width % kTileWidth != 0) { throw new Exception("Invalid document width: " + width); } if (height % kTileHeight != 0) { throw new Exception("Invalid document height: " + width); } var tilesX = width / kTileWidth; var tilesY = height / kTileHeight; var mapLayer = document.FindLayer("Map"); if (mapLayer == null) { throw new Exception("'Map' layer is missing"); } }
public static UiTreeRoot Parse(string psdPath) { using (var document = PsdDocument.Create(psdPath)) { var uiTree = new UiTreeRoot(); uiTree.Name = Path.GetFileName(psdPath); uiTree.Width = document.Width; uiTree.Height = document.Height; uiTree.Configs = _ParseConfig(document); PsdLayerConfig config = uiTree.Configs.GetLayerConfig(DocumentRootMagicLayerId); uiTree.Pivot = _GetPivot(config); uiTree.XAnchor = _GetXAnchorType(config); uiTree.YAnchor = _GetYAnchorType(config); var imageResource = document.ImageResources; var resolutionProperty = imageResource["Resolution"] as Reader_ResolutionInfo; int horizontalResolution = Convert.ToInt32(resolutionProperty.Value["HorizontalRes"]); uiTree.HorizontalPixelPerInch = horizontalResolution; foreach (PsdLayer layer in document.Childs) { uiTree.Children.Add(_ParsePsdLayerRecursive(uiTree, layer)); } return(uiTree); } }
internal ImageResource(PsdDocument document, ImageResourceId id, string name, byte[] data) { this.document = document; this.data = data; Id = id; Name = name; }
private void RecordAllPsdInformation() { if (!string.IsNullOrEmpty(exporter.psdFile)) { var psd = PsdDocument.Create(exporter.psdFile); if (psd != null) { try { var rootSize = new Vector2(psd.Width, psd.Height); ExportUtility.InitPsdExportEnvrioment(exporter, rootSize); rootNode = new GroupNode(new Rect(Vector2.zero, rootSize), 0, -1); rootNode.displayName = exporter.name; var groupDatas = ExportUtility.CreatePictures(psd.Childs, rootSize, exporter.ruleObj.defultUISize, exporter.ruleObj.forceSprite); if (groupDatas != null) { foreach (var groupData in groupDatas) { rootNode.AddChild(groupData); ExportUtility.ChargeTextures(exporter, groupData); } } TreeViewUtility.TreeToList <GroupNode>(rootNode, exporter.groups, true); EditorUtility.SetDirty(exporter); } catch (Exception e) { psd.Dispose(); throw e; } psd.Dispose(); } } }
private static Sprite ImportLayer(PsdDocument psdDoc, ImportUserData importSettings, ImportLayerData layerSettings, TextureImporterSettings psdUnityImport) { if (layerSettings == null) { return(null); } PsdLayer psdLayer = GetPsdLayerByIndex(psdDoc, layerSettings.indexId); if (psdLayer.IsGroup) { return(null); } // Generate the texture Texture2D layerTexture = GetLayerTexture(psdDoc, psdLayer, layerSettings); if (layerTexture == null) { return(null); } // Save the texture as an asset Sprite layerSprite = SaveAsset(psdLayer, psdUnityImport, layerTexture, importSettings, layerSettings); return(layerSprite); }
private static Sprite CreateSpriteAsset(PsdDocument psdDoc, ImportUserData importSettings, ImportLayerData layerSettings, TextureImporterSettings psdUnityImport) { if (layerSettings == null) { return(null); } PsdLayer psdLayer = GetPsdLayerByIndex(psdDoc, layerSettings.indexId); if (psdLayer.IsGroup) { return(null); } // Generate the texture Texture2D layerTexture = GetLayerTexture(psdDoc, psdLayer, layerSettings.ScaleFactor); if (layerTexture == null) { return(null); } var layerPath = PathUtils.GetLayerPath(psdLayer, importSettings.fileNaming, importSettings.groupMode); // Save the texture as an asset return(SaveAsset(layerPath, psdUnityImport, layerTexture, importSettings.TargetDirectory, importSettings.PackingTag, layerSettings)); }
public static void Reconstruct(Object psdFile, ImportUserData importSettings, ImportLayerData reconstructRoot, Vector2 documentPivot, IReconstructor reconstructor) { string psdPath = GetPsdFilepath(psdFile); if (string.IsNullOrEmpty(psdPath)) { return; } using (var psdDoc = PsdDocument.Create(psdPath)) { ReconstructData data = GetReconstructData(psdDoc, psdPath, documentPivot, importSettings, reconstructRoot); var GO = reconstructor.Reconstruct(reconstructRoot, data, Selection.activeGameObject); if (GO != null) { EditorGUIUtility.PingObject(GO); Selection.activeGameObject = GO; } } }
//加载PSD void LoadPSD(string path) { //判断是ps文件 if (path.EndsWith(".psb")) { psd = PsdDocument.Create(path); } }
private void OpenPsdDocument() { if (System.IO.File.Exists(psdPath)) { psd = PsdDocument.Create(psdPath); m_TreeView = null; } }
public void UnLoadDocument() { if (psd != null) { psd.Dispose(); psd = null; } }
private string GetILSType(string file) { var fi = new FileInfo(file); var fileName = fi.Name; Console.WriteLine("###################"); Console.WriteLine(fileName); // startwith(String, StringComparison) : 비교할 문자열, 비교하는 방법 열거형(enum) // StringComparison : https://docs.microsoft.com/ko-kr/dotnet/api/system.stringcomparison?view=netframework-4.8 // 이 로직은 결국 filename을 가져와서 파일이름을 비교( 파일명 앞부분이 코드 ) 하여 ILSType을 지정하게끔 한다 if (fileName.StartsWith(ILSType.FilePrefix1_NC, StringComparison.CurrentCultureIgnoreCase)) { return(ILSType.Code1_NC); } if (fileName.StartsWith(ILSType.FilePrefix2_JC, StringComparison.CurrentCultureIgnoreCase)) { return(ILSType.Code2_JC); } if (fileName.StartsWith(ILSType.FilePrefix3_CE, StringComparison.CurrentCultureIgnoreCase)) { return(ILSType.Code3_CE); } if (fileName.StartsWith(ILSType.FilePrefix4_ET, StringComparison.CurrentCultureIgnoreCase)) { return(ILSType.Code4_ET); } else if (fileName.StartsWith("8")) //모식도, 3D 교차점 { var document = PsdDocument.Create(file); var totalLayerList = document.Childs.Reverse(); var fisrtLayer = totalLayerList.FirstOrDefault(); var firstChild = fisrtLayer.Childs.Reverse().FirstOrDefault(); if (firstChild.Name.StartsWith("Arrow_")) { return(ILSType.Code5_MimeticDiagram); } else if (firstChild.Name.EndsWith("_AI")) { return(ILSType.Code6_CrossRoadPoint3D); } } else { var document = PsdDocument.Create(file); var totalLayerList = document.Childs.Reverse(); var fisrtLayer = totalLayerList.FirstOrDefault(); if (fisrtLayer.Name.Equals("Title")) { return(ILSType.Code7_RestAreaSummaryMap_Mapy); } else if (fisrtLayer.Name.Equals("Title_set")) { return(ILSType.Code8_RestAreaSummaryMap_Gini); } } return(null); }
/// <summary> /// Prepares the icc profile. /// </summary> void PrepareIccProfile(PsdDocument document) { var profileResource = document.ImageResources.FirstOrDefault(x => x is IccProfileResource) as IccProfileResource; if (profileResource != null) { colorManager.SetProfile(profileResource.ProfileData); } }
private static PfiDocument ProcessDocument(PsdDocument psd) { var doc = new PfiDocument(); doc.size = new Vector2(psd.Width, psd.Height); doc.root = new PfiFolder(""); ProcessChildren(psd, doc.root, psd); return(doc); }
public static PfiDocument Import(string psdPath) { using (var psd = PsdDocument.Create(psdPath)) { var doc = ProcessDocument(psd); doc.name = Path.GetFileNameWithoutExtension(psdPath); return(doc); } }
public void LayerGroupsImageResourceTest(string psdPath) { PsdDocument psdDocument = PsdDocument.Load(psdPath); Assert.True(psdDocument.ImageResources.ContainsKey(ImageResourceId.LayerGroups)); output.WriteLine(string.Join(" ", psdDocument.ImageResources[ImageResourceId.LayerGroups].data.Select(b => b.ToString()))); }
public static void Menu_ImportPsd() { var file = Selection.activeObject; var filePath = AssetDatabase.GetAssetPath(file); using (var psd = PsdDocument.Create(filePath)) { Import(filePath); } }
private void RefreshFile(string filename) { PsdDocument document = PsdDocument.Create(filename); this.filename = filename; this.itemsSource = new List <TreeViewItemViewModel>(); this.itemsSource.Add(new PSDItemViewModel(document)); this.NotifyOfPropertyChange(() => this.ItemsSource); this.NotifyOfPropertyChange(() => this.CanRefresh); this.NotifyOfPropertyChange(() => this.Title); }
public void LoadDocument() { UnLoadDocument(); #if UNITY_EDITOR if (psd2Ui.asset != null) { string path = AssetDatabase.GetAssetPath(psd2Ui.asset); if (path.EndsWith(".psd")) psd = PsdDocument.Create(path); } #endif }
private void Test() { string filename = string.Empty; using (PsdDocument document = PsdDocument.Create(filename)) { foreach (var item in document.Childs) { Console.WriteLine("LayerName : " + item.Name); } } }
private string GetILSType(string file) { var fi = new FileInfo(file); var fileName = fi.Name; if (fileName.StartsWith(ILSType.FilePrefix1_NC, StringComparison.CurrentCultureIgnoreCase)) { return(ILSType.Code1_NC); } else if (fileName.StartsWith(ILSType.FilePrefix2_JC, StringComparison.CurrentCultureIgnoreCase)) { return(ILSType.Code2_JC); } else if (fileName.StartsWith(ILSType.FilePrefix3_CE, StringComparison.CurrentCultureIgnoreCase)) { return(ILSType.Code3_CE); } else if (fileName.StartsWith(ILSType.FilePrefix4_ET, StringComparison.CurrentCultureIgnoreCase)) { return(ILSType.Code4_ET); } else if (fileName.StartsWith("8")) { var document = PsdDocument.Create(fileName); var totalLayerList = document.Childs.Reverse(); var fisrtLayer = totalLayerList.FirstOrDefault(); var firstChild = fisrtLayer.Childs.FirstOrDefault(); if (firstChild.Name.StartsWith("Arrow_")) { return(ILSType.Code5_MimeticDiagram); } else if (firstChild.Name.EndsWith("_AI")) { return(ILSType.Code6_CrossRoadPoint3D); } } else { var document = PsdDocument.Create(fileName); var totalLayerList = document.Childs.Reverse(); var fisrtLayer = totalLayerList.FirstOrDefault(); if (fisrtLayer.Name.Equals("Title")) { return(ILSType.Code7_RestAreaSummaryMap_Mapy); } else if (fisrtLayer.Name.Equals("Title_set")) { return(ILSType.Code8_RestAreaSummaryMap_Gini); } } return(null); }
public PSDItemViewModel(PsdDocument document) { this.document = document; this.Items.Add(new PropertiesItemViewModel("Resources", document.Resources, this)); this.Items.Add(new PropertiesItemViewModel("ImageResources", document.ImageResources, this)); foreach (var item in document.Childs) { this.Items.Add(new LayerItemViewModel(item, this)); } }
/* * 2020.02.27 파일 정보 텍스트 박스 값 입력( 박찬규 ) */ public void setTxtBox(string path, PsdDocument doc, StringBuilder sb) { BeginInvoke((MethodInvoker)(() => { FileNameBox.Text = Path.GetFileNameWithoutExtension(path); //파일명 텍스트박스 2020.02.27 파일의 확장자를 제외한 파일명을 가져온다. (박찬규) FileExtensionName.Text = Path.GetExtension(path); //파일 확장명 텍스트 박스 2020.02.27 파일의 확장자만 가져온다. (박찬규) FileChannelCount.Text = doc.FileHeaderSection.NumberOfChannels.ToString(); FileWidth.Text = doc.Width.ToString(); FileHeight.Text = doc.Height.ToString(); FileDepth.Text = doc.FileHeaderSection.Depth.ToString(); FileColorMode.Text = doc.FileHeaderSection.ColorMode.ToString(); // 72 * 72 이런식으로 들어가 있을 것 FilePixel.Text = sb.ToString(); #region 맵피, 지니에 해당하는 파일 pixcel이 모바일 pixcel일 경우. var pixel = sb.ToString(); if (pixel != "72*72") { if (pixel == "146*146") { FilePixel.Text = pixel; if (_isAutoClose) { _validatePsdFileVM.Description = "모바일 Pixel"; //this.Close(); } else { MessageBox.Show("모바일 Pixel"); } } else { var errorMsg = "픽셀 값 오류"; FilePixel.Text = pixel; errorProvider1.SetError(FilePixel, errorMsg); if (_isAutoClose) { _validatePsdFileVM.Description = errorMsg; //this.Close(); } else { MessageBox.Show(errorMsg); return; } } } #endregion })); }
public void LoadDocument() { UnLoadDocument(); #if UNITY_EDITOR if (asset != null) { string path = UnityEditor.AssetDatabase.GetAssetPath(asset); if (path.EndsWith(".psd")) { psd = PsdDocument.Create(path); } } #endif }
private void ImportPSD() { var psdFile = DialogHelper.OpenPSDFileDialog("psd文件", psdFilePath.Value); if (!string.IsNullOrEmpty(psdFile)) { psdFilePath.Value = psdFile; var fileName = System.IO.Path.GetFileNameWithoutExtension(psdFile); using (PsdDocument doc = PsdDocument.Create(psdFile)) { this.uiInfo = ExportUtility.CreatePictures(doc, fileName); UpdateView(); } } }
private static PfiLayer ProcessImageLayer(PsdDocument psd, PsdLayer psdLayer) { var layer = new PfiLayer(psdLayer.Name); layer.texture = GetLayerTexture(psdLayer); var x = psdLayer.Left + psdLayer.Width / 2; var y = psd.Height - (psdLayer.Top + psdLayer.Height / 2); x -= psd.Width / 2; y -= psd.Height / 2; layer.position = new Vector2(x, y); return(layer); }
public PsdPreviewer(TreeViewState state, PsdDocument psd) : base(state) { this.psd = psd; var m_MultiColumnHeaderState = CreateDefaultMultiColumnHeaderState(); this.multiColumnHeader = new MultiColumnHeader(m_MultiColumnHeaderState); this.multiColumnHeader.canSort = false; this.rowHeight = kRowHeights; this.columnIndexForTreeFoldouts = 1; this.showAlternatingRowBackgrounds = true; this.showBorder = true; this.customFoldoutYOffset = (kRowHeights - EditorGUIUtility.singleLineHeight) * 0.5f; // center foldout in the row since we also center content. See RowGUI this.extraSpaceBeforeIconAndLabel = kToggleWidth; Reload(); }
private static Texture2D GetLayerTexture(PsdDocument psdDoc, PsdLayer psdLayer, ImportLayerData setting) { if (psdLayer == null || psdLayer.IsGroup) { return(null); } Texture2D layerTexture = GetTexture(psdLayer); if (setting.ScaleFactor != ScaleFactor.Full) { int mipMapLevel = setting.ScaleFactor == ScaleFactor.Half ? 1 : 2; layerTexture = ScaleTextureByMipmap(layerTexture, mipMapLevel); } return(layerTexture); }
private static PsdLayerConfigSet _ParseConfig(PsdDocument document) { IProperties imageResources = document.ImageResources; if (imageResources.Contains("XmpMetadata")) { var xmpImageResource = imageResources["XmpMetadata"] as Reader_XmpMetadata; var xmpValue = xmpImageResource.Value["Xmp"] as string; return(ParseXmp(xmpValue)); } else { return(new PsdLayerConfigSet()); } }
/// <summary> /// Parse the given file /// </summary> GraphicVisual IFileParser.Parse(string filename) { colorManager = new ColorSpaceManager(); var group = new GraphicGroup(); using (PsdDocument document = PsdDocument.Create(filename)) { Size size = new Size(document.Width, document.Height); PrepareIccProfile(document); ParseLayers(document, size, group); } CommonHelper.CleanUpTempDir(); return(group); }