@@ -148,10 +148,18 @@ defmodule Scenic.Utilities.Texture do
148
148
149
149
# --------------------------------------------------------
150
150
def get ( texture , x , y )
151
- def get ( { :g , w , h , p , _ } , x , y ) when x <= w and y <= h , do: nif_get_g ( p , y * w + x )
152
- def get ( { :ga , w , h , p , _ } , x , y ) when x <= w and y <= h , do: nif_get_ga ( p , y * w + x )
153
- def get ( { :rgb , w , h , p , _ } , x , y ) when x <= w and y <= h , do: nif_get_rgb ( p , y * w + x )
154
- def get ( { :rgba , w , h , p , _ } , x , y ) when x <= w and y <= h , do: nif_get_rgba ( p , y * w + x )
151
+
152
+ def get ( { :g , w , h , p , _ } , x , y ) when x >= 0 and x <= w and y >= 0 and y <= h ,
153
+ do: nif_get_g ( p , y * w + x )
154
+
155
+ def get ( { :ga , w , h , p , _ } , x , y ) when x >= 0 and x <= w and y >= 0 and y <= h ,
156
+ do: nif_get_ga ( p , y * w + x )
157
+
158
+ def get ( { :rgb , w , h , p , _ } , x , y ) when x >= 0 and x <= w and y >= 0 and y <= h ,
159
+ do: nif_get_rgb ( p , y * w + x )
160
+
161
+ def get ( { :rgba , w , h , p , _ } , x , y ) when x >= 0 and x <= w and y >= 0 and y <= h ,
162
+ do: nif_get_rgba ( p , y * w + x )
155
163
156
164
defp nif_get_g ( _ , _ ) , do: :erlang . nif_error ( "Did not find nif_get_g" )
157
165
defp nif_get_ga ( _ , _ ) , do: :erlang . nif_error ( "Did not find nif_get_ga" )
@@ -161,25 +169,25 @@ defmodule Scenic.Utilities.Texture do
161
169
# --------------------------------------------------------
162
170
def put! ( texture , x , y , color )
163
171
164
- def put! ( { :g , w , h , p , hints } , x , y , color ) when x <= w and y <= h do
172
+ def put! ( { :g , w , h , p , hints } , x , y , color ) when x >= 0 and x <= w and y >= 0 and y <= h do
165
173
g = prep_color ( :g , color )
166
174
nif_put ( p , y * w + x , g )
167
175
{ :g , w , h , p , hints }
168
176
end
169
177
170
- def put! ( { :ga , w , h , p , hints } , x , y , color ) when x <= w and y <= h do
178
+ def put! ( { :ga , w , h , p , hints } , x , y , color ) when x >= 0 and x <= w and y >= 0 and y <= h do
171
179
{ g , a } = prep_color ( :ga , color )
172
180
nif_put ( p , y * w + x , g , a )
173
181
{ :ga , w , h , p , hints }
174
182
end
175
183
176
- def put! ( { :rgb , w , h , p , hints } , x , y , color ) when x <= w and y <= h do
184
+ def put! ( { :rgb , w , h , p , hints } , x , y , color ) when x >= 0 and x <= w and y >= 0 and y <= h do
177
185
{ r , g , b } = prep_color ( :rgb , color )
178
186
nif_put ( p , y * w + x , r , g , b )
179
187
{ :rgb , w , h , p , hints }
180
188
end
181
189
182
- def put! ( { :rgba , w , h , p , hints } , x , y , color ) when x <= w and y <= h do
190
+ def put! ( { :rgba , w , h , p , hints } , x , y , color ) when x >= 0 and x <= w and y >= 0 and y <= h do
183
191
{ r , g , b , a } = Color . to_rgba ( color )
184
192
nif_put ( p , y * w + x , r , g , b , a )
185
193
{ :rgba , w , h , p , hints }
0 commit comments