public void ReadFromFile()
        {
            var path = EditorUtility.OpenFilePanel("Load graded file", _settings.FilePath ?? "", "png");

            if (!string.IsNullOrEmpty(path))
            {
                _settings.FilePath = path;

                if (File.Exists(_settings.FilePath))
                {
                    var data = File.ReadAllBytes(_settings.FilePath);

                    var screenshottexture = new Texture2D(16, 16, TextureFormat.ARGB32, false);
                    screenshottexture.LoadImage(data);

                    var imageResult = ImageResult.FromTexture(screenshottexture);

                    if (imageResult != null)
                    {
                        LUTResult lutResult = imageResult.GetLUT(_settings.LUT);

                        if (lutResult != null)
                        {
                            _lutWriter.SaveLUT(lutResult);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public bool ReadLUT(out LUTResult lutResult)
        {
            _photoshopProtocol.SendJSCommand("takeSnapshot();" +
                                             " function takeSnapshot ()" +
                                             " { var desc = new ActionDescriptor();" +
                                             " var sref = new ActionReference(); sref.putClass(charIDToTypeID(\"SnpS\"));" +
                                             "desc.putReference(charIDToTypeID(\"null\"), sref);" +
                                             "var fref = new ActionReference();" +
                                             " fref.putProperty(charIDToTypeID(\"HstS\")," +
                                             " charIDToTypeID(\"CrnH\")); " +
                                             "desc.putReference(charIDToTypeID(\"From\"), fref );" +
                                             " executeAction(charIDToTypeID(\"Mk  \"), desc, DialogModes.NO );} ");

            var rulerunits = _photoshopProtocol.SendJSCommand("app.preferences.rulerUnits;");

            _photoshopProtocol.SendJSCommand("app.preferences.rulerUnits = Units.PIXELS;");
            _photoshopProtocol.SendJSCommand(string.Format("app.activeDocument.crop(new Array(0,0,{0},{1}), 0, {0}, {1})", ToolSettings.Instance.LUT.Width, ToolSettings.Instance.LUT.Height));

            ImageResult imageData;

            _photoshopProtocol.ReceiveImage("", out imageData);

            _photoshopProtocol.SendJSCommand("revertToLastSnapshot(); " +
                                             "function revertToLastSnapshot() " +
                                             "{ var docRef = app.activeDocument; " +
                                             "var hsObj = docRef.historyStates; " +
                                             "var hsLength = hsObj.length; " +
                                             "for (var i=hsLength - 1;i>-1;i--) { " +
                                             "if (hsObj[i].snapshot) { " +
                                             "docRef.activeHistoryState = docRef.historyStates[i]; break; } } }");

            _photoshopProtocol.SendJSCommand(string.Format("app.preferences.rulerUnits = {0};", rulerunits));

            lutResult = null;

            if (imageData != null)
            {
                lutResult = imageData.GetLUT(_settings.LUT);
                ToolSettings.Instance.Message = "Done.";
                return(true);
            }

            ToolSettings.Instance.Message = "Error reading LUT from Photoshop Image.";
            return(false);
        }
        public bool ReadLUT( out LUTResult lutResult )
        {
            _photoshopProtocol.SendJSCommand( "takeSnapshot();" +
                                                 " function takeSnapshot ()" +
                                                 " { var desc = new ActionDescriptor();" +
                                                 " var sref = new ActionReference(); sref.putClass(charIDToTypeID(\"SnpS\"));" +
                                                 "desc.putReference(charIDToTypeID(\"null\"), sref);" +
                                                 "var fref = new ActionReference();" +
                                                 " fref.putProperty(charIDToTypeID(\"HstS\")," +
                                                 " charIDToTypeID(\"CrnH\")); " +
                                                 "desc.putReference(charIDToTypeID(\"From\"), fref );" +
                                                 " executeAction(charIDToTypeID(\"Mk  \"), desc, DialogModes.NO );} " );

            var rulerunits = _photoshopProtocol.SendJSCommand( "app.preferences.rulerUnits;" );
            _photoshopProtocol.SendJSCommand( "app.preferences.rulerUnits = Units.PIXELS;" );
            _photoshopProtocol.SendJSCommand( string.Format( "app.activeDocument.crop(new Array(0,0,{0},{1}), 0, {0}, {1})", ToolSettings.Instance.LUT.Width, ToolSettings.Instance.LUT.Height ) );

            ImageResult imageData;
            _photoshopProtocol.ReceiveImage( "", out imageData );

            _photoshopProtocol.SendJSCommand( "revertToLastSnapshot(); " +
                                                 "function revertToLastSnapshot() " +
                                                 "{ var docRef = app.activeDocument; " +
                                                 "var hsObj = docRef.historyStates; " +
                                                 "var hsLength = hsObj.length; " +
                                                 "for (var i=hsLength - 1;i>-1;i--) { " +
                                                 "if (hsObj[i].snapshot) { " +
                                                 "docRef.activeHistoryState = docRef.historyStates[i]; break; } } }" );

            _photoshopProtocol.SendJSCommand( string.Format( "app.preferences.rulerUnits = {0};", rulerunits ) );

            lutResult = null;

            if ( imageData != null )
            {
                lutResult = imageData.GetLUT( _settings.LUT );
                ToolSettings.Instance.Message = "Done.";
                return true;
            }

            ToolSettings.Instance.Message = "Error reading LUT from Photoshop Image.";
            return false;
        }
Beispiel #4
0
        public void Reload()
        {
            if (string.IsNullOrEmpty(_settings.FilePath))
            {
                ReadFromFile();
                return;
            }

            if (File.Exists(_settings.FilePath))
            {
                var data = File.ReadAllBytes(_settings.FilePath);

                var screenshottexture = new Texture2D(16, 16, TextureFormat.ARGB32, false);
                screenshottexture.LoadImage(data);

                var imageResult = ImageResult.FromTexture(screenshottexture);

                if (imageResult != null)
                {
                    LUTResult lutResult = imageResult.GetLUT(_settings.LUT);

                    if (lutResult != null)
                    {
                        _lutWriter.SaveLUT(lutResult);
                    }

                    lutResult.Release();
                }

                Texture2D.DestroyImmediate(screenshottexture);
            }
            else
            {
                if (EditorUtility.DisplayDialog("File doesnt exist", "Target file doesn't exit. Please select a new one.", "ok", "cancel"))
                {
                    ReadFromFile();
                    return;
                }
            }
        }
		public void SaveLUT( LUTResult lutResult )
		{
			if ( lutResult == null )
			{
				ToolSettings.Instance.Message = "Error while reading LUT data.";
				return;
			}

			var assetpath = _texturePath;

			bool justBrowsed = false;

			if ( string.IsNullOrEmpty( assetpath ) )
			{
				if ( EditorUtility.DisplayDialog( "Browse?", "There is no current path to save the file to.", "Browse", "Cancel" ) )
				{
					var path = EditorUtility.SaveFilePanelInProject( "Save as", Path.GetFileName( _texturePath ), "png", "Please enter a file name to save the texture to" );

					justBrowsed = true;

					if ( string.IsNullOrEmpty( path ) )
					{
						return;
					}

					_texturePath = path;
				}
				else
				{
					return;
				}
			}

			if ( File.Exists( _texturePath ) && !justBrowsed && !_overwrite )
			{
				if ( !EditorUtility.DisplayDialog( "Overwrite?", "File already exists. This action will overwrite the current file. Do you want to continue?", "Overwrite", "Cancel" ) )
					return;
			}

			File.WriteAllBytes( _texturePath, lutResult.Texture.EncodeToPNG() );
			AssetDatabase.Refresh();
			var text = AssetDatabase.LoadAssetAtPath( _texturePath, typeof( Texture2D ) ) as Texture2D;
			if ( text != null )
			{
				text.wrapMode = TextureWrapMode.Clamp;
				text.filterMode = FilterMode.Bilinear;
			}

			TextureImporter tImporter = AssetImporter.GetAtPath( _texturePath ) as TextureImporter;
			if ( tImporter != null )
			{
				tImporter.mipmapEnabled = false;
				tImporter.isReadable = true;
				tImporter.textureType = TextureImporterType.Default;
				tImporter.filterMode = FilterMode.Bilinear;
				tImporter.anisoLevel = 0;
				tImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;
				tImporter.wrapMode = TextureWrapMode.Clamp;
				tImporter.linearTexture = true;
				tImporter.maxTextureSize = 1024;
				AssetDatabase.ImportAsset( _texturePath, ImportAssetOptions.ForceUpdate );
			}
		}
        public void SaveLUT(LUTResult lutResult)
        {
            if (lutResult == null)
            {
                ToolSettings.Instance.Message = "Error while reading LUT data.";
                return;
            }

            var assetpath = _texturePath;

            bool justBrowsed = false;

            if (string.IsNullOrEmpty(assetpath))
            {
                if (EditorUtility.DisplayDialog("Browse?", "There is no current path to save the file to.", "Browse", "Cancel"))
                {
                    var path = EditorUtility.SaveFilePanelInProject("Save as", Path.GetFileName(_texturePath), "png", "Please enter a file name to save the texture to");

                    justBrowsed = true;

                    if (string.IsNullOrEmpty(path))
                    {
                        return;
                    }

                    _texturePath = path;
                }
                else
                {
                    return;
                }
            }

            if (File.Exists(_texturePath) && !justBrowsed && !_overwrite)
            {
                if (!EditorUtility.DisplayDialog("Overwrite?", "File already exists. This action will overwrite the current file. Do you want to continue?", "Overwrite", "Cancel"))
                {
                    return;
                }
            }

            File.WriteAllBytes(_texturePath, lutResult.Texture.EncodeToPNG());
            AssetDatabase.Refresh();
            var text = AssetDatabase.LoadAssetAtPath(_texturePath, typeof(Texture2D)) as Texture2D;

            if (text != null)
            {
                text.wrapMode   = TextureWrapMode.Clamp;
                text.filterMode = FilterMode.Bilinear;
            }

            TextureImporter tImporter = AssetImporter.GetAtPath(_texturePath) as TextureImporter;

            if (tImporter != null)
            {
                tImporter.mipmapEnabled  = false;
                tImporter.isReadable     = true;
                tImporter.textureType    = TextureImporterType.Default;
                tImporter.filterMode     = FilterMode.Bilinear;
                tImporter.anisoLevel     = 0;
                tImporter.textureFormat  = TextureImporterFormat.AutomaticTruecolor;
                tImporter.wrapMode       = TextureWrapMode.Clamp;
                tImporter.linearTexture  = true;
                tImporter.maxTextureSize = 1024;
                AssetDatabase.ImportAsset(_texturePath, ImportAssetOptions.ForceUpdate);
            }
        }