[Libreoffice-commits] .: 2 commits - android/Bootstrap android/experimental sal/android

Tor Lillqvist tml at kemper.freedesktop.org
Thu May 31 06:29:14 PDT 2012


 android/Bootstrap/src/org/libreoffice/android/Bootstrap.java                                 |    8 +
 android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java |   69 ++++++++--
 sal/android/lo-bootstrap.c                                                                   |   44 ++++++
 3 files changed, 114 insertions(+), 7 deletions(-)

New commits:
commit 8c803ef23294288001f9f1557c9777ffa3e5586e
Author: Tor Lillqvist <tlillqvist at suse.com>
Date:   Thu May 31 16:13:19 2012 +0300

    Display the rendered document
    
    Change-Id: Ie0735d4eb903b38a44bef8110bf520cfde54cb09

diff --git a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
index c39741e..0778ad9 100644
--- a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
+++ b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java
@@ -29,8 +29,13 @@
 package org.libreoffice.android.examples;
 
 import android.app.Activity;
+import android.graphics.Bitmap;
 import android.os.Bundle;
 import android.util.Log;
+import android.widget.ImageView;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 
 import com.sun.star.uno.UnoRuntime;
 
@@ -128,12 +133,18 @@ public class DocumentLoader
             Log.i(TAG, "  " + t.getTypeName());
     }
 
