Understanding Bitmap memory layout

1,174 views
Skip to first unread message

Thingfish

unread,
Oct 4, 2010, 6:04:25 AM10/4/10
to android-ndk
Hi

Trying to get an understanding of how bitmap data is arranged in
memory, but aside from bitmap.h and the plasma example there doesn't
seem to be much documentation. Have a few questions I hope you can
help answer :)

1) Taking a look at the AndroidBitmapInfo struct from bitmap.h:

typedef struct {
uint32_t width;
uint32_t height;
uint32_t stride;
int32_t format;
uint32_t flags; // 0 for now
} AndroidBitmapInfo;

I assume width and height, are bitmap dimensions in pixels. From what
I can google stride seems to be the width of a bitmap line in bytes,
possible including padding? Is this correct, and if so, is padding
relevant for all configs/formats?


2) Comparing enum AndroidBitmapFormat from bitmap.h and Bitmap.Config
from the Android SDK I find "matching" definitions such as
Config.ARGB_8888 from the SDK and ANDROID_BITMAP_FORMAT_RGBA_8888 from
the NDK. Doesn't the ordering of the letters usually signal the
bitmasks used to extract the individual components? So why are they
different, and which one is correct? :)

Thingfish

unread,
Oct 4, 2010, 7:52:23 AM10/4/10
to android-ndk
After a bunch of segfaults :) I can partially answer this myself.

1) Seems to be no extra padding for Config.ARGB_8888, not that
surprising since it automatically fits on 4-byte boundaries.

2) libswscale gives the correct result when the data is treated as
RGBA, so I guess the definitions from bitmap.h are more correct.

devi prasad

unread,
Oct 4, 2010, 8:00:34 AM10/4/10
to andro...@googlegroups.com
FWIW, I too have concluded that Config.ARGB_8888 is same as RGBA. A
few days ago I had posted a message saying that ARGB_8888 is not
friendly with OpenGL and so on. In the meantime, I have found that
there are the same.

dp

> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>

Ken Turkowski

unread,
Oct 6, 2010, 12:29:24 PM10/6/10
to andro...@googlegroups.com
There seems to be two definitions of what something like "RGBA" means:
- R, G, B, A is the ordering of pixel components in a stream
- (R << 24) | (G << 16) | (B << 8) | (A << 0) is the location of components in an int32
The former is machine independent, and the latter is endian-dependent.

On a big-endian machine, the two definitions are equivalent, but on a little-endian machine, the components are reversed.
Reply all
Reply to author
Forward
0 new messages