public void Encode(
            IReadOnlyPixelRows image,
            CancellationToken cancellationToken = default)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            AssertCanEncodeImage(image);

            var pixelInfo = image.PixelType.ComponentInfo;

            // TODO: change components to dynamic/controlled (maybe in encoder options)
            bool imageHasAlpha        = pixelInfo.HasComponentType(VectorComponentChannel.Alpha);
            bool encoderSupportsAlpha = true; // TODO: implement (encoderState.Encoder.SupportedComponents HasAttribute();)
            int  colors     = 3;              // TODO: also implement grayscale
            int  alpha      = (imageHasAlpha && encoderSupportsAlpha) ? 1 : 0;
            int  components = colors + alpha;

            int imageMaxDepth   = pixelInfo.MaxBitDepth;
            int encoderMinDepth = 8; // TODO: implement
            int encoderMaxDepth = 8; // TODO: implement
            int variableDepth   = Math.Max(encoderMinDepth, imageMaxDepth);
            int depth           = Math.Min(encoderMaxDepth, variableDepth);

            var provider = new PixelRowProvider(image, components, depth, cancellationToken);

            Write(provider);

            FrameIndex++;
        }
Beispiel #2
0
        protected override void Write(PixelRowProvider image)
        {
            // TODO: add forcedFilter option

            StbSharp.ImageWrite.Png.Write(
                Writer, image, EncoderOptions.CompressionLevel, null, null, RecyclableArrayPool.Shared);
        }
        protected override void Write(PixelRowProvider image)
        {
            bool useFloatPixels = image.Depth > 8;
            bool allowSubsample = EncoderOptions.Subsampling == JpegSubsampling.Allow;
            bool forceSubsample = EncoderOptions.Subsampling == JpegSubsampling.Force;

            StbSharp.ImageWrite.Jpeg.WriteCore(
                Writer, image, useFloatPixels, EncoderOptions.Quality, allowSubsample, forceSubsample);
        }
Beispiel #4
0
        protected override void Write(PixelRowProvider image)
        {
            // TODO: allow different bit depths

            throw new NotImplementedException();


            byte[] pixeldata = new byte[image.Width * image.Height * 4];
            for (int i = 0; i < image.Height; i++)
            {
                image.GetByteRow(i, pixeldata);
            }
        }
 protected abstract void Write(PixelRowProvider image);
        protected override void Write(PixelRowProvider image)
        {
            // TODO: allow different bit depths

            StbSharp.ImageWrite.Bmp.Write(Writer, image);
        }
Beispiel #7
0
 protected override void Write(PixelRowProvider image)
 {
     StbSharp.ImageWrite.Tga.Write(Writer, image, EncoderOptions.UseRunLengthEncoding);
 }