Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hey guys.

I know this has been convered before, but the other posts haven't helped me resolve the issue completly.

The SE47 as we all knows uses twice the amout of memory as it should when converting bitmaps.

My workaround is to do the following

Create an IDIB using IDIB data (depth and nColorScheme from the IDIB of the screen) so it is a native bitmap (am I correct in assuming this?)

Load my bitmap (4bpp indexed bitmap)
Get the palette info for the loaded bmp (RBG components)
For each pixel convert it to an RBG value
For that RBG value convert it to native format (of the IBitmap of the screen)
Write the value to the pBmp field of the IDIB I created.

Now I haven't got this 100% working, what I would like to know from those that have solved this problem is is my solution going to work as i expect it to? ie will it actually convert my 4bit bmps read in from the resource file to native format bmps for efficient blitting to the screen?

Where I am failing at the moment is the conversion itself. I am having issues where the images seam to be split down the middle, I am sure this is something I am doing though.

Your help is appreciated.

Mick Robertson

How are you obtaining the pixels from the bitmap you loaded - are you doing it manually by examining the raw Windows bitmap, or does BREW 2.0 have some helper functions? If you are doing it manually [the "split down the middle" statement makes me think that this may be the case], are you accounting for the padding added to each row of a Windows bitmap?

How are you obtaining the pixels from the bitmap you loaded - are you doing it manually by examining the raw Windows bitmap, or does BREW 2.0 have some helper functions? If you are doing it manually [the "split down the middle" statement makes me think that this may be the case], are you accounting for the padding added to each row of a Windows bitmap?

simon wrote:How are you obtaining the pixels from the bitmap you loaded - are you doing it manually by examining the raw Windows bitmap, or does BREW 2.0 have some helper functions? If you are doing it manually [the "split down the middle" statement makes me think that this may be the case], are you accounting for the padding added to each row of a Windows bitmap?
Of course, the pitch! How do I calcualte that? (My bitmap graphics knowledge is limited). Do each rows have to be a multiple of 4 or something?

simon wrote:How are you obtaining the pixels from the bitmap you loaded - are you doing it manually by examining the raw Windows bitmap, or does BREW 2.0 have some helper functions? If you are doing it manually [the "split down the middle" statement makes me think that this may be the case], are you accounting for the padding added to each row of a Windows bitmap?
Of course, the pitch! How do I calcualte that? (My bitmap graphics knowledge is limited). Do each rows have to be a multiple of 4 or something?

MickRob wrote:Of course, the pitch! How do I calcualte that? (My bitmap graphics knowledge is limited). Do each rows have to be a multiple of 4 or something?
Pretty much, yeah :) I can't seem to find a good resource right now, bug googling for "windows bitmap specification" or suchlike should be enough to tell you everything you need :)

MickRob wrote:Of course, the pitch! How do I calcualte that? (My bitmap graphics knowledge is limited). Do each rows have to be a multiple of 4 or something?
Pretty much, yeah :) I can't seem to find a good resource right now, bug googling for "windows bitmap specification" or suchlike should be enough to tell you everything you need :)

MickRob wrote:Hey guys.
Load my bitmap (4bpp indexed bitmap)
Get the palette info for the loaded bmp (RBG components)
For each pixel convert it to an RBG value
For that RBG value convert it to native format (of the IBitmap of the screen)
Write the value to the pBmp field of the IDIB I created.
Mick Robertson
Hi,
Could you share the following steps in actual code:
Get the palette info for the loaded bmp (RBG components)
For each pixel convert it to an RBG value
For that RBG value convert it to native format (of the IBitmap of the screen)
Write the value to the pBmp field of the IDIB I created.
:D ;)

MickRob wrote:Hey guys.
Load my bitmap (4bpp indexed bitmap)
Get the palette info for the loaded bmp (RBG components)
For each pixel convert it to an RBG value
For that RBG value convert it to native format (of the IBitmap of the screen)
Write the value to the pBmp field of the IDIB I created.
Mick Robertson
Hi,
Could you share the following steps in actual code:
Get the palette info for the loaded bmp (RBG components)
For each pixel convert it to an RBG value
For that RBG value convert it to native format (of the IBitmap of the screen)
Write the value to the pBmp field of the IDIB I created.
:D ;)

Get the palette info for the loaded bmp (RBG components)
You need to get the number of bits per pixel. This can be found at byte 28 in the file. (Or just use the correct field in the bitmap header structure. Then you need to get the start of the palette (byte 10) so you can get the RGBA values for each pixel.
For each pixel convert it to an RBG value
Now you need to parse each pixel (depending on if you are using 4 bit, 8 bit or 24bit, if using 24 bit there is no palette) and get the RGBA (from the data or the palette depending on bpp)
For that RBG value convert it to native format (of the IBitmap of the screen)
Get the screen bitmap and call IBitmap_RBGtoNative() passing in the RGB val (you can get this using MAKERGB).
Write the value to the pBmp field of the IDIB I created
Now you get the IDIB of the bitmap you want to write to (create an IBitmap or IDIB) and write the values to the pBmp field of the IDIB.

Get the palette info for the loaded bmp (RBG components)
You need to get the number of bits per pixel. This can be found at byte 28 in the file. (Or just use the correct field in the bitmap header structure. Then you need to get the start of the palette (byte 10) so you can get the RGBA values for each pixel.
For each pixel convert it to an RBG value
Now you need to parse each pixel (depending on if you are using 4 bit, 8 bit or 24bit, if using 24 bit there is no palette) and get the RGBA (from the data or the palette depending on bpp)
For that RBG value convert it to native format (of the IBitmap of the screen)
Get the screen bitmap and call IBitmap_RBGtoNative() passing in the RGB val (you can get this using MAKERGB).
Write the value to the pBmp field of the IDIB I created
Now you get the IDIB of the bitmap you want to write to (create an IBitmap or IDIB) and write the values to the pBmp field of the IDIB.

Well, all my images are 8-bit deep.
IDIB *dib = NULL;
IDISPLAY_CreateDIBitmap(iDisplay,&dib,(int8)bitmapDepth,(int16)bitmapW,(int16)bitmapH);
for(int32 t = 0; t < bitmapW * bitmapH; t++)
dib->pBmp[t] = bitmapData[t];
I can't set up the palette. The whole thing keeps crashing...
dib->cntRGB = (uint16)((colorsUsed == 0) ? 256 : colorsUsed);
for(int tt = 0; tt < dib->cntRGB; tt++)
{
RGBQUAD *rgbQ = &rgbData[bitmapData[tt]];
dib->pRGB[tt] = IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgbQ->red,rgbQ->green,rgbQ->blue));

If I do the below instead of the above, then the game won't crash, but the colors were all messed up.
dib->nColorScheme = IDIB_COLORSCHEME_565;
Frankly, the BREW documentation leaves a bit to desire. I don't even know if dib->pRGB has been allocated proper spaces or not.... :mad:
MickRob wrote:Get the palette info for the loaded bmp (RBG components)
You need to get the number of bits per pixel. This can be found at byte 28 in the file. (Or just use the correct field in the bitmap header structure. Then you need to get the start of the palette (byte 10) so you can get the RGBA values for each pixel.
For each pixel convert it to an RBG value
Now you need to parse each pixel (depending on if you are using 4 bit, 8 bit or 24bit, if using 24 bit there is no palette) and get the RGBA (from the data or the palette depending on bpp)
For that RBG value convert it to native format (of the IBitmap of the screen)
Get the screen bitmap and call IBitmap_RBGtoNative() passing in the RGB val (you can get this using MAKERGB).
Write the value to the pBmp field of the IDIB I created
Now you get the IDIB of the bitmap you want to write to (create an IBitmap or IDIB) and write the values to the pBmp field of the IDIB.

Well, all my images are 8-bit deep.
IDIB *dib = NULL;
IDISPLAY_CreateDIBitmap(iDisplay,&dib,(int8)bitmapDepth,(int16)bitmapW,(int16)bitmapH);
for(int32 t = 0; t < bitmapW * bitmapH; t++)
dib->pBmp[t] = bitmapData[t];
I can't set up the palette. The whole thing keeps crashing...
dib->cntRGB = (uint16)((colorsUsed == 0) ? 256 : colorsUsed);
for(int tt = 0; tt < dib->cntRGB; tt++)
{
RGBQUAD *rgbQ = &rgbData[bitmapData[tt]];
dib->pRGB[tt] = IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgbQ->red,rgbQ->green,rgbQ->blue));

If I do the below instead of the above, then the game won't crash, but the colors were all messed up.
dib->nColorScheme = IDIB_COLORSCHEME_565;
Frankly, the BREW documentation leaves a bit to desire. I don't even know if dib->pRGB has been allocated proper spaces or not.... :mad:
MickRob wrote:Get the palette info for the loaded bmp (RBG components)
You need to get the number of bits per pixel. This can be found at byte 28 in the file. (Or just use the correct field in the bitmap header structure. Then you need to get the start of the palette (byte 10) so you can get the RGBA values for each pixel.
For each pixel convert it to an RBG value
Now you need to parse each pixel (depending on if you are using 4 bit, 8 bit or 24bit, if using 24 bit there is no palette) and get the RGBA (from the data or the palette depending on bpp)
For that RBG value convert it to native format (of the IBitmap of the screen)
Get the screen bitmap and call IBitmap_RBGtoNative() passing in the RGB val (you can get this using MAKERGB).
Write the value to the pBmp field of the IDIB I created
Now you get the IDIB of the bitmap you want to write to (create an IBitmap or IDIB) and write the values to the pBmp field of the IDIB.

for(int tt = 0; tt < dib->cntRGB; tt++)
{
// RGBQUAD *rgbQ = &rgbData[bitmapData[tt]];
dib->pRGB[tt] = IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(0xff,0x00,0xff));

Even the above would crash...same if I used ...=&rgbData[tt];
brew_newbie wrote:Well, all my images are 8-bit deep.
IDIB *dib = NULL;
IDISPLAY_CreateDIBitmap(iDisplay,&dib,(int8)bitmapDepth,(int16)bitmapW,(int16)bitmapH);
for(int32 t = 0; t < bitmapW * bitmapH; t++)
dib->pBmp[t] = bitmapData[t];
I can't set up the palette. The whole thing keeps crashing...
dib->cntRGB = (uint16)((colorsUsed == 0) ? 256 : colorsUsed);
for(int tt = 0; tt < dib->cntRGB; tt++)
{
RGBQUAD *rgbQ = &rgbData[bitmapData[tt]];
dib->pRGB[tt] = IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgbQ->red,rgbQ->green,rgbQ->blue));

If I do the below instead of the above, then the game won't crash, but the colors were all messed up.
dib->nColorScheme = IDIB_COLORSCHEME_565;
Frankly, the BREW documentation leaves a bit to desire. I don't even know if dib->pRGB has been allocated proper spaces or not.... :mad:

for(int tt = 0; tt < dib->cntRGB; tt++)
{
// RGBQUAD *rgbQ = &rgbData[bitmapData[tt]];
dib->pRGB[tt] = IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(0xff,0x00,0xff));

Even the above would crash...same if I used ...=&rgbData[tt];
brew_newbie wrote:Well, all my images are 8-bit deep.
IDIB *dib = NULL;
IDISPLAY_CreateDIBitmap(iDisplay,&dib,(int8)bitmapDepth,(int16)bitmapW,(int16)bitmapH);
for(int32 t = 0; t < bitmapW * bitmapH; t++)
dib->pBmp[t] = bitmapData[t];
I can't set up the palette. The whole thing keeps crashing...
dib->cntRGB = (uint16)((colorsUsed == 0) ? 256 : colorsUsed);
for(int tt = 0; tt < dib->cntRGB; tt++)
{
RGBQUAD *rgbQ = &rgbData[bitmapData[tt]];
dib->pRGB[tt] = IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgbQ->red,rgbQ->green,rgbQ->blue));

