GithubHelp home page GithubHelp logo

Comments (9)

HinTak avatar HinTak commented on July 21, 2024

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.

stenson avatar stenson commented on July 21, 2024

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 Paths 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)

download-1
download-2

from skia-python.

HinTak avatar HinTak commented on July 21, 2024

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.

HinTak avatar HinTak commented on July 21, 2024

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.

stenson avatar stenson commented on July 21, 2024

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.

HinTak avatar HinTak commented on July 21, 2024

@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.

HinTak avatar HinTak commented on July 21, 2024

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.

stenson avatar stenson commented on July 21, 2024

Ah thanks! That works perfectly just pip installing the .whl file directly — and skia.TableColorFilter.MakeARGB now works perfectly as well

from skia-python.

HinTak avatar HinTak commented on July 21, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.