Link to home
Start Free TrialLog in
Avatar of Olympus
Olympus

asked on

32bpp->24bpp with BitBlt/StretchBlt

In my program, it is necessary to convert the screen capture image from the screen's bit depth (usually
32bpp) to a 24bit format. With this code, I get about 0.5 to 1.0 seconds of lag (system freeze; the
mouse cannot be moved) during StretchBlt() when converting from my desktop depth of 32bits to 24bits.
As far as I can tell, this could perhaps be windows XP dependant?

Here's the code:

HBITMAP Bitmap;
int ScreenWidth, ScreenHeight, Width, Height, Scale;
HDC DesktopDC, CaptureDC;
BITMAPINFO BitmapInfo;
unsigned char *Data;

Scale = 50;
DesktopDC = GetDC(GetDesktopWindow());
ScreenWidth = GetDeviceCaps(DesktopDC, HORZRES);
ScreenHeight = GetDeviceCaps(DesktopDC, VERTRES);
Width = (ScreenWidth * Scale) / 100;
Height = (ScreenHeight * Scale) / 100;

memset(&BitmapInfo.bmiHeader, 0, sizeof(BitmapInfo.bmiHeader));
BitmapInfo.bmiHeader.biWidth = Width;
BitmapInfo.bmiHeader.biHeight = Height;
BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = 24;
BitmapInfo.bmiHeader.biCompression = BI_RGB;

CaptureDC = CreateCompatibleDC(DesktopDC);
Bitmap = CreateDIBSection(DesktopDC, &BitmapInfo, DIB_RGB_COLORS, (void **)&Data, 0, 0);

SelectObject(CaptureDC, Bitmap);
StretchBlt(CaptureDC, 0, 0, Width, Height, DesktopDC, 0, 0, ScreenWidth, ScreenHeight, SRCCOPY); //
1 second freeze occurs here...

Any suggestions? It seems as if StrechBlt() is freezing up due to having to convert from 32bpp to 24bpp.
I have the exact same problem when doing BitBlt() from the screen to a bitmap of similar size.
Avatar of jkr
jkr
Flag of Germany image

This behaviour is not a big surprise - it's the sheer amount of data that has to be processed...
Avatar of Olympus
Olympus

ASKER

Yes, but this behaviour is non existant on 9x platforms. (Confirmed this morning.) Windows shouldn't be using realtime priority whilst processing the data. Is there a better way around this?
>>Yes, but this behaviour is non existant on 9x platforms

You seem to forget that since NT4, the GDI has been moved into kernel space - it should work like Win9x on NT3.51 :o)
The code consumes large amount of memory. What is the size of your machine's available physical memory ? It seems to me that the 500ms wait is caused by memory swapping.

If you still plan use the codes in a machine with a small amount of available memory, change the code to use a multi-thread mechanisme (of course with critical section locks). In this mechanisme, your user-interface is still active (e.g. mouse & keyboard is still usable) while waiting the memory swap complete.

Regards,


Seno Hardijanto
Avatar of Olympus

ASKER

Memory is not the concern.. i have over 250 megs free at any given time; and PLUS the code causes ZERO cpu freeze on my 98 partition.
Avatar of Olympus

ASKER

(This is not being run on an application with a GUI.)
You're right;

I test your codes with my XP machine, there is no glitch in memory utilization, only in CPU usage (up to 50%). But in my environment there is no difference whether I use 16 bits or 32 bits screen depth, and ScretchBlt function call consumes CPU only about 100-200 ms (I use PIII 900Mhz).

Some of the GDI call were not performed by the CPU itself. The processor only relay the calls to the graphic adapter. So, I think you need to concern about the graphic adapter.
Avatar of Olympus

ASKER

There is no easy way to do the bpp conversion better with API functions?
Dear Olympus

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jkr"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Avatar of Olympus

ASKER

Well senohp was able to reproduce the problem; is there a way to do this with GetDIBits and StretchDIBits to get rid of the delays in BitBlt and StretchBlt?
Please update and finalize this old, open question. Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,

** Mindphaser - Community Support Moderator **

P.S.  Click your Member Profile, choose View Question History to go through all your open and locked questions to update them.
Avatar of Olympus

ASKER

3; refund would be best.
ASKER CERTIFIED SOLUTION
Avatar of Mindphaser
Mindphaser

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial