Closed stenson closed 7 months ago
Yes, those two classes are substantiallly different after m87. If you had something you have been using that you like to work in m12x, posting some small examples (ideally complete/stand-alone) would be useful.
I use skia.TableColorFilter.MakeARGB
regularly to do alpha-channel contrast cuts on graphics (i.e. blurring them and then "choking" the blur with an alpha contrast cut), so I'd very much like to see that carried forward in skia-python.
I've adapted one of the notebook examples in skia-python to demonstrate how I use the skia.TableColorFilter.MakeARGB
. I've made available as an interactive notebook (https://colab.research.google.com/drive/1s43QdL7W0RyUB1_Z2Vg8iW3kPVZQxlNe?usp=sharing), and copied the code inline below with the images that result.
This isn't a great example in terms of "why I want it" (since this just ends up looking like a rounded rectangle), but I do regularly use this effect with Path
s to simulate high-contrast film stock, which is an effect that I've found almost impossible to achieve in realtime with code with any other python libraries.
import skia
import contextlib
from IPython.display import display, Image
@contextlib.contextmanager
def draw_target(width=100, height=100, save=None):
surface = skia.Surface(width, height)
canvas = surface.getCanvas()
yield canvas
image = surface.makeImageSnapshot()
pimg = Image(data=image.encodeToData())
if save:
with open(save, "wb") as img:
img.write(image.encodeToData())
display(pimg)
with draw_target(save="test.png") as canvas:
paint = skia.Paint(Color=skia.ColorBLACK, MaskFilter=skia.MaskFilter.MakeBlur(skia.kNormal_BlurStyle, 5.0))
rect = skia.Rect.MakeXYWH(10, 10, 50, 50)
canvas.drawRect(rect, paint)
def contrast_cut(mp=127, w=5):
ct = bytearray(256)
for i in range(256):
if i < mp - w: ct[i] = 0
elif i < mp: ct[i] = int((255.0/2)*(1-(mp-i)/w))
elif i == mp: ct[i] = 127
elif i < mp + w: ct[i] = int(127+(255.0/2)*((i-mp)/w))
else: ct[i] = 255
return ct
with draw_target() as canvas:
ct = contrast_cut(157, 15)
image = skia.Image.MakeFromEncoded(skia.Data.MakeFromFileName("test.png"))
paint = skia.Paint(ColorFilter=skia.TableColorFilter.MakeARGB(ct, None, None, None))
canvas.drawImage(image, 0, 0, paint)
Oh, it probably isn't hard to put it back - it is mentioned in skia's release note how to:
https://github.com/google/skia/blob/main/RELEASE_NOTES.md
Milestone 116
The deprecated SkTableColorFilter class and its methods have been removed. Clients should use SkColorFilters::Table and SkColorFilters::TableARGB (defined in include/core/SkColorFilter.h).
Fixed in https://github.com/kyamagu/skia-python/pull/222 - if you could download the new build and give it a go to your code base and see what else is needed, that would be nice. Since skia m122 should be out any time now, skia-python m121 should be released in the next few days (and #222 will get a README.m121, etc before that).
By the way, I needed to change one line in your code - many image-related API gains a new "skia.SampleOption" class argument. For now, just the default constructor is available in skia-python. If you need anything else, let us know. It is supposed to replace the ealier "FilterQuality" arguments (mentioned in relnotes/README.m116.md ) . The one line change is as below (the last line in your code above):
- canvas.drawImage(image, 0, 0, paint)
+ canvas.drawImage(image, 0, 0, skia.SamplingOptions(), paint)
Thank for looking into it! Is there a doc on how to pip install a pre-release version of skia-python from a branch and have it use the pre-built artifacts? I tried pip install git+https://github.com/HinTak/skia-python.git@m121-public
but that tries (and fails) to build skia from scratch.
@stenson I believe you can download the CI build artefacts at the bottom of
https://github.com/kyamagu/skia-python/actions/runs/7563583701 , unpack it , pick the one you need (presumably x86_64 linux) and just "pip install
The CI builds are linked from the action tab - https://github.com/kyamagu/skia-python/actions - you want the latest m121 public build.
Ah thanks! That works perfectly just pip installing the .whl file directly — and skia.TableColorFilter.MakeARGB
now works perfectly as well
@stenson if you find anything else you need that's broken since m87, filing them in the next few days would be a good idea. we'll put it in if it isn't too troublesome to add.
I’ve been using
skia.TableColorFilter.MakeARGB
extensively for a while now in the m87 version, and I can see there was a port ofskia.TableColorFilter.Make
(without ARGB) and a commented-out port ofskia.TableColorFilter.MakeARGB
— is there a chance of that backfill function being uncommented or ofSkColorFilter::TableARGB
being exposed?