internal void AddOutput(int ioId, IOutputDestination destination) { if (_inputs.ContainsKey(ioId) || _outputs.ContainsKey(ioId)) { throw new ArgumentException("ioId", $"ioId {ioId} has already been assigned"); } _outputs.Add(ioId, destination); }
public BuildEndpoint BuildCommandString(IBytesSource source, int?sourceIoId, IOutputDestination dest, int?destIoId, string commandString, ICollection <InputWatermark> watermarks) { sourceIoId = sourceIoId ?? GenerateIoId(); AddInput(sourceIoId.Value, source); destIoId = destIoId ?? GenerateIoId(); AddOutput(destIoId.Value, dest); if (watermarks != null) { foreach (var w in watermarks) { if (w.IoId == null && w.Source == null) { throw new ArgumentException("InputWatermark instances cannot have both a null IoId and a null Source"); } if (w.IoId == null) { w.IoId = this.GenerateIoId(); } if (w.Source != null) { AddInput(w.IoId.Value, w.Source); } } } dynamic nodeData = new { command_string = new { kind = "ir4", value = commandString, decode = sourceIoId, encode = destIoId, watermarks = watermarks?.Select(w => w.ToImageflowDynamic()).ToArray() } }; return(new BuildEndpoint(this, nodeData, null, null)); }
public static async Task CopyFromStreamAsync(this IOutputDestination dest, Stream stream, CancellationToken cancellationToken) { if (stream.CanRead && stream.CanSeek) { await dest.RequestCapacityAsync((int)stream.Length); } const int bufferSize = 81920; var buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0) { await dest.WriteAsync(new ArraySegment <byte>(buffer, 0, bytesRead), cancellationToken) .ConfigureAwait(false); } await dest.FlushAsync(cancellationToken); }
public BuildEndpoint Encode(IOutputDestination destination, IEncoderPreset encoderPreset) => Encode(destination, Builder.GenerateIoId(), encoderPreset);
public BuildEndpoint Encode(IOutputDestination destination, int ioId, IEncoderPreset encoderPreset) { Builder.AddOutput(ioId, destination); return(new BuildEndpoint(Builder, new { encode = new { io_id = ioId, preset = encoderPreset?.ToImageflowDynamic() } }, this, null)); }
/// <summary> /// Modify the input image (source) with the given command string and watermarks and encode to the (dest) /// </summary> /// <param name="source"></param> /// <param name="dest"></param> /// <param name="commandString"></param> /// <param name="watermarks"></param> /// <returns></returns> public BuildEndpoint BuildCommandString(IBytesSource source, IOutputDestination dest, string commandString, ICollection <InputWatermark> watermarks) => BuildCommandString(source, null, dest, null, commandString, watermarks);
public BuildEndpoint BuildCommandString(IBytesSource source, int?sourceIoId, IOutputDestination dest, int?destIoId, string commandString) => BuildCommandString(source, sourceIoId, dest, destIoId, commandString, null);
public BuildEndpoint BuildCommandString(IBytesSource source, IOutputDestination dest, string commandString) => BuildCommandString(source, null, dest, null, commandString);
public BuildEndpoint BuildCommandString(byte[] source, IOutputDestination dest, string commandString) => BuildCommandString(new BytesSource(source), dest, commandString);