zxing with GWT

106 views
Skip to first unread message

onur

unread,
Jul 11, 2009, 9:38:43 AM7/11/09
to zxing
Is zxing translateable to GWT? How can I include core.jar file? Do I
have to create a new .gwt.xml file?

srowen

unread,
Jul 11, 2009, 9:49:37 AM7/11/09
to zxing
Hmm, meaning is the core code compatible with the subset of Java that
GWT understands? I haven't tried it, but expect that actually most or
all of it is. The problem is that you won't have any way to get an
image into the framework in GWT, I think. That would be interseting
though if one could decode in javascript.

If you look at zxing.appspot.com you will see an encoder that is
written with GWT. The encoding is not done directly there; it calls to
the Google Chart Server for that. You can see the source in the
project. Maybe that is a solution for you.

Onur Gündüz

unread,
Jul 11, 2009, 10:29:22 AM7/11/09
to zx...@googlegroups.com
srowen,

ImageIO class would be a problem, but I just want to use qrcode.Decoder class.
I think I have to make a new JAR which includes source code as well. Then
the source code must be inherited through a .gwt.xml file. But I actually don't know
how to achieve this exactly :)

I've looked at the example on appspot, they are not including the whole com.google.zxing
package. I think they simply extracted necessary code, and created new classes.
This is the only solution comes to my mind too, but an example of including whole,
or a portion of zxing package into a GWT app would be great...
--
Onur

Onur Gündüz

unread,
Jul 11, 2009, 2:26:49 PM7/11/09
to zx...@googlegroups.com
I tried to compile BitMatrix class. No luck.

Compiling module com.onurgunduz.qrdec.Qrdec
   Compiling 5 permutations
   Worker permutation 0 of 5
      [ERROR] An internal compiler exception occurred
