Comments (9)
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.
from skia-python.
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)
from skia-python.
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).
from skia-python.
Fixed in #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)
from skia-python.
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.
from skia-python.
@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 " . I have never done that myself, however :-).
from skia-python.
The CI builds are linked from the action tab - https://github.com/kyamagu/skia-python/actions - you want the latest m121 public build.
from skia-python.
Ah thanks! That works perfectly just pip installing the .whl file directly — and skia.TableColorFilter.MakeARGB
now works perfectly as well
from skia-python.
@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.
from skia-python.
Related Issues (20)
- Raspberry Pi 4 Support (linux 32-bit arm) HOT 8
- Newer system gets an extra skip on exit in testing HOT 2
- AttributeError: 'skia.Paint' object has no attribute 'setTextScaleX' HOT 1
- How to underline and strikethrough fonts? HOT 4
- Binding the skparagraph module
- Mac font is thicker than Linux font HOT 3
- deprecation of `distutils`upstream for python >= 3.12 HOT 8
- m122: SkFontMgr::RefDefault() has been deleted HOT 5
- Is there a way to use skia.Surface to export high quality images? HOT 5
- Missing `getBlendMode` on `skia.Paint` objects HOT 7
- "instance = class() ; instance.initGL()" vs "instance = class.MakeGL()
- rgb r and b are working in reverse fashion... HOT 1
- rgb r and b are working in reverse fashion... HOT 1
- Improve SamplingOptions, and adding test cases HOT 7
- Identify what breaks in m122 for font(typeface("")) on mac os HOT 7
- Support for Python 3.12 HOT 2
- Build for python3.21 HOT 1
- "Shader Compilation Error" HOT 12
- python3.7 could not pip install skia-python HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from skia-python.