Image Filter Class

Note

These interface classes are not intended for direct usage; rather they should be inherited by your own subclass. (See Anatomy of a LightWave Python Plug-in)

Handler

class lwsdk.IImageFilter

Bases: lwsdk.lwsdk.IHandlerFuncs, lwsdk.lwsdk.IInterfaceFuncs, lwsdk.lwsdk.IGizmoFuncs, lwsdk.lwsdk.IItemFuncs

Proxy of C++ PCore::IImageFilter class

 flags() → int

Returns a Python integer sequence. The first element of the array is the count of flags within the array. The rest of the array contains 1 flag per member. This is a new system. The older bitwise system ran out of buffers. The settings for the buffers can be found in lwfilter.h.

Please see the "negative.py" Python Image Filter example script for more detail on this method.

 process(LWFilterAccess arg0)

This is where the image filter does its work. For each frame, the filter is given access to the red, green, blue and alpha channels of the rendered image, along with any other image buffers requested by the flags function. The access structure, described below, provides image information and functions for examining the buffers and writing new RGB and alpha values.

Access

class lwsdk.LWFilterAccess(*args)

Bases: object

Proxy of C++ PCore::LWFilterAccess class

 end → LWTime

The end time for the frame. This will be the same as LWFilterAccess.start unless the frame was rendered with motion blur, in which case the difference between them can be considered the exposure time for the frame.

 frame → LWFrame

The frame number.

 getLine(int type, int y) → PyObject

This method is a Python-based replacement of the actual LWFilterAccess::getLine() method.

It returns a Python sequence holding the entire scanline from the specified buffer. y = 0 is the top line of the buffer, and y = height - 1 is the bottom line. Don't try to look past the end of a scanline. Layout may not store scanlines contiguously for a given buffer. In fact, scanlines aren't guaranteed to exist at all until they're requested through these functions. The type codes are of the form lwsdk.LWBUF_* listed in lwfilter.h, and are not to be confused with the buffer flags (lwsdk.LWBUFF_*, note the additional "F"). Generally, each buffer flag has a corresponding buffer type. None is returned for invalid type codes, or type codes for buffers not requested by the flags function.

 height → int

The height dimension, in pixels, of all of the image buffers.

 monitor → LWMonitor

The filter can use this LWMonitor class instance to update the user about its progress through the frame. This also allows the user to cancel the rendering during the filter's processing. The monitor mechanism is the same one provided by the monitor global. As with all monitors, the number of steps should be kept fairly low since checking for abort can have significant overhead on some systems.

 process_rgb(int row, PyObject r, PyObject g, PyObject b, PyObject a)

This is a Python-only method that accepts all pixels buffers at once, and replaces the functionality of the LWFilterAccess::setAlpha() and LWFilterAccess::setRGB() per-pixel methods. Using this method results in improved performance in a Python Image Filter plug-in.

 setAlpha(int x, int y, float alpha)

Use this function to set the alpha value of a filter, one pixel at a time.

(It is recommended that you use the LWFilterAccess::process_rgb() method instead to improve performance.)

 setRGB(int x, int y, LWFVector rgb)

Use this function to set the output values of the filter one pixel at a time. The input RGBA buffers do not change as the output buffers are modified. A filter must set every pixel in the output image even if it does not alter the value, but it can set them in any order.

(It is recommended that you use the LWFilterAccess::process_rgb() method instead to improve performance.)

 start → LWTime

The start time for the frame. This will be the same as LWFilterAccess.end unless the frame was rendered with motion blur, in which case the difference between them can be considered the exposure time for the frame.

 width → int

The width dimension, in pixels, of all of the image buffers.

Factory

class lwsdk.ImageFilterFactory(name, klass)

Bases: lwsdk.lwsdk.IImageFilterFactory

Default Python Factory for IImageFilter

 create(context)
 destroy(instance)

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class black_and_white(lwsdk.IImageFilter):
    def __init__(self, context):
        super(black_and_white, self).__init__()

        self._context_flags = context

        self._gamma = 0.0  # this would be modified by a GUI
[...]
    # LWImageFilter ---------------------------------------
    def process(self, fa):
        mon = fa.monitor
        mon.init(mon.data, fa.height / 8)

        for row in range(fa.height):
            r = fa.getLine(lwsdk.LWBUF_RED, row)
            g = fa.getLine(lwsdk.LWBUF_GREEN, row)
            b = fa.getLine(lwsdk.LWBUF_BLUE, row)
            a = fa.getLine(lwsdk.LWBUF_ALPHA, row)
[...]
ServerRecord = { lwsdk.ImageFilterFactory("LW_PyBlackAndWhite", black_and_white) : ServerTagInfo }

Table Of Contents

Previous topic

Custom Object Class

Next topic

Global Classes

This Page