If I do the below instead of the above, then the game won't crash, but the colors were all messed up.
dib->nColorScheme = IDIB_COLORSCHEME_565;
Frankly, the BREW documentation leaves a bit to desire. I don't even know if dib->pRGB has been allocated proper spaces or not.... :mad:

it doesnt look like you are checking for errors, are you getting SUCCESS with IDISPLAY_CreateDIBitmap? is there any particular reason you arent using GetDeviceBitmap?
http://brewforums.qualcomm.com/showthread.php?t=5653&highlight=getdevice...
-Tyndal

it doesnt look like you are checking for errors, are you getting SUCCESS with IDISPLAY_CreateDIBitmap? is there any particular reason you arent using GetDeviceBitmap?
http://brewforums.qualcomm.com/showthread.php?t=5653&highlight=getdevice...
-Tyndal

Well, I a Windows BMP stored in a data array and that's the one I am trying to CONVERTBMP on. Yeah, it is on the SE-47, so I am trying to roll my own CONVERTBMP without success.
I use IDISPLAY_CreateDIBitmap so I can pass in information from the Windows BMP.
IDISPLAY_CreateDIBitmap has been a-ok everytime. I left out a bunch of debugs and checks...
tyndal wrote:it doesnt look like you are checking for errors, are you getting SUCCESS with IDISPLAY_CreateDIBitmap? is there any particular reason you arent using GetDeviceBitmap?
http://brewforums.qualcomm.com/showthread.php?t=5653&highlight=getdevice...
-Tyndal

