PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/base/Drivers/S3Trio64/BitmapFileHeader.cs

#
C# | 62 lines | 46 code | 6 blank | 10 comment | 3 complexity | dba1020efaa431e413646d3d3217168b MD5 | raw file
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Research Singularity
  4. //
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. //
  7. // File: BitmapFileHeader.cs
  8. //
  9. // Note:
  10. //
  11. #define BUG
  12. using System;
  13. using System.Runtime.InteropServices;
  14. using Microsoft.SingSharp;
  15. using Microsoft.Singularity;
  16. using Microsoft.Singularity.Channels;
  17. namespace Microsoft.Singularity.Io
  18. {
  19. #if BUG
  20. [CLSCompliant(false)]
  21. [StructLayout(LayoutKind.Explicit)]
  22. public pointerfree struct BITMAPFILEHEADER {
  23. [FieldOffset( 0)] public ushort bfType;
  24. [FieldOffset( 2)] public uint bfSize;
  25. [FieldOffset( 6)] public ushort bfReserved1;
  26. [FieldOffset( 8)] public ushort bfReserved2;
  27. [FieldOffset(10)] public int bfOffBits;
  28. #else
  29. [CLSCompliant(false)]
  30. [StructLayout(LayoutKind.Sequential, Pack=2)]
  31. public pointerfree struct BITMAPFILEHEADER {
  32. public ushort bfType;
  33. public uint bfSize;
  34. public ushort bfReserved1;
  35. public ushort bfReserved2;
  36. public int bfOffBits;
  37. #endif
  38. public static BITMAPFILEHEADER Read(byte[]! in ExHeap buffer,
  39. int offset, out int used)
  40. {
  41. if (buffer == null || offset < 0 ||
  42. offset + sizeof(BITMAPFILEHEADER) > buffer.Length) {
  43. unchecked {
  44. Tracing.Log(Tracing.Error,
  45. "BITMAPFILEHEADER Read(offset={0}, length={1})",
  46. (UIntPtr)(uint)offset,
  47. (UIntPtr)(uint)buffer.Length);
  48. }
  49. throw new OverflowException("Read source invalid.");
  50. }
  51. used = offset + /*sizeof(BITMAPFILEHEADER)*/ 14;
  52. ref BITMAPFILEHEADER bmfh = ref buffer[offset];
  53. return bmfh;
  54. }
  55. }
  56. } // namespace Microsoft.Singularity.Io