Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
StandardImageHelper.Android.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 #if SILICONSTUDIO_PLATFORM_ANDROID
4 using System;
5 using System.IO;
6 using System.Runtime.InteropServices;
7 using SiliconStudio.Core;
8 using Android.Graphics;
9 using SiliconStudio.Core.Mathematics;
10 
11 namespace SiliconStudio.Paradox.Graphics
12 {
13  /// <summary>
14  /// This class is responsible to provide image loader for png, gif, bmp.
15  /// </summary>
16  partial class StandardImageHelper
17  {
18  public unsafe static Image LoadFromMemory(IntPtr pSource, int size, bool makeACopy, GCHandle? handle)
19  {
20  using (var memoryStream = new UnmanagedMemoryStream((byte*)pSource, size))
21  using (var bitmap = (Bitmap)BitmapFactory.DecodeStream(memoryStream))
22  {
23  var bitmapData = bitmap.LockPixels();
24 
25  var image = Image.New2D(bitmap.Width, bitmap.Height, 1, PixelFormat.B8G8R8A8_UNorm, 1, bitmap.RowBytes);
26 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
27  // Directly load image as RGBA instead of BGRA, because OpenGL ES devices don't support it out of the box (extension).
28  CopyMemoryBGRA(image.PixelBuffer[0].DataPointer, bitmapData, image.PixelBuffer[0].BufferStride);
29 #else
30  Utilities.CopyMemory(image.PixelBuffer[0].DataPointer, bitmapData, image.PixelBuffer[0].BufferStride);
31 #endif
32  bitmap.UnlockPixels();
33 
34  if (handle != null)
35  handle.Value.Free();
36  else if (!makeACopy)
37  Utilities.FreeMemory(pSource);
38 
39  return image;
40  }
41 
42  }
43 
44  public static void SaveGifFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream)
45  {
46  throw new NotImplementedException();
47  }
48 
49  public static void SaveTiffFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream)
50  {
51  throw new NotImplementedException();
52  }
53 
54  public static void SaveBmpFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream)
55  {
56  throw new NotImplementedException();
57  }
58 
59  public static void SaveJpgFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream)
60  {
61  throw new NotImplementedException();
62  }
63 
64  public static void SavePngFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream)
65  {
66  SaveFromMemory(pixelBuffers, count, description, imageStream, Bitmap.CompressFormat.Png);
67  }
68 
69  public static void SaveWmpFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream)
70  {
71  throw new NotImplementedException();
72  }
73 
74  private static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, Bitmap.CompressFormat imageFormat)
75  {
76  var colors = pixelBuffers[0].GetPixels<int>();
77  using (var bitmap = Bitmap.CreateBitmap(colors, description.Width, description.Height, Bitmap.Config.Argb8888))
78  {
79  bitmap.Compress(imageFormat, 0, imageStream);
80  }
81  }
82  }
83 }
84 #endif
_In_ size_t count
Definition: DirectXTexP.h:174
_In_ size_t _In_ size_t size
Definition: DirectXTexP.h:175