Well, I a Windows BMP stored in a data array and that's the one I am trying to CONVERTBMP on. Yeah, it is on the SE-47, so I am trying to roll my own CONVERTBMP without success.
I use IDISPLAY_CreateDIBitmap so I can pass in information from the Windows BMP.
IDISPLAY_CreateDIBitmap has been a-ok everytime. I left out a bunch of debugs and checks...
tyndal wrote:it doesnt look like you are checking for errors, are you getting SUCCESS with IDISPLAY_CreateDIBitmap? is there any particular reason you arent using GetDeviceBitmap?
http://brewforums.qualcomm.com/showthread.php?t=5653&highlight=getdevice...
-Tyndal

So, I went ahead and used the GetDeviceBitmap approach and I am smelling success is nearing. My images are up side down and mirrored left to right though, WTF?
Also, when the width is 32, the dib->nPitch shows 31 in the emulator, what's going on?
And on some images, the colors are all screwed up but not on some other. All images are 8-bits.
int i = 0;
for(int32 y = 0; y < bitmapHeight; y++)
{
for(int32 x = 0; x < bitmapWidth; x++)
{
RGBQUAD *rgb = &rgbData[bitmapData[i++]];
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->rgbRed,rgb->rgbGreen,rgb->rgbBlue));

When dib->nPitch does not match the bitmapWidth, the images get skewed, but if I replace dib->nPitch with bitmapWidth, then the images come out right but up-side-down and left-to-right mirrored. And some images got their colors all messed up.
All results were observed on Emulator 2.0 and the SE-47 skin.
MAX, can Qualcomm release the CONVERTBMP code???
brew_newbie wrote:Well, I a Windows BMP stored in a data array and that's the one I am trying to CONVERTBMP on. Yeah, it is on the SE-47, so I am trying to roll my own CONVERTBMP without success.
I use IDISPLAY_CreateDIBitmap so I can pass in information from the Windows BMP.
IDISPLAY_CreateDIBitmap has been a-ok everytime. I left out a bunch of debugs and checks...

So, I went ahead and used the GetDeviceBitmap approach and I am smelling success is nearing. My images are up side down and mirrored left to right though, WTF?
Also, when the width is 32, the dib->nPitch shows 31 in the emulator, what's going on?
And on some images, the colors are all screwed up but not on some other. All images are 8-bits.
int i = 0;
for(int32 y = 0; y < bitmapHeight; y++)
{
for(int32 x = 0; x < bitmapWidth; x++)
{
RGBQUAD *rgb = &rgbData[bitmapData[i++]];
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->rgbRed,rgb->rgbGreen,rgb->rgbBlue));

When dib->nPitch does not match the bitmapWidth, the images get skewed, but if I replace dib->nPitch with bitmapWidth, then the images come out right but up-side-down and left-to-right mirrored. And some images got their colors all messed up.
All results were observed on Emulator 2.0 and the SE-47 skin.
MAX, can Qualcomm release the CONVERTBMP code???
brew_newbie wrote:Well, I a Windows BMP stored in a data array and that's the one I am trying to CONVERTBMP on. Yeah, it is on the SE-47, so I am trying to roll my own CONVERTBMP without success.
I use IDISPLAY_CreateDIBitmap so I can pass in information from the Windows BMP.
IDISPLAY_CreateDIBitmap has been a-ok everytime. I left out a bunch of debugs and checks...

i = 0;
for(int32 y = bitmapHeight -1; y > 0; y--)
{
for(int32 x = 0; x < bitmapWidth; x++)
{
RGBQUAD *rgb = &rgbData[bitmapData[i++]];
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->rgbRed,rgb->rgbGreen,rgb->rgbBlue));

