Advertisement

BITMAP STUFF

Started by February 09, 2000 03:34 PM
17 comments, last by ThaUnknownProgga 24 years, 6 months ago
ALRIGHT. I''m going insane here. I need any help possible on writing a bitmap. Well, kinda on writing a bitmap. I guess moreso on converting a bitmap to 24bit and then saving it to the harddrive. If you''ll look at my previous post "writing a bitmap" you can see two bitmaps that show the problem i encounter when writing the file. Those color bars, the skewing...it''s unexplainable. Furthermore, I recently blitted all the pixels to the screen and it looks right there, the only problem is saving! I also discovered that it actually doesn''t skew it in a set way, it changes the colors and skews it depending on the colors in the bitmap. WHAT IS GOING ON HERE! PLEASE, any and all help is appreciated!!!
My guess is that you are trying to save an 8bpp image to a 24bpp file, which would give you a skewing as three pixels gets crammed into one. It could be a 16bpp image too of course.

When blitting to the screen GDI, or whatever API you''re using, converts the pixel format used in your image to the format used on the screen.
Advertisement
Ok, but I write three seperate bytes, one for each color. Well anyway, how would i solve the problem you''re talking about? (you can see my code and before/after pictures at here)

I think the problem may be in this line:

outpixel = *((WORD *)(Bitmap_in+loop2 + loop * Pitch));

loop2 needs to advance two at a time. (This may be
the case, but your for loop was cut off in the
previous message).
I looked at the source and the only thing I could think of, except what LordFoul mentioned, was this: When working with DirectDrawSurfaces you need to use Lock to acquire a pointer to the buffer.

As for the images, there are no skewing going on, the part above the color bars is just shifted about 64pixels to the right (or maybe 256-64 to the left). The part below the bars is as they should be.
Here is the newest version of that section of the code:
(I subsituted '@' in for the less than sign because the less than sign screws up)

for (loop2=0;loop2@Pitch;loop2+=2){outpixel = *((WORD *)(Bitmap_in+loop2+loop*Pitch));  


still does the same thing. and btw, the surface is locked.

BTW, thank you to everyone for helping me so far!

Edited by - ThaUnknownProgga on 2/9/00 9:57:29 PM
Advertisement

The problem may be with using Pitch as the bound for
your inner loop. Use width (the actual size you
used to declare the surface) times 2. Pitch and
width aren''t necessarily the same.
Alright, i changed it, but in this situation the width is 256 and the pitch is 512...so nothing different happened.
Well I finished my bitmap saving function just last night, and I was so thrilled when I finally got it to work. So I'll show you how I did mine and maybe that might help.

tmp_buffer is the source image
bitmap.buffer is the destination memory
Then I just write out the bitmap.buffer

This is after I've already flipped the bitmap...
// lt = less than
for(i=0; i lt Width*Height; i++)
{
WORD color;

// Set the color according to the pixel format
if(dd_pixel_format == DD_PIXEL_FORMAT555)
{
color = ((WORD*)tmp_buffer) ;

((BYTE*)bitmap.buffer)[i*3+0] = ((color&0x1f)<<3);
((BYTE*)bitmap.buffer)[i*3+1] = (((color>>5)&0x1f)<<3);
((BYTE*)bitmap.buffer)[i*3+2] = (((color>>10)&0x1f)<<3);
}
else if(dd_pixel_format == DD_PIXEL_FORMAT565)
{
color = ((WORD*)tmp_buffer);

((BYTE*)bitmap.buffer)[i*3+0] = ((color&0x1f)<<3);
((BYTE*)bitmap.buffer)[i*3+1] = (((color>>5)&0x3f)<<2);
((BYTE*)bitmap.buffer)[i*3+2] = (((color>>11)&0x1f)<<3);
}
}


Edited by - lshadow on 2/9/00 11:12:37 PM
Working on: DoP
I STILL haven''t solved this problem! All I need to do is be able to open any bit-depth bitmap, and store it on the harddrive in a packfile so that i can later retrieve it. i was planning on just writing out 24 bit bitmaps to the pack file (because i can read those easily) but aparently that''s not going to work. ANY help and i do mean ANY will be greatly appreciated! (and i do mean GREATLY!)

This topic is closed to new replies.

Advertisement