Creating SkColorFilter from SkPaint Object

51 views
Skip to first unread message

Faizan Naikwade

unread,
Dec 16, 2022, 9:51:22 AM12/16/22
to skia-discuss
Hi,
  I currently have a SkPaint Object. I wanted to know if I can get SkColorFilter using it. Is there any way to achieve that? I know we can write a runtime effect for lerp but just wanted to ask you guys if I can leverage already existing skia api

Brian Osman

unread,
Dec 16, 2022, 9:54:07 AM12/16/22
to skia-d...@googlegroups.com
It's not clear exactly what you're asking: The SkPaint includes several different effects/fields that define (almost) everything about how a particular canvas operation is performed. That includes the shader (what color to generate at each pixel), as well as a color filter (how to transform the color that comes out of the shader). You can get the color filter that's stored on a paint (getColorFilter), but I think you're asking about something more complicated than that.

On Fri, Dec 16, 2022 at 9:51 AM Faizan Naikwade <naikwad...@gmail.com> wrote:
Hi,
  I currently have a SkPaint Object. I wanted to know if I can get SkColorFilter using it. Is there any way to achieve that? I know we can write a runtime effect for lerp but just wanted to ask you guys if I can leverage already existing skia api

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/510dd4e4-ce6e-4aee-a139-b182e410b968n%40googlegroups.com.

Faizan Naikwade

unread,
Dec 18, 2022, 10:49:36 AM12/18/22
to skia-d...@googlegroups.com
Hi,
  I want to use the Lerp Effect in SkColorFilter it expects two SkColorFilters and a floating  value and returns a SkColorFilter. I have two SkPaint objects. But getColorFilter function on SkPaint object is returning nullptr as they are not set using setColorFilter first. And I am stuck in how to achieve the same. Can you provide me with some suggestions on this?


Brian Osman

unread,
Dec 19, 2022, 10:11:23 AM12/19/22
to skia-d...@googlegroups.com
SkPaint has quite a few fields that control many aspects of painting, and not all of them can be lerped (it doesn't even make sense to do so, for some of them):
- Geometry controls, like whether to stroke or fill the shape, whether or not to antialias, and path effects like dashing
- The pattern to use for filling/stroking, which is defined by the SkShader (or the constant color, if there is no SkShader)
- The blend mode to apply against the destination color

However, I'm guessing you actually want to lerp the SkShader, not the entire SkPaint? In that case, you can use SkSL to do the same thing as SkColorFilters::Lerp, but for SkShaders: https://fiddle.skia.org/c/b99739ca782237c483f826e1fc31d919

On Sun, Dec 18, 2022 at 10:49 AM Faizan Naikwade <naikwad...@gmail.com> wrote:
Hi,
  I want to use the Lerp Effect in SkColorFilter it expects two SkColorFilters and a floating  value and returns a SkColorFilter. I have two SkPaint objects. But getColorFilter function on SkPaint object is returning nullptr as they are not set using setColorFilter first. And I am stuck in how to achieve the same. Can you provide me with some suggestions on this?


On Fri, 16 Dec 2022 at 20:24, 'Brian Osman' via skia-discuss <skia-d...@googlegroups.com> wrote:
It's not clear exactly what you're asking: The SkPaint includes several different effects/fields that define (almost) everything about how a particular canvas operation is performed. That includes the shader (what color to generate at each pixel), as well as a color filter (how to transform the color that comes out of the shader). You can get the color filter that's stored on a paint (getColorFilter), but I think you're asking about something more complicated than that.

On Fri, Dec 16, 2022 at 9:51 AM Faizan Naikwade <naikwad...@gmail.com> wrote:
Hi,
  I currently have a SkPaint Object. I wanted to know if I can get SkColorFilter using it. Is there any way to achieve that? I know we can write a runtime effect for lerp but just wanted to ask you guys if I can leverage already existing skia api

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/510dd4e4-ce6e-4aee-a139-b182e410b968n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/CAMcBjo64ptE9XFUJJReFLWKGzhjs4Ff5b_6OYFF%3DTrX9eiEUzg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages