Beispiel #1
0
    public async Task <bool> Render(
        ThumbnailsRenderContext ctx,
        ThumbnailsRenderFileInfo fileInfo,
        ThumbnailsRenderOption option)
    {
        await _fileService.ReadFileStream(fileInfo.FileHandle, videoStream =>
        {
            using var formatContext = new FormatContext(videoStream);

            var attachedPicStream = formatContext.FindAttachedPicStream();

            if (attachedPicStream != null)
            {
                DrawAttachedPicture(ctx, attachedPicStream);
            }
            else
            {
                var audioStream = formatContext.FindBestAudioStream();

                if (audioStream == null)
                {
                    throw new InvalidDataException("No audio stream found");
                }

                DrawWaves(ctx, audioStream);
            }

            return(ValueTask.FromResult(true));
        });

        return(true);
    }
Beispiel #2
0
 protected override Task <bool> Render(
     ThumbnailsRenderContext ctx,
     ThumbnailsRenderFileInfo fileInfo,
     ThumbnailsRenderOption option)
 {
     Assert.AreEqual(MimeType.image_png, fileInfo.MimeType);
     return(Task.FromResult(true));
 }
Beispiel #3
0
    public virtual bool IsSupported(ThumbnailsRenderFileInfo fileInfo)
    {
        if (fileInfo.Type.HasFlag(FileType.File) && fileInfo.MimeType != null &&
            fileInfo.MimeType.Mime.StartsWith("audio/", StringComparison.Ordinal))
        {
            return(true);
        }

        return(false);
    }
Beispiel #4
0
    public async Task <bool> Render(
        ThumbnailsRenderContext ctx,
        ThumbnailsRenderFileInfo fileInfo,
        ThumbnailsRenderOption option)
    {
        await _fileService.ReadFileStream(
            fileInfo.FileHandle,
            videoStream => ValueTask.FromResult(DrawVideo(videoStream, ctx)));

        return(true);
    }
Beispiel #5
0
    async Task <bool> IThumbnailsRenderer.Render(
        ThumbnailsRenderContext ctx,
        ThumbnailsRenderFileInfo fileInfo,
        ThumbnailsRenderOption option)
    {
        if (!IsSupported(fileInfo))
        {
            return(false);
        }

        return(await Render(ctx, fileInfo, option));
    }
Beispiel #6
0
    /// <inheritdoc />
    protected override async Task <bool> Render(
        ThumbnailsRenderContext ctx,
        ThumbnailsRenderFileInfo fileInfo,
        ThumbnailsRenderOption option)
    {
        // use the following code maybe faster. https://github.com/kleisauke/net-vips/issues/128
        // > sourceVipsImage = Image.Thumbnail(localPath, loadImageSize, loadImageSize, noRotate: false);
        return(await _fileService.ReadFileStream(
                   fileInfo.FileHandle,
                   stream =>
        {
            var sourceVipsImage = Image.ThumbnailStream(
                stream,
                (int)(ThumbnailUtils.DefaultMaxWidth * ctx.Density),
                height: (int)(ThumbnailUtils.DefaultMaxHeight * ctx.Density),
                noRotate: false);

            sourceVipsImage = sourceVipsImage.Colourspace(Enums.Interpretation.Srgb).Cast(Enums.BandFormat.Uchar);
            if (!sourceVipsImage.HasAlpha())
            {
                sourceVipsImage = sourceVipsImage.Bandjoin(255);
            }

            var imageWidth = sourceVipsImage.Width;
            var imageHeight = sourceVipsImage.Height;

            var sourceImageDataPtr = sourceVipsImage.WriteToMemory(out _);
            sourceVipsImage.Close();

            try
            {
                using var colorspace = SKColorSpace.CreateSrgb();
                var sourceImageInfo = new SKImageInfo(
                    imageWidth,
                    imageHeight,
                    SKColorType.Rgba8888,
                    SKAlphaType.Unpremul,
                    colorspace);

                using var image =
                          SKImage.FromPixels(sourceImageInfo, sourceImageDataPtr, sourceImageInfo.RowBytes);
                ThumbnailUtils.DrawShadowView(ctx, new SkImageView(image));
            }
            finally
            {
                NetVips.NetVips.Free(sourceImageDataPtr);
            }

            return ValueTask.FromResult(true);
        }));
    }
Beispiel #7
0
    public virtual bool IsSupported(ThumbnailsRenderFileInfo fileInfo)
    {
        if (_cacheSupportMimeTypes == null)
        {
            _cacheSupportMimeTypes = SupportMimeTypes;
        }

        var fileMimeType = fileInfo.MimeType;

        if (fileInfo.Type.HasFlag(FileType.File) &&
            fileMimeType != null &&
            _cacheSupportMimeTypes.Value.Contains(fileMimeType) &&
            fileInfo.Size <= MaxFileSize)
        {
            return(true);
        }

        return(false);
    }
 public bool IsSupported(ThumbnailsRenderFileInfo fileInfo)
 {
     return(_wrappedThumbnailsRenderer.IsSupported(fileInfo));
 }
 public Task <bool> Render(ThumbnailsRenderContext ctx, ThumbnailsRenderFileInfo fileInfo, ThumbnailsRenderOption option)
 {
     RenderCount++;
     return(_wrappedThumbnailsRenderer.Render(ctx, fileInfo, option));
 }
Beispiel #10
0
 protected abstract Task <bool> Render(ThumbnailsRenderContext ctx, ThumbnailsRenderFileInfo fileInfo, ThumbnailsRenderOption option);