Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2917

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/17/2917/1

fdo#62591 - change Impress remote slide previews building

* Store bitmaps directly instead of byte arrays.
* Store bitmaps with shadows instead of one set with shadows and another
  without them.

This change should optimize memory usage a bit.

Change-Id: Ied7ce57a660438a06167e8984d16a6f26ebd8c23
---
M android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java
M android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java
2 files changed, 26 insertions(+), 44 deletions(-)



diff --git a/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java 
b/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java
index 0aab5a6..8f1ba7d 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java
@@ -21,10 +21,7 @@
 import android.content.ServiceConnection;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
-import android.graphics.Canvas;
 import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.RectF;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.support.v4.content.LocalBroadcastManager;
@@ -38,7 +35,6 @@
 import android.widget.AdapterView.OnItemSelectedListener;
 import android.widget.ImageView;
 import android.widget.TextView;
-
 import com.actionbarsherlock.app.SherlockFragment;
 
 public class PresentationFragment extends SherlockFragment {
@@ -306,24 +302,7 @@
 
         @Override
         protected Bitmap createBitmap(int position) {
-            Bitmap aBitmap = mSlideShow.getImage(position);
-            final int borderWidth = 8;
-
-            Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
-            p.setShadowLayer(borderWidth, 0, 0, Color.BLACK);
-
-            RectF aRect = new RectF(borderWidth, borderWidth, borderWidth
-                            + aBitmap.getWidth(), borderWidth
-                            + aBitmap.getHeight());
-            Bitmap aOut = Bitmap.createBitmap(aBitmap.getWidth() + 2
-                            * borderWidth, aBitmap.getHeight() + 2
-                            * borderWidth, aBitmap.getConfig());
-            Canvas canvas = new Canvas(aOut);
-            canvas.drawColor(getResources().getColor(R.color.light_grey));
-            canvas.drawRect(aRect, p);
-            canvas.drawBitmap(aBitmap, null, aRect, null);
-
-            return aOut;
+            return mSlideShow.getImage(position);
         }
     }
 }
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java 
b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java
index 3925fe2..8b7a8e1 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java
@@ -9,17 +9,20 @@
 package org.libreoffice.impressremote.communication;
 
 import org.libreoffice.impressremote.R;
-import org.libreoffice.impressremote.Globals;
 
-import android.util.Log;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.RectF;
 import android.util.SparseArray;
+
 
 public class SlideShow {
 
-    private SparseArray<byte[]> mPreviewImages = new SparseArray<byte[]>();
+    private SparseArray<Bitmap> mPreviews = new SparseArray<Bitmap>();
     private SparseArray<String> mNotes = new SparseArray<String>();
 
     private int mSize = 0;
@@ -47,28 +50,28 @@
     }
 
     protected void putImage(int aSlide, byte[] aImage) {
-        mPreviewImages.put(aSlide, aImage);
+        Bitmap aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length);
+        final int borderWidth = 8;
+
+        Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
+        p.setShadowLayer(borderWidth, 0, 0, Color.BLACK);
+
+        RectF aRect = new RectF(borderWidth, borderWidth, borderWidth
+                        + aBitmap.getWidth(), borderWidth
+                        + aBitmap.getHeight());
+        Bitmap aOut = Bitmap.createBitmap(aBitmap.getWidth() + 2
+                        * borderWidth, aBitmap.getHeight() + 2
+                        * borderWidth, aBitmap.getConfig());
+        Canvas canvas = new Canvas(aOut);
+        canvas.drawColor(mContext.getResources().getColor(R.color.light_grey));
+        canvas.drawRect(aRect, p);
+        canvas.drawBitmap(aBitmap, null, aRect, null);
+
+        mPreviews.put(aSlide, aOut);
     }
 
     public Bitmap getImage(int aSlide) {
-        byte[] aImage = mPreviewImages.get(aSlide);
-        if (aImage == null) {
-            return BitmapFactory.decodeResource(mContext.getResources(),
-                            R.drawable.image_loading);
-        }
-        Bitmap aBitmap = null;
-        try {
-            aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length);
-        } catch (OutOfMemoryError e) {
-            Log.e(Globals.TAG, "Bitmap decoding error byte length: " + aImage.length +
-                  "first 4 bytes: " + aImage[0] + " " + aImage[1] + " " + aImage[2] + " " + 
aImage[3] +
-                  "Exception " + e);
-        }
-        if (aBitmap == null) {
-            return BitmapFactory.decodeResource(mContext.getResources(),
-                            R.drawable.image_loading);
-        }
-        return aBitmap;
+        return mPreviews.get(aSlide);
     }
 
     protected void putNotes(int aSlide, String aNotes) {

-- 
To view, visit https://gerrit.libreoffice.org/2917
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ied7ce57a660438a06167e8984d16a6f26ebd8c23
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Artur Dryomov <artur.dryomov@gmail.com>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.