Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

NativeMapView.addImage without copying bitmap into Java #11111

Merged
merged 2 commits into from
Feb 12, 2018

Conversation

tobrun
Copy link
Member

@tobrun tobrun commented Feb 2, 2018

Follow up from external PR in #11000. Capturing from @ivovandongen that the config validation part should be re-added:

    // Check/correct config
    if (image.getConfig() != Bitmap.Config.ARGB_8888) {
      image = image.copy(Bitmap.Config.ARGB_8888, false);
    }

cc @jaegs

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Feb 2, 2018
@tobrun tobrun added this to the android-v6.0.0 milestone Feb 2, 2018
@tobrun tobrun self-assigned this Feb 2, 2018
@jaegs
Copy link
Contributor

jaegs commented Feb 2, 2018

Maybe the validation part should go here:

if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
// TODO: convert
throw std::runtime_error("bitmap decoding: bitmap format invalid");
}

@tobrun
Copy link
Member Author

tobrun commented Feb 9, 2018

@jaegs you are right, will add the conversion on the c++ side.

@ivovandongen I tested image conversion with:

Bitmap bitmap = Bitmap.createBitmap(createColors(), WIDTH, HEIGHT, Bitmap.Config.RGB_565);
mapboxMap.addImage("image", bitmap);

GeoJsonSource geoJsonSource = new GeoJsonSource("source", Feature.fromGeometry(Point.fromCoordinates(new double[] {0, 0})));
mapboxMap.addSource(geoJsonSource);

SymbolLayer symbolLayer = new SymbolLayer("layer", "source");
symbolLayer.withProperties(iconImage("image"));
mapboxMap.addLayer(symbolLayer);

And I was able to debug that the conversion is happening as expected:

screen shot 2018-02-09 at 10 54 44

This resulted in:

screen shot 2018-02-09 at 10 56 11

@@ -128,5 +127,12 @@ PremultipliedImage Bitmap::GetImage(jni::JNIEnv& env, jni::Object<Bitmap> bitmap
return { Size{ info.width, info.height }, std::move(pixels) };
}

jni::Object<Bitmap> Bitmap::Copy(jni::JNIEnv& env, jni::Object<Bitmap> bitmap) {
using Signature = jni::Object<Bitmap>(jni::Object<Config>, jni::jboolean);
auto method = _class.GetMethod<Signature>(env, "copy");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be static to cache the method lookup

@tobrun
Copy link
Member Author

tobrun commented Feb 12, 2018

Could you re-review @ivovandongen? static keyword was added.

@tobrun tobrun merged commit ff747a8 into release-boba Feb 12, 2018
@tobrun tobrun deleted the tvn-add-image branch February 12, 2018 14:57
@tobrun tobrun mentioned this pull request Feb 13, 2018
23 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants