Example #1
0
    protected Texture AllocateFromImageStream_GDI(Stream dataStream, ref ImageInformation info)
    {
      Texture texture = null;
      try
      {
        if (dataStream.CanSeek)
          dataStream.Position = 0;
        Image image = Image.FromStream(dataStream);

        // Scale down larger images
        int resizeWidth = MAX_TEXTURE_DIMENSION;
        int resizeHeight = MAX_TEXTURE_DIMENSION;

        if (_decodeWidth > 0)
          resizeWidth = Math.Min(_decodeWidth, MAX_TEXTURE_DIMENSION);

        if (_decodeHeight > 0)
          resizeHeight = Math.Min(_decodeHeight, MAX_TEXTURE_DIMENSION);

       image.ExifAutoRotate();

        if (image.Size.Width > resizeWidth || image.Size.Height > resizeHeight)
        {
          var oldImage = image;
          image = ImageUtilities.ResizeImage(image, resizeWidth, resizeHeight);
          oldImage.Dispose();
        }

        // Write uncompressed data to temporary stream.
        using (var loadStream = new MemoryStream())
        {
          image.Save(loadStream, ImageFormat.Bmp);
          image.Dispose();
          loadStream.Position = 0;
          texture = Texture.FromStream(GraphicsDevice.Device, loadStream, (int)loadStream.Length, _decodeWidth, _decodeHeight, 1,
            Usage.None, Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0, out info);
        }
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Warn("TextureAssetCore: Error loading texture from stream using GDI", ex);
      }
      return texture;
    }
Example #2
0
 /// <summary>
 /// Creates a <see cref="VolumeTexture"/> from a memory buffer.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="levelCount">The level count.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="format">The format.</param>
 /// <param name="pool">The pool.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="mipFilter">The mip filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <param name="palette">The palette.</param>
 /// <returns>
 /// A <see cref="VolumeTexture"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture)</unmanaged>
 public static unsafe VolumeTexture FromMemory(Device device, byte[] buffer, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette)
 {
     palette = new PaletteEntry[256];
     fixed (void* pImageInfo = &imageInformation)
         return CreateFromMemory(device, buffer, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette);
 }
Example #3
0
 /// <summary>
 /// Creates a <see cref="CubeTexture"/> from a stream.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="stream">The stream.</param>
 /// <param name="sizeBytes">The size bytes.</param>
 /// <param name="size">The size.</param>
 /// <param name="levelCount">The level count.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="format">The format.</param>
 /// <param name="pool">The pool.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="mipFilter">The mip filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <param name="palette">The palette.</param>
 /// <returns>
 /// A <see cref="CubeTexture"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DCubeTexture9** ppCubeTexture)</unmanaged>
 public static unsafe CubeTexture FromStream(Device device, Stream stream, int sizeBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette)
 {
     palette = new PaletteEntry[256];
     fixed (void* pImageInfo = &imageInformation)
         return CreateFromStream(device, stream, sizeBytes, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette);
 }
Example #4
0
    protected void AllocateFromFile(string path)
    {
      lock (_syncObj)
        _state = State.LoadingSync;

      Texture texture;
      ImageInformation info = new ImageInformation();
      try
      {
        using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 2048, true))
          texture = AllocateFromImageStream(stream, ref info);
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Warn("TextureAssetCore: Error loading texture from file '{0}'", e, path);
        return;
      }
      FinalizeAllocation(texture, info.Width, info.Height);
    }
Example #5
0
 /// <summary>
 /// Loads a volume from a file in memory.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="memory">The memory.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInMemory(Volume volume, byte[] memory, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] palette, out ImageInformation imageInformation)
 {
     unsafe
     {
         fixed (void* pMemory = memory)
             fixed (void* pImageInformation = &imageInformation)
                 D3DX9.LoadVolumeFromFileInMemory(volume, palette, new IntPtr(&destinationBox), (IntPtr)pMemory, memory.Length, new IntPtr(&sourceBox), filter, colorKey, (IntPtr)pImageInformation);
     }
 }
