How to grey/blur screen, while own window is on top?

Windows specific forum
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: How to grey/blur screen, while own window is on top?

Post by Thunder93 »

lol! @TI-994A
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: How to grey/blur screen, while own window is on top?

Post by Thunder93 »

I think RASHAD code came the closest to the dim-out desktop effect that was asked for. However, the Taskbar and application desktop toolbars aren't covered.

netmaestro has nice tiny code that covers the entire screen but doesn't do the gradual dim-out.

You'll have to work with one of these. I don't remember ever seeing a single Win API to-do this procedure.

Blur effect doesn't seem to be what you really want?
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How to grey/blur screen, while own window is on top?

Post by RASHAD »

# 1 : Grayed full screen
Modal window (Not realy) :)

Code: Select all

ExamineDesktops()

WW = DesktopWidth(0)
WH  = DesktopHeight(0)

CreateImage(0,WW,WH)
hDC = StartDrawing(ImageOutput(0))
              BitBlt_(hDC,0,0,WW,WH,GetDC_(GetDesktopWindow_()), 0, 0, #SRCCOPY)
          StopDrawing()
          StartDrawing(ImageOutput(0))
              For x = 0 To WW - 1
                For y = 0 To WH - 1
                  color = Point(x, y)
                  gray = (Red(color) + Green(color) + Blue(color)) /3 
                  gray = RGB(gray, gray, gray)
                  Plot(x, y, gray)
                Next y
              Next x
          StopDrawing()   

OpenWindow(0,0,0,WW,WH,"",#PB_Window_BorderLess| #PB_Window_Invisible)

myBrush = CreatePatternBrush_(ImageID(0))
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, myBrush)
;InvalidateRect_(WindowID(0),0,1)
FreeImage(0)

AnimateWindow_(WindowID(0),3000,#AW_BLEND| #AW_ACTIVATE)

OpenWindow(1,0,0,800,600,"",#PB_Window_SystemMenu |#PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget| #PB_Window_ScreenCentered,WindowID(0)) 
StringGadget(1,10,10, 200,24,"",#ES_CENTER)
ButtonGadget(2,10,40,80,22,"Exit")

Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
             Quit = 1
             
      Case #WM_LBUTTONDOWN, #WM_RBUTTONDOWN, #WM_LBUTTONUP,#WM_RBUTTONUP,#WM_LBUTTONDBLCLK, #WM_RBUTTONDBLCLK, #WM_MBUTTONDOWN, #WM_MBUTTONUP, #WM_MBUTTONDBLCLK
               GetCursorPos_ (@p.POINT)
               If WindowFromPoint_(p\y << 32 + p\x) = WindowID(0)
                   SendMessage_(#HWND_BROADCAST, #WM_SYSCOMMAND, #SC_HOTKEY, WindowID(1))
                EndIf
             
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
             
            Case 2
             
          EndSelect
  EndSelect
Until Quit =1
# 2 :Using [wilbert] blured snippet

Code: Select all

ExamineDesktops()
WW = DesktopWidth(0)
WH  = DesktopHeight(0)

CreateImage(0,WW,WH) 
hDC = StartDrawing(ImageOutput(0)) 
BitBlt_(hDC,0,0,WW,WH,GetDC_(GetDesktopWindow_()),x,y, #SRCCOPY) 
StopDrawing()

 Procedure Gaussian1D(*PixelBuf32, NumPixels, NextPixelOffset = 4)
 
  !mov ecx, [p.v_NumPixels]
  !sub ecx, 3
  !js gaussian1d_exit
  !mov eax, [p.v_NextPixelOffset] 
 
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !mov rdx, [p.p_PixelBuf32]
    !movd mm1, [rdx]
    !movd mm4, [rdx + rax]
  CompilerElse
    !mov edx, [p.p_PixelBuf32]
    !movd mm1, [edx]
    !movd mm4, [edx + eax]
  CompilerEndIf
  !punpcklbw mm1, mm1
  !punpcklbw mm4, mm4
  !psrlw mm1, 4
  !psrlw mm4, 4
  !movq mm2, mm1
  !movq mm3, mm1
 
  ; loop
  !gaussian1d_loop0:
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !movd mm5, [rdx + rax * 2]
  CompilerElse
    !movd mm5, [edx + eax * 2]
  CompilerEndIf
  !punpcklbw mm5, mm5
  !psrlw mm5, 4
  !gaussian1d_loop1:
  !movq mm0, mm2
  !paddw mm0, mm3
  !paddw mm0, mm4
  !psllw mm0, 2
  !paddw mm0, mm1
  !paddw mm0, mm3
  !paddw mm0, mm3
  !paddw mm0, mm5
  !psrlw mm0, 8
  !packuswb mm0, mm0
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    !movd [rdx], mm0
    !add rdx, rax
  CompilerElse
    !movd [edx], mm0
    !add edx, eax
  CompilerEndIf
  !movq mm1, mm2
  !movq mm2, mm3
  !movq mm3, mm4
  !movq mm4, mm5
  !dec ecx
  !jns gaussian1d_loop0
  !cmp ecx, -3
  !jne gaussian1d_loop1
  !gaussian1d_exit:
  !emms
 
EndProcedure
 
 Procedure Gaussian2D(*PixelBuf32, Width, Height,  BufferPitch = 0)
  
  If BufferPitch = 0
    BufferPitch = Width << 2
  EndIf
 
  Protected i.i = 0
  While i < Height
    Gaussian1D(*PixelBuf32 + BufferPitch * i, Width)
    i + 1 
  Wend
 
  i = 0
  While i < Width
    Gaussian1D(*PixelBuf32 + i << 2, Height, BufferPitch)
    i + 1 
  Wend
 
EndProcedure
 
 Procedure GaussianBlur(Image, Strength = 2)
 
  Protected.i i, w, h, x, y, max_x, max_y
 
  If StartDrawing(ImageOutput(0))
    w = OutputWidth()
    h = OutputHeight()
   
    If DrawingBufferPixelFormat() & $60; 32 bit buffer ?
      For i = 0 To Strength
        Gaussian2D(DrawingBuffer(), w, h,  DrawingBufferPitch())
      Next
    Else
      max_x = w - 1
      max_y = h - 1
      Dim Buffer.l(max_y, max_x)
      DrawingMode(#PB_2DDrawing_AllChannels)
      For y = 0 To max_y
        For x = 0 To max_x
          Buffer(y, x) = Point(x, y)
        Next
      Next
      For i = 0 To Strength
        Gaussian2D(@Buffer(), w, h)
      Next
      For y = 0 To max_y
        For x = 0 To max_x
          Plot(x, y, Buffer(y, x))
        Next
      Next
    EndIf
    StopDrawing()
   
  EndIf
 
EndProcedure
 
OpenWindow(0,0,0,WW,WH,"", #PB_Window_BorderLess| #PB_Window_Invisible)
GaussianBlur(0) 
  
myBrush = CreatePatternBrush_(ImageID(0))
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, myBrush)
FreeImage(0)

AnimateWindow_(WindowID(0),3000,#AW_BLEND| #AW_ACTIVATE)

OpenWindow(1,0,0,800,600,"", #PB_Window_SystemMenu |#PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget| #PB_Window_ScreenCentered, WindowID(0))  
StringGadget(1,10,10, 200,24,"", #ES_CENTER)
ButtonGadget(2,10,40,80,22,"Exit")

Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
              Quit = 1
             
      Case #WM_LBUTTONDOWN, #WM_RBUTTONDOWN, #WM_LBUTTONUP,#WM_RBUTTONUP, #WM_LBUTTONDBLCLK, #WM_RBUTTONDBLCLK, #WM_MBUTTONDOWN, #WM_MBUTTONUP, #WM_MBUTTONDBLCLK
               GetCursorPos_ (@p.POINT)
               If WindowFromPoint_(p\y << 32 + p\x) = WindowID(0)
                   SendMessage_(#HWND_BROADCAST, #WM_SYSCOMMAND, #SC_HOTKEY, WindowID(1))
               EndIf
       
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              
            Case 2
              
          EndSelect
  EndSelect 
Until Quit =1
Egypt my love
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Re: How to grey/blur screen, while own window is on top?

Post by va!n »

Thanks for all your replies and examples. The methode with the special Win32 API isnt listed here. However i will use a solution, you guys posted here! *thumbs up*
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Puffolino
User
User
Posts: 49
Joined: Thu Jan 05, 2012 12:27 am

Re: How to grey/blur screen, while own window is on top?

Post by Puffolino »

How to get a smooth blur effect when using different blur factors within an image?
I'd like to have a gradient between lower blurring on one side of the image to higher blurring effect on the other side, so I use image stripes to do that. The resulting image is not as good as I thought, you can recognize the stripe borders...

Code: Select all


#ImageTemp=123

Procedure Gaussian1D(*PixelBuf32, NumPixels, NextPixelOffset = 4)

	!mov ecx, [p.v_NumPixels]
	!sub ecx, 3
	!js gaussian1d_exit
	!mov eax, [p.v_NextPixelOffset]

	CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
		!mov rdx, [p.p_PixelBuf32]
		!movd mm1, [rdx]
		!movd mm4, [rdx + rax]
	CompilerElse
		!mov edx, [p.p_PixelBuf32]
		!movd mm1, [edx]
		!movd mm4, [edx + eax]
	CompilerEndIf
	!punpcklbw mm1, mm1
	!punpcklbw mm4, mm4
	!psrlw mm1, 4
	!psrlw mm4, 4
	!movq mm2, mm1
	!movq mm3, mm1

	; loop
	!gaussian1d_loop0:
	CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
		!movd mm5, [rdx + rax * 2]
	CompilerElse
		!movd mm5, [edx + eax * 2]
	CompilerEndIf
	!punpcklbw mm5, mm5
	!psrlw mm5, 4
	!gaussian1d_loop1:
	!movq mm0, mm2
	!paddw mm0, mm3
	!paddw mm0, mm4
	!psllw mm0, 2
	!paddw mm0, mm1
	!paddw mm0, mm3
	!paddw mm0, mm3
	!paddw mm0, mm5
	!psrlw mm0, 8
	!packuswb mm0, mm0
	CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
		!movd [rdx], mm0
		!add rdx, rax
	CompilerElse
		!movd [edx], mm0
		!add edx, eax
	CompilerEndIf
	!movq mm1, mm2
	!movq mm2, mm3
	!movq mm3, mm4
	!movq mm4, mm5
	!dec ecx
	!jns gaussian1d_loop0
	!cmp ecx, -3
	!jne gaussian1d_loop1
	!gaussian1d_exit:
	!emms

EndProcedure
Procedure Gaussian2D(*PixelBuf32, Width, Height,  BufferPitch = 0)

	If BufferPitch = 0
		BufferPitch = Width << 2
	EndIf

	Protected i.i = 0
	While i < Height
		Gaussian1D(*PixelBuf32 + BufferPitch * i, Width)
		i + 1
	Wend

	i = 0
	While i < Width
		Gaussian1D(*PixelBuf32 + i << 2, Height, BufferPitch)
		i + 1
	Wend

EndProcedure
Procedure GaussianBlur(Image, Strength = 2)

	Protected.i i, w, h, x, y, max_x, max_y

	If StartDrawing(ImageOutput(image))
		w = OutputWidth()
		h = OutputHeight()

		If DrawingBufferPixelFormat() & $60; 32 bit buffer ?
			For i = 0 To Strength
				Gaussian2D(DrawingBuffer(), w, h,  DrawingBufferPitch())
			Next
		Else
			max_x = w - 1
			max_y = h - 1
			Dim Buffer.l(max_y, max_x)
			DrawingMode(#PB_2DDrawing_AllChannels)
			For y = 0 To max_y
				For x = 0 To max_x
					Buffer(y, x) = Point(x, y)
				Next
			Next
			For i = 0 To Strength
				Gaussian2D(@Buffer(), w, h)
			Next
			For y = 0 To max_y
				For x = 0 To max_x
					Plot(x, y, Buffer(y, x))
				Next
			Next
		EndIf
		StopDrawing()

	EndIf

EndProcedure

Procedure BlurImage(image,left,right)

	Protected i,p,q,w
	Protected x,y

	#BlurOverlap=10
	#BlurOverlapHalf=#BlurOverlap>>1

	If left+right

		x=ImageWidth(image)
		y=ImageHeight(image)

		If left=right

		Else

			p=0
			w=x/10

			For i=0 To 9
				If i=9
					w=x-p
				EndIf
				If p>#BlurOverlap
					q=#BlurOverlap
				Else
					q=0
				EndIf
				
				GrabImage(image,#ImageTemp,p-q,0,w+q,y)
				GaussianBlur(#ImageTemp,(i*right+(9-i)*left)/2+1)
				If q
					GrabImage(#ImageTemp,#ImageTemp,#BlurOverlapHalf,0,w+#BlurOverlapHalf,y)
				EndIf
				StartDrawing(ImageOutput(image))
				DrawImage(ImageID(#ImageTemp),p-q>>1,0)
				LineXY(p-q,0,p-q,50,#Red)
				LineXY(p,0,p,50,#Blue)
				StopDrawing()
				p+w
			Next i

		EndIf
	EndIf

EndProcedure

img=1
UseJPEGImageDecoder()
LoadImage(img,"...Example.jpg")
FormWidth=ImageWidth(img)
FormHeight=ImageHeight(img)
ResizeImage(img,FormWidth,FormHeight)

BlurImage(img,0,9)

OpenWindow(0, 0, 0, FormWidth, FormHeight, "...", #PB_Window_BorderLess )
StickyWindow(0, 1)
CanvasGadget(0, 0, 0, FormWidth, FormHeight)
SetGadgetAttribute(0, #PB_Canvas_Image, ImageID(img))

Repeat
	Select WaitWindowEvent()

	Case #WM_CHAR
		Break
	Case #PB_Event_Gadget
		Select EventType()
		Case #PB_EventType_LeftClick
			Break
		EndSelect

	EndSelect
ForEver
Post Reply