コード例 #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="CC_Condition"/> class
        /// </summary>
        /// <param name="condition">The if condition</param>
        /// <param name="ifCommand">The command for when the if condition is true</param>
        /// <param name="elseCommand">The command for when the if condition is false</param>
        public CC_Condition(ConditionDelegate condition, IConversionCommand ifCommand, IConversionCommand elseCommand)
        {
            if (condition == null || ifCommand == null || elseCommand == null)
            {
                throw new ArgumentNullException();
            }

            Condition    = condition;
            IfCommands   = new IConversionCommand[] { ifCommand };
            ElseCommands = new IConversionCommand[] { elseCommand };
        }
コード例 #2
0
        private IConversionCommand[] FindPathCA(Type From, Type To)
        {
            List <IConversionCommand> CAPath = null;

            foreach (var ca in ColorConverter.ChromaticAdaptions)
            {
                IConversionCommand[] p1, p2;

                if (ca.ColorType != From)
                {
                    p1 = FindPath(From, ca.ColorType);
                }
                else
                {
                    p1 = new IConversionCommand[0];
                }

                if (ca.ColorType != To)
                {
                    p2 = FindPath(ca.ColorType, To);
                }
                else
                {
                    p2 = new IConversionCommand[0];
                }

                if (p1 != null && p2 != null && (CAPath == null || CAPath.Count < p1.Length + p2.Length + 1))
                {
                    CA     = ca;
                    CAPath = new List <IConversionCommand>();
                    CAPath.AddRange(p1);
                    CAPath.Add(new CC_ExecuteMethod(ca.Method));
                    CAPath.AddRange(p2);
                }
            }

            if (CAPath != null)
            {
                return(CAPath.ToArray());
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Resolves a conversion command into a set of commands of type
        /// <see cref="CC_Assign"/> or <see cref="CC_ExecuteMethod"/>
        /// </summary>
        /// <param name="cmd">The command to resolve</param>
        /// <param name="outCmds">The resolved output commands</param>
        private void FindCommand(IConversionCommand cmd, List <IConversionCommand> outCmds)
        {
            if (cmd is CC_Assign || cmd is CC_ExecuteMethod || cmd is CC_ILWriter)
            {
                outCmds.Add(cmd);
            }
            else
            {
                var condition = cmd as CC_Condition;
                if (condition != null)
                {
                    FindCommand(condition, outCmds); return;
                }

                var convert = cmd as CC_Convert;
                if (convert != null)
                {
                    FindConvertTo(convert.InColor, convert.OutColor, outCmds); return;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Sets the conversion method
        /// </summary>
        public override void SetConversionMethod()
        {
            Type inType     = InColor.GetType();
            Type outType    = OutColor.GetType();
            int  inChCount  = InColor.ChannelCount;
            int  outChCount = OutColor.ChannelCount;
            bool doCA       = Data.IsCARequired;

            SetPathsDict();
            IConversionCommand[] cmds;

            if (inType == outType)
            {
                if (!doCA)
                {
                    if (inChCount == outChCount)
                    {
                        cmds = new IConversionCommand[] { new CC_Assign(InColor.ChannelCount) }
                    }
                    ;
                    else
                    {
                        cmds = FindPath(inType);
                    }
                }
                else
                {
                    CA = ColorConverter.ChromaticAdaptions.FirstOrDefault(t => t.ColorType == inType);
                    if (CA != null)
                    {
                        cmds = new IConversionCommand[] { new CC_ExecuteMethod(CA.Method) }
                    }
                    ;
                    else
                    {
                        cmds = FindPathCA(inType, outType);
                    }
                }
            }
            else if (doCA)
            {
                cmds = FindPathCA(inType, outType);
            }
            else
            {
                cmds = FindPath(inType, outType);
            }

            if (cmds == null)
            {
                throw new ConversionNotFoundException(inType, outType);
            }
            if (CA != null)
            {
                Data.SetCAData(CA);
            }

            var outCmds = new List <IConversionCommand>();

            FindCommands(cmds, outCmds);
            WriteMethod(outCmds);
            WriteRangeCheck(OutColor);
            if (IsLastG)
            {
                Write(OpCodes.Ret);
            }
        }