Example #6
0
 /// <summary>
 /// Loads a volume from a file in a strean.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="stream">The stream.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInStream(Volume volume, Stream stream, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] palette, out ImageInformation imageInformation)
 {
     unsafe
     {
         fixed (void* pImageInformation = &imageInformation)
             CreateFromFileInStream(volume, stream, filter, colorKey, new IntPtr(&sourceBox), new IntPtr(&destinationBox), palette, (IntPtr)pImageInformation);
     }
 }
Example #7
0
 /// <summary>
 /// Loads a volume from a file in a stream.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="stream">The stream.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInStream(Volume volume, Stream stream, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] palette, out ImageInformation imageInformation)
 {
     unsafe
     {
         fixed(void *pImageInformation = &imageInformation)
         CreateFromFileInStream(volume, stream, filter, colorKey, new IntPtr(&sourceBox), new IntPtr(&destinationBox), palette, (IntPtr)pImageInformation);
     }
 }
Example #8
0
 /// <summary>
 /// Loads a volume from a file on the disk.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileW([In] IDirect3DVolume9* pDestVolume,[In] const PALETTEENTRY* pDestPalette,[In] const D3DBOX* pDestBox,[In] const wchar_t* pSrcFile,[In] const D3DBOX* pSrcBox,[In] unsigned int Filter,[In] D3DCOLOR ColorKey,[In] D3DXIMAGE_INFO* pSrcInfo)</unmanaged>
 public static void FromFile(Volume volume, string fileName, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] palette, out ImageInformation imageInformation)
 {
     unsafe
     {
         fixed (void* pImageInformation = &imageInformation)
             D3DX9.LoadVolumeFromFileW(volume, palette, new IntPtr(&destinationBox), fileName, new IntPtr(&sourceBox), filter, colorKey, (IntPtr)pImageInformation);
     }
 }
Example #9
0
 /// <summary>
 /// Loads a volume from a file in memory.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="memory">The memory.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInMemory(Volume volume, byte[] memory, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] palette, out ImageInformation imageInformation)
 {
     unsafe
     {
         fixed(void *pMemory = memory)
         fixed(void *pImageInformation = &imageInformation)
         D3DX9.LoadVolumeFromFileInMemory(volume, palette, new IntPtr(&destinationBox), (IntPtr)pMemory, memory.Length, new IntPtr(&sourceBox), filter, colorKey, (IntPtr)pImageInformation);
     }
 }
Example #10
0
 /// <summary>
 /// Loads a volume from a file in a stream.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="stream">The stream.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInStream(Volume volume, Stream stream, Filter filter, int colorKey, Box sourceBox, Box destinationBox, out ImageInformation imageInformation)
 {
     FromFileInStream(volume, stream, filter, colorKey, sourceBox, destinationBox, null, out imageInformation);
 }
Example #11
0
 /// <summary>
 /// Loads a volume from a file in memory.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="memory">The memory.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInMemory(Volume volume, byte[] memory, Filter filter, int colorKey, Box sourceBox, Box destinationBox, out ImageInformation imageInformation)
 {
     FromFileInMemory(volume, memory, filter, colorKey, sourceBox, destinationBox, null, out imageInformation);
 }
Example #12
0
 /// <summary>
 /// Loads a volume from a file on the disk.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileW([In] IDirect3DVolume9* pDestVolume,[In] const PALETTEENTRY* pDestPalette,[In] const D3DBOX* pDestBox,[In] const wchar_t* pSrcFile,[In] const D3DBOX* pSrcBox,[In] unsigned int Filter,[In] D3DCOLOR ColorKey,[In] D3DXIMAGE_INFO* pSrcInfo)</unmanaged>
 public static void FromFile(Volume volume, string fileName, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] palette, out ImageInformation imageInformation)
 {
     unsafe
     {
         fixed(void *pImageInformation = &imageInformation)
         D3DX9.LoadVolumeFromFileW(volume, palette, new IntPtr(&destinationBox), fileName, new IntPtr(&sourceBox), filter, colorKey, (IntPtr)pImageInformation);
     }
 }
