public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Bitmap bmp = inputPin.Read <Bitmap>(request); if (bmp == null) { return(null); } bmp = bmp.ResizeIfNeeded( (request is BitmapPinRequest) ? (request as BitmapPinRequest).DesiredSize : bmp.Size ); int radiusX = (int)Math.Round(radiusXPin.Read <double>(request)); int radiusY = (int)Math.Round(radiusYPin.Read <double>(request)); if (algorithm == BlurAlgorithm.StackBlur) { BitmapFilters.StackBlur(bmp, radiusX, radiusY); return(bmp); } else { Bitmap blurred = BitmapFilters.Blur(bmp, radiusX, radiusY, algorithm == BlurAlgorithm.BoxBlur); bmp.Dispose(); return(blurred); } } return(null); }
public Task PutStreamFullPinnedCacheThrows() { return(TestStore(Context, Clock, async store => { using (var pinContext = store.CreatePinContext()) { var pinRequest = new PinRequest(pinContext); var r = await store.PutRandomAsync(Context, MaxSizeHard / 3); ResultTestExtensions.ShouldBeSuccess((BoolResult)r); Clock.Increment(); Assert.True(await store.ContainsAsync(Context, r.ContentHash, pinRequest)); Clock.Increment(); r = await store.PutRandomAsync(Context, MaxSizeHard / 3); Clock.Increment(); Assert.True(await store.ContainsAsync(Context, r.ContentHash, pinRequest)); Clock.Increment(); var data = ThreadSafeRandom.GetBytes(MaxSizeHard / 2); using (var dataStream = new MemoryStream(data)) { var result = await store.PutStreamAsync(Context, dataStream, ContentHashType, null); Assert.False(result.Succeeded); } await store.SyncAsync(Context); } })); }
public Task SuccessivePutStreamsFullPinnedCacheSucceed() { return(TestStore(Context, Clock, async store => { using (var pinContext = store.CreatePinContext()) { var pinRequest = new PinRequest(pinContext); var r = await store.PutRandomAsync(Context, MaxSizeHard / 3).ShouldBeSuccess(); Clock.Increment(); Assert.True(await store.ContainsAsync(Context, r.ContentHash, pinRequest)); Clock.Increment(); r = await store.PutRandomAsync(Context, MaxSizeHard / 3); Clock.Increment(); Assert.True(await store.ContainsAsync(Context, r.ContentHash, pinRequest)); Clock.Increment(); var data = ThreadSafeRandom.GetBytes(MaxSizeHard / 2); using (var dataStream = new MemoryStream(data)) { await store.PutStreamAsync(Context, dataStream, ContentHashType, null).ShouldBeSuccess(); } await store.SyncAsync(Context); } })); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Bitmap bmp1 = input1Pin.Read <Bitmap>(request); Bitmap bmp2 = input2Pin.Read <Bitmap>(request); if (bmp1 == null && bmp2 == null) { return(null); } if (bmp1 != null && bmp2 == null) { return(bmp1); } if (bmp1 == null && bmp2 != null) { return(bmp2); } Size sz = (request is BitmapPinRequest) ? (request as BitmapPinRequest).DesiredSize : new Size( Math.Min(bmp1.Size.Width, bmp2.Size.Width), Math.Min(bmp1.Size.Height, bmp2.Size.Height) ); Bitmap bmp = new Bitmap(sz.Width, sz.Height, PixelFormat.Format32bppPArgb); double mix = mixPin.Read <double>(request); if (cmMix != mix) { if (ia == null) { ia = new ImageAttributes(); } if (cm == null) { cm = new ColorMatrix( new float[][] { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0f, 0f, 0f, 0, 1 } } ); } cm.Matrix33 = (float)mix; cmMix = mix; ia.SetColorMatrix(cm); } using (Graphics g = Graphics.FromImage(bmp)) { g.DrawImageUnscaled(bmp1, 0, 0); g.CompositingMode = CompositingMode.SourceOver; g.DrawImage(bmp2, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, ia); } bmp1.Dispose(); bmp2.Dispose(); return(bmp); } return(null); }
/// <inheritdoc /> public async Task <HttpResponseMessage> RemovePinForLocker(PinRequest req) { var token = Constants.Token; this._client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var jsonToSend = JsonConvert.SerializeObject(req); var content = new StringContent(jsonToSend, Encoding.UTF8, Constants.Headers.ContentType); var result = await this._api.RemovePinForLocker(Constants.Headers.ContentType, content); return(result); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName) && (cachedBmp == null || cachedBmpName != fileName)) { try { cachedBmp = new Bitmap(fileName); cachedBmpName = fileName; } catch { if (cachedSizedBmp != null) { cachedSizedBmp.Dispose(); } if (cachedBmp != null) { cachedBmp.Dispose(); } cachedSizedBmp = null; cachedBmp = null; cachedBmpName = null; } } if (cachedBmp != null) { BitmapPinRequest bp = request as BitmapPinRequest; if (bp != null) { if (cachedSizedBmp != null) { lock (cachedSizedBmp) { if (cachedSizedBmp.Size == bp.DesiredSize) { return(new Bitmap(cachedSizedBmp)); } else { cachedSizedBmp.Dispose(); cachedSizedBmp = null; } } } Debug.Print("Recaching bitmap {0}", bp.DesiredSize); cachedSizedBmp = new Bitmap(cachedBmp, bp.DesiredSize); return(new Bitmap(cachedSizedBmp)); } return(new Bitmap(cachedBmp)); } } return(null); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Size sz = (request is BitmapPinRequest) ? (request as BitmapPinRequest).DesiredSize : new Size(256, 256); Bitmap bmp = new Bitmap(sz.Width, sz.Height, PixelFormat.Format32bppArgb); BitmapData bd = bmp.LockBits(new Rectangle(0, 0, sz.Width, sz.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); CBlend.Noise(bd.Scan0, (UInt32)(bd.Stride * bd.Height), oMask, aMask); bmp.UnlockBits(bd); return(bmp); } return(null); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Bitmap source = inputPin.Read <Bitmap>(request); if (source == null) { return(null); } Size sz = ((request is BitmapPinRequest) ? (request as BitmapPinRequest).DesiredSize : source.Size); Bitmap bmp = new Bitmap(sz.Width, sz.Height, PixelFormat.Format32bppPArgb); double rM = rMulPin.Read <double>(request); double gM = gMulPin.Read <double>(request); double bM = bMulPin.Read <double>(request); double rB = rBiasPin.Read <double>(request); double gB = gBiasPin.Read <double>(request); double bB = bBiasPin.Read <double>(request); if (ia == null) { ia = new ImageAttributes(); } if (cm == null) { cm = new ColorMatrix( new float[][] { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0f, 0f, 0f, 0, 1 } } ); } cm.Matrix00 = (float)rM; cm.Matrix11 = (float)gM; cm.Matrix22 = (float)bM; cm.Matrix40 = (float)rB; cm.Matrix41 = (float)gB; cm.Matrix42 = (float)bB; ia.SetColorMatrix(cm); using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(Color.Black); g.CompositingMode = CompositingMode.SourceOver; g.DrawImage(source, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, ia); } source.Dispose(); return(bmp); } return(null); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { if (cached == null) { cached = inputPin.Read <Bitmap>(request); } if (cached != null) { return(new Bitmap(cached)); } } return(null); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { double time = (request != null ? request.Time : DateTime.Now.TimeOfDay.TotalSeconds); double freq = frequencyPin.Read <double>(request); double phase = phasePin.Read <double>(request); double amp = ampPin.Read <double>(request); double bias = biasPin.Read <double>(request); return(Math.Sin((freq * time + phase) * Math.PI * 2) * amp + bias); } return(base.GetPinValue(pin, request)); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Size sz = (request is BitmapPinRequest) ? ((BitmapPinRequest)request).DesiredSize : size; Color c = colorPin.Read <Color>(); Bitmap bmp = new Bitmap(sz.Width, sz.Height, PixelFormat.Format32bppArgb); Rectangle r = bmp.GetEntireRect(); BitmapData bd = bmp.LockBits(r, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); CBlend.Clear(bd.Scan0, (UInt32)(bd.Stride * bd.Height), (uint)c.ToArgb(), 0xFFFFFFFF); bmp.UnlockBits(bd); return(bmp); } return(null); }
/// <inheritdoc /> public async Task <ResponseBase> RemovePinForLocker(Pin newPin) { var request = new PinRequest(); request.Pin = newPin; var responseData = new ResponseBase() { HasBeenSuccessful = false }; var result = await this._apiWrapper.RemovePinForLocker(request); string content = await result.Content.ReadAsStringAsync(); if (result.StatusCode == HttpStatusCode.OK) { try { var deserializedContent = JsonConvert.DeserializeObject <ResponseBase>(content); if (!deserializedContent.HasBeenSuccessful) { responseData.HasBeenSuccessful = false; responseData.Error = "Internal Server Error"; return(responseData); } responseData.HasBeenSuccessful = true; responseData.Error = null; return(responseData); } catch (Exception e) { Console.WriteLine(e.StackTrace); responseData.HasBeenSuccessful = false; responseData.Error = "Deserialization Error"; return(responseData); } } else { responseData.HasBeenSuccessful = false; responseData.Error = "Internal Error" + result.StatusCode.ToString();; return(responseData); } }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == output) { Color color1 = color1Pin.Read <Color>(request); Color color2 = color2Pin.Read <Color>(request); double mix = mixPin.Read <double>(request); mix = Math.Abs(mix) % 1; double iMix = 1.0 - mix; return(Color.FromArgb( (int)(color1.A * iMix + color2.A * mix), (int)(color1.R * iMix + color2.R * mix), (int)(color1.G * iMix + color2.G * mix), (int)(color1.B * iMix + color2.B * mix) )); } return(null); }
public static PinResponse VertifyPin(string pin) { PinRequest request = new PinRequest { VPIN = pin }; string requestString = JsonConvert.SerializeObject(request); HttpHelper httpHelper = new HttpHelper(); HttpItem httpItem = new HttpItem(); httpItem.Method = "POST"; httpItem.URL = Const.VerifyPinUri; httpItem.Postdata = Convert.ToString(requestString); httpItem.ResultType = ResultType.String; HttpResult html = httpHelper.GetHtml(httpItem); if (html.StatusCode != HttpStatusCode.OK) { throw new Exception(string.IsNullOrEmpty(html.Html) ? (string.IsNullOrEmpty(html.StatusDescription) ? "Post Data Error!" : html.StatusDescription) : html.Html); } return JsonConvert.DeserializeObject<PinResponse>(html.Html); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Bitmap bmp = inputPin.Read <Bitmap>(request); if (bmp == null) { return(null); } bmp = bmp.ResizeIfNeeded( (request is BitmapPinRequest) ? (request as BitmapPinRequest).DesiredSize : bmp.Size ); Rectangle r = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bData = bmp.LockBits(r, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); CBlend.CRemap(bData.Scan0, (UInt32)(bData.Stride * bData.Height), mask); bmp.UnlockBits(bData); return(bmp); } return(null); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Size sz = (request is BitmapPinRequest) ? ((BitmapPinRequest)request).DesiredSize : new Size(256, 256); Color c1 = color1Pin.Read <Color>(); Color c2 = color2Pin.Read <Color>(); float angle = (float)(directionPin.Read <double>()); Bitmap bmp = new Bitmap(sz.Width, sz.Height, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(bmp)) { Rectangle r = bmp.GetEntireRect(); Brush b; if (this.gType == GradientType.Linear) { b = new LinearGradientBrush(r, c1, c2, angle); } else { g.Clear(c1); GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(r); if (this.gType == GradientType.RadialInvert) { Color x = c1; c1 = c2; c2 = x; } PathGradientBrush pgb = new PathGradientBrush(gp); pgb.WrapMode = WrapMode.Tile; pgb.CenterColor = c1; pgb.SurroundColors = new Color[] { c2 }; b = pgb; } g.FillRectangle(b, r); b.Dispose(); } return(bmp); } return(null); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Bitmap bmp1 = input1Pin.Read <Bitmap>(request); Bitmap bmp2 = input2Pin.Read <Bitmap>(request); if (bmp1 == null && bmp2 == null) { return(null); } if (bmp2 == null) { return(bmp1); } if (bmp1 == null) { return(bmp2); } Size sz = (request is BitmapPinRequest) ? (request as BitmapPinRequest).DesiredSize : new Size( Math.Min(bmp1.Size.Width, bmp2.Size.Width), Math.Min(bmp1.Size.Height, bmp2.Size.Height) ); bmp1 = bmp1.ResizeIfNeeded(sz); bmp2 = bmp2.ResizeIfNeeded(sz); Rectangle r = new Rectangle(0, 0, sz.Width, sz.Height); double mix = mixPin.Read <double>(request); BitmapData b1Data = bmp1.LockBits(r, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); BitmapData b2Data = bmp2.LockBits(r, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); CBlend.Blend(blendMode, b1Data.Scan0, b2Data.Scan0, (UInt32)(b1Data.Stride * b1Data.Height), (float)mix, useSrcAlpha); bmp1.UnlockBits(b1Data); bmp2.UnlockBits(b2Data); bmp2.Dispose(); return(bmp1); } return(null); }
public override object GetPinValue(Pin pin, PinRequest request) { if (pin == outputPin) { Bitmap bmp = inputPin.Read <Bitmap>(request); if (bmp == null) { return(null); } bmp = bmp.ResizeIfNeeded( (request is BitmapPinRequest) ? (request as BitmapPinRequest).DesiredSize : bmp.Size ); if (jpegCodec == null) { jpegCodec = ImageCodecInfo.GetImageEncoders().First((enc) => enc.MimeType.Contains("jpeg")); epar = new EncoderParameters(1); } if (eparQ != quality) { epar.Param[0] = new EncoderParameter(Encoder.Quality, quality); eparQ = quality; } MemoryStream ms = new MemoryStream(); bmp.Save(ms, jpegCodec, epar); bmp.Dispose(); ms.Position = 0; if (hack != 0) { Random r = new Random(); byte[] content = new byte[ms.Length]; ms.Read(content, 0, (int)ms.Length); for (int i = 0; i < content.Length; i++) { if (r.Next(10000) < hack) { content[i] = (byte)r.Next(255); } } ms.Dispose(); ms = new MemoryStream(content); } Bitmap nbmp = bmp; try { nbmp = new Bitmap(ms); Guid[] gs = ((Image)nbmp).FrameDimensionsList; foreach (var g in gs) { Debug.Print("{0} {1}", gs.Length, g); } } catch { nbmp = bmp; } if (nbmp != bmp) { bmp.Dispose(); } return(nbmp); } return(null); }
protected void OnPinRequest(EventArgs e) { PinRequest?.Invoke(this, e); }
private void OnPinMatrixRequest() { PinRequest?.Invoke(this, null); }