From 3a4db8a878273c2ef20b318f022fed6092cbca60 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 21 Nov 2013 22:37:32 +0300 Subject: [PATCH] [yopme] Fixed transform from GL pixel format to Java Bitmap. --- .../mapswithme/yopme/BackscreenActivity.java | 4 +- .../mapswithme/yopme/map/MapDataProvider.java | 5 ++- .../com/mapswithme/yopme/map/MapRenderer.java | 11 +++-- .../mapswithme/yopme/util/PixelBuffer.java | 40 ++++++++++++++----- map/yopme_render_policy.cpp | 4 +- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java b/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java index 25b18dd5fe..ab20870fdc 100644 --- a/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java +++ b/android/YoPme/src/com/mapswithme/yopme/BackscreenActivity.java @@ -402,11 +402,11 @@ public class BackscreenActivity extends BSActivity implements LocationListener return; } - data = mMapDataProvider.getMapData(getLocation(), mZoomLevel, null, getLocation()); + data = mMapDataProvider.getMapData(this, getLocation(), mZoomLevel, null, getLocation()); } else if (mMode == Mode.POI) { - data = mMapDataProvider.getMapData(mPoint, mZoomLevel, mIsPoi ? mPoint : null, getLocation()); + data = mMapDataProvider.getMapData(this, mPoint, mZoomLevel, mIsPoi ? mPoint : null, getLocation()); calculateDistance(); } diff --git a/android/YoPme/src/com/mapswithme/yopme/map/MapDataProvider.java b/android/YoPme/src/com/mapswithme/yopme/map/MapDataProvider.java index f24c05a2c6..006c6c4b4d 100644 --- a/android/YoPme/src/com/mapswithme/yopme/map/MapDataProvider.java +++ b/android/YoPme/src/com/mapswithme/yopme/map/MapDataProvider.java @@ -1,5 +1,7 @@ package com.mapswithme.yopme.map; +import android.content.Context; + import com.mapswithme.yopme.PoiPoint; @@ -10,5 +12,6 @@ public interface MapDataProvider public final static double ZOOM_DEFAULT = 11; public final static double COMFORT_ZOOM = 17; - MapData getMapData(PoiPoint viewPortCenter, double zoom, PoiPoint poi, PoiPoint myLocation); + MapData getMapData(Context context, PoiPoint viewPortCenter, + double zoom, PoiPoint poi, PoiPoint myLocation); } diff --git a/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java b/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java index 8140b1ff19..e8fc02954f 100644 --- a/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java +++ b/android/YoPme/src/com/mapswithme/yopme/map/MapRenderer.java @@ -1,10 +1,13 @@ package com.mapswithme.yopme.map; +import android.content.Context; import android.graphics.Bitmap; + import com.mapswithme.yopme.PoiPoint; import com.mapswithme.yopme.map.MwmFilesObserver.EventType; import com.mapswithme.yopme.map.MwmFilesObserver.MwmFilesListener; import com.mapswithme.yopme.util.PixelBuffer; +import com.yotadevices.sdk.utils.BitmapUtils; public class MapRenderer implements MapDataProvider, MwmFilesListener { @@ -38,7 +41,8 @@ public class MapRenderer implements MapDataProvider, MwmFilesListener } @Override - public MapData getMapData(PoiPoint viewPortCenter, double zoom, PoiPoint poi, PoiPoint myLocation) + public MapData getMapData(Context context, PoiPoint viewPortCenter, + double zoom, PoiPoint poi, PoiPoint myLocation) { synchronized (MapRenderer.class) { @@ -59,7 +63,8 @@ public class MapRenderer implements MapDataProvider, MwmFilesListener hasPoi, poiLat, poiLon, hasLocation, myLat, myLon)) { - final Bitmap bmp = mPixelBuffer.readBitmap(); + Bitmap bmp = mPixelBuffer.readBitmap(); + bmp = BitmapUtils.prepareImageForBS(context, bmp); mPixelBuffer.detachFromThread(); return new MapData(bmp, poi); } @@ -69,7 +74,7 @@ public class MapRenderer implements MapDataProvider, MwmFilesListener } - private native void nativeCreateFramework (int width, int height); + private native void nativeCreateFramework(int width, int height); private native boolean nativeRenderMap(double vpLat, double vpLon, double zoom, boolean hasPoi, double poiLat, double poiLon, diff --git a/android/YoPme/src/com/mapswithme/yopme/util/PixelBuffer.java b/android/YoPme/src/com/mapswithme/yopme/util/PixelBuffer.java index 2fa5d3312c..982dd2707e 100644 --- a/android/YoPme/src/com/mapswithme/yopme/util/PixelBuffer.java +++ b/android/YoPme/src/com/mapswithme/yopme/util/PixelBuffer.java @@ -4,7 +4,14 @@ import java.nio.IntBuffer; import java.util.Arrays; import java.util.Comparator; +import javax.microedition.khronos.opengles.GL10; + import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.ColorMatrix; +import android.graphics.ColorMatrixColorFilter; +import android.graphics.Matrix; +import android.graphics.Paint; import android.opengl.EGL14; import android.opengl.EGLConfig; import android.opengl.EGLContext; @@ -127,19 +134,30 @@ public class PixelBuffer GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); Log.d(TAG, "Read bitmap. Width = " + mWidth + ", Heigth = " + mHeight); - IntBuffer ib = IntBuffer.allocate(mWidth * mHeight); - GLES20.glReadPixels(0, 0, mWidth, mHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib); - // Convert upside down mirror-reversed image to right-side up normal image. - final IntBuffer ibt = IntBuffer.allocate(ib.capacity()); - for (int i = 0; i < mHeight; ++i) - for (int j = 0; j < mWidth; ++j) - ibt.put((mHeight-i-1)*mWidth + j, ib.get(i*mWidth + j)); + int b[] = new int[mWidth * mHeight]; + IntBuffer ib = IntBuffer.wrap(b); + ib.position(0); + GLES20.glReadPixels(0, 0, mWidth, mHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib); + + Bitmap glbitmap = Bitmap.createBitmap(b, mWidth, mHeight, Bitmap.Config.ARGB_8888); + ib = null; // we're done with ib + b = null; // we're done with b, so allow the memory to be freed + + final float[] cmVals = { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; + + Paint paint = new Paint(); + paint.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(cmVals))); + + Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + canvas.drawBitmap(glbitmap, 0, 0, paint); + glbitmap = null; + + Matrix matrix = new Matrix(); + matrix.preScale(1.0f, -1.0f); + return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); - ib = null; - final Bitmap bmp = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888); - bmp.copyPixelsFromBuffer(ibt); - return bmp; } class ConfigSorter implements Comparator diff --git a/map/yopme_render_policy.cpp b/map/yopme_render_policy.cpp index 594143644b..ef36c9cb9c 100644 --- a/map/yopme_render_policy.cpp +++ b/map/yopme_render_policy.cpp @@ -199,7 +199,7 @@ void YopmeRP::DrawFrame(shared_ptr const & e, ScreenBase const & s) drawOverlay->merge(*overlay); - pScreen->applyStates(); + pScreen->applySharpStates(); pScreen->clear(m_bgColor, false); drawOverlay->draw(pScreen, math::Identity()); @@ -213,7 +213,7 @@ void YopmeRP::DrawFrame(shared_ptr const & e, ScreenBase const & s) BlitInfo info; info.m_srcSurface = renderTarget; info.m_srcRect = m2::RectI(0, 0, width, height); - info.m_texRect = m2::RectU(1, 1, width - 1, height - 1); + info.m_texRect = m2::RectU(0, 0, width, height); info.m_matrix = math::Identity(); pScreen->beginFrame();