1. Graphics Problems
- Posted by euman at bellsouth.net Apr 03, 2002
- 434 views
Hello all, I have a program that uses graphics exclusivly for the GUI and I have one minor problem. Im using DIBSections for the imagery and double buffering the images with memory DC's so I can bitblt the images to screen when needed at certain locations. What Ive found is in 256 color mode the screen and images retain their respective palette until my window looses focus. I have this short piece of code that works fine for any window that may overlap my window but if any window is exclusive to the screen size (full screen) and recieves focus then my window losses its palette when it regains focus. elsif iMsg = WM_ACTIVATE then if LOWORD(wParam) = 0 then hdc = GetDC(hwnd) savedDC = c_func(xSaveDC,{hdc}) ReleaseDC(hwnd, hdc) elsif LOWORD(wParam) = 1 or LOWORD(wParam) = 2 then if lParam = hwnd then ShowWindow(hwnd, SW_SHOWNORMAL) junk = c_func(xRestoreDC,{hdc, -1}) c_proc(UpdateWindow, {hwnd}) end if any ideas? Euman euman at bellsouth.net 5 2 1 - 1 - n - 5 The Doors
2. Re: Graphics Problems
- Posted by euman at bellsouth.net Apr 03, 2002
- 413 views
----- Original Message ----- From: "Bernie Ryan" <xotron at localnet.com> > euman at bellsouth.net wrote: > > Hello all, > > > > I have a program that uses graphics exclusivly for the GUI and I have > > one minor >> <snip> > Euman: > The -1 in RestoreDC maybe causing a problem if somewhere > in your program or windows the device context stack has > been disturbed. > Bernie Thanks Bernie for the reply.! Here is a bit more info on my problem that might help you help me. I also create a private DC, I use CS_OWNDC. (eg. poke4(wndclass + style, CS_OWNDC) ) a private device context is preserved throughout the lifetime of its associated window, you need to retrieve its handle only once. the private device context is not retrieved from the GDI device-context cache. This means that any attribute changes (in modes, colors, origins, and graphic objects) that you make to a private device context are preserved until you explicitly modify them. So I ask this: If I issue SaveDC( ) when my windows is deactivated and RestoreDC( ) when my window is re-Activated how can the DC stack become corrupt in an unactive state? Maybe this will help??? Euman euman at bellsouth.net .
3. Re: Graphics Problems
- Posted by euman at bellsouth.net Apr 03, 2002
- 419 views
----- Original Message ----- From: "Chris Bensler" <bensler at mail.com> To: "EUforum" <EUforum at topica.com> > Have you tried resetting the palette on WM_ACTIVATE? > > Exotica requires you to rebuild custom graphics on WM_ACTIVATE. If not, > the video memory buffer is corrupted from other windows, and the custom > bitmaps are thrashed. > I assume, it's a similar situation. > > Chris > Thanks Chris for the reply.! I had tried resetting the palette initially and it didnt work. I even tried using a memory DC to hold the window image and bitblt this back to the hwndDC when the program came back into focus. The image is there but has an awfull looking palette (all green and red and, neither of these colors are in the the real image). I have a routine in the code to move the window around the screen and noticed that when the image looks as it should (colors) that the image does not drag smoothly but when this (Red &Green) image comes up, the image can be dragged around smoothly as it does in 16 bit+ modes. Im frustrated..... Thanks again, I 'll post the code if anyone would like. Euman euman at bellsouth.net 5 2 1 - 1 - n - 5 The Doors
4. Re: Graphics Problems
- Posted by euman at bellsouth.net Apr 03, 2002
- 415 views
> > Euman: > The -1 in RestoreDC maybe causing a problem if somewhere > in your program or windows the device context stack has > been disturbed. > Bernie > Bernie you helpfull freind! you indirectly (possibly) solved the whole mess. you pointed right at the answer: RestoreDC( ) -1 look at the DC it should be "savedDC" if lParam = hwnd then ShowWindow(hwnd, SW_SHOWNORMAL) junk = c_func(xRestoreDC,{hdc, -1}) c_proc(UpdateWindow, {hwnd}) end if Thanks, I'll get back to you if this doesnt work! Euman euman at bellsouth.net
5. Re: Graphics Problems
- Posted by euman at bellsouth.net Apr 04, 2002
- 404 views
Hello, I think this should be book marked as one of the best sites that explains palettes in Windows. (interested parties ofcourse) http://www.compuphase.com/palette.htm Euman euman at bellsouth.net
6. Re: Graphics Problems
- Posted by euman at bellsouth.net Apr 04, 2002
- 424 views
Hello all, I hope I write this right! See if you can wrap your brain around this.... My Graphics problem is not really an issue of my DC being corrupt but instead a palette issue after all. I downloaded this utility that allows you to snoop the palette across the system and running apps. http://www.compuphase.com/palspy.zip I opened Jasc PSP 7.0 and the palette the image I am displaying doesnt match the palette from my program when I have SaveDC( ), RestoreDC and then RealizePalette( ). The problem is that there are 20 colors that Windows uses for a "system palette" and my "logical palette" contains (3) colors that are system colors, these make my logical palette become unorginized. I read that using PC_NOCOLLAPSE would eliminate this problem but it doesnt seem to be working as advertised on Win 98 SE. What I am going to do is take the (3) colors and slightly change these in the image to different RGB values so they no longer are mapped to the system colors to see if this works. I'll get back to you all to let you know my findings. Euman
7. Re: Graphics Problems
- Posted by euman at bellsouth.net Apr 04, 2002
- 435 views
Hello all, Here is my updated Palette code! I initialize the palette when I create my first DDB (DIB) my DibSection code is not included here for size purposes. This code originated with Win32lib but has evolved into this much faster piece (maybe the Win32lib guys will like this?) Keep in mind that when you use hDIB = c_func( xCreateDIBitmap that this only creates a bitmap thats Device-Dependant and will default to using the system palette (I really should change this for less confusion, maybe later) Dib-Sections are not Dependant and can render using a logical palette which this code in global function createDIB presents "palette routine". There is a way to convert DDB bitmaps to DibSections but I havent included this code either. (READ MORE BELOW CODE) -- (highly modified!)Code from win32lib development -- "contains palette code and optimizations" -- Euman 2002 global atom newpal, palinfo newpal = 0 ----------------------------------------------------------------------------- function packScanLine( sequence pixels ) -- convert a scanline of data into a packed scanline integer fill sequence packed packed = pixels fill = and_bits( length( packed ), 4 - 1 ) if fill then packed = packed & repeat( 0, 4-fill ) end if return packed end function global atom ple ple = myalloc(1028) constant --CBM_CREATEDIB = #2, CBM_INIT = #4 atom memBitmapInfo integer pal_exist pal_exist = 0 global atom hPal --hpal = 0 global sequence spal global function createDIB(atom hdc, sequence pal, sequence pixels) integer palSize, headerSize, bitsPer, h, w, at atom memBits, hDIB, onine, lnine sequence ret palSize = length(pal) bitsPer = 8 -- size of bitmap w = length( pixels[1] ) h = length( pixels ) -- calculate the size of the BITMAPINFO header headerSize = 40 + (4 * palSize ) -- Allocate memory for DIB memBitmapInfo = myalloc(headerSize) -- build the bitmap info header mypoke4( memBitmapInfo + 0, 40 ) mypoke4( memBitmapInfo + 4, w ) -- Width in pixels. mypoke4( memBitmapInfo + 8, -h ) -- Height in pixels. mypoke ( memBitmapInfo + 12, {1,0} ) -- 1 color plane. mypoke ( memBitmapInfo + 14, {8,0} ) -- bits per pixel. mypoke4( memBitmapInfo + 32, 256 ) -- Colors used. mypoke4( memBitmapInfo + 36, 256 ) -- Colors used. for i = 1 to h do pixels[i] = packScanLine( pixels[i] ) end for -- get bytes per scanline w = length( pixels[1] ) -- Allocate storage memBits = myalloc(h * w) -- copy pixels to memory at = memBits for i = 1 to h do mypoke( at, pixels[i] ) at = at + w end for at = memBitmapInfo + 40 if pal_exist = 0 then c_proc(xSetSystemPaletteUse,{hdc, 1}) onine = myalloc(40) lnine = myalloc(40) junk = c_func(xGetSystemPaletteEntries,{hdc, 0, 10, onine}) junk = c_func(xGetSystemPaletteEntries,{hdc, 246, 255, lnine}) for i = 1 to palSize do if i < 11 then if i = 1 then junk = c_func(xCopyMemory,{at, onine, 40}) at += 40 end if elsif i > 246 then if i = 247 then junk = c_func(xCopyMemory,{at, lnine, 40}) at += 40 end if else mypoke(at, pal[i]) at = at + 4 end if end for myfree(onine) myfree(lnine) pokew(ple + 0, #300) pokew(ple + 2, 256) junk = c_func(xCopyMemory,{ple+4, at - 1024, 1024}) newpal = c_func(xCreatePalette,{ple}) junk = c_func(xSetPaletteEntries, {newpal, 0, 255, ple+4}) hPal = c_func(xSelectPalette, {hdc, newpal, 1}) junk = c_func(xRealizePalette, {hdc}) junk = c_func(xSelectPalette, {hdc, hPal, 1}) pal_exist = 1 else junk = c_func(xCopyMemory,{at, ple+4, 1024}) end if -- Create the DIB. hDIB = c_func( xCreateDIBitmap, { hdc, memBitmapInfo, CBM_INIT, memBits, memBitmapInfo, 0} ) myfree(memBits) myfree(memBitmapInfo) return hDIB end function --from windproc( ) elsif iMsg = WM_ACTIVATE then if LOWORD(wParam) = 0 then hPal = c_func(xSelectPalette, {hdc, newpal, 0}) junk = c_func(xRealizePalette, {hdc}) InvalidateRect(hwnd, NULL, 0) savedDC = c_func(xSaveDC,{hdc}) --junk = 0 elsif LOWORD(wParam) = 1 or LOWORD(wParam) = 2 then if savedDC > 0 then junk = c_func(xRestoreDC,{hdc, -1}) hPal = c_func(xSelectPalette, {hdc, newpal, 0}) junk = c_func(xRealizePalette, {hdc}) InvalidateRect(hwnd, NULL, 0) end if end if return junk -- remember to return the ret-val from RealizePalette( ) This is really all there is to palette creation and It now works to display multiple images that looks proper on all bit levels (assuming a palette compatible graphics card and monitor is installed.) I can answer just about any question you might have about palettes now that Ive spent three days researching this. Thanks again to all the help Wolf, Bernie and Chris! Euman euman at bellsouth.net 5 2 1 - 1 - n - 5 The Doors
8. Re: Graphics Problems
- Posted by euman at bellsouth.net Apr 04, 2002
- 415 views
Before someone gets on me about one of the routines heres an ammended version if pal_exist = 0 then c_proc(xSetSystemPaletteUse,{hdc, 1}) onine = myalloc(40) lnine = myalloc(40) junk = c_func(xGetSystemPaletteEntries,{hdc, 0, 10, onine}) junk = c_func(xGetSystemPaletteEntries,{hdc, 246, 255, lnine}) junk = c_func(xCopyMemory,{at, onine, 40}) at += 40 for i = 10 to 245 do mypoke(at, pal[i]) at = at + 4 end for junk = c_func(xCopyMemory,{at, lnine, 40}) at += 40 Euman euman at bellsouth.net 5 2 1 - 1 - n - 5 The Doors