Esempio n. 1
0
        public static RasterCacheResult RasterizePicture(SKPicture picture, GRContext context, SKMatrix ctm, SKColorSpace dst_color_space, bool checkerboard)
        {
            TRACE_EVENT0("flutter", "RasterCachePopulate");

            //C++ TO C# CONVERTER TODO TASK: Only lambda expressions having all locals passed by reference can be converted to C#:
            //ORIGINAL LINE: return Rasterize(context, ctm, dst_color_space, checkerboard, picture->cullRect(), [=](SKCanvas* canvas)
            return(Rasterize(context, ctm, dst_color_space, checkerboard, picture.CullRect, (SKCanvas canvas) =>
            {
                canvas.DrawPicture(picture);
            }));
        }
        protected virtual SKImage ConvertProfile(SKImage data, float width, float height)
        {
            using SKImage srcImg = data;
            SKImageInfo info = new SKImageInfo((int)width, (int)height,
                                               SKImageInfo.PlatformColorType, SKAlphaType.Opaque, SKColorSpace.CreateSrgb());
            // this is the important part. set the destination ColorSpace as
            // `SKColorSpace.CreateSrgb()`. Skia will then be able to automatically convert
            // the original CMYK colorspace, to this new sRGB colorspace.

            SKImage newImg = SKImage.Create(info);

            srcImg.ScalePixels(newImg.PeekPixels(), SKFilterQuality.None);

            // Remove transparency
            var bitmap = RemoveTransparency(srcImg);

            newImg = SKImage.FromBitmap(bitmap);
            // now when doing this resize, Skia knows the original ColorSpace, and the
            // destination ColorSpace, and converts the colors from CMYK to sRGB.
            return(newImg);
        }
Esempio n. 3
0
 public static SKBitmap?ToBitmap(this SKPicture skPicture, SKColor background, float scaleX, float scaleY, SKColorType skColorType, SKAlphaType skAlphaType, SKColorSpace skColorSpace)
Esempio n. 4
0
 public static bool ToImage(this SKPicture skPicture, Stream stream, SKColor background, SKEncodedImageFormat format, int quality, float scaleX, float scaleY, SKColorType skColorType, SKAlphaType skAlphaType, SKColorSpace skColorSpace)
 {
     using (var skBitmap = skPicture.ToBitmap(background, scaleX, scaleY, skColorType, skAlphaType, skColorSpace))
     {
Esempio n. 5
0
    private static unsafe bool DrawVideo(Stream videoStream, ThumbnailsRenderContext ctx)
    {
        using var formatContext = new FormatContext(videoStream);
        var stream = formatContext.FindBestVideoStream();

        if (stream == null)
        {
            return(false);
        }

        using var videoStreamDecoder = stream.CreateStreamDecoder();

        try
        {
            if (videoStreamDecoder.Duration <= 0)
            {
                videoStreamDecoder.SeekFrame(10 * 1000000);
            }

            if (videoStreamDecoder.Duration > 3)
            {
                videoStreamDecoder.SeekFrame(videoStreamDecoder.Duration / 3);
            }
        }
        catch (FFmpegException err)
        {
            Console.WriteLine("Seek failed: " + err);
        }

        var destinationSize = ThumbnailUtils.ContainSize(
            new SKSize(videoStreamDecoder.FrameWidth, videoStreamDecoder.FrameHeight),
            new SKSize(ThumbnailUtils.DefaultMaxWidth * ctx.Density, ThumbnailUtils.DefaultMaxHeight * ctx.Density)).ToSizeI();

        var sourcePixelFormat = videoStreamDecoder.PixelFormat;

        if (!videoStreamDecoder.MoveNext())
        {
            throw new InvalidDataException("Can't decode the video.");
        }

        using var vfc =
                  new VideoFrameConverter(
                      videoStreamDecoder.FrameWidth,
                      videoStreamDecoder.FrameHeight,
                      sourcePixelFormat,
                      destinationSize.Width,
                      destinationSize.Height);

        var convertedFrame = vfc.Convert(videoStreamDecoder.Current.Value);

        using var colorspace = SKColorSpace.CreateSrgb();

        var sourceImageInfo = new SKImageInfo(
            convertedFrame.width,
            convertedFrame.height,
            SKColorType.Rgba8888,
            SKAlphaType.Unpremul,
            colorspace);

        using var image =
                  SKImage.FromPixels(sourceImageInfo, (IntPtr)convertedFrame.data[0], sourceImageInfo.RowBytes);

        _cachedDecorationImage ??= SKImage.FromEncodedData(ReadDecorationImage());
        ThumbnailUtils.DrawShadowView(
            ctx,
            new SkImageView(image),
            _cachedDecorationImage,
            new SKColor(0, 0, 0),
            minSize: new SKSize(24, 24));
        return(true);
    }