ebiten/colorm.go

101 lines
3.1 KiB
Go
Raw Normal View History

// Copyright 2014 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2014-12-09 15:16:04 +01:00
2014-12-09 14:09:22 +01:00
package ebiten
import (
2016-10-31 16:13:19 +01:00
"github.com/hajimehoshi/ebiten/internal/affine"
2014-12-09 14:09:22 +01:00
)
// ColorMDim is a dimension of a ColorM.
2016-10-31 16:13:19 +01:00
const ColorMDim = affine.ColorMDim
// A ColorM represents a matrix to transform coloring when rendering an image.
//
// A ColorM is applied to the source alpha color
// while an Image's pixels' format is alpha premultiplied.
// Before applying a matrix, a color is un-multiplied, and after applying the matrix,
// the color is multiplied again.
2014-12-26 03:31:20 +01:00
//
// The initial value is identity.
type ColorM struct {
2016-10-31 16:13:19 +01:00
impl affine.ColorM
2014-12-09 14:09:22 +01:00
}
2014-12-14 14:05:44 +01:00
// Concat multiplies a color matrix with the other color matrix.
2016-02-15 15:08:10 +01:00
// This is same as muptiplying the matrix other and the matrix c in this order.
2014-12-29 11:04:18 +01:00
func (c *ColorM) Concat(other ColorM) {
2016-10-31 16:13:19 +01:00
c.impl.Concat(other.impl)
2014-12-09 14:09:22 +01:00
}
2014-12-25 20:22:06 +01:00
// Add adds a color matrix with the other color matrix.
2014-12-29 11:04:18 +01:00
func (c *ColorM) Add(other ColorM) {
2016-10-31 16:13:19 +01:00
c.impl.Add(other.impl)
2014-12-25 20:22:06 +01:00
}
2016-02-15 20:46:28 +01:00
// Scale scales the matrix by (r, g, b, a).
2015-01-03 10:35:44 +01:00
func (c *ColorM) Scale(r, g, b, a float64) {
2016-10-31 16:13:19 +01:00
c.impl.Scale(r, g, b, a)
2015-01-03 10:35:44 +01:00
}
2016-02-15 20:46:28 +01:00
// Translate translates the matrix by (r, g, b, a).
2015-01-03 10:35:44 +01:00
func (c *ColorM) Translate(r, g, b, a float64) {
2016-10-31 16:13:19 +01:00
c.impl.Translate(r, g, b, a)
2015-01-03 10:35:44 +01:00
}
2016-02-06 15:56:02 +01:00
// RotateHue rotates the hue.
func (c *ColorM) RotateHue(theta float64) {
2016-10-31 16:13:19 +01:00
c.impl.RotateHue(theta)
}
// ChangeHSV changes HSV (Hue-Saturation-Value) values.
// hueTheta is a radian value to ratate hue.
// saturationScale is a value to scale saturation.
// valueScale is a value to scale value (a.k.a. brightness).
//
// This conversion uses RGB to/from YCrCb conversion.
func (c *ColorM) ChangeHSV(hueTheta float64, saturationScale float64, valueScale float64) {
2016-10-31 16:13:19 +01:00
c.impl.ChangeHSV(hueTheta, saturationScale, valueScale)
2016-02-06 15:56:02 +01:00
}
2016-10-31 16:13:19 +01:00
// Element returns a value of a matrix at (i, j).
func (c *ColorM) Element(i, j int) float64 {
return c.impl.Element(i, j)
}
2016-10-31 16:13:19 +01:00
// SetElement sets an element at (i, j).
func (c *ColorM) SetElement(i, j int, value float64) {
c.impl.SetElement(i, j, value)
}
2014-12-14 14:24:17 +01:00
// Monochrome returns a color matrix to make an image monochrome.
func Monochrome() ColorM {
2016-10-31 16:13:19 +01:00
return ColorM{affine.Monochrome()}
2014-12-09 14:09:22 +01:00
}
2016-05-14 13:43:36 +02:00
// ScaleColor is deprecated as of 1.2.0-alpha. Use Scale instead.
func ScaleColor(r, g, b, a float64) ColorM {
2016-10-31 16:13:19 +01:00
return ColorM{affine.ScaleColor(r, g, b, a)}
}
2016-05-14 13:43:36 +02:00
// TranslateColor is deprecated as of 1.2.0-alpha. Use Translate instead.
func TranslateColor(r, g, b, a float64) ColorM {
2016-10-31 16:13:19 +01:00
return ColorM{affine.TranslateColor(r, g, b, a)}
}
2016-05-14 13:43:36 +02:00
// RotateHue is deprecated as of 1.2.0-alpha. Use RotateHue member function instead.
func RotateHue(theta float64) ColorM {
2016-10-31 16:13:19 +01:00
return ColorM{affine.RotateHue(theta)}
2014-12-14 17:45:41 +01:00
}