-    static void dumpBytes(byte[] image)
+    static void dumpBytes(String imageName, byte[] image)
     {
-        for (int i = 0; i < 160; i += 16) {
+        if (image == null) {
+            Log.i(TAG, imageName + " is null");
+            return;
+        }
+        Log.i(TAG, imageName + " is " + image.length + " bytes");
+
+        for (int i = 0; i < Math.min(image.length, 160); i += 16) {
             String s = "";
-            for (int j = 0; j < 16; j++)
-                s = s + String.format(" %02x", image[i+j]);
+            for (int j = i; j < Math.min(image.length, i+16); j++)
+                s = s + String.format(" %02x", image[j]);
 
             Log.i(TAG, s);
         }
@@ -202,13 +213,16 @@ public class DocumentLoader
             String[] inputs = input.split(":");
             for (int i = 0; i < inputs.length; i++) {
                 com.sun.star.beans.PropertyValue loadProps[] =
-                    new com.sun.star.beans.PropertyValue[2];
+                    new com.sun.star.beans.PropertyValue[3];
                 loadProps[0] = new com.sun.star.beans.PropertyValue();
                 loadProps[0].Name = "Hidden";
                 loadProps[0].Value = new Boolean(true);
                 loadProps[1] = new com.sun.star.beans.PropertyValue();
                 loadProps[1].Name = "ReadOnly";
                 loadProps[1].Value = new Boolean(true);
+                loadProps[2] = new com.sun.star.beans.PropertyValue();
+                loadProps[2].Name = "Preview";
+                loadProps[2].Value = new Boolean(true);
 
                 String sUrl = "file://" + inputs[i];
 
@@ -278,9 +292,50 @@ public class DocumentLoader
 
                 byte[] image = bitmap.getDIB();
 
-                Log.i(TAG, "image is " + image.length + " bytes");
+                dumpBytes("image", image);
+
+                byte[] mask = bitmap.getMaskDIB();
+
+                dumpBytes("mask", mask);
+
+                if (image[0] != 'B' || image[1] != 'M') {
+                    Log.e(TAG, "getDIB() didn't return a BMP file");
+                    return;
+                }
+
+                ByteBuffer imagebb = ByteBuffer.wrap(image);
+                imagebb.order(ByteOrder.LITTLE_ENDIAN);
+
+                if (imagebb.getInt(0x0e) != 40) {
+                    Log.e(TAG, "getDIB() didn't return a DIB with BITMAPINFOHEADER");
+                    return;
+                }
+
+                if (imagebb.getShort(0x1c) != 24) {
+                    Log.e(TAG, "getDIB() didn't return a 24 bpp DIB");
+                    return;
+                }
+
+                if (imagebb.getInt(0x1e) != 0) {
+                    Log.e(TAG, "getDIB() didn't return a BI_RGB DIB");
+                    return;
+                }
+
+                int width = imagebb.getInt(0x12);
+                int height = imagebb.getInt(0x16);
+
+                ByteBuffer argb = ByteBuffer.allocateDirect(width * height * 4);
+
+                Bootstrap.twiddle_BGR_to_RGBA(image, imagebb.getInt(0x0a), width, height, argb);
+
+                ImageView imageView = new ImageView(this);
+
+                Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+                bm.copyPixelsFromBuffer(argb);
+
+                imageView.setImageBitmap(bm);
 
-                dumpBytes(image);
+                setContentView(imageView);
             }
         }
         catch (Exception e) {
commit 9776138e973e22cfd4ae418782ab87d01335ad22
Author: Tor Lillqvist <tlillqvist at suse.com>
Date:   Thu May 31 16:11:44 2012 +0300

    Add a BGR to RGBA twiddling JNI function
    
    Change-Id: Iafa2c1805eea2f521479dc97d5668d82b1c91bef

diff --git a/android/Bootstrap/src/org/libreoffice/android/Bootstrap.java b/android/Bootstrap/src/org/libreoffice/android/Bootstrap.java
index 25fded8..47366a2 100644
--- a/android/Bootstrap/src/org/libreoffice/android/Bootstrap.java
+++ b/android/Bootstrap/src/org/libreoffice/android/Bootstrap.java
@@ -39,6 +39,7 @@ import fi.iki.tml.CommandLine;
 
 import java.io.File;
 import java.io.InputStream;
+import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Scanner;
 
@@ -108,6 +109,13 @@ public class Bootstrap extends NativeActivity
     // the Android logging mechanism, or stops the redirection.
     public static native boolean redirect_stdio(boolean state);
 
+    // The DIB returned by css.awt.XBitmap.getDIB is in BGR_888 form, at least
+    // for Writer documents. We need it in Android's Bitmap.Config.ARGB_888
+    // format, which actually is RGBA_888, whee... At least in Android 4.0.3,
+    // at least on my device. No idea if it is always like that or not, the
+    // documentation sucks.
+    public static native void twiddle_BGR_to_RGBA(byte[] source, int offset, int width, int height, ByteBuffer destination);
+
     // This setup() method is called 1) in apps that use *this* class as their activity from onCreate(),
     // and 2) should be called from other kinds of LO code using apps.
     public static void setup(Activity activity)
diff --git a/sal/android/lo-bootstrap.c b/sal/android/lo-bootstrap.c
index 9adadef..fed7a4d 100644
--- a/sal/android/lo-bootstrap.c
+++ b/sal/android/lo-bootstrap.c
@@ -1862,6 +1862,50 @@ Java_org_libreoffice_android_Bootstrap_redirect_1stdio(JNIEnv* env,
 }
 
 __attribute__ ((visibility("default")))
+void
+Java_org_libreoffice_android_Bootstrap_twiddle_1BGR_1to_1RGBA(JNIEnv* env,
+                                                              jobject clazz,
+                                                              jbyteArray source,
+                                                              jint offset,
+                                                              jint width,
+                                                              jint height,
+                                                              jobject destination)
+{
+    jbyte *dst = (jbyte*) (*env)->GetDirectBufferAddress(env, destination);
+    void *a = (*env)->GetPrimitiveArrayCritical(env, source, NULL);
+    jbyte *src = ((jbyte *) a) + offset;
+
+    jbyte *srcp;
+    jbyte *dstp = dst;
+    int step = ((((width * 3) - 1) / 4) + 1) * 4;
+
+    int i, j;
+
+    (void) clazz;
+
+    if (height > 0) {
+        srcp = src + step * (height - 1);
+        step = -step;
+    } else {
+        srcp = src;
+    }
+
+    LOGI("twiddle: src=%p, srcp=%p, dstp=%p, step=%d", src, srcp, dstp, step);
+
+    for (i = 0; i < height; i++) {
+        for (j = 0; j < width; j++) {
+            *dstp++ = srcp[j*3+2];
+            *dstp++ = srcp[j*3+1];
+            *dstp++ = srcp[j*3+0];
+            *dstp++ = 0xFF;
+        }
+        srcp += step;
+    }
+
+    (*env)->ReleasePrimitiveArrayCritical(env, source, a, 0);
+}
+
+__attribute__ ((visibility("default")))
 JavaVM *
 lo_get_javavm(void)
 {


More information about the Libreoffice-commits mailing list