summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/Bitmap.java92
1 files changed, 73 insertions, 19 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index c7ae2cf..b2f4379 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -200,8 +200,6 @@ public final class Bitmap implements Parcelable {
* check if a bitmap has changed.
*
* @return The current generation ID for this bitmap.
- *
- * @hide
*/
public int getGenerationId() {
return nativeGenerationId(mNativeBitmap);
@@ -247,25 +245,80 @@ public final class Bitmap implements Parcelable {
}
}
+ /**
+ * Possible bitmap configurations. A bitmap configuration describes
+ * how pixels are stored. This affects the quality (color depth) as
+ * well as the ability to display transparent/translucent colors.
+ */
public enum Config {
// these native values must match up with the enum in SkBitmap.h
+
+ /**
+ * Each pixel is stored as a single translucency (alpha) channel.
+ * This is very useful to efficiently store masks for instance.
+ * No color information is stored.
+ * With this configuration, each pixel requires 1 byte of memory.
+ */
ALPHA_8 (2),
+
+ /**
+ * Each pixel is stored on 2 bytes and only the RGB channels are
+ * encoded: red is stored with 5 bits of precision (32 possible
+ * values), green is stored with 6 bits of precision (64 possible
+ * values) and blue is stored with 5 bits of precision.
+ *
+ * This configuration can produce slight visual artifacts depending
+ * on the configuration of the source. For instance, without
+ * dithering, the result might show a greenish tint. To get better
+ * results dithering should be applied.
+ *
+ * This configuration may be useful when using opaque bitmaps
+ * that do not require high color fidelity.
+ */
RGB_565 (4),
+
+ /**
+ * Each pixel is stored on 2 bytes. The three RGB color channels
+ * and the alpha channel (translucency) are stored with a 4 bits
+ * precision (16 possible values.)
+ *
+ * This configuration is mostly useful if the application needs
+ * to store translucency information but also needs to save
+ * memory.
+ *
+ * It is recommended to use {@link #ARGB_8888} instead of this
+ * configuration.
+ *
+ * @deprecated Because of the poor quality of this configuration,
+ * it is advised to use {@link #ARGB_8888} instead.
+ */
+ @Deprecated
ARGB_4444 (5),
+
+ /**
+ * Each pixel is stored on 4 bytes. Each channel (RGB and alpha
+ * for translucency) is stored with 8 bits of precision (256
+ * possible values.)
+ *
+ * This configuration is very flexible and offers the best
+ * quality. It should be used whenever possible.
+ */
ARGB_8888 (6);
+ final int nativeInt;
+
+ @SuppressWarnings({"deprecation"})
+ private static Config sConfigs[] = {
+ null, null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
+ };
+
Config(int ni) {
this.nativeInt = ni;
}
- final int nativeInt;
- /* package */ static Config nativeToConfig(int ni) {
+ static Config nativeToConfig(int ni) {
return sConfigs[ni];
}
-
- private static Config sConfigs[] = {
- null, null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
- };
}
/**
@@ -475,6 +528,7 @@ public final class Bitmap implements Parcelable {
case ALPHA_8:
newConfig = Config.ALPHA_8;
break;
+ //noinspection deprecation
case ARGB_4444:
case ARGB_8888:
default:
@@ -752,7 +806,7 @@ public final class Bitmap implements Parcelable {
}
// Scale by tdensity / sdensity, rounding up.
- return ( (size * tdensity) + (sdensity >> 1) ) / sdensity;
+ return ((size * tdensity) + (sdensity >> 1)) / sdensity;
}
/**
@@ -790,14 +844,12 @@ public final class Bitmap implements Parcelable {
/**
* Tell the bitmap if all of the pixels are known to be opaque (false)
* or if some of the pixels may contain non-opaque alpha values (true).
- * Note, for some configs (e.g. RGB_565) this call is ignore, since it does
- * not support per-pixel alpha values.
+ * Note, for some configs (e.g. RGB_565) this call is ignored, since it
+ * does not support per-pixel alpha values.
*
* This is meant as a drawing hint, as in some cases a bitmap that is known
* to be opaque can take a faster drawing case than one that may have
* non-opaque per-pixel alpha values.
- *
- * @hide
*/
public void setHasAlpha(boolean hasAlpha) {
nativeSetHasAlpha(mNativeBitmap, hasAlpha);
@@ -1066,13 +1118,9 @@ public final class Bitmap implements Parcelable {
* Given another bitmap, return true if it has the same dimensions, config,
* and pixel data as this bitmap. If any of those differ, return false.
* If other is null, return false.
- *
- * @hide (just needed internally right now)
*/
public boolean sameAs(Bitmap other) {
- return this == other ||
- (other != null &&
- nativeSameAs(mNativeBitmap, other.mNativeBitmap));
+ return this == other || (other != null && nativeSameAs(mNativeBitmap, other.mNativeBitmap));
}
/**
@@ -1099,7 +1147,13 @@ public final class Bitmap implements Parcelable {
@Override
public void finalize() {
- nativeDestructor(mNativeBitmap);
+ try {
+ super.finalize();
+ } catch (Throwable t) {
+ // Ignore
+ } finally {
+ nativeDestructor(mNativeBitmap);
+ }
}
}