public void SetForegroundColor(System.Drawing.Color c1)
        {
            // Desc2
            PhotoshopTypeLibrary.IActionDescriptor Desc2 = CreateRGBColorDescriptor(c1);

            __SetAppColor((int)con.phKeyForegroundColor, Desc2);
        }
        public PhotoshopTypeLibrary.IActionDescriptor[] CreateOpacityStops(double[] OA)
        {
            const int max_location = 4096;
            const int min_location = 0;

            System.Diagnostics.Debug.Assert(OA.Length > 1);

            var opacity_stops = new PhotoshopTypeLibrary.IActionDescriptor[OA.Length];
            int count         = 0;
            int step          = max_location / (OA.Length - 1);

            foreach (double O in OA)
            {
                System.Diagnostics.Debug.Assert(O <= 100);
                System.Diagnostics.Debug.Assert(O >= 0);

                int location = max_location - (step * count);
                System.Diagnostics.Debug.Assert(location <= max_location);
                System.Diagnostics.Debug.Assert(location >= min_location);

                const int midpoint = 50;
                opacity_stops[count] = CreateOpacityStop(O, location, midpoint);
                count++;
            }
            return(opacity_stops);
        }
        public void SetForegroundColor(int red, int green, int blue)
        {
            // Desc2
            PhotoshopTypeLibrary.IActionDescriptor Desc2 = CreateRGBColorDescriptor(red, green, blue);

            __SetAppColor((int)con.phKeyForegroundColor, Desc2);
        }
        public void CreateDocument(int pixelwidth, int pixelheight, int ppi, int fill, int mode, string name)
        {
            System.Diagnostics.Debug.Assert(pixelwidth > 0);
            System.Diagnostics.Debug.Assert(pixelheight > 0);
            System.Diagnostics.Debug.Assert(ppi > 0);
            CheckEnum(mode, (int)con.phClassRGBColorMode);
            CheckEnum(fill, (int)con.phEnumTransparent, (int)con.phEnumBackgroundColor, (int)con.phEnumWhite);


            // Creates a new document


            // Create Desc2
            var Desc2 = this.m_app.MakeDescriptor();

            Desc2.PutString((int)con.phKeyName, name);
            Desc2.PutClass((int)con.phKeyMode, mode);
            Desc2.PutUnitDouble((int)con.phKeyWidth, (int)con.phUnitDistance, pixelwidth);
            Desc2.PutUnitDouble((int)con.phKeyHeight, (int)con.phUnitDistance, pixelheight);
            Desc2.PutUnitDouble((int)con.phKeyResolution, (int)con.phUnitDensity, ppi);
            Desc2.PutEnumerated((int)con.phKeyFill, (int)con.phTypeFill, fill);

            // Create Desc1
            PhotoshopTypeLibrary.IActionDescriptor Desc1 = this.m_app.MakeDescriptor();
            Desc1.PutObject((int)con.phKeyNew, (int)con.phClassDocument, Desc2);


            int old_count = GetDocumentCount();

            // Play the Event Into Photoshop
            PlayEvent((int)con.phEventMake, Desc1, (int)con.phDialogSilent, PlayBehavior.checknone);

            //DocumentAPI.CheckDocumentCount(old_count + 1);
        }
        public void FlattenImage()
        {
            //PhotoshopTypeLibrary.IActionDescriptor Desc1 = this.m_app.MakeDescriptor();
            PhotoshopTypeLibrary.IActionDescriptor Desc1 = null;
            // Play the event in photoshop
            PlayEvent((int)con.phEventFlattenImage, Desc1, (int)con.phDialogSilent, PlayBehavior.checkresult);

            CheckLayerCount(-1, 0);
        }
        public int get_type_from_descriptor(PhotoshopTypeLibrary.IActionDescriptor desc, int prop_id)
        {
            // Returns the type for a property stored in a descriptor

            int v;

            System.Diagnostics.Debug.Assert(desc != null);
            System.Diagnostics.Debug.Assert(desc_has_key(desc, prop_id));

            desc.GetType(prop_id, out v);
            return(v);
        }
        public bool desc_has_key(PhotoshopTypeLibrary.IActionDescriptor desc, int key)
        {
            /*
             * Utility function to quickly check whether a descriptor has a key
             *
             * Usage:
             *
             * if ( desc_has_key( desc1 , (int) con.phKeyForegroundColor ) )
             * {
             *		System.Console.WriteLine( "This descriptor has the key" );
             * }
             */

            int hk;

            desc.HasKey(key, out hk);
            return(hk != 0);
        }
        public Object get_value_from_object(int obj_classid, int object_index, int prop_id)
        {
            /*
             * Returns an Object that represents the value in the descriptor.
             *
             * obj_id - id for object to get prop from
             * prop_id - id for prop value to get
             * index - (-1) = use current object, else use the object at the given index
             */

            var ref1 = get_reference_to_object_property_by_index(obj_classid, object_index, prop_id);

            PhotoshopTypeLibrary.IActionDescriptor result = m_control.GetActionProperty(ref1);

            Object retval = get_value_from_descriptor(result, prop_id);

            return(retval);
        }
        public void __SetAppColor(int color_id, PhotoshopTypeLibrary.IActionDescriptor RGBCOLORDESC)
        {
            CheckEnum(color_id, (int)con.phKeyForegroundColor, (int)con.phKeyBackgroundColor);

            // Ref1
            var Ref1 = this.m_app.MakeReference();

            Ref1.PutProperty((int)con.phClassColor, color_id);

            // Desc1
            var Desc1 = this.m_app.MakeDescriptor();

            Desc1.PutReference((int)con.phKeyNull, Ref1);
            Desc1.PutObject((int)con.phKeyTo, (int)con.phClassRGBColor, RGBCOLORDESC);

            // Play the event in photoshop
            PlayEvent((int)con.phEventSet, Desc1, (int)con.phDialogSilent, PlayBehavior.checknone);
        }
        public PhotoshopTypeLibrary.IActionDescriptor[] CreateColorStops(System.Drawing.Color[] CA)
        {
            const int max_location = 4096;
            const int min_location = 0;

            System.Diagnostics.Debug.Assert(CA.Length > 1);

            var color_stops = new PhotoshopTypeLibrary.IActionDescriptor[CA.Length];
            int count       = 0;
            int step        = max_location / (CA.Length - 1);

            foreach (System.Drawing.Color C in CA)
            {
                int location = max_location - (step * count);
                System.Diagnostics.Debug.Assert(location <= max_location);
                System.Diagnostics.Debug.Assert(location >= min_location);

                const int midpoint = 50;
                color_stops[count] = CreateColorStop(C, location, midpoint);
                count++;
            }
            return(color_stops);
        }
