def __call__(self, *frames, **kwargs):
        channel = kwargs.get('channel', lib.DefaultChannels)
        # TODO force_python should go away and this should become a wrapper for
        # evaluate_python

        # We're gonna be using this a lot, so let's cast it to a C int just
        # once (and get the error early if it's a bogus type)
        c_channel = ffi.cast('ChannelType', channel)

        # TODO any gc concerns in this?
        for f in frames:
            assert isinstance(f, ImageFrame)

        # XXX how to handle frames of different sizes?  gravity?  scaling?  first
        # frame as the master?  hm
        frame = frames[0]

        # TODO does this create a blank image or actually duplicate the pixels??  docs say it actually copies with (0, 0) but the code just refs the same pixel cache?
        # TODO could use an inplace version for, e.g. the SVG-style compose operators
        # TODO also might want a different sized clone!
        with magick_try() as exc:
            new_stack = lib.CloneImage(frame._frame, 0, 0, lib.MagickTrue, exc.ptr)
            exc.check(new_stack == ffi.NULL)

        # TODO: set image to full-color.
        # TODO: work out how this works, how different colorspaces work, and waht the ImageType has to do with anything
        # QUESTION: this doesn't actually do anything.  how does it work?  does it leave indexes populated?  what happens if this isn't done?
        #  if (SetImageStorageClass(fx_image,DirectClass) == MagickFalse) {
        #      InheritException(exception,&fx_image->exception);
        #      fx_image=DestroyImage(fx_image);
        #      return((Image *) NULL);
        #    }

        out_view = lib.AcquireCacheView(new_stack)

        # TODO i need to be a list
        in_view = lib.AcquireCacheView(frame._frame)

        state = FilterState()

        for y in range(frame._frame.rows):

            with magick_try() as exc:
                q = lib.GetCacheViewAuthenticPixels(out_view, 0, y, frame._frame.columns, 1, exc.ptr)
                exc.check(q == ffi.NULL)

            # TODO is this useful who knows
            #fx_indexes=GetCacheViewAuthenticIndexQueue(fx_view);

            for x in range(frame._frame.columns):
                # TODO per-channel things
                # TODO for usage: see line 1453

                #GetMagickPixelPacket(image,&pixel);
                #(void) InterpolateMagickPixelPacket(image,fx_info->view[i],image->interpolate, point.x,point.y,&pixel,exception);

                # Set up state object
                # TODO document that this is reused, or somethin
                state._color = BaseColor._from_pixel(q)
                ret = self.impl(state)

                #q.red = c_api.RoundToQuantum(<c_api.MagickRealType> ret.c_struct.red * c_api.QuantumRange)
                #q.green = c_api.RoundToQuantum(<c_api.MagickRealType> ret.c_struct.green * c_api.QuantumRange)
                #q.blue = c_api.RoundToQuantum(<c_api.MagickRealType> ret.c_struct.blue * c_api.QuantumRange)
                # TODO black, opacity?
                # TODO seems like this should apply to any set of channels, but
                # IM's -fx only understands RGB

                # TODO this is a little invasive, but given that this inner
                # loop runs for every fucking pixel, i'd like to avoid method
                # calls as much as possible.  even that rgb() can add up
                rgb = ret.rgb()
                lib.sanpera_pixel_from_doubles_channel(q, rgb._array, c_channel)

                # XXX this is actually black
                #  if (((channel & IndexChannel) != 0) && (fx_image->colorspace == CMYKColorspace)) {
                #      (void) FxEvaluateChannelExpression(fx_info[id],IndexChannel,x,y, &alpha,exception);
                #      SetPixelIndex(fx_indexes+x,RoundToQuantum((MagickRealType) QuantumRange*alpha));
                #    }

                q += 1  # q++

            with magick_try() as exc:
                lib.SyncCacheViewAuthenticPixels(in_view, exc.ptr)
                # TODO check exception, return value

        # XXX destroy in_view
        # XXX destroy out_view s

        return Image(new_stack)


# ------------------------------------------------------------------------------
# Compiled filter support.  Uses operator overloading hackery to convert the
# filter function to a list of bytecode ops that operate on a stack, then
# evaluates the whole thing in C.
# The result is sure faster than Python, and actually faster than -fx.
dataset/ETHPy150Open eevee/sanpera/sanpera/filters.py/python_image_filter.__call__/original