Example #13
0
 /// <summary>
 /// Loads a volume from a file on the disk.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileW([In] IDirect3DVolume9* pDestVolume,[In] const PALETTEENTRY* pDestPalette,[In] const D3DBOX* pDestBox,[In] const wchar_t* pSrcFile,[In] const D3DBOX* pSrcBox,[In] unsigned int Filter,[In] D3DCOLOR ColorKey,[In] D3DXIMAGE_INFO* pSrcInfo)</unmanaged>
 public static void FromFile(Volume volume, string fileName, Filter filter, int colorKey, Box sourceBox, Box destinationBox, out ImageInformation imageInformation)
 {
     FromFile(volume, fileName, filter, colorKey, sourceBox, destinationBox, null, out imageInformation);
 }
Example #14
0
 /// <summary>
 /// Creates a <see cref="VolumeTexture"/> from a stream.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="stream">The stream.</param>
 /// <param name="sizeBytes">The size bytes.</param>
 /// <param name="size">The size.</param>
 /// <param name="levelCount">The level count.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="format">The format.</param>
 /// <param name="pool">The pool.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="mipFilter">The mip filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="VolumeTexture"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture)</unmanaged>
 public static unsafe VolumeTexture FromStream(Device device, Stream stream, int sizeBytes, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation)
 {
     fixed (void* pImageInfo = &imageInformation)
         return CreateFromStream(device, stream, sizeBytes, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null);
 }
Example #15
0
        /// <summary>
        /// Creates a <see cref="Texture"/> from a file
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="filename">The filename.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="levelCount">The level count.</param>
        /// <param name="usage">The usage.</param>
        /// <param name="format">The format.</param>
        /// <param name="pool">The pool.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="mipFilter">The mip filter.</param>
        /// <param name="colorKey">The color key.</param>
        /// <param name="imageInformation">The image information.</param>
        /// <param name="palette">The palette.</param>
        /// <returns>
        /// A <see cref="Texture"/>
        /// </returns>
        /// <unmanaged>HRESULT D3DXCreateTextureFromFileExW([In] IDirect3DDevice9* pDevice,[In] const wchar_t* pSrcFile,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[In] void* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DTexture9** ppTexture)</unmanaged>
        public static unsafe Texture FromFile(Device device, string filename, int width, int height, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette)
        {
            palette = new PaletteEntry[256];

            fixed(void *pImageInfo = &imageInformation)
            return(CreateFromFile(device, filename, width, height, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette));
        }
Example #16
0
        /// <summary>
        /// Loads a volume from a file on the disk.
        /// </summary>
        /// <param name="volume">The volume.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="colorKey">The color key.</param>
        /// <param name="sourceBox">The source box.</param>
        /// <param name="destinationBox">The destination box.</param>
        /// <param name="imageInformation">The image information.</param>
        /// <returns>
        /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
        /// </returns>
        /// <unmanaged>HRESULT D3DXLoadVolumeFromFileW([In] IDirect3DVolume9* pDestVolume,[In] const PALETTEENTRY* pDestPalette,[In] const D3DBOX* pDestBox,[In] const wchar_t* pSrcFile,[In] const D3DBOX* pSrcBox,[In] unsigned int Filter,[In] D3DCOLOR ColorKey,[In] D3DXIMAGE_INFO* pSrcInfo)</unmanaged>
        public static void FromFile(Volume volume, string fileName, Filter filter, int colorKey, Box sourceBox, Box destinationBox, out ImageInformation imageInformation)
        {

            FromFile(volume, fileName, filter, colorKey, sourceBox, destinationBox, null, out imageInformation);
        }
