Exemplo n.º 1
0
        public SKRuntimeEffectUniforms(SKRuntimeEffect effect)
        {
            if (effect == null)
            {
                throw new ArgumentNullException(nameof(effect));
            }

            names    = effect.Uniforms.ToArray();
            uniforms = new Dictionary <string, Variable> ();
            data     = effect.UniformSize is int size && size > 0
                                ? SKData.Create(effect.UniformSize)
                                : SKData.Empty;

            for (var i = 0; i < names.Length; i++)
            {
                var name    = names[i];
                var uniform = SkiaApi.sk_runtimeeffect_get_uniform_from_index(effect.Handle, i);
                uniforms[name] = new Variable {
                    Index  = i,
                    Name   = name,
                    Offset = (int)SkiaApi.sk_runtimeeffect_uniform_get_offset(uniform),
                    Size   = (int)SkiaApi.sk_runtimeeffect_uniform_get_size_in_bytes(uniform),
                };
            }
        }
Exemplo n.º 2
0
        public SKData CopyToData()
        {
            var data = SKData.Create(BytesWritten);

            CopyTo(data.Data);
            return(data);
        }
Exemplo n.º 3
0
 public static SKImage FromEncodedData(byte[] data)
 {
     if (data == null)
     {
         throw new ArgumentNullException(nameof(data));
     }
     if (data.Length == 0)
     {
         throw new ArgumentException("The data buffer was empty.");
     }
     unsafe
     {
         fixed(byte *b = data)
         {
             using (var skdata = SKData.Create((IntPtr)b, data.Length))
                 using (var codec = SKCodec.Create(skdata))
                     using (var bitmap = SKBitmap.Decode(codec, codec.Info)) {
                         if (bitmap == null)
                         {
                             return(null);
                         }
                         return(FromBitmap(bitmap));
                     }
         }
     }
 }
Exemplo n.º 4
0
 public static SKBitmap Decode(ReadOnlySpan <byte> buffer, SKImageInfo bitmapInfo)
 {
     fixed(byte *b = buffer)
     {
         using var skdata = SKData.Create((IntPtr)b, buffer.Length);
         using var codec  = SKCodec.Create(skdata);
         return(Decode(codec, bitmapInfo));
     }
 }
Exemplo n.º 5
0
 public static SKImageInfo DecodeBounds(ReadOnlySpan <byte> buffer)
 {
     fixed(byte *b = buffer)
     {
         using var skdata = SKData.Create((IntPtr)b, buffer.Length);
         using var codec  = SKCodec.Create(skdata);
         return(codec?.Info ?? SKImageInfo.Empty);
     }
 }
Exemplo n.º 6
0
        public void Reset()
        {
            if (data.Size == 0)
            {
                return;
            }

            data = SKData.Create(data.Size);
        }
Exemplo n.º 7
0
 public static SKImage FromPixelCopy(SKImageInfo info, Stream pixels, int rowBytes)
 {
     if (pixels == null)
     {
         throw new ArgumentNullException(nameof(pixels));
     }
     using (var data = SKData.Create(pixels)) {
         return(FromPixelData(info, data, rowBytes));
     }
 }
Exemplo n.º 8
0
		public static SKBitmap Decode (byte[] buffer, SKImageInfo bitmapInfo)
		{
			if (buffer == null) {
				throw new ArgumentNullException (nameof (buffer));
			}

			fixed (byte* b = buffer) {
				using (var skdata = SKData.Create ((IntPtr)b, buffer.Length))
				using (var codec = SKCodec.Create (skdata)) {
					return Decode (codec, bitmapInfo);
				}
			}
		}
Exemplo n.º 9
0
		public static SKImageInfo DecodeBounds (byte[] buffer)
		{
			if (buffer == null) {
				throw new ArgumentNullException (nameof (buffer));
			}

			fixed (byte* b = buffer) {
				using (var skdata = SKData.Create ((IntPtr)b, buffer.Length))
				using (var codec = SKCodec.Create (skdata)) {
					return codec?.Info ?? SKImageInfo.Empty;
				}
			}
		}
Exemplo n.º 10
0
        public static SKImage FromEncodedData(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }

            using (var skdata = SKData.Create(filename)) {
                if (skdata == null)
                {
                    return(null);
                }
                return(FromEncodedData(skdata));
            }
        }
Exemplo n.º 11
0
        public static SKImage FromEncodedData(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (data.Length == 0)
            {
                throw new ArgumentException("The data buffer was empty.");

                fixed(byte *b = data)
                {
                    using (var skdata = SKData.Create((IntPtr)b, data.Length)) {
                        return(FromEncodedData(skdata));
                    }
                }
        }