colorm.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright 2014 Hajime Hoshi
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ebiten
  15. import (
  16. "image/color"
  17. "github.com/hajimehoshi/ebiten/v2/internal/affine"
  18. )
  19. // ColorMDim is the dimension of a ColorM.
  20. //
  21. // Deprecated: as of v2.5. Use the colorm package instead.
  22. const ColorMDim = affine.ColorMDim
  23. // A ColorM represents a matrix to transform coloring when rendering an image.
  24. //
  25. // A ColorM is applied to the straight alpha color
  26. // while an Image's pixels' format is alpha premultiplied.
  27. // Before applying a matrix, a color is un-multiplied, and after applying the matrix,
  28. // the color is multiplied again.
  29. //
  30. // The initial value is identity.
  31. //
  32. // Deprecated: as of v2.5. Use the colorm package instead.
  33. type ColorM struct {
  34. impl affine.ColorM
  35. _ [0]func() // Marks as non-comparable.
  36. }
  37. func (c *ColorM) affineColorM() affine.ColorM {
  38. if c.impl != nil {
  39. return c.impl
  40. }
  41. return affine.ColorMIdentity{}
  42. }
  43. // String returns a string representation of ColorM.
  44. //
  45. // Deprecated: as of v2.5. Use the colorm package instead.
  46. func (c *ColorM) String() string {
  47. return c.affineColorM().String()
  48. }
  49. // Reset resets the ColorM as identity.
  50. //
  51. // Deprecated: as of v2.5. Use the colorm package instead.
  52. func (c *ColorM) Reset() {
  53. c.impl = affine.ColorMIdentity{}
  54. }
  55. // Apply pre-multiplies a vector (r, g, b, a, 1) by the matrix
  56. // where r, g, b, and a are clr's values in straight-alpha format.
  57. // In other words, Apply calculates ColorM * (r, g, b, a, 1)^T.
  58. //
  59. // Deprecated: as of v2.5. Use the colorm package instead.
  60. func (c *ColorM) Apply(clr color.Color) color.Color {
  61. return c.affineColorM().Apply(clr)
  62. }
  63. // Concat multiplies a color matrix with the other color matrix.
  64. // This is same as multiplying the matrix other and the matrix c in this order.
  65. //
  66. // Deprecated: as of v2.5. Use the colorm package instead.
  67. func (c *ColorM) Concat(other ColorM) {
  68. o := other.impl
  69. if o == nil {
  70. return
  71. }
  72. c.impl = c.affineColorM().Concat(o)
  73. }
  74. // Scale scales the matrix by (r, g, b, a).
  75. //
  76. // Deprecated: as of v2.5. Use ColorScale or the colorm package instead.
  77. func (c *ColorM) Scale(r, g, b, a float64) {
  78. c.impl = c.affineColorM().Scale(float32(r), float32(g), float32(b), float32(a))
  79. }
  80. // ScaleWithColor scales the matrix by clr.
  81. //
  82. // Deprecated: as of v2.5. Use ColorScale or the colorm package instead.
  83. func (c *ColorM) ScaleWithColor(clr color.Color) {
  84. cr, cg, cb, ca := clr.RGBA()
  85. if ca == 0 {
  86. c.Scale(0, 0, 0, 0)
  87. return
  88. }
  89. c.Scale(float64(cr)/float64(ca), float64(cg)/float64(ca), float64(cb)/float64(ca), float64(ca)/0xffff)
  90. }
  91. // Translate translates the matrix by (r, g, b, a).
  92. //
  93. // Deprecated: as of v2.5. Use the colorm package instead.
  94. func (c *ColorM) Translate(r, g, b, a float64) {
  95. c.impl = c.affineColorM().Translate(float32(r), float32(g), float32(b), float32(a))
  96. }
  97. // RotateHue rotates the hue.
  98. // theta represents rotating angle in radian.
  99. //
  100. // Deprecated: as of v2.5. Use the colorm package instead.
  101. func (c *ColorM) RotateHue(theta float64) {
  102. c.ChangeHSV(theta, 1, 1)
  103. }
  104. // ChangeHSV changes HSV (Hue-Saturation-Value) values.
  105. // hueTheta is a radian value to rotate hue.
  106. // saturationScale is a value to scale saturation.
  107. // valueScale is a value to scale value (a.k.a. brightness).
  108. //
  109. // This conversion uses RGB to/from YCrCb conversion.
  110. //
  111. // Deprecated: as of v2.5. Use the colorm package instead.
  112. func (c *ColorM) ChangeHSV(hueTheta float64, saturationScale float64, valueScale float64) {
  113. c.impl = affine.ChangeHSV(c.affineColorM(), hueTheta, float32(saturationScale), float32(valueScale))
  114. }
  115. // Element returns a value of a matrix at (i, j).
  116. //
  117. // Deprecated: as of v2.5. Use the colorm package instead.
  118. func (c *ColorM) Element(i, j int) float64 {
  119. return float64(c.affineColorM().At(i, j))
  120. }
  121. // SetElement sets an element at (i, j).
  122. //
  123. // Deprecated: as of v2.5. Use the colorm package instead.
  124. func (c *ColorM) SetElement(i, j int, element float64) {
  125. c.impl = affine.ColorMSetElement(c.affineColorM(), i, j, float32(element))
  126. }
  127. // IsInvertible returns a boolean value indicating
  128. // whether the matrix c is invertible or not.
  129. //
  130. // Deprecated: as of v2.5. Use the colorm package instead.
  131. func (c *ColorM) IsInvertible() bool {
  132. return c.affineColorM().IsInvertible()
  133. }
  134. // Invert inverts the matrix.
  135. // If c is not invertible, Invert panics.
  136. //
  137. // Deprecated: as of v2.5. Use the colorm package instead.
  138. func (c *ColorM) Invert() {
  139. c.impl = c.affineColorM().Invert()
  140. }