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);
 }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 public BuildEndpoint Encode(IOutputDestination destination, IEncoderPreset encoderPreset) =>
 Encode(destination, Builder.GenerateIoId(), encoderPreset);
Esempio n. 5
0
 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));
 }
Esempio n. 6
0
 /// <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);
Esempio n. 7
0
 public BuildEndpoint BuildCommandString(IBytesSource source, int?sourceIoId, IOutputDestination dest,
                                         int?destIoId, string commandString)
 => BuildCommandString(source, sourceIoId, dest, destIoId, commandString, null);
Esempio n. 8
0
 public BuildEndpoint BuildCommandString(IBytesSource source, IOutputDestination dest, string commandString) => BuildCommandString(source, null, dest, null, commandString);
Esempio n. 9
0
 public BuildEndpoint BuildCommandString(byte[] source, IOutputDestination dest, string commandString) => BuildCommandString(new BytesSource(source), dest, commandString);