effects package
effects depends on Graphic
effects contains no classes.
License
The effects package is marked as Compatible, which means any game can use it.
Classes
A FakeDrawable is a "window" into a real Drawable. It has its own drawing state, and its own ideas about how big it is, but its pixel data is actually just a reference to the pixel data of the real Drawable.
This is useful, for instance, for using the various scaling functions below on a small subset of a Graphic without extra copies. (It can also be used with BoxDown.)
A FakeDrawable counts as a reference to its real counterpart for garbage collection purposes.
- fake = SubCritical.Construct("FakeDrawable", real, [x], [y], [width], [height])
- Create a FakeDrawable as a window into the real Drawable. The optional parameters define a rectangle subset of the real Drawable that this FakeDrawable will impersonate.
- fake:Update()
fake:Update(x, y, width, height)
- If fake is a GraphicsDevice or another FakeDrawable, call Update on the appropriate subset of it. If it is not, do nothing.
Utility functions
- SCUtil.BoxDown(source, destination, xf, yf)
- This quickly copies the pixel data in source to destination, scaling down by a factor of xf on the X axis and yf on the Y axis using a simple box filter. source must be xf times wider and yf times taller than destination.
- This is suitable for simple oversampling, whereby you render at a much higher resolution and scale down for display. In that case, the destination will probably be the screen.
- The case of xf=2,yf=2 is specially optimized.
- new_graphic = SCUtil.Flip(old_graphic)
- old_graphic can be any Drawable. new_graphic will be a new Graphic containing the image data from old_graphic rotated 180 degrees.
- frisket = SCUtil.MakeFrisketDirectly(graphic)
- graphic can be any Drawable. frisket will be a new Frisket containing exactly the green channel data from graphic, without any colorspace conversion.
- MakeFrisketDirectly is only suitable for use on graphics with green channel data already in the correct colorspace. If you don't know what this means, don't use MakeFrisketDirectly or things will look bad.
- frisket = SCUtil.MakeFrisketFromAlpha(graphic)
- graphic can be any Drawable. frisket will be a new Frisket equivalent to graphic (minus color information).
- frisket = SCUtil.MakeFrisketFromGrayscale(graphic)
- graphic can be any Drawable. frisket will be a new Frisket which is more opaque where graphic is brighter and more transparent where graphic is darker. The red, green, and blue channels are weighted according to their contribution to human perception of brightness. The alpha channel of graphic, if any, is ignored.
- frisket = SCUtil.MakeFrisketFromRed(graphic)
frisket = SCUtil.MakeFrisketFromGreen(graphic)
frisket = SCUtil.MakeFrisketFromBlue(graphic)
- graphic can be any Drawable. frisket will be a new Frisket which is more opaque where graphic is brighter and more transparent where graphic is darker. Only the specified channel of the graphic contributes. (You can use this to store three or four different, related Friskets in one Graphic.)
- frisket = SCUtil.MakeFrisketFromGrayscaleQuickly(graphic)
- graphic can be any Drawable. frisket will be a new Frisket which is more opaque where graphic is brighter and more transparent where graphic is darker. The red, green, and blue channels contribute equally to the final value. The alpha channel of graphic, if any, is ignored.
- new_graphic = SCUtil.MirrorHorizontal(old_graphic)
- old_graphic can be any Drawable. new_graphic will be a new Graphic containing the image data from old_graphic flipped along the X axis.
- new_graphic = SCUtil.MirrorVertical(old_graphic)
- old_graphic can be any Drawable. new_graphic will be a new Graphic containing the image data from old_graphic flipped along the Y axis.
- function my_render_function(x, y) ... return r,g,b[,a] end
graphic = SCUtil.Render(my_render_function, width, height[, alpha])
- graphic will contain a new Graphic, width x height, containing image data provided by my_render_function.
- my_render_function is a function you provide. Its parameters, x and y, are integer coordinates such that 0 <= x < width and 0 <= y < height. Its return values (r,g,b), are numbers between 0 and 1, inclusive. They are interpreted in a linear colorspace (that is, 0.5 is half as bright as 1). If alpha is true, your function must return a fourth number, a, denoting the degree of opacity between 0 (transparent) and 1 (opaque). If alpha is false or not specified, the returned graphic is fully opaque.
- It is unwise to cause an error in my_render_function or to return an unexpected number of values.
- function my_render_function(x, y) ... return r,g,b[,a] end
graphic = SCUtil.RenderPreCompressed(my_render_function, width, height[, alpha])
- This behaves exactly as Render above, with one exception. The r, g, and b return values of my_render_function are assumed to be in an sRGB colorspace. (One might use this function to implement an image loader in Lua.)
- function my_render_function(x, y) ... return a end
frisket = SCUtil.RenderFrisket(my_render_function, width, height)
- This behaves exactly as Render above, but creates a Frisket instead.
- new_graphic = SCUtil.RotateLeft(old_graphic)
- old_graphic can be any Drawable. new_graphic will be a new Graphic containing the image data from old_graphic rotated 90 degrees counter-clockwise.
- new_graphic = SCUtil.RotateRight(old_graphic)
- old_graphic can be any Drawable. new_graphic will be a new Graphic containing the image data from old_graphic rotated 90 degrees clockwise.
- new_graphic = SCUtil.ScaleBest(old_graphic, width, height)
- old_graphic can be any Drawable. new_graphic will be a new Graphic containing the image data from old_graphic scaled to width x height using Lanczos3 windowed sinc filtering. Alpha channels are handled correctly, but might behave contrary to your expectations.
- Like many other forms of high-quality resampling, Lancsoz3 filtering will cause some "fringing." This is normal.
- new_graphic = SCUtil.ScaleFast(old_graphic, width, height)
- old_graphic can be any Drawable. new_graphic will be a new Graphic containing the image data from old_graphic scaled to width x height using nearest-neighbor "filtering." Alpha channels are handled.
- This is ugly, but fast.
Back to index