Example #1
0
        /// <summary>
        /// Create new writeable bitmap.
        /// </summary>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="format">Format.</param>
        public WriteableBitmapImpl(int width, int height, PixelFormat?format = null)
        {
            PixelHeight = height;
            PixelWidth  = width;

            var colorType = PixelFormatHelper.ResolveColorType(format);

            var runtimePlatform = AvaloniaLocator.Current?.GetService <IRuntimePlatform>();

            if (runtimePlatform != null)
            {
                _bitmap = new SKBitmap();

                var nfo  = new SKImageInfo(width, height, colorType, SKAlphaType.Premul);
                var blob = runtimePlatform.AllocBlob(nfo.BytesSize);

                _bitmap.InstallPixels(nfo, blob.Address, nfo.RowBytes, null, s_releaseDelegate, blob);
            }
            else
            {
                _bitmap = new SKBitmap(width, height, colorType, SKAlphaType.Premul);
            }

            _bitmap.Erase(SKColor.Empty);
        }
        public WriteableBitmapImpl(PixelSize size, Vector dpi, PixelFormat?format = null)
        {
            PixelSize = size;
            Dpi       = dpi;

            var colorType = PixelFormatHelper.ResolveColorType(format);

            var runtimePlatform = AvaloniaGlobals.RuntimePlatform;

            if (runtimePlatform != null)
            {
                _bitmap = new SKBitmap();

                var nfo  = new SKImageInfo(size.Width, size.Height, colorType, SKAlphaType.Premul);
                var blob = runtimePlatform.AllocBlob(nfo.BytesSize);

                _bitmap.InstallPixels(nfo, blob.Address, nfo.RowBytes, s_releaseDelegate, blob);
            }
            else
            {
                _bitmap = new SKBitmap(size.Width, size.Height, colorType, SKAlphaType.Premul);
            }

            _bitmap.Erase(SKColor.Empty);
        }
Example #3
0
        public MediaStreamInfo ToStreamInfo()
        {
            MediaStreamInfo stream = null;

            if (CodecType == "audio")
            {
                stream = new AudioStreamInfo {
                    ChannelLayout = this.ChannelLayout,
                    ChannelCount  = this.ChannelCount,
                    SampleFormat  = FfmpegHelper.ParseSampleFormat(SampleFormat),
                    SampleRate    = SampleRate,
                };
            }
            else if (CodecType == "video")
            {
                stream = new VideoStreamInfo {
                    PixelFormat = PixelFormatHelper.Parse(PixelFormat),
                    Width       = this.Width,
                    Height      = this.Height
                };

                if (Tags != null && Tags.TryGetValue("rotate", out var rotate))
                {
                    ((VideoStreamInfo)stream).Rotate = (int)rotate;
                }
            }
            else if (CodecType == "subtitle")
            {
                stream = new SubtitleStreamInfo
                {
                };
            }
            else if (CodecType == "data")
            {
                stream = new DataStreamInfo
                {
                };
            }
            else
            {
                stream = new MediaStreamInfo();
            }

            stream.Codec = Profile != null?CodecInfo.Create(CodecIdHelper.Parse(CodecName), Profile).Name : CodecName;

            if (TimeBase != null && Rational.TryParse(TimeBase, out var timeBase))
            {
                stream.TimeBase = timeBase;
            }


            stream.Duration  = Duration ?? TimeSpan.Zero;
            stream.StartTime = StartTime ?? TimeSpan.Zero;

            stream.FrameCount = FrameCount;


            return(stream);
        }
        private BitmapPalette GetPalette(PixelFormat format, DeterministicRandom random)
        {
            Array formatEnumValues = PixelFormatHelper.GetEnumValues(typeof(PixelFormat), "MS.Internal.PixelFormatEnum");
            Type  formatType       = format.GetType();

            PropertyInfo getFormatProp = formatType.GetProperty("Format", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);

            if (getFormatProp == null)
            {
                throw new InvalidOperationException("Could not get the Format property from the format type " + format.ToString());
            }

            Enum formatValue = (Enum)getFormatProp.GetValue(format, null);

            List <Color> colors         = new List <Color>();
            int          numberOfColors = 0;

            switch (formatValue.ToString())
            {
            case "Indexed1":
                numberOfColors = 2;
                break;

            case "Indexed2":
                numberOfColors = 4;
                break;

            case "Indexed4":
                numberOfColors = 16;
                break;

            case "Indexed8":
                numberOfColors = 256;
                break;

            default:
                return(null);
            }

            //HACK: these colors should be supplied by the stress framework
            for (int i = 0; i < numberOfColors; i++)
            {
                colors.Add(RandomColor(random));
            }

            return(new BitmapPalette(colors));
        }
        /// <summary>
        /// Create image info for given parameters.
        /// </summary>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="format">Format.</param>
        /// <returns></returns>
        private static SKImageInfo MakeImageInfo(int width, int height, PixelFormat?format)
        {
            var colorType = PixelFormatHelper.ResolveColorType(format);

            return(new SKImageInfo(Math.Max(width, 1), Math.Max(height, 1), colorType, SKAlphaType.Premul));
        }