Пример #11
0
        public void dump_descriptor(PhotoshopTypeLibrary.IActionDescriptor desc1, int indent)
        {
            string indent_text = "  ";
            int    num_items;

            desc1.GetCount(out num_items);

            log.WriteLine("Descriptor ({0} items)", num_items);
            for (int i = 0; i < num_items; i++)
            {
                int child_key;
                int child_type;

                desc1.GetKey(i, out child_key);
                desc1.GetType(child_key, out child_type);

                string indent_str = " ";///commoncs.libstring.Multiply(indent_text, indent + 1);

                log.Write(indent_str);
                log.Write("[{0}] ", i.ToString());
                log.WriteLine(" ( {0} ) ", IDToStr(child_type));

                log.Write(indent_str + "-");

                if (child_type == (int)PSConstants.phTypeObject)
                {
                    PhotoshopTypeLibrary.IActionDescriptor child_desc;
                    int child_class_id;

                    desc1.GetObject(child_key, out child_class_id, out child_desc);

                    string sss = string.Format(" ( {0} ) ( {1} ) ", IDToStr(child_key), IDToStr(child_class_id));
                    log.WriteLine(sss);

                    dump_descriptor(child_desc, indent + 1);
                }
                else if (child_type == (int)PSConstants.phTypeObjectReference)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)PSConstants.phTypeText)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)PSConstants.phTypeBoolean)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)PSConstants.phTypeEnumerated)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)PSConstants.phTypeType)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)PSConstants.phTypePath)
                {
                    log.WriteLine("<handled type>");
                }
                else
                {
                    log.WriteLine("<unhandled type>");
                }
            }
        }