Example #17
0
        /// <summary>
        /// Creates a <see cref="VolumeTexture"/> from a memory buffer.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="buffer">The buffer.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="levelCount">The level count.</param>
        /// <param name="usage">The usage.</param>
        /// <param name="format">The format.</param>
        /// <param name="pool">The pool.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="mipFilter">The mip filter.</param>
        /// <param name="colorKey">The color key.</param>
        /// <param name="imageInformation">The image information.</param>
        /// <param name="palette">The palette.</param>
        /// <returns>
        /// A <see cref="VolumeTexture"/>
        /// </returns>
        /// <unmanaged>HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture)</unmanaged>
        public static unsafe VolumeTexture FromMemory(Device device, byte[] buffer, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette)
        {
            palette = new PaletteEntry[256];

            fixed(void *pImageInfo = &imageInformation)
            return(CreateFromMemory(device, buffer, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette));
        }
Example #18
0
 /// <summary>
 /// Loads a volume from a file in memory.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="memory">The memory.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInMemory(Volume volume, byte[] memory, Filter filter, int colorKey, Box sourceBox, Box destinationBox, out ImageInformation imageInformation)
 {
     FromFileInMemory(volume, memory, filter, colorKey, sourceBox, destinationBox, null, out imageInformation);
 }
Example #19
0
 /// <summary>
 /// Creates a <see cref="VolumeTexture"/> from a stream.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="stream">The stream.</param>
 /// <param name="sizeBytes">The size bytes.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="levelCount">The level count.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="format">The format.</param>
 /// <param name="pool">The pool.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="mipFilter">The mip filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="VolumeTexture"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture)</unmanaged>
 public static unsafe VolumeTexture FromStream(Device device, Stream stream, int sizeBytes, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation)
 {
     fixed(void *pImageInfo = &imageInformation)
     return(CreateFromStream(device, stream, sizeBytes, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null));
 }
Example #20
0
        /// <summary>
        /// Loads a volume from a file in a strean.
        /// </summary>
        /// <param name="volume">The volume.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="colorKey">The color key.</param>
        /// <param name="sourceBox">The source box.</param>
        /// <param name="destinationBox">The destination box.</param>
        /// <param name="imageInformation">The image information.</param>
        /// <returns>
        /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
        /// </returns>
        /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
        public static void FromFileInStream(Volume volume, Stream stream, Filter filter, int colorKey, Box sourceBox, Box destinationBox, out ImageInformation imageInformation)
        {

            FromFileInStream(volume, stream, filter, colorKey, sourceBox, destinationBox, null, out imageInformation);
        }
Example #21
0
 /// <summary>
 /// Creates a <see cref="CubeTexture"/> from a memory buffer.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="size">The size.</param>
 /// <param name="levelCount">The level count.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="format">The format.</param>
 /// <param name="pool">The pool.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="mipFilter">The mip filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="CubeTexture"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DCubeTexture9** ppCubeTexture)</unmanaged>
 public static unsafe CubeTexture FromMemory(Device device, byte[] buffer, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation)
 {
     fixed(void *pImageInfo = &imageInformation)
     return(CreateFromMemory(device, buffer, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null));
 }
Example #22
0
 /// <summary>
 /// Creates a <see cref="CubeTexture"/> from a memory buffer.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="size">The size.</param>
 /// <param name="levelCount">The level count.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="format">The format.</param>
 /// <param name="pool">The pool.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="mipFilter">The mip filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="CubeTexture"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DCubeTexture9** ppCubeTexture)</unmanaged>
 public static unsafe CubeTexture FromMemory(Device device, byte[] buffer, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation)
 {
     fixed (void* pImageInfo = &imageInformation)
         return CreateFromMemory(device, buffer, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null);
 }
Example #23
0
        /// <summary>
        /// Creates a <see cref="CubeTexture"/> from a stream.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="sizeBytes">The size bytes.</param>
        /// <param name="size">The size.</param>
        /// <param name="levelCount">The level count.</param>
        /// <param name="usage">The usage.</param>
        /// <param name="format">The format.</param>
        /// <param name="pool">The pool.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="mipFilter">The mip filter.</param>
        /// <param name="colorKey">The color key.</param>
        /// <param name="imageInformation">The image information.</param>
        /// <param name="palette">The palette.</param>
        /// <returns>
        /// A <see cref="CubeTexture"/>
        /// </returns>
        /// <unmanaged>HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DCubeTexture9** ppCubeTexture)</unmanaged>
        public static unsafe CubeTexture FromStream(Device device, Stream stream, int sizeBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette)
        {
            palette = new PaletteEntry[256];

            fixed(void *pImageInfo = &imageInformation)
            return(CreateFromStream(device, stream, sizeBytes, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette));
        }
