|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectprocessing.core.PImage
Storage class for pixel data. This is the base class for most image and pixel information, such as PGraphics and the video library classes.
Code for copying, resizing, scaling, and blending contributed by toxi
| Field Summary | |
java.lang.Object |
cache
for subclasses that need to store info about the image |
int |
format
Format for this image, one of RGB, ARGB or ALPHA. |
int |
height
|
int |
imageMode
|
boolean |
modified
modified portion of the image |
int |
mx1
|
int |
mx2
|
int |
my1
|
int |
my2
|
PApplet |
parent
Path to parent object that will be used with save(). |
int[] |
pixels
|
boolean |
smooth
|
int |
width
|
| Constructor Summary | |
PImage()
Create an empty image object, set its format to RGB. |
|
PImage(java.awt.Image img)
Construct a new PImage from a java.awt.Image. |
|
PImage(int width,
int height)
Create a new RGB (alpha ignored) image of a specific size. |
|
PImage(int width,
int height,
int format)
|
|
| Method Summary | |
void |
blend(int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
Blends one area of this image to another area. |
void |
blend(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
Copies area of one image into another PImage object. |
static int |
blendColor(int c1,
int c2,
int mode)
Blend two colors based on a particular mode. |
java.lang.Object |
clone()
Duplicate an image, returns new PImage object. |
void |
copy(int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2)
Copy things from one area of this image to another area in the same image. |
void |
copy(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2)
Copies area of one image into another PImage object. |
void |
filter(int kind)
Method to apply a variety of basic filters to this image. |
void |
filter(int kind,
float param)
Method to apply a variety of basic filters to this image. |
PImage |
get()
Returns a copy of this PImage. |
int |
get(int x,
int y)
Returns an ARGB "color" type (a packed 32 bit int with the color. |
PImage |
get(int x,
int y,
int w,
int h)
Grab a subsection of a PImage, and copy it into a fresh PImage. |
void |
imageMode(int mode)
The mode can only be set to CORNERS or CORNER, because the others are just too weird for the other functions. |
void |
init(int width,
int height,
int format)
Function to be used by subclasses to setup their own bidness. |
void |
loadPixels()
Call this when you want to mess with the pixels[] array. |
void |
mask(int[] alpha)
Set alpha channel for an image. |
void |
mask(PImage alpha)
Set alpha channel for an image using another image as the source. |
void |
noSmooth()
Disable smoothing. |
void |
save(java.lang.String path)
Save this image to disk. |
void |
set(int x,
int y,
int c)
Silently ignores if the coordinate is outside the image. |
void |
set(int dx,
int dy,
PImage src)
|
void |
smooth()
If true in PImage, use bilinear interpolation for copy() operations. |
void |
updatePixels()
Call this when finished messing with the pixels[] array. |
void |
updatePixels(int x1,
int y1,
int x2,
int y2)
Mark the pixels in this region as needing an update. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public int format
public int[] pixels
public int width
public int height
public PApplet parent
public int imageMode
public boolean smooth
public java.lang.Object cache
public boolean modified
public int mx1
public int my1
public int mx2
public int my2
| Constructor Detail |
public PImage()
public PImage(int width,
int height)
public PImage(int width,
int height,
int format)
public PImage(java.awt.Image img)
| Method Detail |
public void init(int width,
int height,
int format)
public void imageMode(int mode)
public void smooth()
public void noSmooth()
public void loadPixels()
public void updatePixels()
public void updatePixels(int x1,
int y1,
int x2,
int y2)
This is not currently used by any of the renderers, however the api is structured this way in the hope of being able to use this to speed things up in the future.
Note that when using imageMode(CORNERS), the x2 and y2 positions are non-inclusive.
public int get(int x,
int y)
If the image is in RGB format (i.e. on a PVideo object), the value will get its high bits set, just to avoid cases where they haven't been set already.
If the image is in ALPHA format, this returns a white with its alpha value set.
This function is included primarily for beginners. It is quite slow because it has to check to see if the x, y that was provided is inside the bounds, and then has to check to see what image type it is. If you want things to be more efficient, access the pixels[] array directly.
public PImage get(int x,
int y,
int w,
int h)
public PImage get()
public void set(int x,
int y,
int c)
public void set(int dx,
int dy,
PImage src)
public void mask(int[] alpha)
Strictly speaking the "blue" value from the source image is used as the alpha color. For a fully grayscale image, this is correct, but for a color image it's not 100% accurate. For a more accurate conversion, first use filter(GRAY) which will make the image into a "correct" grayscake by performing a proper luminance-based conversion.
public void mask(PImage alpha)
public void filter(int kind)
public void filter(int kind,
float param)
public void copy(int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2)
public void copy(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2)
public static int blendColor(int c1,
int c2,
int mode)
A useful reference for blending modes and their algorithms can be found in the SVG specification.
It is important to note that Processing uses "fast" code, not necessarily "correct" code. No biggie, most software does. A nitpicker can find numerous "off by 1 division" problems in the blend code where >>8 or >>7 is used when strictly speaking /255.0 or /127.0 should have been used.
For instance, exclusion (not intended for real-time use) reads r1 + r2 - ((2 * r1 * r2) / 255) because 255 == 1.0 not 256 == 1.0. In other words, (255*255)>>8 is not the same as (255*255)/255. But for real-time use the shifts are preferrable, and the difference is insignificant for applications built with Processing.
public void blend(int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
blendColor(int,int,int)
public void blend(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
blendColor(int,int,int)
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedExceptionpublic void save(java.lang.String path)
As of revision 0100, this function requires an absolute path, in order to avoid confusion. To save inside the sketch folder, use the function savePath() from PApplet, or use saveFrame() instead.
As of revision 0115, when using Java 1.4 and later, you can write
to several formats besides tga and tiff. If Java 1.4 is installed
and the extension used is supported (usually png, jpg, jpeg, bmp,
and tiff), then those methods will be used to write the image.
To get a list of the supported formats for writing, use:
println(javax.imageio.ImageIO.getReaderFormatNames())
To use the original built-in image writers, use .tga as the extension, or don't include an extension, in which case .tif will be added.
The ImageIO API claims to support wbmp files, however they probably require a black and white image. Basic testing produced a zero-length file with no error.
As of revision 0116, savePath() is not needed if this object has been created (as recommended) via createImage() or createGraphics() or one of its neighbors.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||