using System.IO;
using Mox.Shared.Renderer;
using SharpDX.Direct2D1;
using SharpDX.WIC;
using Bitmap = SharpDX.Direct2D1.Bitmap;

namespace Mox.SharpDX.Renderer
{
	public class DirectXImage : ImageBase
	{
		public DirectXImage(WindowRenderTarget _renderTarget2D, ImagingFactory _wicFactory, byte[] _data)
		{
			var decoder = new BitmapDecoder(_wicFactory, new MemoryStream(_data), DecodeOptions.CacheOnDemand);
			var frame = decoder.GetFrame(0);
			var converter = new FormatConverter(_wicFactory);
			converter.Initialize(frame, global::SharpDX.WIC.PixelFormat.Format32bppPBGRA);
			m_Bitmap = Bitmap.FromWicBitmap(_renderTarget2D, converter);
		}

		public override int Width
		{
			get
			{
				return m_Bitmap.PixelSize.Width;
			}
		}

		public override int Height
		{
			get
			{
				return m_Bitmap.PixelSize.Height;
			}
		}

		public Bitmap Image
		{
			get
			{
				return m_Bitmap;
			}
		}

		private Bitmap m_Bitmap;
	}
}
