Jump to content

  • Log In with Google      Sign In   
  • Create Account


16-bit hell


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 27 November 1999 - 04:17 PM

Ok, I've been writing some framework for a game, but I haven't gotten very far due to the fact that I can't load a 16-bitmap correctly. If the macro and code look weird, yell at Andre LaMothe, it's his book I'm reading

#define _RGB16BIT565(r,g,b) ((r%32) + ((g%64)<<6) + ((b%32)<<11)) //This is the macro to smash the bytes together
///////////////////////////////////////////
lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
USHORT *vidbuffer = (USHORT *)ddsd.lpSurface;
for(int y=0;y{
for(int x=0;x{
UCHAR blue = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
green = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
red = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];
USHORT pixel = _RGB16BIT565(red,green,blue);
vidbuffer[x+y*(ddsd.lPitch/2)] = pixel;
}
}
///////////////////////////////////////////

The bitmaps being loaded are actual 16-bit, not 24. The above code makes a wonderful greyscale picture of whatever bitmap I've loaded. If I shift a few bits here or there, I manage to get some rather 'interesting' effects, but I just can't get the actual bitmap with the right colors to display.

Oh, and if it matters, the bitmaps were created in Ulead Video Paint and saved as 16-bit bitmaps.

Thanks in advance...


Sponsor:

#2 derwiath   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 November 1999 - 08:02 PM

Helloy...
Don't know what your problem is but you should check out the ddutil.h /.cpp files included with the sdk. In there you have functions who is loading bitmapps directly into dx-surfaces.
It is more fun to do it yourself but atleast you could use them to see if it is your bitmapreading-algorithm that is messing with ya.

/Derwiath


#3 Theses   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 November 1999 - 10:19 PM

uhh what the hell is this?

UCHAR
blue=bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
green=bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
red=bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];

mmmm i seriously doubt you wanted all three colors to have the same (y*IMAGE_HEIGHT*2+x*2)in it



#4 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 26 November 1999 - 05:05 AM

Thanks for the suggestion. I really wanted to do it myself, but I'm getting to the point that I don't care anymore . I'll have a look at the stuff that comes with the SDK.

No, I don't want each color to be the same, but that is as close as I can get it to being normal. Since I don't move any bits, the image is in black and white. If I try to ajust the colors, they totally bug out and give me things that people see when they take too much acid.


#5 Strabbi   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 November 1999 - 06:05 AM

Have you tried replacing:

UCHAR blue = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
green = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
red = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];
USHORT pixel = _RGB16BIT565(red,green,blue);

with:

USHORT pixel = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];



#6 VisualLR   Members   -  Reputation: 272

Like
Likes
Like

Posted 26 November 1999 - 06:12 AM

Try replacing this:

UCHAR
b = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
g = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
r = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];

with this:

b = bitmap.buffer[(i*3)+0] >> 3);
g = bitmap.buffer[(i*3)+1] >> 3);
r = bitmat.buffer[(i*3)+2] >> 3);

however, I used that to convert 24bit bitmaps to 16bit bitmaps, so if something weird happens, try saving your bitmap as 24bit and then loading it using that.

also, the macro I used is:

#define _RGB16BIT(r,g,b) ((b%32) + ((g%32) << 5) + ((r%32) << 10))

hope that's useful... later!

------------------
Luis Sempe
visuallr@netscape.net
http://www.geocities.com/SiliconValley/6276



#7 frizb   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 November 1999 - 02:13 PM

It looks like you are using 6 bits for blue. Can someone tell me if I'm wrong? The macro right above me looks more like it.

------------------
Still Learning...


#8 Aidan   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 November 1999 - 08:25 AM

I think you get wrong input data from the bitmap.buffer .
You get an greyscale image with the
UCHAR blue = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];
green = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];
red = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];

because the RGB values are all the same, so I think the program has loaded the right data. (Because, you get a grey value when R,G,B values are the same.
Extracting the value from the buffer seems to be the problem. I don't know how the data is distributed in the "buffer", but this is essential to solving the problem.

VisualLR has introduced another problem to the 16-bit hell. He transforms his 888, RGB value to a 555-bit value with 5-bits for red, 5 for green and 5 for blue. This isn't mostly right(it depends on the graphic card), so many cards use the 565-bit style.

->Aidan


#9 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 27 November 1999 - 04:14 PM

Hehehehe, got it.

I ended up using a cheapo color-scaling algorithm to load 24-bit images and dither them down to 16. The pics still look pretty good, but it only works on images where the height and width are divisible by 4, 400, 64, 256, etc. That's really not a problem, so I'm pretty damn satisfied.

Now it's time for the hard stuff .

Thanks to all who posted


#10 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 27 November 1999 - 04:17 PM

Oh yah, here's the code if you wanna see it. It uses the same macro as the one above:

lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
USHORT *primary_buffer = (USHORT *)ddsd.lpSurface;
for (int index_y = 0; index_y < bitmap.bitmapinfoheader.biHeight; index_y++)
{
for (int index_x = 0; index_x < bitmap.bitmapinfoheader.biWidth; index_x++)
{
UCHAR blue = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3+0])>>3,
green = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3+1])>>3,
red = (bitmap.buffer[index_y*bitmap.bitmapinfoheader.biWidth*3 + index_x*3+2])>>3;
USHORT pixel = _RGB16BIT565(red,green,blue);
primary_buffer[index_x + (index_y*ddsd.lPitch >> 1)] = pixel;
}
}





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS