/// <summary> /// Function to create 1D Gorgon image data from a single System.Drawing.Image. /// </summary> /// <param name="wic">Windows Imaging Component interface to use.</param> /// <param name="image">An image to convert.</param> /// <param name="options">Options for image conversion.</param> /// <returns>The converted image data.</returns> public static GorgonImageData Create1DImageDataFromImage(GorgonWICImage wic, Image image, GorgonGDIOptions options) { if (options.Format == BufferFormat.Unknown) { options.Format = GetBufferFormat(image.PixelFormat); } if (options.Format == BufferFormat.Unknown) { throw new GorgonException(GorgonResult.FormatNotSupported, string.Format(Resources.GORGFX_FORMAT_NOT_SUPPORTED, image.PixelFormat)); } if (options.Width < 1) { options.Width = image.Width; } options.MipCount = options.MipCount < 1 ? GorgonImageData.GetMaxMipCount(options.Width) : options.MipCount.Min(GorgonImageData.GetMaxMipCount(options.Width)); // Create our settings. var settings = new GorgonTexture1DSettings { Width = options.Width, MipCount = options.MipCount, ArrayCount = 1, Format = options.Format, AllowUnorderedAccessViews = options.AllowUnorderedAccess, ShaderViewFormat = options.ViewFormat, Usage = options.Usage }; // Create our image data. var data = new GorgonImageData(settings); // Using the image, convert to a WIC bitmap object. using (Bitmap bitmap = wic.CreateWICImageFromImage(image)) { for (int mipLevel = 0; mipLevel < data.Settings.MipCount; mipLevel++) { var buffer = data.Buffers[mipLevel]; // Convert to a GorgonImageData type container. wic.AddWICBitmapToImageData(bitmap, options.Filter, options.Dither, buffer, options.UseClipping); } } return(data); }
/// <summary> /// Function to create 1D Gorgon image data from multiple single System.Drawing.Images. /// </summary> /// <param name="wic">Windows Imaging Component interface to use.</param> /// <param name="images">Images to convert.</param> /// <param name="options">The options for the image conversion.</param> /// <returns>The converted image data.</returns> public static GorgonImageData Create1DImageDataFromImages(GorgonWICImage wic, IList <Image> images, GorgonGDIOptions options) { if (options.Format == BufferFormat.Unknown) { options.Format = GetBufferFormat(images[0].PixelFormat); } if (options.Format == BufferFormat.Unknown) { throw new GorgonException(GorgonResult.FormatNotSupported, string.Format(Resources.GORGFX_FORMAT_NOT_SUPPORTED, images[0].PixelFormat)); } if (images.Any(item => item.PixelFormat != images[0].PixelFormat)) { throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_IMAGE_MUST_BE_SAME_FORMAT, images[0].PixelFormat)); } if (options.Width < 1) { options.Width = images[0].Width; } if (options.ArrayCount < 1) { options.ArrayCount = 1; } options.MipCount = options.MipCount < 1 ? 1 : options.MipCount.Min(GorgonImageData.GetMaxMipCount(options.Width)); // Create our settings. var settings = new GorgonTexture1DSettings { Width = options.Width, MipCount = options.MipCount, ArrayCount = options.ArrayCount, Format = options.Format, AllowUnorderedAccessViews = options.AllowUnorderedAccess, ShaderViewFormat = options.ViewFormat, Usage = options.Usage }; if ((options.ArrayCount * options.MipCount) > images.Count) { throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_IMAGE_MIPCOUNT_ARRAYCOUNT_TOO_LARGE); } // Create our image data. var data = new GorgonImageData(settings); for (int array = 0; array < data.Settings.ArrayCount; array++) { for (int mipLevel = 0; mipLevel < data.Settings.MipCount; mipLevel++) { var image = images[array * data.Settings.MipCount + mipLevel]; if (image == null) { continue; } // Using the image, convert to a WIC bitmap object. using (var bitmap = wic.CreateWICImageFromImage(image)) { var buffer = data.Buffers[mipLevel, array]; wic.AddWICBitmapToImageData(bitmap, options.Filter, options.Dither, buffer, options.UseClipping); } } } return(data); }