Merge: doc: fixed some typos and other misc. corrections
[nit.git] / lib / gamnit / android19.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
15 # Variation using features from Android API 19
16 #
17 # Add support for `TextureAsset::premultiply_alpha = false` on Android.
18 module android19 is
19 android_api_min 19
20 android_api_target 22
21 end
22
23 import android
24 intrude import display_android
25 intrude import gamnit_android
26 intrude import android::load_image
27
28 in "Java" `{
29 import android.graphics.Bitmap;
30 import android.graphics.BitmapFactory;
31 `}
32
33 redef class TextureAsset
34
35 redef fun load_bitmap(asset_manager, path)
36 do
37 var stream = asset_manager.native_assets_manager.open(path.to_java_string)
38 return new NativeBitmap.from_stream_ex(stream, premultiply_alpha)
39 end
40 end
41
42 redef class NativeCByteArray
43
44 # The data was not premultiplied, don't unmultiply it
45 redef fun unmultiply(w, h) do end
46 end
47
48 redef class NativeBitmap
49
50 # Load from `input_stream` with optional `premultiply_alpha`
51 new from_stream_ex(input_stream: NativeInputStream, premultiply_alpha: Bool) in "Java" `{
52 BitmapFactory.Options opts = new BitmapFactory.Options();
53 opts.inPremultiplied = premultiply_alpha; // API 19
54 return BitmapFactory.decodeStream(input_stream, null, opts);
55 `}
56 end