Will display the images right for most images, but for some other, the images get skewed and the colors messed up. I guess it all has to do with the alignment of the bitmaps. But why did I have to reverse the y loop? I thought nPitch is supposed to do that. Or are Windows bitmap stored upside down?
:confused:
brew_newbie wrote:So, I went ahead and used the GetDeviceBitmap approach and I am smelling success is nearing. My images are up side down and mirrored left to right though, WTF?
Also, when the width is 32, the dib->nPitch shows 31 in the emulator, what's going on?
And on some images, the colors are all screwed up but not on some other. All images are 8-bits.
int i = 0;
for(int32 y = 0; y < bitmapHeight; y++)
{
for(int32 x = 0; x < bitmapWidth; x++)
{
RGBQUAD *rgb = &rgbData[bitmapData[i++]];
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->rgbRed,rgb->rgbGreen,rgb->rgbBlue));

When dib->nPitch does not match the bitmapWidth, the images get skewed, but if I replace dib->nPitch with bitmapWidth, then the images come out right but up-side-down and left-to-right mirrored. And some images got their colors all messed up.
All results were observed on Emulator 2.0 and the SE-47 skin.
MAX, can Qualcomm release the CONVERTBMP code???

i = 0;
for(int32 y = bitmapHeight -1; y > 0; y--)
{
for(int32 x = 0; x < bitmapWidth; x++)
{
RGBQUAD *rgb = &rgbData[bitmapData[i++]];
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->rgbRed,rgb->rgbGreen,rgb->rgbBlue));

Will display the images right for most images, but for some other, the images get skewed and the colors messed up. I guess it all has to do with the alignment of the bitmaps. But why did I have to reverse the y loop? I thought nPitch is supposed to do that. Or are Windows bitmap stored upside down?
:confused:
brew_newbie wrote:So, I went ahead and used the GetDeviceBitmap approach and I am smelling success is nearing. My images are up side down and mirrored left to right though, WTF?
Also, when the width is 32, the dib->nPitch shows 31 in the emulator, what's going on?
And on some images, the colors are all screwed up but not on some other. All images are 8-bits.
int i = 0;
for(int32 y = 0; y < bitmapHeight; y++)
{
for(int32 x = 0; x < bitmapWidth; x++)
{
RGBQUAD *rgb = &rgbData[bitmapData[i++]];
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->rgbRed,rgb->rgbGreen,rgb->rgbBlue));

When dib->nPitch does not match the bitmapWidth, the images get skewed, but if I replace dib->nPitch with bitmapWidth, then the images come out right but up-side-down and left-to-right mirrored. And some images got their colors all messed up.
All results were observed on Emulator 2.0 and the SE-47 skin.
MAX, can Qualcomm release the CONVERTBMP code???

brew_newbie wrote:
Or are Windows bitmap stored upside down?
yup.
http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

brew_newbie wrote:
Or are Windows bitmap stored upside down?
yup.
http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

Hi Tyndal,
Thanks for all your pointers. They have helped me along :)
Would you know how BREW DIB are aligned and stored when the phone is a 16-bit phone? I need to figure out to line my 8-bit bmp in a 16-bit IDIB.
It does not look like the BREW doc describes the DIB all too well... :rolleyes:
tyndal wrote:yup.
http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

Hi Tyndal,
Thanks for all your pointers. They have helped me along :)
Would you know how BREW DIB are aligned and stored when the phone is a 16-bit phone? I need to figure out to line my 8-bit bmp in a 16-bit IDIB.
It does not look like the BREW doc describes the DIB all too well... :rolleyes:
tyndal wrote:yup.
http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

Look down in the Data Types section of the Brew 2 documentation. The IDIB structure is explained in fair detail.
As for Windows Bitmaps...IIRC each scan must have a pitch that is a multiple of 32 bits. The easy way to make the calculation is:
nWidthOfScanInBytes = (nWidthInBytes + 3) & ~3;
Yes, by default, Windows bitmaps are stored bottom-up. If the Height parameter of the header is negative, it's stored top-down. Not sure that all implementations of BMP readers understand that latter part, though.

