pouët.net

Go to bottom

4kb image tech question

category: general [glöplog]
 
What's the best (smallest) way to put a an image on the screen?
added on the 2008-07-28 17:57:10 by xernobyl xernobyl
MS Paint.
added on the 2008-07-28 17:58:16 by kusma kusma
Paint. And a really small brush.

Xernobyl: can you be a bit more specific?
added on the 2008-07-28 18:00:51 by psonice psonice
He probably means it in terms of framework overload.
added on the 2008-07-28 18:02:09 by tomaes tomaes
iq posted some code with StretchDIBits here some days ago, that should do fine.
added on the 2008-07-28 18:11:35 by skrebbel skrebbel
i always did something like that:

Code: void draw(HDC hDC) { for(int x = 0; x < 1024; x++) { for(int y = 0; y < 768; y++) { SetPixel(hDC, x, y, RGB(0,0,0))); } } } void main() { HDC hDC; HWND hWnd; DEVMODE dmScreenSettings; dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = 1024; dmScreenSettings.dmPelsHeight = 768; dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN); hWnd = CreateWindowExA(0, "edit", NULL, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, NULL); hDC = GetDC(hWnd); ShowCursor(FALSE); draw(hDC); while(!GetAsyncKeyState(VK_ESCAPE)) { } }
added on the 2008-07-28 18:32:01 by src src
ahyes, and i guess iq meant that the draw function could be replaced by
Code:static BITMAPINFO bmi = { {sizeof(BITMAPINFOHEADER), XRES, -YRES, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, {0,0,0,0} }; StretchDIBits( hDC, 0, 0, XRES, YRES, 0,0, XRES,YRES, buffer, &bmi, DIB_RGB_COLORS, SRCCOPY );
added on the 2008-07-28 19:19:54 by skrebbel skrebbel
skrebbel: I couldn't get that to work... but it's still commented on my code, and I couldn't take screenshots with the src way.
added on the 2008-07-28 20:28:16 by xernobyl xernobyl
for taking screenshots replace this line:
Code: while(!GetAsyncKeyState(VK_ESCAPE)) { }


with this stuff:
Code: MSG msg; while(GetAsyncKeyState(VK_ESCAPE) == 0) { if(PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) { switch(msg.message) { case WM_KEYDOWN: //go = 0; break; case WM_PAINT: break; } } }


i encountered this issue, too, i think it's a winapi problem...
added on the 2008-07-28 20:36:03 by src src
you need to implement your own windows class with a WndProc and an event loop (the PeekMessage+DispatchMessage thing) to be able to get screenshots.

my full code is more or less this one:

Code: #include <windows.h> #define XRES 1280 #define YRES 1024 // #define TAKESCREENSHOT static const BITMAPINFO bmi = { {sizeof(BITMAPINFOHEADER),XRES,-YRES,1,32,BI_RGB,0,0,0,0,0},{0,0,0,0} }; static DEVMODE screenSettings = { #if _MSC_VER < 1400 {0},0,0,148,0,0x001c0000,{0},0,0,0,0,0,0,0,0,0,{0},0,32,XRES,YRES,0,0, #else {0},0,0,156,0,0x001c0000,{0},0,0,0,0,0,{0},0,32,XRES,YRES,{0},0, #endif #if(WINVER >= 0x0400) 0,0,0,0,0,0, #if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400) 0,0 #endif #endif }; static unsigned int buffer[XRES*YRES]; void renderImage( unsigned int *buffer, int xres, int yres ); void entrypoint( void ) { if( ChangeDisplaySettings(&screenSettings,CDS_FULLSCREEN)) return; ShowCursor( 0 ); HDC hDC = GetDC( CreateWindowEx( 0,"static",0,WS_VISIBLE|WS_POPUP|WS_CLIPSIBLINGS|WS_MAXIMIZE,0,0,0,0,0,0,0,0) ); StretchDIBits(hDC,0,0,XRES,SYRES,0,0,XRES,SYRES,buffer,&bmi,DIB_RGB_COLORS,SRCCOPY); renderImage( buffer, XRES, YRES ); #ifdef TAKESCREENSHOT static const unsigned char head32[18] = { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, XRES&255, XRES>>8, YRES&255, YRES>>8, 0x20, 0x00 }; HANDLE h = CreateFile( "out.tga", GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); unsigned long wr; WriteFile( h, head32, 18, &wr, 0 ); for( int i=0; i<YRES; i++ ) WriteFile( h, buffer+XRES*(YRES-1-i), XRES*4, &wr, 0 ); CloseHandle( h ); #endif do { StretchDIBits(hDC,0,0,XRES,YRES,0,0,XRES,YRES,buffer,&bmi,DIB_RGB_COLORS,SRCCOPY); }while( !GetAsyncKeyState(VK_ESCAPE)); ExitProcess(0); }


it's basically src´s code, just that by making the devmode struct static data I win few bytes (with my compiler+options). There is also that code to take a screenshot.

added on the 2008-07-28 20:44:32 by iq iq
i'm curious why it wins few bytes in such a case
I knew it had something to do with the loop, but I was hoping there was a smaller way to get it done.
added on the 2008-07-28 20:58:03 by xernobyl xernobyl
But you can do your small-version without the PeekMessageA-stuff and include the other code in a bigger version of your 4k gfx. I don't think that anyone gets mad with you if he can't take a screenshot of the small version ;)
added on the 2008-07-29 00:14:23 by src src
You've got a point...
added on the 2008-07-29 01:13:40 by xernobyl xernobyl
spongebob has a point.
added on the 2008-07-29 17:13:17 by elkmoose elkmoose
iq: what is the size you can get with your compiller? here: 2.5K with VC9express :\ any one?

login

Go to top