Пример #12
0
        public Object get_value_from_descriptor(PhotoshopTypeLibrary.IActionDescriptor desc, int prop_id)
        {
            ///
            ///<summary>
            ///
            /// Given a descriptor and a propid, will return an Object containing
            /// the value
            ///
            /// If there is no prop_id, then returns null
            ///
            /// Workitem: this should really return an exception if the property doesn't
            /// exist or it should return an additional error code.
            ///
            ///</summary>
            ///


            if (!desc_has_key(desc, prop_id))
            {
                // If the descriptor does not contain the key, return null
                return(null);
            }

            // Stores the object being returned
            Object o = null;

            // Determine the type of the object
            int type = 0;

            type = get_type_from_descriptor(desc, prop_id);

            if (type == (int)PSConstants.phTypeChar)
            {
                string v;
                desc.GetString(prop_id, out v);
                o = (string)v;
            }
            else if (type == (int)PSConstants.phTypeInteger)
            {
                int v;
                desc.GetInteger(prop_id, out v);
                o = v;
            }
            else if (type == (int)PSConstants.phTypeFloat)
            {
                double v;
                desc.GetDouble(prop_id, out v);
                o = v;
            }
            else if (type == (int)PSConstants.phTypeBoolean)
            {
                int v;
                desc.GetBoolean(prop_id, out v);
                o = v;
            }
            else if (type == (int)PSConstants.phTypeUnitFloat)
            {
                // WORKITEM: Return an array instead
                int    unit_id;
                double v;
                desc.GetUnitDouble(prop_id, out unit_id, out v);
                o = v;
            }
            else if (type == (int)PSConstants.phTypeEnumerated)
            {
                // WORKITEM: Return an array instead
                int enum_type;
                int enum_value;
                desc.GetEnumerated(prop_id, out enum_type, out enum_value);
                o = enum_value;
            }
            else if (type == (int)PSConstants.phTypeObject)
            {
                // WORKITEM: Return an array instead
                int class_id;
                PhotoshopTypeLibrary.IActionDescriptor v;
                desc.GetObject(prop_id, out class_id, out v);
                o = v;
            }
            else if (type == (int)PSConstants.phTypePath)
            {
                string v;
                desc.GetPath(prop_id, out v);
                o = v;
            }
            else
            {
                string type_name = GetNameFromTypeID(type);
                string msg       = "Unsupported type " + type_name;
                var    e         = new PhotoshoProxyError(msg);
                throw (e);
            }


            return(o);
        }
Пример #13
0
        public void PlayEvent(int event_id, PhotoshopTypeLibrary.IActionDescriptor parameter_desc, int show_ui, PlayBehavior action)
        {
            /*event_id - the event to play
             * parameter_descriptor - a descriptor containing the parameters for the event
             * dialog_options - whether to show UI or not
             * action - the kind of error checking to use. Possilble values are checkresult,checknonresult, and checknone
             *
             *
             * checkresult and checknonresult will cause
             * ExtensionError exceptions to be thrown if Photoshop
             * says there is an error. Regardless of the value used
             * for action, a number of ExtensionError exceptions may
             * be thrown.
             *
             */

            string event_id_str = GetNameFromEventID(event_id);

            //self.log.Header( "Play %s (0x%d) " % (event_id_str, event_id ) )


            PhotoshopTypeLibrary.IActionDescriptor result_desc = m_control.Play(event_id, parameter_desc, show_ui);

            // phKeyMessage may be present and contain more information about the event
            // store the value in msg
            string msg = null;


            if (result_desc != null)
            {
                object msg_o = get_value_from_descriptor(result_desc, (int)PSConstants.phKeyMessage);
                msg = (string)msg_o;;

                dump_descriptor(result_desc, 0);
            }

            bool success = false;

            // Depending on the action there are different criterias for success
            if (action == PlayBehavior.checkresult)
            {
                // Succes is one of the following:
                // - Play() did not return a descriptor
                // - Play() did return a descriptor and that did not contain phKeyMessage
                success = ((result_desc == null) || ((result_desc != null) && (msg == null)));
            }
            else if (action == PlayBehavior.checknonresult)
            {
                // Success is:
                // - Play() did return a descriptor and there is a message
                success = ((result_desc != null) && (msg != null));
            }
            else
            {
                // action == self.checknone ) :
                // Whatever happened is success
                // checknone is for temporary code, callers should end up using checkresult or checknonresult
                success = true;
            }

            if (!success)
            {
                string error_msg = "Photoshop ExtensionError: Failure on Event " + event_id_str;
                if (msg != null)
                {
                    error_msg += msg;
                    var e = new PhotoshoProxyError(error_msg);
                    throw (e);
                }
            }

            //self.log.Header( "PLAY" )
            //self.DumpDescriptor( result_desc, 0)
        }
 public void _end_save(string filename, PhotoshopTypeLibrary.IActionDescriptor Desc1)
 {
     // Play the event in photoshop
     PlayEvent((int)con.phEventSave, Desc1, (int)con.phDialogSilent, PlayBehavior.checknone);
     CheckFileExists(filename);
 }