Look down in the Data Types section of the Brew 2 documentation. The IDIB structure is explained in fair detail.
As for Windows Bitmaps...IIRC each scan must have a pitch that is a multiple of 32 bits. The easy way to make the calculation is:
nWidthOfScanInBytes = (nWidthInBytes + 3) & ~3;
Yes, by default, Windows bitmaps are stored bottom-up. If the Height parameter of the header is negative, it's stored top-down. Not sure that all implementations of BMP readers understand that latter part, though.

One important thing to note is that (except in the case of DIBs created with IDISPLAY_CreateDIBitmap()) you should not change any of the fields in the IDIB structure. This is because the object may have its own private data members that must be consistent with the IDIB fields. This is definitely the case with the default device compatible bitmap implementation.
The logic behind CONVERTBMP() is quite simple:
1) Create a DIB from the BMP data.
2) Get the device bitmap.
3) Use the device bitmap to create a compatible bitmap with the same width and height of the BMP.
4) Use IBITMAP_BltIn() to blit from the DIB to the device compatible bitmap.
5) Release the DIB and the device bitmap.
6) Return the device compatible bitmap.
Obviously, there's a lot of stuff behind step 1. If your BMP data resides in .BMP file or a resource file, implementing step 1 is simply a matter of calling ISHELL_LoadBitmap() or ISHELL_LoadResBitmap(). Otherwise, you have to decode the BMP data yourself.

One important thing to note is that (except in the case of DIBs created with IDISPLAY_CreateDIBitmap()) you should not change any of the fields in the IDIB structure. This is because the object may have its own private data members that must be consistent with the IDIB fields. This is definitely the case with the default device compatible bitmap implementation.
The logic behind CONVERTBMP() is quite simple:
1) Create a DIB from the BMP data.
2) Get the device bitmap.
3) Use the device bitmap to create a compatible bitmap with the same width and height of the BMP.
4) Use IBITMAP_BltIn() to blit from the DIB to the device compatible bitmap.
5) Release the DIB and the device bitmap.
6) Return the device compatible bitmap.
Obviously, there's a lot of stuff behind step 1. If your BMP data resides in .BMP file or a resource file, implementing step 1 is simply a matter of calling ISHELL_LoadBitmap() or ISHELL_LoadResBitmap(). Otherwise, you have to decode the BMP data yourself.

Unfortunately, I have to decode the BMP data myself and stick that in an IDIB/IBITMAP struct. I can't load it from the .bar file...
markb wrote:One important thing to note is that (except in the case of DIBs created with IDISPLAY_CreateDIBitmap()) you should not change any of the fields in the IDIB structure. This is because the object may have its own private data members that must be consistent with the IDIB fields. This is definitely the case with the default device compatible bitmap implementation.
The logic behind CONVERTBMP() is quite simple:
1) Create a DIB from the BMP data.
2) Get the device bitmap.
3) Use the device bitmap to create a compatible bitmap with the same width and height of the BMP.
4) Use IBITMAP_BltIn() to blit from the DIB to the device compatible bitmap.
5) Release the DIB and the device bitmap.
6) Return the device compatible bitmap.
Obviously, there's a lot of stuff behind step 1. If your BMP data resides in .BMP file or a resource file, implementing step 1 is simply a matter of calling ISHELL_LoadBitmap() or ISHELL_LoadResBitmap(). Otherwise, you have to decode the BMP data yourself.

Unfortunately, I have to decode the BMP data myself and stick that in an IDIB/IBITMAP struct. I can't load it from the .bar file...
markb wrote:One important thing to note is that (except in the case of DIBs created with IDISPLAY_CreateDIBitmap()) you should not change any of the fields in the IDIB structure. This is because the object may have its own private data members that must be consistent with the IDIB fields. This is definitely the case with the default device compatible bitmap implementation.
The logic behind CONVERTBMP() is quite simple:
1) Create a DIB from the BMP data.
2) Get the device bitmap.
3) Use the device bitmap to create a compatible bitmap with the same width and height of the BMP.
4) Use IBITMAP_BltIn() to blit from the DIB to the device compatible bitmap.
5) Release the DIB and the device bitmap.
6) Return the device compatible bitmap.
Obviously, there's a lot of stuff behind step 1. If your BMP data resides in .BMP file or a resource file, implementing step 1 is simply a matter of calling ISHELL_LoadBitmap() or ISHELL_LoadResBitmap(). Otherwise, you have to decode the BMP data yourself.

