示例#1
0
        internal BitmapSurface(uint width, uint height, PixelFormat pixelFormat)
        {
            PixelFormat = pixelFormat;
            BytesPerPixel = ((byte)pixelFormat & (byte)PixelFormat.BppFormatMask) >> (byte)PixelFormat.BppFormatOffs;
            Height = height;
            Width  = width;

            Stride = (uint)Width * (uint)BytesPerPixel;
            ByteLength = Stride * (uint)Height;

            // create memory section and map
            _section = CreateFileMapping(new IntPtr(-1), IntPtr.Zero, 0x04, 0, ByteLength, null);
            ImageData = MapViewOfFile(_section, 0xF001F, 0, 0, ByteLength);

            var mediaPixelFormat = BytesPerPixel == 2 ? PixelFormats.Bgr555 : BytesPerPixel == 4 ? PixelFormats.Bgr32 : PixelFormats.Default;
            BitmapSource = Imaging.CreateBitmapSourceFromMemorySection(_section, (int)Width, (int)Height, mediaPixelFormat, (int)Width * BytesPerPixel, 0) as InteropBitmap;
            ImageUIntPtr = (uint*)ImageData;
            ImageWordPtr = (ushort*)ImageData;
            ImageBytePtr = (byte*)ImageData;
        }
示例#2
0
 private Color(ushort color)
 {
     colval = color;
     bytepp = 2;
     format = PixelFormat.Bpp16A1R5G5B5;
 }
示例#3
0
 private Color(uint color)
 {
     colval = color;
     bytepp = 4;
     format = PixelFormat.Bpp32A8R8G8B8;
 }
示例#4
0
 public static Color FromARGB(byte a, byte r, byte g, byte b, PixelFormat format = PixelFormat.Bpp32A8R8G8B8)
 {
     uint  value;
     Color color;
     switch (format) {
         case PixelFormat.Bpp16A1R5G5B5: value = (uint)((r & 0x1F) << 10 | (g & 0x1F) << 5 | (b & 0x1F));
                                         if (a > 0) value |= 0xFF000000;
                                         color = (ushort)(value & 0x0000FFFF);
                                         break;
         case PixelFormat.Bpp32A8R8G8B8: value = (uint)(a << 24 | r << 16 | g << 8 | b);
                                         color = (uint)value;
                                         break;
         default: throw new NotImplementedException();
     }
     return color;
 }
示例#5
0
 public static Color FromARGB(byte r, byte g, byte b, PixelFormat format = PixelFormat.Bpp32A8R8G8B8)
 {
     return FromARGB(0xFF, r, g, b, format);
 }
示例#6
0
 internal BitmapSurface(uint width, uint height, byte[] bytes, PixelFormat pixelFormat = PixelFormat.Bpp16A1R5G5B5) : this(width, height, pixelFormat)
 {
     fixed(byte* _bytes = bytes) {
         CreateFromPBytes(width, height, _bytes);
     }
 }
示例#7
0
 internal BitmapSurface(BitmapSource bitmap, PixelFormat pixelFormat = PixelFormat.Bpp16A1R5G5B5) : this((uint)bitmap.Width, (uint)bitmap.Height, pixelFormat)
 {
     using (MemoryStream outStream = new MemoryStream()) {
         BitmapEncoder enc = new BmpBitmapEncoder();
         enc.Frames.Add(BitmapFrame.Create(bitmap));
         enc.Save(outStream);
         var _bitmap = new Bitmap(outStream);
         CreateFromBitmap(_bitmap);
     }
 }
示例#8
0
 internal BitmapSurface(Bitmap bitmap, PixelFormat pixelFormat = PixelFormat.Bpp16A1R5G5B5) : this((ushort)bitmap.Width, (ushort)bitmap.Height, pixelFormat)
 {
     CreateFromBitmap(bitmap);
 }