Example #6
0
 /// <summary>
 /// Returns the <see cref="System.Drawing.Imaging"/> pixel format correspond to the specified <see cref="Microsoft.Psi.Imaging"/> pixel format.
 /// </summary>
 /// <param name="pixelFormat">The <see cref="Microsoft.Psi.Imaging"/> pixel format.</param>
 /// <returns>The corresponding <see cref="System.Drawing.Imaging"/> pixel format.</returns>
 public static System.Drawing.Imaging.PixelFormat ToSystemPixelFormat(this PixelFormat pixelFormat)
 {
     return(PixelFormatHelper.ToSystemPixelFormat(pixelFormat));
 }
Example #7
0
 /// <summary>
 /// Returns the <see cref="Microsoft.Psi.Imaging"/> pixel format correspond to the specified <see cref="System.Drawing.Imaging"/> pixel format.
 /// </summary>
 /// <param name="pixelFormat">The <see cref="System.Drawing.Imaging"/> pixel format.</param>
 /// <returns>The corresponding <see cref="Microsoft.Psi.Imaging"/> pixel format.</returns>
 public static PixelFormat ToPsiPixelFormat(this System.Drawing.Imaging.PixelFormat pixelFormat)
 {
     return(PixelFormatHelper.FromSystemPixelFormat(pixelFormat));
 }
Example #8
0
 /// <summary>
 /// Returns the number of bytes per pixel for a given pixel format.
 /// </summary>
 /// <param name="pixelFormat">Pixel format for which to find bytes per pixel.</param>
 /// <returns>Number of bytes per pixel for the given pixel format.</returns>
 public static int GetBytesPerPixel(this PixelFormat pixelFormat)
 {
     return(PixelFormatHelper.GetBytesPerPixel(pixelFormat));
 }
Example #9
0
 public void Parse(string text, PixelFormat type)
 {
     Assert.Equal(type, PixelFormatHelper.Parse(text));
 }
Example #10
0
 /// <summary>
 /// Returns the number of bits per channel (bit depth) for a given pixel format.
 /// </summary>
 /// <param name="pixelFormat">Pixel format for which to find bits per channel.</param>
 /// <returns>Number of bits per channel for the given pixel format.</returns>
 public static int GetBitsPerChannel(this PixelFormat pixelFormat)
 {
     return(PixelFormatHelper.GetBitsPerChannel(pixelFormat));
 }
Example #11
0
 internal PixelFormat(PixelFormatEnum pixelFormatEnum)
 {
     BitsPerPixel = PixelFormatHelper.GetPixelFormatBPP(pixelFormatEnum);
     IsIndexed    = PixelFormatHelper.GetPixelFormatIndexed(pixelFormatEnum);
     Format       = pixelFormatEnum;
 }