That's it! By looping the x until the padded width, I got the images right, but for some images, the colors seemed inverted somehow.
RGBQUAD *rgb = (RGBQUAD*)(((byte*)pSrc) + sizeof(Bitmap));
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->red,rgb->green,rgb->blue));
Notice the cast to uint8, is that a problem? RGB_ToNative returns an uint32?
Getting closer and closer... :D
Bitmap is just the Windows bitmap header. Maybe I should not do a sizeof ?
johnse wrote:Look down in the Data Types section of the Brew 2 documentation. The IDIB structure is explained in fair detail.
As for Windows Bitmaps...IIRC each scan must have a pitch that is a multiple of 32 bits. The easy way to make the calculation is:
nWidthOfScanInBytes = (nWidthInBytes + 3) & ~3;
Yes, by default, Windows bitmaps are stored bottom-up. If the Height parameter of the header is negative, it's stored top-down. Not sure that all implementations of BMP readers understand that latter part, though.

That's it! By looping the x until the padded width, I got the images right, but for some images, the colors seemed inverted somehow.
RGBQUAD *rgb = (RGBQUAD*)(((byte*)pSrc) + sizeof(Bitmap));
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->red,rgb->green,rgb->blue));
Notice the cast to uint8, is that a problem? RGB_ToNative returns an uint32?
Getting closer and closer... :D
Bitmap is just the Windows bitmap header. Maybe I should not do a sizeof ?
johnse wrote:Look down in the Data Types section of the Brew 2 documentation. The IDIB structure is explained in fair detail.
As for Windows Bitmaps...IIRC each scan must have a pitch that is a multiple of 32 bits. The easy way to make the calculation is:
nWidthOfScanInBytes = (nWidthInBytes + 3) & ~3;
Yes, by default, Windows bitmaps are stored bottom-up. If the Height parameter of the header is negative, it's stored top-down. Not sure that all implementations of BMP readers understand that latter part, though.

On some images, I get artifacts like a straight black line at the top of the image...
Please help guys...I have scoured the docs, but none of them provides a complete picture...
brew_newbie wrote:That's it! By looping the x until the padded width, I got the images right, but for some images, the colors seemed inverted somehow.
RGBQUAD *rgb = (RGBQUAD*)(((byte*)pSrc) + sizeof(Bitmap));
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->red,rgb->green,rgb->blue));
Notice the cast to uint8, is that a problem? RGB_ToNative returns an uint32?
Getting closer and closer... :D
Bitmap is just the Windows bitmap header. Maybe I should not do a sizeof ?

On some images, I get artifacts like a straight black line at the top of the image...
Please help guys...I have scoured the docs, but none of them provides a complete picture...
brew_newbie wrote:That's it! By looping the x until the padded width, I got the images right, but for some images, the colors seemed inverted somehow.
RGBQUAD *rgb = (RGBQUAD*)(((byte*)pSrc) + sizeof(Bitmap));
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->red,rgb->green,rgb->blue));
Notice the cast to uint8, is that a problem? RGB_ToNative returns an uint32?
Getting closer and closer... :D
Bitmap is just the Windows bitmap header. Maybe I should not do a sizeof ?

