-
Jan 16th, 2022, 08:23 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Cairo Image Operator: CAIRO_OPERATOR_CLEAR is it acting weirdly?
Hi to the Cairo squad.
Just wondering if you are experiencing any weirdness of the CAIRO_OPERATOR_CLEAR function?
Unless I'm reading it wrong, it's supposed to do this:
Instead, for me, it's erasing all of Surface 1 no matter what I do.
* Large image on Surface 1, small image on Surface 2 (with transparent areas). Erased all of Surface 1.
* Tried making the whole of surface 1 black, then second surface with tiny image (rest of image was transparent). Erased all of Surface 1.
* Tried same above with cairo.imagelist.item (with transparent areas). Erased all of Surface 1.
Something's afoot!
Anyone know what's up? I've found the other operator functions to be perfect as is.
The link I was reading about it.
https://www.cairographics.org/operators/
-
Jan 16th, 2022, 09:57 AM
#2
Re: Cairo Image Operator: CAIRO_OPERATOR_CLEAR is it acting weirdly?
It looks like Cairo/RC6 is treating the entire surface as a block, so that's why the underlying surface is being cleared. If you use the various shape drawing methods (e.g. Ellipse) then CAIRO_OPERATOR_CLEAR appears to work as you are expecting. E.g.:
Code:
Dim s1 As cCairoSurface
Set s1 = Cairo.CreateSurface(300, 300)
With s1.CreateContext
.Ellipse 100, 100, 200, 200
.SetSourceColor vbWhite
.Fill
.Operator = CAIRO_OPERATOR_CLEAR
.Ellipse 200, 200, 300, 300
.SetSourceColor vbRed
.Fill
End With
Results in a circle with a "bite" taken out of it.
I'm not sure if this is something Olaf can change, or if it is working as designed.
-
Jan 16th, 2022, 06:00 PM
#3
Thread Starter
Hyperactive Member
Re: Cairo Image Operator: CAIRO_OPERATOR_CLEAR is it acting weirdly?
Thanks for checking Jpbro. It's weird, as the operators generally work for surfaces (from what I've used so far), not just vector things.
-
Jan 18th, 2022, 03:22 AM
#4
Re: Cairo Image Operator: CAIRO_OPERATOR_CLEAR is it acting weirdly?
Originally Posted by -Corso->
Thanks for checking Jpbro. It's weird, as the operators generally work for surfaces (from what I've used so far), not just vector things.
The thing with "Surfaces, when they contain a Sprite-Shape" is,
that they do not contain any true (Vector-)Path-Information (unless the Surface was derived from an SVG).
So, the only thing that can be done on Image(Pxl)Surfaces in that regard,
(of gathering "a kind of Path-Info for a certain Sprite-Shape"),
is via analyzing their underlying Pixels, looking at their Alpha-Channel...
And the Cairo-Command which does such an Alpha-Channel-based analyzing, is:
- CC.MaskSurface
Below is some Demo-Code, which renders the same Sprite 3 times in different "modes":
- normally (with full color+alpha-info, using CC.RenderSurfaceContent)
- color-stamping (using CC.MaskSurface in conjunction with a prior set SourceColor)
- and "full out-masking" (using CC.MaskSurface after priorily setting the Clear-Operator)
Code:
Option Explicit
Private CC As cCairoContext, Sprite As cCairoSurface
Private Sub Form_Load()
Set CC = Cairo.CreateSurface(1024, 768).CreateContext
Set Sprite = Cairo.ImageList.AddIconFromResourceFile("", "shell32", 167)
Redraw
End Sub
Private Sub Redraw()
CC.Paint 1, Cairo.CreateSolidPatternLng(vbWhite)
'normal, full-color-rendering (with alpha) onto the Main-Surface
CC.RenderSurfaceContent Sprite, 10, 10
CC.SetSourceColor vbRed 'Color-Stamping a certain Sprite-Shape
CC.MaskSurface Sprite, 80, 10 'this uses only the Alpha-Channel of the Sprite
CC.Operator = CAIRO_OPERATOR_CLEAR 'complete "out-masking" via Clear-Operator
CC.MaskSurface Sprite, 150, 10
Set Picture = CC.Surface.Picture
End Sub
HTH
Olaf
Last edited by Schmidt; Jan 18th, 2022 at 03:26 AM.
-
Jan 18th, 2022, 08:37 AM
#5
Thread Starter
Hyperactive Member
-
Jan 19th, 2022, 10:29 AM
#6
Re: Cairo Image Operator: CAIRO_OPERATOR_CLEAR is it acting weirdly?
Originally Posted by -Corso->
'All' the hand drawn objects in the game-test have a necessary, dark outline for visual appeal.
It's easy to make, but I needed to clip that outline out for other lighting effects.
I think I'll visit masksurface function for it instead.
You can use the GaussionBlur-Method for that:
Code:
Option Explicit
Private CC As cCairoContext, Sprite As cCairoSurface, SpHalo As cCairoSurface
Private Sub Form_Load()
Set CC = Cairo.CreateSurface(1024, 768).CreateContext
Set Sprite = Cairo.ImageList.AddIconFromResourceFile("", "shell32", 167, 64, 64)
Set SpHalo = CreateHaloFor(Sprite)
Caption = "Sprite=" & Sprite.Width & "x" & Sprite.Height & _
", Halo=" & SpHalo.Width & "x" & Sprite.Height
Redraw
End Sub
Private Sub Redraw()
CC.Paint 1, Cairo.CreateSolidPatternLng(vbWhite)
'normal, full-color- (with alpha) onto the Main-Surface
CC.RenderSurfaceContent Sprite, 10, 10 'render the Sprite normally
CC.RenderSurfaceContent SpHalo, 80, 10 'render the Halo normally
CC.SetSourceColor vbBlack: CC.MaskSurface SpHalo, 150, 10 'Color-Stamping of the Halo in black
'finally a combination of the Sprite (and a black Halo) at the same place
CC.RenderSurfaceContent Sprite, 220, 10
CC.SetSourceColor vbBlack: CC.MaskSurface SpHalo, 220, 10 '
Set Picture = CC.Surface.Picture
End Sub
Function CreateHaloFor(Srf As cCairoSurface) As cCairoSurface
Set CreateHaloFor = Cairo.CreateSurface(Srf.Width, Srf.Height)
With CreateHaloFor.CreateContext
Dim Blur As cCairoSurface, ROffs As Long
Set Blur = Srf.GaussianBlur(3.3, ROffs)
.RenderSurfaceContent Blur, -ROffs, -ROffs
.Operator = CAIRO_OPERATOR_CLEAR
.MaskSurface Srf
End With
End Function
The above code will produce this:
HTH
Olaf
-
Jan 19th, 2022, 09:51 PM
#7
Thread Starter
Hyperactive Member
Re: [RESOLVED] Cairo Image Operator: CAIRO_OPERATOR_CLEAR is it acting weirdly?
Ah neat, thanks Olaf. I'll keep that one in mind for other effects later.
By the way, I have been meaning to ask. Do we need to do this anymore?
Private Sub Form_Terminate()
Construction_Zone.CleanupRichClientDll 'Remove all the surfaces and items to recover memory
I've noticed the examples lately don't have this, should we keep cleaning up as normal?
(I have no idea, unless there is something special in the RC6 now?)
-
Jan 19th, 2022, 10:59 PM
#8
Re: [RESOLVED] Cairo Image Operator: CAIRO_OPERATOR_CLEAR is it acting weirdly?
Originally Posted by -Corso->
By the way, I have been meaning to ask. Do we need to do this anymore?
Private Sub Form_Terminate()
Construction_Zone.CleanupRichClientDll 'Remove all the surfaces and items to recover memory
I've noticed the examples lately don't have this...
The RC6 does not require these Cleanup-Calls anymore...
Olaf
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|