BitmapData.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // System.Drawing.Imaging.BitmapData.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected]
  6. //
  7. // (C) 2002 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Runtime.InteropServices;
  11. namespace System.Drawing.Imaging
  12. {
  13. [StructLayout(LayoutKind.Sequential)]
  14. public sealed class BitmapData {
  15. int width, height, stride;
  16. PixelFormat pixel_format;
  17. IntPtr address;
  18. int reserved;
  19. public int Height {
  20. get {
  21. return height;
  22. }
  23. set {
  24. height = value;
  25. }
  26. }
  27. public int Width {
  28. get {
  29. return width;
  30. }
  31. set {
  32. width = value;
  33. }
  34. }
  35. public PixelFormat PixelFormat {
  36. get {
  37. return pixel_format;
  38. }
  39. set {
  40. pixel_format = value;
  41. }
  42. }
  43. public int Reserved {
  44. get {
  45. return reserved;
  46. }
  47. set {
  48. reserved = value;
  49. }
  50. }
  51. public IntPtr Scan0 {
  52. get {
  53. return address;
  54. }
  55. set {
  56. address = value;
  57. }
  58. }
  59. public int Stride {
  60. get {
  61. return stride;
  62. }
  63. set {
  64. stride = value;
  65. }
  66. }
  67. internal unsafe void swap_red_blue_bytes ()
  68. {
  69. byte *start = (byte *) (void *) this.Scan0;
  70. int stride = this.Stride;
  71. for (int line = 0; line < this.Height; line++){
  72. // Exchange red <=> blue bytes
  73. // fixed (byte *pbuf = start) {
  74. byte* curByte = start;
  75. for (int i = 0; i < this.Width; i++) {
  76. byte t = *(curByte+2);
  77. *(curByte+2) = *curByte;
  78. *curByte = t;
  79. curByte += 3;
  80. }
  81. // }
  82. start += stride;
  83. }
  84. }
  85. }
  86. }