Adjusting y > 0 to y >= 0 killed off the line, but still, some images don't have their colors right...seems inverted or shifted...
I simply compared CONVERTBMP with my own version and the CONVERTBMP gets stuff right. Note: so far, only attempted to test on the Emulator to see that the new function is equivalent to the old one.
The BREW DIB doc does not seem to describe how to line the pixels for a 16-bit depth screen....more trials and errors I guess.... :(
brew_newbie wrote:On some images, I get artifacts like a straight black line at the top of the image...
Please help guys...I have scoured the docs, but none of them provides a complete picture...

Adjusting y > 0 to y >= 0 killed off the line, but still, some images don't have their colors right...seems inverted or shifted...
I simply compared CONVERTBMP with my own version and the CONVERTBMP gets stuff right. Note: so far, only attempted to test on the Emulator to see that the new function is equivalent to the old one.
The BREW DIB doc does not seem to describe how to line the pixels for a 16-bit depth screen....more trials and errors I guess.... :(
brew_newbie wrote:On some images, I get artifacts like a straight black line at the top of the image...
Please help guys...I have scoured the docs, but none of them provides a complete picture...

brew_newbie wrote:
RGBQUAD *rgb = (RGBQUAD*)(((byte*)pSrc) + sizeof(Bitmap));
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->red,rgb->green,rgb->blue));
Notice the cast to uint8, is that a problem? RGB_ToNative returns an uint32?
What form is the source BMP? Is it an 8-bit paletted BMP? or a 32-bit BMP?
You seem to be assuming above that the data in the bitmap is RGBQUADs, but that is only true for 32-bit BMP data. If it's an 8-bit paletted BMP, you need to dereference through the palette to get the RGBQUAD...
Then, yes, the cast to (uint8) is likely an error. How did you set up the DIB? as a paletted 8-bit? In which case, RGBToNative isn't going to work. If you actually are using a Native Bitmap in the DIB, you need to see what the native width of the pixels is (likely 16 bits). In which case, you want to do something like:
uint16* pStartOfScan = (uint16*)&dib->pBmp[y * dib->nPitch];
pStartOfScan += x;
*pStartOfScan = (uint16)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib), MAKE_RGB(rgb->red,rgb->green,rgb->blue));
Of course, since you are looping and processing every pixel, you would be much better off using pointers rather than calculating the address for every pixel.

brew_newbie wrote:
RGBQUAD *rgb = (RGBQUAD*)(((byte*)pSrc) + sizeof(Bitmap));
dib->pBmp[y * dib->nPitch + x ] = (uint8)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib),MAKE_RGB(rgb->red,rgb->green,rgb->blue));
Notice the cast to uint8, is that a problem? RGB_ToNative returns an uint32?
What form is the source BMP? Is it an 8-bit paletted BMP? or a 32-bit BMP?
You seem to be assuming above that the data in the bitmap is RGBQUADs, but that is only true for 32-bit BMP data. If it's an 8-bit paletted BMP, you need to dereference through the palette to get the RGBQUAD...
Then, yes, the cast to (uint8) is likely an error. How did you set up the DIB? as a paletted 8-bit? In which case, RGBToNative isn't going to work. If you actually are using a Native Bitmap in the DIB, you need to see what the native width of the pixels is (likely 16 bits). In which case, you want to do something like:
uint16* pStartOfScan = (uint16*)&dib->pBmp[y * dib->nPitch];
pStartOfScan += x;
*pStartOfScan = (uint16)IBITMAP_RGBToNative(IDIB_TO_IBITMAP(dib), MAKE_RGB(rgb->red,rgb->green,rgb->blue));
Of course, since you are looping and processing every pixel, you would be much better off using pointers rather than calculating the address for every pixel.

I am attempting to get this working and I am 'almost' there with it... The colors look right and the image it mostly correct except for some distortion in the first 2 or 3 rows of the graphic when displayed...
This is my conversion loop, can anyone tell me what I am doing wrong?
This is for converting an 8-bit windows bitmap...
for(y = height-1; y >= 0 ; y--)
{
for(x = 0; x < width; x++)
{
//each pixel (byte) in source should be an index into the palette
rgbquad = pPalette[*pData++];
//convert to native format and store in the dest bitmap
pDIB->pBmp[ y * pDIB->nPitch + x ] =
(byte)IBITMAP_RGBToNative(pDeviceBmp, NTOHL(rgbquad));
}
pData += rowPadding;

I am attempting to get this working and I am 'almost' there with it... The colors look right and the image it mostly correct except for some distortion in the first 2 or 3 rows of the graphic when displayed...
This is my conversion loop, can anyone tell me what I am doing wrong?
This is for converting an 8-bit windows bitmap...
for(y = height-1; y >= 0 ; y--)
{
for(x = 0; x < width; x++)
{
//each pixel (byte) in source should be an index into the palette
rgbquad = pPalette[*pData++];
//convert to native format and store in the dest bitmap
pDIB->pBmp[ y * pDIB->nPitch + x ] =
(byte)IBITMAP_RGBToNative(pDeviceBmp, NTOHL(rgbquad));
}
pData += rowPadding;

I found my problem. I wasn't sending in a complete buffer for conversion.
It now seems to be working for 4,8,24 bit bmps.
If anyone still has this problem I'm willing to share...

I found my problem. I wasn't sending in a complete buffer for conversion.
It now seems to be working for 4,8,24 bit bmps.
If anyone still has this problem I'm willing to share...