コード例 #1
0
        public void SendToPhotoshop()
        {
            ImageResult imageResult;

            if (_backBufferHandler.ReadBackBuffer(out imageResult))
            {
                if (_settings.AddLut)
                {
                    Texture2D luttexture = _cameraCollection.GetCurrentEffectTexture();

                    if (_settings.ApplyColorGrading && luttexture != null)
                    {
                        if (!imageResult.AddLUTFromTexture(_settings.LUT, luttexture))
                        {
                            _settings.Message = "Couldnt add the LUT to the image. Try changing the lut size or settings";

                            return;
                        }
                    }
                    else
                    {
                        if (!imageResult.AddLUT(_settings.LUT))
                        {
                            _settings.Message = "Couldnt add the LUT to the image. Try changing the lut size or settings";

                            return;
                        }
                    }
                }

                if (SendImage(imageResult))
                {
                    _photoshopProtocol.SendJSCommand("app.activeDocument.bitsPerChannel = BitsPerChannelType.SIXTEEN;" +
                                                     "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 );} ");

                    ToolSettings.Instance.Message = "Sent";
                }
                else
                {
                    ToolSettings.Instance.Message = "Error sending the image to Photoshop";
                }
            }
            else
            {
                _settings.Message = "No camera selected";
            }
        }
コード例 #2
0
        public void SaveToFile()
        {
            ImageResult imageResult;

            if (_backBufferHandler.ReadBackBuffer(out imageResult))
            {
                var path = EditorUtility.SaveFilePanel("Save reference file", _settings.FilePath ?? "", "reference", "png");
                if (!string.IsNullOrEmpty(path))
                {
                    _settings.FilePath = path;

                    if (_settings.AddLut)
                    {
                        Texture2D luttexture = _cameraCollection.GetCurrentEffectTexture();

                        if (_settings.ApplyColorGrading && luttexture != null)
                        {
                            if (!imageResult.AddLUTFromTexture(_settings.LUT, luttexture))
                            {
                                _settings.Message = "Couldnt add the LUT to the image. Try changing the lut size or settings";

                                return;
                            }
                        }
                        else
                        {
                            if (!imageResult.AddLUT(_settings.LUT))
                            {
                                _settings.Message = "Couldnt add the LUT to the image. Try changing the lut size or settings";

                                return;
                            }
                        }
                    }

                    var texture = imageResult.GenerateTexture2D();

                    if (texture != null)
                    {
                        File.WriteAllBytes(_settings.FilePath, texture.EncodeToPNG());
                    }
                    ;

                    Texture2D.DestroyImmediate(texture);
                }
            }
            else
            {
                _settings.Message = "No camera selected";
            }
        }