/// <summary> /// Sets the chromatic adaption data /// </summary> /// <param name="ca">The chromatic adaption data</param> public void SetCAData(ChromaticAdaption ca) { if (ca == null) { throw new ArgumentNullException(); } var data = ca.GetCAData(this); _CAData = data; CAData = data.DataPointer; }
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); } }
/// <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); } }