Methods Summary |
---|
public void | change()Update the generationId.
mGenerationId++;
|
public static Bitmap | createBitmap(java.io.File input, boolean isMutable, com.android.resources.Density density)Creates and returns a {@link Bitmap} initialized with the given file content.
return createBitmap(input, getPremultipliedBitmapCreateFlags(isMutable), density);
|
public static Bitmap | createBitmap(java.io.File input, java.util.Set createFlags, com.android.resources.Density density)Creates and returns a {@link Bitmap} initialized with the given file content.
// create a delegate with the content of the file.
Bitmap_Delegate delegate = new Bitmap_Delegate(ImageIO.read(input), Config.ARGB_8888);
return createBitmap(delegate, createFlags, density.getDpiValue());
|
private static Bitmap | createBitmap(android.graphics.Bitmap_Delegate delegate, java.util.Set createFlags, int density)
// get its native_int
long nativeInt = sManager.addNewDelegate(delegate);
int width = delegate.mImage.getWidth();
int height = delegate.mImage.getHeight();
boolean isMutable = createFlags.contains(BitmapCreateFlags.MUTABLE);
boolean isPremultiplied = createFlags.contains(BitmapCreateFlags.PREMULTIPLIED);
// and create/return a new Bitmap with it
return new Bitmap(nativeInt, null /* buffer */, width, height, density, isMutable,
isPremultiplied, null /*ninePatchChunk*/, null /* layoutBounds */);
|
public static Bitmap | createBitmap(java.io.InputStream input, boolean isMutable, com.android.resources.Density density)Creates and returns a {@link Bitmap} initialized with the given stream content.
return createBitmap(input, getPremultipliedBitmapCreateFlags(isMutable), density);
|
public static Bitmap | createBitmap(java.io.InputStream input, java.util.Set createFlags, com.android.resources.Density density)Creates and returns a {@link Bitmap} initialized with the given stream content.
// create a delegate with the content of the stream.
Bitmap_Delegate delegate = new Bitmap_Delegate(ImageIO.read(input), Config.ARGB_8888);
return createBitmap(delegate, createFlags, density.getDpiValue());
|
public static Bitmap | createBitmap(java.awt.image.BufferedImage image, boolean isMutable, com.android.resources.Density density)Creates and returns a {@link Bitmap} initialized with the given {@link BufferedImage}
return createBitmap(image, getPremultipliedBitmapCreateFlags(isMutable), density);
|
public static Bitmap | createBitmap(java.awt.image.BufferedImage image, java.util.Set createFlags, com.android.resources.Density density)Creates and returns a {@link Bitmap} initialized with the given {@link BufferedImage}
// create a delegate with the given image.
Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.ARGB_8888);
return createBitmap(delegate, createFlags, density.getDpiValue());
|
static java.awt.image.BufferedImage | createCopy(java.awt.image.BufferedImage image, int imageType, int alpha)Creates and returns a copy of a given BufferedImage.
if alpha is different than 255, then it is applied to the alpha channel of each pixel.
int w = image.getWidth();
int h = image.getHeight();
BufferedImage result = new BufferedImage(w, h, imageType);
int[] argb = new int[w * h];
image.getRGB(0, 0, image.getWidth(), image.getHeight(), argb, 0, image.getWidth());
if (alpha != 255) {
final int length = argb.length;
for (int i = 0 ; i < length; i++) {
int a = (argb[i] >>> 24 * alpha) / 255;
argb[i] = (a << 24) | (argb[i] & 0x00FFFFFF);
}
}
result.setRGB(0, 0, w, h, argb, 0, w);
return result;
|
public static int | getBufferedImageType(int nativeBitmapConfig)
switch (Config.nativeToConfig(nativeBitmapConfig)) {
case ALPHA_8:
return BufferedImage.TYPE_INT_ARGB;
case RGB_565:
return BufferedImage.TYPE_INT_ARGB;
case ARGB_4444:
return BufferedImage.TYPE_INT_ARGB;
case ARGB_8888:
return BufferedImage.TYPE_INT_ARGB;
}
return BufferedImage.TYPE_INT_ARGB;
|
public android.graphics.Bitmap.Config | getConfig()Returns the Android bitmap config. Note that this not the config of the underlying
Java2D bitmap.
return mConfig;
|
public static android.graphics.Bitmap_Delegate | getDelegate(Bitmap bitmap)Returns the native delegate associated to a given {@link Bitmap_Delegate} object.
// ---- Public Helper methods ----
return sManager.getDelegate(bitmap.mNativeBitmap);
|
public static android.graphics.Bitmap_Delegate | getDelegate(long native_bitmap)Returns the native delegate associated to a given an int referencing a {@link Bitmap} object.
return sManager.getDelegate(native_bitmap);
|
public java.awt.image.BufferedImage | getImage()Returns the {@link BufferedImage} used by the delegate of the given {@link Bitmap}.
return mImage;
|
public static java.awt.image.BufferedImage | getImage(Bitmap bitmap)Returns the {@link BufferedImage} used by the delegate of the given {@link Bitmap}.
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(bitmap.mNativeBitmap);
if (delegate == null) {
return null;
}
return delegate.mImage;
|
private static java.util.Set | getPremultipliedBitmapCreateFlags(boolean isMutable)
Set<BitmapCreateFlags> createFlags = EnumSet.of(BitmapCreateFlags.PREMULTIPLIED);
if (isMutable) {
createFlags.add(BitmapCreateFlags.MUTABLE);
}
return createFlags;
|
public boolean | hasAlpha()Returns the hasAlpha rendering hint
return mHasAlpha && mConfig != Config.RGB_565;
|
public boolean | hasMipMap()
// TODO: check if more checks are required as in hasAlpha.
return mHasMipMap;
|
static boolean | nativeCompress(long nativeBitmap, int format, int quality, java.io.OutputStream stream, byte[] tempStorage)
Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
"Bitmap.compress() is not supported", null /*data*/);
return true;
|
static int | nativeConfig(long nativeBitmap)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return 0;
}
return delegate.mConfig.nativeInt;
|
static Bitmap | nativeCopy(long srcBitmap, int nativeConfig, boolean isMutable)
Bitmap_Delegate srcBmpDelegate = sManager.getDelegate(srcBitmap);
if (srcBmpDelegate == null) {
return null;
}
BufferedImage srcImage = srcBmpDelegate.getImage();
int width = srcImage.getWidth();
int height = srcImage.getHeight();
int imageType = getBufferedImageType(nativeConfig);
// create the image
BufferedImage image = new BufferedImage(width, height, imageType);
// copy the source image into the image.
int[] argb = new int[width * height];
srcImage.getRGB(0, 0, width, height, argb, 0, width);
image.setRGB(0, 0, width, height, argb, 0, width);
// create a delegate with the content of the stream.
Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.nativeToConfig(nativeConfig));
return createBitmap(delegate, getPremultipliedBitmapCreateFlags(isMutable),
Bitmap.getDefaultDensity());
|
static void | nativeCopyPixelsFromBuffer(long nb, java.nio.Buffer src)
// FIXME implement native delegate
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
"Bitmap.copyPixelsFromBuffer is not supported.", null, null /*data*/);
|
static void | nativeCopyPixelsToBuffer(long nativeBitmap, java.nio.Buffer dst)
// FIXME implement native delegate
Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
"Bitmap.copyPixelsToBuffer is not supported.", null, null /*data*/);
|
static Bitmap | nativeCreate(int[] colors, int offset, int stride, int width, int height, int nativeConfig, boolean isMutable)
int imageType = getBufferedImageType(nativeConfig);
// create the image
BufferedImage image = new BufferedImage(width, height, imageType);
if (colors != null) {
image.setRGB(0, 0, width, height, colors, offset, stride);
}
// create a delegate with the content of the stream.
Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.nativeToConfig(nativeConfig));
return createBitmap(delegate, getPremultipliedBitmapCreateFlags(isMutable),
Bitmap.getDefaultDensity());
|
static Bitmap | nativeCreateFromParcel(android.os.Parcel p)
// This is only called by Bitmap.CREATOR (Parcelable.Creator<Bitmap>), which is only
// used during aidl call so really this should not be called.
Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
"AIDL is not suppored, and therefore Bitmaps cannot be created from parcels.",
null /*data*/);
return null;
|
static void | nativeDestructor(long nativeBitmap)
sManager.removeJavaReferenceFor(nativeBitmap);
|
static void | nativeErase(long nativeBitmap, int color)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
}
BufferedImage image = delegate.mImage;
Graphics2D g = image.createGraphics();
try {
g.setColor(new java.awt.Color(color, true));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
} finally {
g.dispose();
}
|
static Bitmap | nativeExtractAlpha(long nativeBitmap, long nativePaint, int[] offsetXY)
Bitmap_Delegate bitmap = sManager.getDelegate(nativeBitmap);
if (bitmap == null) {
return null;
}
// get the paint which can be null if nativePaint is 0.
Paint_Delegate paint = Paint_Delegate.getDelegate(nativePaint);
if (paint != null && paint.getMaskFilter() != null) {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MASKFILTER,
"MaskFilter not supported in Bitmap.extractAlpha",
null, null /*data*/);
}
int alpha = paint != null ? paint.getAlpha() : 0xFF;
BufferedImage image = createCopy(bitmap.getImage(), BufferedImage.TYPE_INT_ARGB, alpha);
// create the delegate. The actual Bitmap config is only an alpha channel
Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.ALPHA_8);
// the density doesn't matter, it's set by the Java method.
return createBitmap(delegate, EnumSet.of(BitmapCreateFlags.MUTABLE),
Density.DEFAULT_DENSITY /*density*/);
|
static int | nativeGenerationId(long nativeBitmap)
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return 0;
}
return delegate.mGenerationId;
|
static int | nativeGetPixel(long nativeBitmap, int x, int y)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return 0;
}
return delegate.mImage.getRGB(x, y);
|
static void | nativeGetPixels(long nativeBitmap, int[] pixels, int offset, int stride, int x, int y, int width, int height)
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
}
delegate.getImage().getRGB(x, y, width, height, pixels, offset, stride);
|
static boolean | nativeHasAlpha(long nativeBitmap)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return true;
}
return delegate.mHasAlpha;
|
static boolean | nativeHasMipMap(long nativeBitmap)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return true;
}
return delegate.mHasMipMap;
|
static boolean | nativeIsPremultiplied(long nativeBitmap)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
return delegate != null && delegate.mIsPremultiplied;
|
static void | nativePrepareToDraw(long nativeBitmap)
// nothing to be done here.
|
static void | nativeReconfigure(long nativeBitmap, int width, int height, int config, int allocSize, boolean isPremultiplied)
Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
"Bitmap.reconfigure() is not supported", null /*data*/);
|
static boolean | nativeRecycle(long nativeBitmap)
sManager.removeJavaReferenceFor(nativeBitmap);
return true;
|
static int | nativeRowBytes(long nativeBitmap)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return 0;
}
return delegate.mImage.getWidth();
|
static boolean | nativeSameAs(long nb0, long nb1)
Bitmap_Delegate delegate1 = sManager.getDelegate(nb0);
if (delegate1 == null) {
return false;
}
Bitmap_Delegate delegate2 = sManager.getDelegate(nb1);
if (delegate2 == null) {
return false;
}
BufferedImage image1 = delegate1.getImage();
BufferedImage image2 = delegate2.getImage();
if (delegate1.mConfig != delegate2.mConfig ||
image1.getWidth() != image2.getWidth() ||
image1.getHeight() != image2.getHeight()) {
return false;
}
// get the internal data
int w = image1.getWidth();
int h = image2.getHeight();
int[] argb1 = new int[w*h];
int[] argb2 = new int[w*h];
image1.getRGB(0, 0, w, h, argb1, 0, w);
image2.getRGB(0, 0, w, h, argb2, 0, w);
// compares
if (delegate1.mConfig == Config.ALPHA_8) {
// in this case we have to manually compare the alpha channel as the rest is garbage.
final int length = w*h;
for (int i = 0 ; i < length ; i++) {
if ((argb1[i] & 0xFF000000) != (argb2[i] & 0xFF000000)) {
return false;
}
}
return true;
}
return Arrays.equals(argb1, argb2);
|
static void | nativeSetHasAlpha(long nativeBitmap, boolean hasAlpha, boolean isPremul)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
}
delegate.mHasAlpha = hasAlpha;
|
static void | nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
}
delegate.mHasMipMap = hasMipMap;
|
static void | nativeSetPixel(long nativeBitmap, int x, int y, int color)
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
}
delegate.getImage().setRGB(x, y, color);
|
static void | nativeSetPixels(long nativeBitmap, int[] colors, int offset, int stride, int x, int y, int width, int height)
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
}
delegate.getImage().setRGB(x, y, width, height, colors, offset, stride);
|
static void | nativeSetPremultiplied(long nativeBitmap, boolean isPremul)
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
}
delegate.mIsPremultiplied = isPremul;
|
static boolean | nativeWriteToParcel(long nativeBitmap, boolean isMutable, int density, android.os.Parcel p)
// This is only called when sending a bitmap through aidl, so really this should not
// be called.
Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
"AIDL is not suppored, and therefore Bitmaps cannot be written to parcels.",
null /*data*/);
return false;
|