@@ -57,4 +57,169 @@ class GrayscaleModifier : DrawModifier {
5757 }
5858 }
5959}
60+
61+ class BrightnessModifier : DrawModifier {
62+ let amount : Double
63+
64+ init ( amount: Double ) {
65+ self . amount = amount
66+ }
67+
68+ // SKIP DECLARE: override fun ContentDrawScope.draw()
69+ override func draw( ) {
70+ // Brightness adjustment: shift RGB values by amount * 255
71+ // amount: -1.0 (black) to 1.0 (white), 0.0 = no change
72+ let shift = Float ( amount * 255.0 )
73+ let brightnessMatrix = ColorMatrix ( floatArrayOf (
74+ Float ( 1 ) , Float ( 0 ) , Float ( 0 ) , Float ( 0 ) , shift,
75+ Float ( 0 ) , Float ( 1 ) , Float ( 0 ) , Float ( 0 ) , shift,
76+ Float ( 0 ) , Float ( 0 ) , Float ( 1 ) , Float ( 0 ) , shift,
77+ Float ( 0 ) , Float ( 0 ) , Float ( 0 ) , Float ( 1 ) , Float ( 0 )
78+ ) )
79+ let brightnessFilter = ColorFilter . colorMatrix ( brightnessMatrix)
80+ let paint = Paint ( ) . apply {
81+ colorFilter = brightnessFilter
82+ }
83+ drawIntoCanvas {
84+ $0. saveLayer ( Rect ( Float ( 0.0 ) , Float ( 0.0 ) , size. width, size. height) , paint)
85+ drawContent ( )
86+ $0. restore ( )
87+ }
88+ }
89+ }
90+
91+ class ContrastModifier : DrawModifier {
92+ let amount : Double
93+
94+ init ( amount: Double ) {
95+ self . amount = amount
96+ }
97+
98+ // SKIP DECLARE: override fun ContentDrawScope.draw()
99+ override func draw( ) {
100+ // Contrast adjustment: scale RGB around 0.5 (128)
101+ // amount: 0.0 = gray, 1.0 = no change, >1.0 = increased contrast
102+ let scale = Float ( amount)
103+ let translate = Float ( ( 1.0 - amount) * 127.5 )
104+ let contrastMatrix = ColorMatrix ( floatArrayOf (
105+ scale, Float ( 0 ) , Float ( 0 ) , Float ( 0 ) , translate,
106+ Float ( 0 ) , scale, Float ( 0 ) , Float ( 0 ) , translate,
107+ Float ( 0 ) , Float ( 0 ) , scale, Float ( 0 ) , translate,
108+ Float ( 0 ) , Float ( 0 ) , Float ( 0 ) , Float ( 1 ) , Float ( 0 )
109+ ) )
110+ let contrastFilter = ColorFilter . colorMatrix ( contrastMatrix)
111+ let paint = Paint ( ) . apply {
112+ colorFilter = contrastFilter
113+ }
114+ drawIntoCanvas {
115+ $0. saveLayer ( Rect ( Float ( 0.0 ) , Float ( 0.0 ) , size. width, size. height) , paint)
116+ drawContent ( )
117+ $0. restore ( )
118+ }
119+ }
120+ }
121+
122+ class SaturationModifier : DrawModifier {
123+ let amount : Double
124+
125+ init ( amount: Double ) {
126+ self . amount = amount
127+ }
128+
129+ // SKIP DECLARE: override fun ContentDrawScope.draw()
130+ override func draw( ) {
131+ // Saturation: 0.0 = grayscale, 1.0 = no change, >1.0 = oversaturated
132+ let saturationMatrix = ColorMatrix ( ) . apply { setToSaturation ( Float ( amount) ) }
133+ let saturationFilter = ColorFilter . colorMatrix ( saturationMatrix)
134+ let paint = Paint ( ) . apply {
135+ colorFilter = saturationFilter
136+ }
137+ drawIntoCanvas {
138+ $0. saveLayer ( Rect ( Float ( 0.0 ) , Float ( 0.0 ) , size. width, size. height) , paint)
139+ drawContent ( )
140+ $0. restore ( )
141+ }
142+ }
143+ }
144+
145+ class HueRotationModifier : DrawModifier {
146+ let degrees : Double
147+
148+ init ( degrees: Double ) {
149+ self . degrees = degrees
150+ }
151+
152+ // SKIP DECLARE: override fun ContentDrawScope.draw()
153+ override func draw( ) {
154+ // Hue rotation using ColorMatrix
155+ let radians = Float ( degrees * Double. pi / 180.0 )
156+ let cos = kotlin. math. cos ( radians)
157+ let sin = kotlin. math. sin ( radians)
158+
159+ // Hue rotation matrix derived from rotation around the (1,1,1) axis in RGB space
160+ let lumR = Float ( 0.213 )
161+ let lumG = Float ( 0.715 )
162+ let lumB = Float ( 0.072 )
163+
164+ let hueMatrix = ColorMatrix ( floatArrayOf (
165+ lumR + cos * ( Float ( 1 ) - lumR) + sin * ( - lumR) ,
166+ lumG + cos * ( - lumG) + sin * ( - lumG) ,
167+ lumB + cos * ( - lumB) + sin * ( Float ( 1 ) - lumB) ,
168+ Float ( 0 ) , Float ( 0 ) ,
169+
170+ lumR + cos * ( - lumR) + sin * Float( 0.143 ) ,
171+ lumG + cos * ( Float ( 1 ) - lumG) + sin * Float( 0.140 ) ,
172+ lumB + cos * ( - lumB) + sin * Float( - 0.283 ) ,
173+ Float ( 0 ) , Float ( 0 ) ,
174+
175+ lumR + cos * ( - lumR) + sin * ( - ( Float ( 1 ) - lumR) ) ,
176+ lumG + cos * ( - lumG) + sin * ( lumG) ,
177+ lumB + cos * ( Float ( 1 ) - lumB) + sin * ( lumB) ,
178+ Float ( 0 ) , Float ( 0 ) ,
179+
180+ Float ( 0 ) , Float ( 0 ) , Float ( 0 ) , Float ( 1 ) , Float ( 0 )
181+ ) )
182+ let hueFilter = ColorFilter . colorMatrix ( hueMatrix)
183+ let paint = Paint ( ) . apply {
184+ colorFilter = hueFilter
185+ }
186+ drawIntoCanvas {
187+ $0. saveLayer ( Rect ( Float ( 0.0 ) , Float ( 0.0 ) , Float ( size. width) , Float ( size. height) ) , paint)
188+ drawContent ( )
189+ $0. restore ( )
190+ }
191+ }
192+ }
193+
194+ class ColorMultiplyModifier : DrawModifier {
195+ let color : androidx . compose . ui . graphics . Color
196+
197+ init ( color: androidx . compose . ui . graphics . Color ) {
198+ self . color = color
199+ }
200+
201+ // SKIP DECLARE: override fun ContentDrawScope.draw()
202+ override func draw( ) {
203+ // Color multiply: multiply each channel by the corresponding color channel
204+ let r = color. red
205+ let g = color. green
206+ let b = color. blue
207+ let a = color. alpha
208+ let multiplyMatrix = ColorMatrix ( floatArrayOf (
209+ r, Float ( 0 ) , Float ( 0 ) , Float ( 0 ) , Float ( 0 ) ,
210+ Float ( 0 ) , g, Float ( 0 ) , Float ( 0 ) , Float ( 0 ) ,
211+ Float ( 0 ) , Float ( 0 ) , b, Float ( 0 ) , Float ( 0 ) ,
212+ Float ( 0 ) , Float ( 0 ) , Float ( 0 ) , a, Float ( 0 )
213+ ) )
214+ let multiplyFilter = ColorFilter . colorMatrix ( multiplyMatrix)
215+ let paint = Paint ( ) . apply {
216+ colorFilter = multiplyFilter
217+ }
218+ drawIntoCanvas {
219+ $0. saveLayer ( Rect ( Float ( 0.0 ) , Float ( 0.0 ) , size. width, size. height) , paint)
220+ drawContent ( )
221+ $0. restore ( )
222+ }
223+ }
224+ }
60225#endif
0 commit comments