protected virtual async ValueTask <AnalyzeOperationContext> GetOperationContextAsync(
     IImageSource source,
     string endpoint,
     CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     if (source is ISerializableImageResource ssource)
     {
         // source image is json-serializable
         if (await IsJsonSerializationSupportedAsync(endpoint, cancellationToken).ConfigureAwait(false))
         {
             // both remote server and image source support json-serialization
             // NOTE: Destination is always inline --> not used on server
             var payload  = new SourceAndDestination(ssource.Uri, null);
             var producer = StreamProducer.Create((ouput, cancellationToken) => new ValueTask(JsonSerializer.SerializeAsync(ouput, payload, _sourceAndDestinationSerializationOptions, cancellationToken)));
             return(AnalyzeOperationContext.Json(producer));
         }
         // remote server does not support json-serialization
         if (Configuration.AllowInlineData)
         {
             // remote server does not support json-serialized images but the inline data is enabled --> proceed
             Logger.LogWarning("Source image supports json serialization but remote server does not thus inline data will be used.");
             return(AnalyzeOperationContext.Inline(source.CreateProducer()));
         }
         // remote server does not support json-serialized images and the inline data is disabled --> throw exception
         throw new InvalidOperationException("Source image supports json serialization but remote server does not. Either enable inline data or use compatible server.");
     }
     // source image is not json-serializable
     if (!Configuration.AllowInlineData)
     {
         throw new InvalidOperationException("Source image does not support json serialization. Either enable inline data or use json-serializable image source.");
     }
     return(AnalyzeOperationContext.Inline(source.CreateProducer()));
 }
 protected virtual async ValueTask <ResizeOperationContext> GetOperationContextAsync(
     IImageSource source,
     IImageDestination destination,
     string endpoint,
     CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     if (source is ISerializableImageResource ssource)
     {
         // source image is json-serializable
         if (await IsJsonSerializationSupportedAsync(endpoint, cancellationToken).ConfigureAwait(false))
         {
             // both remote server and image source support json-serialization
             SourceAndDestination payload;
             IImageDestination?   dest;
             if (destination is ISerializableImageResource sdestination)
             {
                 // image destination does also support json-serialization --> destination in payload, no consumer.
                 payload = new SourceAndDestination(ssource.Uri, sdestination.Uri);
                 dest    = default;
             }
             else
             {
                 // image destination does also support json-serialization --> null in payload, destination is the consumer.
                 payload = new SourceAndDestination(ssource.Uri, default);
                 dest    = destination;
             }
             var producer = StreamProducer.Create((ouput, cancellationToken) => new ValueTask(JsonSerializer.SerializeAsync(ouput, payload, _sourceAndDestinationSerializationOptions, cancellationToken)));
             return(ResizeOperationContext.Json(producer, dest));
         }
         // remote server does not support json-serialization
         if (Configuration.AllowInlineData)
         {
             // remote server does not support json-serialized images but the inline data is enabled --> proceed
             Logger.LogWarning("Source image supports json serialization but remote server does not thus inline data will be used.");
             return(ResizeOperationContext.Inline(source.CreateProducer(), destination));
         }
         // remote server does not support json-serialized images and the inline data is disabled --> throw exception
         throw new InvalidOperationException("Source image supports json serialization but remote server does not. Either enable inline data or use compatible server.");
     }
     // source image is not json-serializable
     if (!Configuration.AllowInlineData)
     {
         throw new InvalidOperationException("Source image does not support json serialization. Either enable inline data or use json-serializable image source.");
     }
     if (destination is ISerializableImageResource)
     {
         if (Configuration.AllowInlineData)
         {
             Logger.LogWarning("Json serializable destination is ignored as source is not json serializable.");
         }
         else
         {
             throw new InvalidOperationException("Destination cannot be json serialized when source is not json serializable.");
         }
     }
     return(ResizeOperationContext.Inline(source.CreateProducer(), destination));
 }