1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Variation using features from Android API 19
17 # Add support for `TextureAsset::premultiply_alpha = false` on Android.
24 intrude import display_android
25 intrude import android
::load_image
28 import android.graphics.Bitmap;
29 import android.graphics.BitmapFactory;
32 redef class TextureAsset
34 redef fun load_bitmap
(asset_manager
, path
)
36 var stream
= asset_manager
.native_assets_manager
.open
(path
.to_java_string
)
37 return new NativeBitmap.from_stream_ex
(stream
, premultiply_alpha
)
41 redef class NativeCByteArray
43 # The data was not premultiplied, don't unmultiply it
44 redef fun unmultiply
(w
, h
) do end
47 redef class NativeBitmap
49 # Load from `input_stream` with optional `premultiply_alpha`
50 new from_stream_ex
(input_stream
: NativeInputStream, premultiply_alpha
: Bool) in "Java" `{
51 BitmapFactory.Options opts = new BitmapFactory.Options();
52 opts.inPremultiplied = premultiply_alpha; // API 19
53 return BitmapFactory.decodeStream(input_stream, null, opts);