Revision: 2420
http://sourceforge.net/p/swingme/code/2420
Author: yuranet
Date: 2021-03-17 22:24:56 +0000 (Wed, 17 Mar 2021)
Log Message:
-----------
handle any image dpi Samsung will throw at us
Modified Paths:
--------------
AndroidME/src_MIDP/javax/microedition/lcdui/Image.java
Modified: AndroidME/src_MIDP/javax/microedition/lcdui/Image.java
===================================================================
--- AndroidME/src_MIDP/javax/microedition/lcdui/Image.java 2021-03-16 13:18:32 UTC (rev 2419)
+++ AndroidME/src_MIDP/javax/microedition/lcdui/Image.java 2021-03-17 22:24:56 UTC (rev 2420)
@@ -112,6 +112,8 @@
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = false;
options.inPurgeable = true; // http://www.droidnova.com/2d-sprite-animation-in-android-addendum,505.html
+ options.inScaled = false;
+ options.inSampleSize = 1;
OutOfMemoryError error = null;
try {
@@ -121,6 +123,8 @@
error = e;
buffInput.reset();
buffInput.mark(1024);
+ options.inScaled = true;
+ options.inSampleSize = 0;
bitmap = BitmapFactory.decodeStream(buffInput,null,options);
}
@@ -128,9 +132,16 @@
throw new IOException("BitmapFactory.decodeStream returned null " + stream + " available=" + available + " " + options.outMimeType + " " + options.outWidth + "x" + options.outHeight + " " + error);
}
- // this should always be none or same as display
+ // for testing/emulating loading images at low res as some Samsungs sometimes do
+ //bitmap.setDensity(getTargetDensity() / options.inSampleSize);
+
+ // some Samsungs will scale the image to be smaller (bitmap=315 system=420)
if (bitmap.getDensity() != Bitmap.DENSITY_NONE && bitmap.getDensity() != getTargetDensity()) {
- System.err.println("unexpected bitmap density " + bitmap.getDensity() + " (system=" + getTargetDensity() + ")");
+ int systemDensity = getTargetDensity();
+ int bitmapDensity = bitmap.getDensity();
+ int w = bitmap.getWidth();
+ int h = bitmap.getHeight();
+ System.err.println("changed bitmap density=" + bitmapDensity + " " + w + "x" + h + " (system=" + systemDensity + " " + scaleFromDensity(w, bitmapDensity, systemDensity) + "x" + scaleFromDensity(h, bitmapDensity, systemDensity) + ")");
}
}
return new Image(bitmap);
@@ -290,7 +301,40 @@
}
public void getRGB(int[] rgb, int offset, int scanlength, int x, int y, int width, int height) {
+ final int scanHeight = height;
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ int bitmapDensity = bitmap.getDensity();
+ int systemDensity = getTargetDensity();
+ if (bitmapDensity != Bitmap.DENSITY_NONE && bitmapDensity != systemDensity) {
+ x = scaleFromDensity(x, systemDensity, bitmapDensity);
+ y = scaleFromDensity(y, systemDensity, bitmapDensity);
+ width = scaleFromDensity(width, systemDensity, bitmapDensity);
+ height = scaleFromDensity(height, systemDensity, bitmapDensity);
+
+ // can end up with 0 height because of rounding error
+ if (height == 0) {
+ height = 1;
+ }
+
+ // can end up 1 more then end through rounding error
+ if (y + height == bitmap.getHeight() + 1) {
+ y = bitmap.getHeight() - height;
+ }
+ }
+ }
+
bitmap.getPixels(rgb, offset, scanlength, x, y, width, height);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ int bitmapDensity = bitmap.getDensity();
+ int systemDensity = getTargetDensity();
+ if (bitmapDensity != Bitmap.DENSITY_NONE && bitmapDensity != systemDensity) {
+ for (int c = offset + scanlength * scanHeight - 1; c >= offset; c--) {
+ rgb[c] = rgb[((c / scanlength) * scanlength) + scaleFromDensity(c % scanlength, systemDensity, bitmapDensity)];
+ }
+ }
+ }
}
public boolean isMutable() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|