string MatchAndGetKey(string Name, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { foreach (string Key in ParameterStore.Keys) { if (Key.Equals(Name)) { return(Key); } } foreach (string Key in ParameterStore.Keys) { if (DecodeMethod(Key).Equals(DecodeMethod(Name))) { return(Key); } } foreach (string Key in ParameterStore.Keys) { if (Key.Equals(DecodeMethod(Name))) { return(Key); } } foreach (string Key in ParameterStore.Keys) { if (DecodeMethod(Key).Equals(Name)) { return(Key); } } return(null); }
public ManualCodec(IEmittingCodec emittingCodec) : base(typeof(T), emittingCodec) { calculateSizeDelegate = (CalculateSizeDelegate)CalculateSizeMethod.CreateDelegate(typeof(CalculateSizeDelegate)); encodeDelegate = (EncodeDelegate)EncodeMethod.CreateDelegate(typeof(EncodeDelegate)); decodeDelegate = (DecodeDelegate)DecodeMethod.CreateDelegate(typeof(DecodeDelegate)); decodeFastDelegate = (DecodeDelegate)DecodeFastMethod.CreateDelegate(typeof(DecodeDelegate)); }
public void DecodeTagsFor(DecodeDelegate decodeDelegate) { foreach (var tag in this) { decodeDelegate(tag, GetData()); } }
public ManualCodec(ICodecContainer codecContainer, IEmittingCodec emittingCodec) : base(typeof(T), emittingCodec) { this.codecContainer = codecContainer; calculateSizeDelegate = (CalculateSizeDelegate)CalculateSizeMethod.CreateDelegate(typeof(CalculateSizeDelegate)); encodeDelegate = (EncodeDelegate)EncodeMethod.CreateDelegate(typeof(EncodeDelegate)); decodeDelegate = (DecodeDelegate)DecodeMethod.CreateDelegate(typeof(DecodeDelegate)); decodeFastDelegate = (DecodeDelegate)DecodeFastMethod.CreateDelegate(typeof(DecodeDelegate)); }
/** * <param name="callback">A delegate to call when the CAPTCHA is solved or timed out.</param> * <param name="img">Raw CAPTCHA image.</param> * <param name="timeout">Solving timeout (in seconds).</param> */ public void Decode(DecodeDelegate callback, byte[] img, int timeout) { PollPayload payload = new PollPayload(); payload.Callback = callback; payload.Captcha = this.Upload(img); payload.Timeout = timeout; new Thread(PollWithCallback).Start(payload); }
/** * <param name="callback">A delegate to call when the CAPTCHA is solved or timed out.</param> * <param name="img">Raw CAPTCHA image.</param> * <param name="timeout">Solving timeout (in seconds).</param> */ public void Decode(DecodeDelegate callback, byte[] img, int timeout) { new Thread(DecodeWithCallback).Start(new DecodePayload() { Callback = callback, Image = img, Timeout = timeout, }); }
/** * <param name="callback">A delegate to call when the CAPTCHA is solved or timed out.</param> * <param name="img">Raw CAPTCHA image.</param> * <param name="timeout">Solving timeout (in seconds).</param> * <param name="ext_data">Extra data used by special captchas types.</param> */ public void Decode(DecodeDelegate callback, int timeout, Hashtable ext_data = null) { PollPayload payload = new PollPayload(); payload.Callback = callback; payload.Captcha = this.Upload(ext_data); payload.Timeout = timeout; new Thread(PollWithCallback).Start(payload); }
public static List <T> Decode <T>(FrameIterator iterator, DecodeDelegate <T> decodeFunction) { var result = new List <T>(); //begin frame, list iterator.Next(); while (!IsNextFrameIsDataStructureEndFrame(iterator)) { result.Add(decodeFunction(iterator)); } //end frame, list iterator.Next(); return(result); }
public static List <T> DecodeContainsNullable <T>(FrameIterator iterator, DecodeDelegate <T> decodeFunction) where T : class { var result = new List <T>(); //begin frame, list iterator.Next(); while (!IsNextFrameIsDataStructureEndFrame(iterator)) { result.Add(IsNextFrameIsNullEndFrame(iterator) ? null : decodeFunction(iterator)); } //end frame, list iterator.Next(); return(result); }
public static List <T> Decode <T>(IEnumerator <Frame> iterator, DecodeDelegate <T> decodeFunction) { var result = new List <T>(); //begin frame, list iterator.Take(); while (!iterator.AtStructEnd()) { result.Add(decodeFunction(iterator)); } //end frame, list iterator.Take(); return(result); }
/// <summary> /// Decode image from Photoshop's channel-separated formats to BGRA. /// </summary> public static unsafe void DecodeImage(BitmapLayer pdnLayer, PhotoshopFile.Layer psdLayer) { var decodeContext = new DecodeContext(psdLayer, pdnLayer.Bounds); DecodeDelegate decoder = null; if (decodeContext.ByteDepth == 4) { decoder = GetDecodeDelegate32(decodeContext.ColorMode); } else { decoder = GetDecodeDelegate(decodeContext.ColorMode); } DecodeImage(pdnLayer, decodeContext, decoder); }
// public static void EncodeNullable<TKey, TValue>(ClientMessage clientMessage, IEnumerable<KeyValuePair<TKey, TValue>> collection, // Action<ClientMessage, TKey> encodeKeyFunc, // Action<ClientMessage, TValue> encodeValueFunc) // { // if (collection == null) // { // clientMessage.Add(NullFrame.Copy()); // } // else // { // Encode(clientMessage, collection, encodeKeyFunc, encodeValueFunc); // } // } public static IList <KeyValuePair <TKey, TValue> > Decode <TKey, TValue>(FrameIterator iterator, DecodeDelegate <TKey> decodeKeyFunc, DecodeDelegate <TValue> decodeValueFunc) { var result = new List <KeyValuePair <TKey, TValue> >(); //begin frame, map iterator.Next(); while (!IsNextFrameIsDataStructureEndFrame(iterator)) { var key = decodeKeyFunc(iterator); var value = decodeValueFunc(iterator); result.Add(new KeyValuePair <TKey, TValue>(key, value)); } //end frame, map iterator.Next(); return(result); }
// public static void EncodeNullable<TKey, TValue>(ClientMessage clientMessage, IEnumerable<KeyValuePair<TKey, TValue>> collection, // Action<ClientMessage, TKey> encodeKeyFunc, // Action<ClientMessage, TValue> encodeValueFunc) // { // if (collection == null) // { // clientMessage.Add(NullFrame.Copy()); // } // else // { // Encode(clientMessage, collection, encodeKeyFunc, encodeValueFunc); // } // } public static IList <KeyValuePair <TKey, TValue> > Decode <TKey, TValue>(IEnumerator <Frame> iterator, DecodeDelegate <TKey> decodeKeyFunc, DecodeDelegate <TValue> decodeValueFunc) { var result = new List <KeyValuePair <TKey, TValue> >(); //begin frame, map iterator.Take(); while (!iterator.AtStructEnd()) { var key = decodeKeyFunc(iterator); var value = decodeValueFunc(iterator); result.Add(new KeyValuePair <TKey, TValue>(key, value)); } //end frame, map iterator.Take(); return(result); }
/// <summary> /// Decode image from Photoshop's channel-separated formats to BGRA. /// </summary> public static void DecodeImage(BitmapLayer pdnLayer, PhotoshopFile.Layer psdLayer) { UnityEngine.Profiling.Profiler.BeginSample("DecodeImage"); var decodeContext = new DecodeContext(psdLayer, pdnLayer.Bounds); DecodeDelegate decoder = null; if (decodeContext.ByteDepth == 4) { decoder = GetDecodeDelegate32(decodeContext.ColorMode); } else { decoder = GetDecodeDelegate(decodeContext.ColorMode); } DecodeImage(pdnLayer, decodeContext, decoder); UnityEngine.Profiling.Profiler.EndSample(); }
/// <summary> /// Decode image from Photoshop's channel-separated formats to BGRA, /// using the specified decode delegate on each row. /// </summary> private static unsafe void DecodeImage(BitmapLayer pdnLayer, DecodeContext decodeContext, DecodeDelegate decoder) { var psdLayer = decodeContext.Layer; var surface = pdnLayer.Surface; var rect = decodeContext.Rectangle; // Convert rows from the Photoshop representation, writing the // resulting ARGB values to to the Paint.NET Surface. for (int y = rect.Top; y < rect.Bottom; y++) { // Calculate index into ImageData source from row and column. int idxSrcPixel = (y - psdLayer.Rect.Top) * psdLayer.Rect.Width + (rect.Left - psdLayer.Rect.Left); int idxSrcByte = idxSrcPixel * decodeContext.ByteDepth; // Calculate pointers to destination Surface. var pDestRow = surface.GetRowAddress(y); var pDestStart = pDestRow + decodeContext.Rectangle.Left; var pDestEnd = pDestRow + decodeContext.Rectangle.Right; // For 16-bit images, take the higher-order byte from the image // data, which is now in little-endian order. if (decodeContext.ByteDepth == 2) { idxSrcByte++; } // Decode the color and alpha channels decoder(pDestStart, pDestEnd, idxSrcByte, decodeContext); SetPDNAlphaRow(pDestStart, pDestEnd, idxSrcByte, decodeContext.ByteDepth, decodeContext.AlphaChannel); // Apply layer masks(s) to the alpha channel var layerMaskAlphaRow = GetMaskAlphaRow(y, decodeContext, decodeContext.LayerMaskContext); var userMaskAlphaRow = GetMaskAlphaRow(y, decodeContext, decodeContext.UserMaskContext); ApplyPDNMask(pDestStart, pDestEnd, layerMaskAlphaRow, userMaskAlphaRow); } }
protected override void OnLoad() { _load = GetMethod <LoadDelegate>("hcp_Load", true); _unload = GetMethod <UnloadDelegate>("hcp_Unload", false); _toValue = GetMethod <ToValueDelegate>("hcp_tovalue", false); _getArgumentHandle = GetMethod <GetArgumentHandleDelegate>("hcp_argat", false); _getMessage = GetMethod <GetMessageDelegate>("hcp_GetMessage", false); _encode = GetMethod <EncodeDelegate>("hcp_Encode", false); _decode = GetMethod <DecodeDelegate>("hcp_Decode", false); _newCodec = GetMethod <NewCodecDelegate>("hcp_NewCodec", false); _closeCodec = GetMethod <CloseCodecDelegate>("hcp_CloseCodec", false); _loadCodec = GetMethod <LoadCodecDelegate>("hcp_LoadCodec", false); _loadModel = GetMethod <LoadModelDelegate>("hcp_LoadModel", false); try { _state = _load(); } catch (Exception x) { throw new Exception("Error occured while calling 'hcp_Load': " + x.Message); } }
public void GetDelegates() { DspToolInfo dll = DllInfo[DllType]; IntPtr pDecode = Native.GetProcAddress(_pDll, "decode"); IntPtr pEncode = Native.GetProcAddress(_pDll, "encode"); IntPtr pDspCorrelateCoefs = _pDll + dll.CorrelateCoefsAddress; IntPtr pDspEncodeFrame = _pDll + dll.EncodeFrameAddress; if (DllType == DspToolType.OpenSource) { pDspCorrelateCoefs = Native.GetProcAddress(_pDll, "correlateCoefs"); pDspEncodeFrame = Native.GetProcAddress(_pDll, "encodeFrame"); } Decode = Marshal.GetDelegateForFunctionPointer <DecodeDelegate>(pDecode); Encode = Marshal.GetDelegateForFunctionPointer <EncodeDelegate>(pEncode); DspCorrelateCoefsDll = Marshal.GetDelegateForFunctionPointer <DspCorrelateCoefsDelegate>(pDspCorrelateCoefs); DspEncodeFrameDll = Marshal.GetDelegateForFunctionPointer <DspEncodeFrameDelegate>(pDspEncodeFrame); }
/// <summary> /// Decode image from Photoshop's channel-separated formats to BGRA. /// </summary> public static JobHandle DecodeImage(BitmapLayer pdnLayer, PhotoshopFile.Layer psdLayer, JobHandle inputDeps) { UnityEngine.Profiling.Profiler.BeginSample("DecodeImage"); var decodeContext = new DecodeContext(psdLayer, pdnLayer.Bounds); DecodeDelegate decoder = null; DecodeType decoderType = 0; if (decodeContext.ByteDepth == 4) { decoder = GetDecodeDelegate32(decodeContext.ColorMode, ref decoderType); } else { decoder = GetDecodeDelegate(decodeContext.ColorMode, ref decoderType); } JobHandle jobHandle = DecodeImage(pdnLayer, decodeContext, decoderType, inputDeps); UnityEngine.Profiling.Profiler.EndSample(); return(jobHandle); }
public void DecodeTagsFor(DecodeDelegate decodeDelegate, IKeepUnrecognizedCfg unrecognizedKeeper, string tag) { BaseClassChain.Add(tag); try { foreach (var t in this) { var data = GetData(); if (decodeDelegate(t, data)) { continue; } BaseClassChain.Add(t); unrecognizedKeeper.UnrecognizedStd.Add(BaseClassChain, data); BaseClassChain.RemoveLast(); } } finally { BaseClassChain.RemoveLast(); } }
/** * <see cref="M:Client.Decode(DecodeDelegate, byte[], int)"/> * <param name="callback">A delegate to call when the CAPTCHA is solved or timed out.</param> * <param name="st">CAPTCHA image byte stream.</param> */ public void Decode(DecodeDelegate callback, Stream st) { this.Decode(callback, this.Load(st), 0); }
/** * <see cref="M:Client.Decode(DecodeDelegate, byte[], int)"/> * <param name="callback">A delegate to call when the CAPTCHA is solved or timed out.</param> * <param name="fn">CAPTCHA image file name.</param> * <param name="timeout">Solving timeout (in seconds).</param> */ public void Decode(DecodeDelegate callback, string fn, int timeout) { this.Decode(callback, this.Load(fn), timeout); }
public void RawSet(string Name, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { if (Name.Trim().Length == 0) return; string SafeName = SafeRawMethod(Name); string SafeValue = SafeRawMethod(Value); string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod); if(Key == null) ParameterStore[SafeName] = new List<string>() { SafeValue }; else ParameterStore[Key] = new List<string>() { SafeValue }; }
/** * <see cref="M:Client.Decode(DecodeDelegate, byte[], int)"/> * <param name="callback">A delegate to call when the CAPTCHA is solved or timed out.</param> * <param name="st">CAPTCHA image byte stream.</param> * <param name="timeout">Solving timeout (in seconds).</param> */ public void Decode(DecodeDelegate callback, Stream st, int timeout) { this.Decode(callback, this.Load(st), timeout); }
/** * <see cref="M:Client.Decode(DecodeDelegate, byte[], int)"/> * <param name="callback">A delegate to call when the CAPTCHA is solved or timed out.</param> * <param name="fn">CAPTCHA image file name.</param> */ public void Decode(DecodeDelegate callback, string fn) { this.Decode(callback, this.Load(fn), 0); }
public static IDictionary <TKey, TValue> DecodeNullable <TKey, TValue>(FrameIterator iterator, DecodeDelegate <TKey> decodeKey, DecodeDelegate <TValue> decodeValue) { return(IsNextFrameIsNullEndFrame(iterator) ? null : Decode(iterator, decodeKey, decodeValue)); }
/** * <see cref="M:Client.Decode(DecodeDelegate, byte[], int)"/> * <param name="callback">A delegate to call when the CAPTCHA is solved or timed out.</param> * <param name="img">Raw CAPTCHA image.</param> */ public void Decode(DecodeDelegate callback, byte[] img) { this.Decode(callback, img, 0); }
public string RawGet(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { string SafeName = SafeRawMethod(Name); string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod); if (Key == null) { throw new Exception("Parameter not found"); } else { List<string> Values = ParameterStore[Key]; return Values[0]; } }
public static T DecodeNullable <T>(ClientMessage.FrameIterator iterator, DecodeDelegate <T> decode) where T : class { return(IsNextFrameIsNullEndFrame(iterator) ? null : decode(iterator)); }
public List<string> RawGetAll(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { string SafeName = SafeRawMethod(Name); string Key = MatchAndGetKey(Name, EncodeMethod, DecodeMethod); if (Key == null) { throw new Exception("Parameter not found"); } else { return new List<string>(ParameterStore[Key]); } }
public bool RawHas(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { string SafeName = SafeRawMethod(Name); string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod); if (Key == null) { return false; } else { return true; } }
public void RawSet(string Name, int Position, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { if (Name.Trim().Length == 0) return; string SafeName = SafeRawMethod(Name); string SafeValue = SafeRawMethod(Value); if (Position < 0) return; string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod); if (Key == null) { ParameterStore[SafeName] = new List<string>() { SafeValue }; } else { if (Position >= ParameterStore[Key].Count) { this.Add(Key, SafeValue); } else { ParameterStore[Key][Position] = SafeValue; } } }
public static IDictionary <TKey, TValue> DecodeNullable <TKey, TValue>(IEnumerator <Frame> iterator, DecodeDelegate <TKey> decodeKey, DecodeDelegate <TValue> decodeValue) { return(iterator.SkipNull() ? null : Decode(iterator, decodeKey, decodeValue)); }
public void RawAdd(string Name, string Value, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { if (Name.Trim().Length == 0) return; string SafeName = SafeRawMethod(Name); string SafeValue = SafeRawMethod(Value); string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod); if (Key == null) { List<string> Values = new List<string>(); Values.Add(SafeValue); ParameterStore.Add(SafeName, Values); } else { ParameterStore[Key].Add(SafeValue); } }
public static IDictionary <TKey, TValue> Decode <TKey, TValue>(FrameIterator iterator, DecodeDelegate <TKey> decodeKey, DecodeDelegate <TValue> decodeValue) { var result = new Dictionary <TKey, TValue>(); //begin frame, map iterator.Next(); while (!IsNextFrameIsDataStructureEndFrame(iterator)) { var key = decodeKey(iterator); var value = decodeValue(iterator); result[key] = value; } //end frame, map iterator.Next(); return(result); }
public void RawRemove(string Name, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { string SafeName = SafeRawMethod(Name); string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod); if (Key != null) { ParameterStore.Remove(Key); } }
public void RawSet(string Name, List<string> Values, SafeRawDelegate SafeRawMethod, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { if (Name.Trim().Length == 0) return; string SafeName = SafeRawMethod(Name); List<string> SafeValues = new List<string>(); foreach (string Value in Values) { SafeValues.Add(SafeRawMethod(Value)); } string Key = MatchAndGetKey(SafeName, EncodeMethod, DecodeMethod); if (Key == null) { ParameterStore.Add(SafeName, SafeValues); } else { ParameterStore[Key] = SafeValues; } }
public static IDictionary <TKey, TValue> Decode <TKey, TValue>(IEnumerator <Frame> iterator, DecodeDelegate <TKey> decodeKey, DecodeDelegate <TValue> decodeValue) { var result = new Dictionary <TKey, TValue>(); //begin frame, map iterator.Take(); while (!iterator.AtStructEnd()) { var key = decodeKey(iterator); var value = decodeValue(iterator); result[key] = value; } //end frame, map iterator.Take(); return(result); }
public static T DecodeNullable <T>(IEnumerator <Frame> iterator, DecodeDelegate <T> decode) where T : class { return(iterator.SkipNull() ? null : decode(iterator)); }
string MatchAndGetKey(string Name, EncodeDelegate EncodeMethod, DecodeDelegate DecodeMethod) { foreach(string Key in ParameterStore.Keys) { if(Key.Equals(Name)) return Key; } foreach(string Key in ParameterStore.Keys) { if(DecodeMethod(Key).Equals(DecodeMethod(Name))) return Key; } foreach(string Key in ParameterStore.Keys) { if(Key.Equals(DecodeMethod(Name))) return Key; } foreach(string Key in ParameterStore.Keys) { if(DecodeMethod(Key).Equals(Name)) return Key; } return null; }