ColorMatrix.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // System.Drawing.Imaging.ColorMatrix.cs
  3. //
  4. // Authors:
  5. // Everaldo Canuto ([email protected])
  6. // Andreas Nahr ([email protected])
  7. // Dennis Hayes ([email protected])
  8. //
  9. // (C) 2002 Ximian, Inc. http://www.ximian.com
  10. //
  11. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System;
  34. namespace System.Drawing.Imaging {
  35. public sealed class ColorMatrix {
  36. private float[] colors;
  37. // constructors
  38. public ColorMatrix()
  39. {
  40. colors = new float[25];
  41. // Set identity matrix by default
  42. colors[0] = 1;
  43. colors[6] = 1;
  44. colors[12] = 1;
  45. colors[18] = 1;
  46. colors[24] = 1;
  47. }
  48. [CLSCompliant(false)]
  49. public ColorMatrix(float[][] newColorMatrix)
  50. {
  51. colors = new float[25];
  52. for (int x = 0; x < 5; x++) {
  53. for (int y = 0; y < 5; y++) {
  54. colors[x * 5 + y] = newColorMatrix[x][y];
  55. }
  56. }
  57. }
  58. // properties
  59. public float this[int row, int column] {
  60. get { return colors[row * 5 + column]; }
  61. set { colors[row * 5 + column] = value; }
  62. }
  63. public float Matrix00 {
  64. get { return colors[0]; }
  65. set { colors[0] = value; }
  66. }
  67. public float Matrix01 {
  68. get { return colors[1]; }
  69. set { colors[1] = value; }
  70. }
  71. public float Matrix02 {
  72. get { return colors[2]; }
  73. set { colors[2] = value; }
  74. }
  75. public float Matrix03 {
  76. get { return colors[3]; }
  77. set { colors[3] = value; }
  78. }
  79. public float Matrix04 {
  80. get { return colors[4]; }
  81. set { colors[4] = value; }
  82. }
  83. public float Matrix10 {
  84. get { return colors[5]; }
  85. set { colors[5] = value; }
  86. }
  87. public float Matrix11 {
  88. get { return colors[6]; }
  89. set { colors[6] = value; }
  90. }
  91. public float Matrix12 {
  92. get { return colors[7]; }
  93. set { colors[7] = value; }
  94. }
  95. public float Matrix13 {
  96. get { return colors[8]; }
  97. set { colors[8] = value; }
  98. }
  99. public float Matrix14 {
  100. get { return colors[9]; }
  101. set { colors[9] = value; }
  102. }
  103. public float Matrix20 {
  104. get { return colors[10]; }
  105. set { colors[10] = value; }
  106. }
  107. public float Matrix21 {
  108. get { return colors[11]; }
  109. set { colors[11] = value; }
  110. }
  111. public float Matrix22 {
  112. get { return colors[12]; }
  113. set { colors[12] = value; }
  114. }
  115. public float Matrix23 {
  116. get { return colors[13]; }
  117. set { colors[13] = value; }
  118. }
  119. public float Matrix24 {
  120. get { return colors[14]; }
  121. set { colors[14] = value; }
  122. }
  123. public float Matrix30 {
  124. get { return colors[15]; }
  125. set { colors[15] = value; }
  126. }
  127. public float Matrix31 {
  128. get { return colors[16]; }
  129. set { colors[16] = value; }
  130. }
  131. public float Matrix32 {
  132. get { return colors[17]; }
  133. set { colors[17] = value; }
  134. }
  135. public float Matrix33 {
  136. get { return colors[18]; }
  137. set { colors[18] = value; }
  138. }
  139. public float Matrix34 {
  140. get { return colors[19]; }
  141. set { colors[19] = value; }
  142. }
  143. public float Matrix40 {
  144. get { return colors[20]; }
  145. set { colors[20] = value; }
  146. }
  147. public float Matrix41 {
  148. get { return colors[21]; }
  149. set { colors[21] = value; }
  150. }
  151. public float Matrix42 {
  152. get { return colors[22]; }
  153. set { colors[22] = value; }
  154. }
  155. public float Matrix43 {
  156. get { return colors[23]; }
  157. set { colors[23] = value; }
  158. }
  159. public float Matrix44 {
  160. get { return colors[24]; }
  161. set { colors[24] = value; }
  162. }
  163. }
  164. }