Page 1 of 1

DisplayRGBFilter() Replacement advice

Posted: Wed Dec 09, 2015 2:46 pm
by hippy
Hi All,

So i'm migrating a project from PB 4.60 to PB 5.40 LTS and i've found that DisplayRGBFilter() has been removed.
I read in the history...

Code: Select all

Removed: DisplayRGBFilter() -> can be replaced with a zoomed sprite with color
I'm not really sure what this means, it there a way to replicate the same effect that's easy?

Cheers,
Hip

Re: DisplayRGBFilter() Replacement advice

Posted: Wed Dec 09, 2015 3:26 pm
by infratec
Hi,

I'm not a graphic guy, but maybe you can use my quick try as replacement:

Code: Select all

Procedure DisplayRGBFilter(x.i, y.i, Width.i, Height.i, R.i, G.i, B.i)
  
  Static RGBSprite.i = -1
  Static OldWidth.i, OldHeight.i, OldColor.i = -1
  
  Protected Color.i
  
  
  Color = RGB(R, G, B)
    
  If Not IsSprite(RGBSprite)
    RGBSprite = CreateSprite(#PB_Any, 1, 1, #PB_Sprite_AlphaBlending)  
  EndIf
  
  If OldColor <> Color
    If StartDrawing(SpriteOutput(RGBSprite))
      Plot(0, 0, Color)
      StopDrawing()
    EndIf
    OldColor = Color
  EndIf
  
  If OldWidth <> Width Or OldHeight <> Height
    ZoomSprite(RGBSprite, Width, Height)
    OldWidth = Width
    OldHeight = Height
  EndIf
  
  DisplayTransparentSprite(RGBSprite, x, y, 128)
EndProcedure



If InitSprite() = 0
  MessageRequester("Error", "Can't open screen & sprite environment!", 0)
  End
EndIf
  
If OpenWindow(0, 0, 0, 320, 200, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  If OpenWindowedScreen(WindowID(0), 0, 0, 320, 200)
    
    CreateSprite(0, 50, 50) ; Erstellt ein leeres Sprites, dies wird komplett schwarz sein
    
    Repeat
      
      Repeat
        Event = WindowEvent()
        
        If Event = #PB_Event_CloseWindow
          End
        EndIf
      Until Event = 0
        
      FlipBuffers()
      ClearScreen(RGB(0, 0, 200)) ; Ein blauer Hintergrund
      
      
      DisplaySprite(0, 10, 10)  ; Darstellung unserer schwarzen Box in der linken oberen Ecke
      DisplaySprite(0, 260, 10) ; Darstellung unserer schwarzen Box in der rechten oberen Ecke
      
      DisplayRGBFilter(15, 15, 10 + i, 100, 0, 128, 128)
      i + 1
      If i = 280
        i = 0
      EndIf
    ForEver
      
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
  EndIf
EndIf
But since I don't know what the original stuff is doing, maybe it is totally wrong.

Bernd

[SOLVED] DisplayRGBFilter() Replacement advice

Posted: Wed Dec 09, 2015 3:33 pm
by hippy
Thank you!


Brilliant, works perfectly!


Cheers,
Hip

Re: DisplayRGBFilter() Replacement advice

Posted: Wed Dec 09, 2015 3:35 pm
by infratec
Good to know.

I just optimized the procedure a bit.

Bernd

Re: DisplayRGBFilter() Replacement advice

Posted: Wed Dec 09, 2015 3:41 pm
by infratec
If you use it more often in one program, maybe a list or a map of the areas is needed to avoid
all time StartDrawing()

Re: DisplayRGBFilter() Replacement advice

Posted: Thu Dec 10, 2015 3:04 am
by Demivec
infratec wrote:If you use it more often in one program, maybe a list or a map of the areas is needed to avoid
all time StartDrawing()
You don't have to redraw the sprite when it's color changes. Its color is determined by an additional parameter.

Code: Select all

Procedure DisplayRGBFilter(x.i, y.i, Width.i, Height.i, R.i, G.i, B.i)
  
  Static RGBSprite.i = 0
;   Static OldWidth.i, OldHeight.i
  Protected Color.i = RGB(R, G, B)
  
  If Not RGBSprite
    RGBSprite = CreateSprite(#PB_Any, 1, 1, #PB_Sprite_AlphaBlending)  
    If StartDrawing(SpriteOutput(RGBSprite))
      Plot(0, 0, RGB(255, 255, 255))
      StopDrawing()
    EndIf
  EndIf
  
;   If OldWidth <> Width Or OldHeight <> Height
    ZoomSprite(RGBSprite, Width, Height)
;     OldWidth = Width
;     OldHeight = Height
;   EndIf
  
  DisplayTransparentSprite(RGBSprite, x, y, 128, Color)
EndProcedure
I also removed the check IsSprite(RGBSprite) to check for initialization. The 'IsXxxxx()' functions have to go through all existing sprite numbers and are thus a costly way to check for something's existence. Since we are really only checking if we have performed our initialization correctly it is better just to check if the initial value has changed.

I also commented out the check to avoid using ZoomSprite() when it is unnecessary. I think that ZoomSprite() is only setting a value and is not a costly function to use frequently.