Example #24
0
    protected Texture AllocateFromImageStream(Stream dataStream, ref ImageInformation info)
    {
      Texture texture = null;
      FIBITMAP image = FIBITMAP.Zero;
      try
      {
        image = FreeImage.LoadFromStream(dataStream);

        // Write uncompressed data to temporary stream.
        using (var memoryStream = new MemoryStream())
        {
          // Scale down larger images
          int resizeWidth = MAX_TEXTURE_DIMENSION;
          int resizeHeight = MAX_TEXTURE_DIMENSION;

          if (_decodeWidth > 0)
            resizeWidth = Math.Min(_decodeWidth, MAX_TEXTURE_DIMENSION);

          if (_decodeHeight > 0)
            resizeHeight = Math.Min(_decodeHeight, MAX_TEXTURE_DIMENSION);

          Stream loadStream = dataStream;
          if (!image.IsNull)
          {
            image = ResizeImage(image, resizeWidth, resizeHeight);
            FreeImage.SaveToStream(image, memoryStream, FREE_IMAGE_FORMAT.FIF_BMP);
            loadStream = memoryStream;
          }

          loadStream.Position = 0;
          texture = Texture.FromStream(GraphicsDevice.Device, loadStream, (int)loadStream.Length, _decodeWidth, _decodeHeight, 1,
            Usage.None, Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0, out info);
        }
      }
      catch (Exception)
      {
        ServiceRegistration.Get<ILogger>().Warn("TextureAssetCore: Error loading texture from stream using FreeImage and DirectX");
      }
      finally
      {
        FreeImage.UnloadEx(ref image);
      }
      return texture;
    }
Example #25
0
 /// <summary>
 /// Creates a <see cref="Texture"/> from a file
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="filename">The filename.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="levelCount">The level count.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="format">The format.</param>
 /// <param name="pool">The pool.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="mipFilter">The mip filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <param name="palette">The palette.</param>
 /// <returns>
 /// A <see cref="Texture"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateTextureFromFileExW([In] IDirect3DDevice9* pDevice,[In] const wchar_t* pSrcFile,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[In] void* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DTexture9** ppTexture)</unmanaged>
 public static unsafe Texture FromFile(Device device, string filename, int width, int height, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette)
 {
     palette = new PaletteEntry[256];
     fixed (void* pImageInfo = &imageInformation)
         return CreateFromFile(device, filename, width, height, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette);
 }
Example #26
0
 protected void AllocateFromStream_NoLock(Stream stream)
 {
   Texture texture;
   ImageInformation info = new ImageInformation();
   try
   {
     stream.Seek(0, SeekOrigin.Begin);
     texture = AllocateFromImageStream(stream, ref info);
   }
   catch (Exception e)
   {
     ServiceRegistration.Get<ILogger>().Warn("TextureAssetCore: Error loading texture from file data stream", e);
     return;
   }
   if (texture != null)
     FinalizeAllocation(texture, info.Width, info.Height);
 }
Example #27
0
 protected Texture AllocateFromImageStream(Stream dataStream, ref ImageInformation info)
 {
   // GDI decoding was measured to be faster in nearly all cases. WIC based was faster, but was missing rotation support and had other dependencies (WPF or SharpDX.WIC).
   // FreeImage decoding is kept in place as fallback to support image formats which are not handled by GDI.
   Texture texture = 
     AllocateFromImageStream_GDI(dataStream, ref info) ??
     AllocateFromImageStream_FreeImage(dataStream, ref info);
   return texture;
 }