com.google.gwt.dev.jjs.InternalCompilerException: Unexpected error during visit.
    at com.google.gwt.dev.jjs.ast.JVisitor.translateException(JVisitor.java:74)
    at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:136)
    at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:81)
    at com.google.gwt.dev.jjs.ast.JIfStatement.traverse(JIfStatement.java:51)
    at com.google.gwt.dev.jjs.ast.JModVisitor.acceptWithInsertRemove(JModVisitor.java:162)
    at com.google.gwt.dev.jjs.ast.JBlock.traverse(JBlock.java:36)
    at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:132)
    at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:94)
    at com.google.gwt.dev.jjs.ast.JForStatement.traverse(JForStatement.java:66)
    at com.google.gwt.dev.jjs.ast.JModVisitor.acceptWithInsertRemove(JModVisitor.java:162)
    at com.google.gwt.dev.jjs.ast.JBlock.traverse(JBlock.java:36)
    at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:132)
    at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:94)
    at com.google.gwt.dev.jjs.ast.JForStatement.traverse(JForStatement.java:66)
    at com.google.gwt.dev.jjs.ast.JModVisitor.acceptWithInsertRemove(JModVisitor.java:162)
    at com.google.gwt.dev.jjs.ast.JBlock.traverse(JBlock.java:36)
    at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:132)
    at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:94)
    at com.google.gwt.dev.jjs.ast.JMethodBody.traverse(JMethodBody.java:52)
    at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:132)
    at com.google.gwt.dev.jjs.ast.JMethod.traverse(JMethod.java:194)
    at com.google.gwt.dev.jjs.ast.JModVisitor.acceptWithInsertRemove(JModVisitor.java:162)
    at com.google.gwt.dev.jjs.ast.JClassType.traverse(JClassType.java:62)
    at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:146)
    at com.google.gwt.dev.jjs.ast.JProgram.traverse(JProgram.java:815)
    at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:132)
    at com.google.gwt.dev.jjs.impl.EqualityNormalizer.execImpl(EqualityNormalizer.java:198)
    at com.google.gwt.dev.jjs.impl.EqualityNormalizer.exec(EqualityNormalizer.java:187)
    at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.compilePermutation(JavaToJavaScriptCompiler.java:139)
    at com.google.gwt.dev.CompilePerms.compile(CompilePerms.java:181)
    at com.google.gwt.dev.ThreadedPermutationWorkerFactory$ThreadedPermutationWorker.compile(ThreadedPermutationWorkerFactory.java:47)
    at com.google.gwt.dev.PermutationWorkerFactory$Manager$WorkerThread.run(PermutationWorkerFactory.java:72)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: com.google.gwt.dev.jjs.ast.JPrimitiveType cannot be cast to com.google.gwt.dev.jjs.ast.JReferenceType
    at com.google.gwt.dev.jjs.impl.EqualityNormalizer$BreakupAssignOpsVisitor.endVisit(EqualityNormalizer.java:86)
    at com.google.gwt.dev.jjs.ast.JBinaryOperation.traverse(JBinaryOperation.java:79)
    at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:132)
    ... 31 more
         [ERROR] at Qrdec.java(20): source[k][v] == 1
            com.google.gwt.dev.jjs.ast.JBinaryOperation
         [ERROR] at Qrdec.java(20): if (source[k][v] == 1) {
  BitMatrix.$set(bits, k, v);
}
            com.google.gwt.dev.jjs.ast.JIfStatement
         [ERROR] at Qrdec.java(19): {
  if (source[k][v] == 1) {
    BitMatrix.$set(bits, k, v);
  }
}
            com.google.gwt.dev.jjs.ast.JBlock
         [ERROR] at Qrdec.java(18): for (int v = 0; v < dimension; ++v) {
  if (source[k][v] == 1) {
    BitMatrix.$set(bits, k, v);
  }
}
            com.google.gwt.dev.jjs.ast.JForStatement
         [ERROR] at Qrdec.java(17): {
  for (int v = 0; v < dimension; ++v) {
    if (source[k][v] == 1) {
      BitMatrix.$set(bits, k, v);
    }
  }
}
            com.google.gwt.dev.jjs.ast.JBlock
         [ERROR] at Qrdec.java(16): for (int k = 0; k < dimension; ++k) {
  for (int v = 0; v < dimension; ++v) {
    if (source[k][v] == 1) {
      BitMatrix.$set(bits, k, v);
    }
  }
}
            com.google.gwt.dev.jjs.ast.JForStatement
         [ERROR] at Qrdec.java(11): {
  final int dimension = null.nullField;
  final BitMatrix bits = BitMatrix.$BitMatrix(new BitMatrix(), dimension);
  for (int k = 0; k < dimension; ++k) {
    for (int v = 0; v < dimension; ++v) {
      if (source[k][v] == 1) {
        BitMatrix.$set(bits, k, v);
      }
    }
  }
  AbsolutePanel.$add(RootPanel.get("resultView"), HTML.$HTML(new HTML(), "<h4>Decoded string:</h4>"));
  AbsolutePanel.$add(RootPanel.get("resultView"), HTML.$HTML(new HTML(), "<p> -  - </p>"));
}
            com.google.gwt.dev.jjs.ast.JBlock
         [ERROR] at Qrdec.java(11): {
  final int dimension = null.nullField;
  final BitMatrix bits = BitMatrix.$BitMatrix(new BitMatrix(), dimension);
  for (int k = 0; k < dimension; ++k) {
    for (int v = 0; v < dimension; ++v) {
      if (source[k][v] == 1) {
        BitMatrix.$set(bits, k, v);
      }
    }
  }
  AbsolutePanel.$add(RootPanel.get("resultView"), HTML.$HTML(new HTML(), "<h4>Decoded string:</h4>"));
  AbsolutePanel.$add(RootPanel.get("resultView"), HTML.$HTML(new HTML(), "<p> -  - </p>"));
}
            com.google.gwt.dev.jjs.ast.JMethodBody
         [ERROR] at Qrdec.java(11): private static final void decodeQR(<null> source);

            com.google.gwt.dev.jjs.ast.JMethod
         [ERROR] at Qrdec.java(9): final class Qrdec extends Object implements EntryPoint
            com.google.gwt.dev.jjs.ast.JClassType
         [ERROR] <no source info>: <JProgram>
            com.google.gwt.dev.jjs.ast.JProgram
      [ERROR] Unrecoverable exception, shutting down
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
    at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.logAndTranslateException(JavaToJavaScriptCompiler.java:604)
    at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.compilePermutation(JavaToJavaScriptCompiler.java:207)
    at com.google.gwt.dev.CompilePerms.compile(CompilePerms.java:181)
    at com.google.gwt.dev.ThreadedPermutationWorkerFactory$ThreadedPermutationWorker.compile(ThreadedPermutationWorkerFactory.java:47)
    at com.google.gwt.dev.PermutationWorkerFactory$Manager$WorkerThread.run(PermutationWorkerFactory.java:72)
    at java.lang.Thread.run(Thread.java:619)
   [ERROR] Not all permutation were compiled , completed (0/5)



2009/7/11 Onur Gündüz <ogu...@gmail.com>



--
Onur

srowen

unread,
Jul 11, 2009, 4:59:28 PM7/11/09
to zxing
Like I said, to use the library, you need some representation of an
image. This is true for decoding. Yes, that is the problem I foresee.
ImageIO would not work with GWT.

And yes, like I said, the code you see did not port decoder or encoder
to GWT Java at all. I show it to you in case that happens to solve
whatever problem you need. That is, perhaps you do not need to port
the decoder.

I do not know about the error in BitMatrix -- sounds like a GWT bug.
Check that you are using the latest version, and if so, file a bug.

Onur Gündüz

unread,
Jul 12, 2009, 11:45:37 AM7/12/09
to zx...@googlegroups.com
srowen,

I am sending a 2d int array from Flash to JS, and then convert it into a BitMatrix.

I extracted decoder unit only.

- It looks like HashTable is not supported in GWT, I replaced them with HashMap.
- In DecodedBitStreamParser, Byte arrays are converted to string with String(byte[]) constructor. It is not supported in GWT also. I wrote a new function to convert byte.

and it is working like a charm now...
--
Onur
Reply all
Reply to author
Forward
0 new messages