From f7f715e94afd1b93d19bfac91f54e590489c9c83 Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Fri, 1 Aug 2014 00:30:19 -0700 Subject: [PATCH] wee, fix a bug in the unzip code and decode pngs --- midp.js | 16 ++++++++++++++-- zipfile.js | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/midp.js b/midp.js index f2d88111..f098d600 100644 --- a/midp.js +++ b/midp.js @@ -501,8 +501,20 @@ Native["javax/microedition/lcdui/Font.init.(III)V"] = function(ctx, stack) { } Native["javax/microedition/lcdui/ImageDataFactory.createImmutableImageDecodeImage.(Ljavax/microedition/lcdui/ImageData;[BII)V"] = function(ctx, stack) { - var length = stack.pop(), offset = stack.pop(), bytes = stack.pop(), image = stack.pop(); - image.data = bytes.buffer.slice(offset, offset + length); + var length = stack.pop(), offset = stack.pop(), bytes = stack.pop(), imageData = stack.pop(); + var blob = new Blob([bytes.buffer.slice(offset, offset + length)], { type: "image/png" }); + var img = new Image(); + img.src = URL.createObjectURL(blob); + img.onload = function() { + imageData["javax/microedition/lcdui/ImageData$width"] = img.naturalWidth; + imageData["javax/microedition/lcdui/ImageData$height"] = img.naturalHeight; + imageData["javax/microedition/lcdui/ImageData$nativeImageData"] = img; + ctx.resume(); + } + img.onerror = function(e) { + ctx.resume(); + } + throw VM.Pause; } Native["com/sun/midp/chameleon/layers/SoftButtonLayer.isNativeSoftButtonLayerSupported0.()Z"] = function(ctx, stack) { diff --git a/zipfile.js b/zipfile.js index fc0833fb..9e525d98 100644 --- a/zipfile.js +++ b/zipfile.js @@ -224,7 +224,6 @@ function inflate(bytes) { ensureBuffer(bufferLength + blockLen); var end = bufferLength + blockLen; - bufferLength = end; for (var n = bufferLength; n < end; ++n) { if (typeof (b = bytes[bytesPos++]) == 'undefined') { eof = true; @@ -232,6 +231,7 @@ function inflate(bytes) { } buffer[n] = b; } + bufferLength = end; return eof; }