本文整理汇总了Java中processing.core.PImage类的典型用法代码示例。如果您正苦于以下问题:Java PImage类的具体用法?Java PImage怎么用?Java PImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PImage类属于processing.core包,在下文中一共展示了PImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSprite
import processing.core.PImage; //导入依赖的package包/类
static public PImage createSprite(PApplet papplet, int size, float exp1, float exp2, float mult){
size = Math.max(32, size);
PImage pimg = papplet.createImage(size, size, PConstants.ARGB);
pimg.loadPixels();
for(int y = 0; y < size; y++){
for(int x = 0; x < size; x++){
int pid = y * size + x;
float xn = ((x+0.5f) / (float)size) * 2f - 1f;
float yn = ((y+0.5f) / (float)size) * 2f - 1f;
float dd = (float) Math.sqrt(xn*xn + yn*yn);
dd = DwUtils.clamp(dd, 0, 1);
dd = (float) Math.pow(dd, exp1);
dd = 1.0f - dd;
dd = (float) Math.pow(dd, exp2);
dd *= mult;
dd = DwUtils.clamp(dd, 0, 1);
pimg.pixels[pid] = ((int)(dd * 255)) << 24 | 0x00FFFFFF;
}
}
pimg.updatePixels();
return pimg;
}
示例2: xmlEvent
import processing.core.PImage; //导入依赖的package包/类
public void xmlEvent(XMLElement element){
data = element;
if(!data.getName().contentEquals("data")){
PApplet.println("SettingsManager:xmlEvent: settings file is not compatible ("+data.getName()+") -> reset");
data = new XMLElement("data");
addSettings("default");
xmlInOut.saveElement(data,settingsPath);
setup();
}else if(!data.hasChildren()){
PApplet.println("SettingsManager:xmlEvent: loaded settings file was empty");
addSettings("default");
xmlInOut.saveElement(data,settingsPath);
setup();
}else{
ready = true;
if(parent.current == 999){
parent.current = data.getIntAttribute("current");
}
PApplet.println("SettingsManager:xmlEvent: successfully loaded");
if(parent.config){
parent.configurator.enable();
}
parent.textures = new PImage[data.getChild(parent.current).countChildren()];
parent.createEmptyTextures();
}
}
示例3: ControllerSprite
import processing.core.PImage; //导入依赖的package包/类
public ControllerSprite(ControlP5 theControlP5, PImage theImage, int theWidth, int theHeight, int theStates) {
sprite = theImage;
width = theWidth;
height = theHeight;
wh = width * height;
_myState = 0;
// cc - added to support a specified # of states
// specify total states, not index - e.g.:
// two total states arg should = 2, even though
// max state index is 1.
theStates--;
// cc - make sure we have at least one state
_totalStates = (theStates >= 0) ? theStates : 0;
display = new PImage(theWidth, theHeight);
display = theControlP5.papplet.createImage(theWidth, theHeight, PApplet.RGB);
update();
}
示例4: putchar
import processing.core.PImage; //导入依赖的package包/类
private void putchar(
final int theC,
final int theX,
final int theY,
final int theColor,
boolean theHighlight,
final PImage theImage,
final PImage theMask,
final int theFontIndex) {
final int myWH = theImage.width * theImage.height;
final int len = charWidth[theFontIndex][theC] * charHeight[theFontIndex];
final int w = theY * theImage.width;
for (int i = 0; i < len; i++) {
final int xpos = theX + i % charWidth[theFontIndex][theC];
final int pos = xpos + w + (i / charWidth[theFontIndex][theC]) * theImage.width;
if (chars[theFontIndex][theC][i] == 0xff000000 && xpos < theImage.width && xpos >= 0 && pos >= 0 && pos < myWH) {
theImage.pixels[pos] = (!theHighlight) ? theColor : 0xffff0000;
theMask.pixels[pos] = 0xffffffff;
}
}
}
示例5: update
import processing.core.PImage; //导入依赖的package包/类
protected void update() {
if (isControlFont) {
ControlP5.papplet.textFont(_myControlFont.getPFont(), _myControlFontSize);
_myWidth = (int) ControlP5.papplet.textWidth(isToUpperCase ? _myText.toUpperCase() : _myText);
} else {
if (!isFixedSize) {
_myHeight = BitFontRenderer.font[_myFontIndex].height;
_myWidth = bitFontRenderer.getWidth(this);
_myWidth += _myText.length() * _myLetterSpacing;
}
_myImage = new PImage(_myWidth, _myHeight);
_myImageMask = new PImage(_myWidth, _myHeight);
set(_myText, _myColor, _myCursorPosition);
}
}
示例6: getProjectorImage
import processing.core.PImage; //导入依赖的package包/类
public PImage getProjectorImage(PApplet applet, int projWidth, int projHeight) {
PImage projectorImage = applet.createImage(projWidth, projHeight, RGB);
projectorImage.loadPixels();
refImage.loadPixels();
int imSize = width * height;
for (int i = 0; i < imSize; i++) {
if (validMask[i]) {
int x = decodedX[i];
int y = decodedY[i];
int offset = y * projWidth + x;
projectorImage.pixels[offset] = refImage.pixels[i];
}
}
projectorImage.updatePixels();
return projectorImage;
}
示例7: getImageDecoded
import processing.core.PImage; //导入依赖的package包/类
public PImage getImageDecoded(int imageId, int mode, int differenceThreshold) {
PImage out = parent.createImage(cameraResX, cameraResY, RGB);
out.loadPixels();
this.mode = mode;
this.threshold = differenceThreshold;
for (int y = 0; y < cameraResY; y += 1) {
for (int x = 0; x < cameraResX; x += 1) {
int offset = x + y * cameraResX;
boolean newValue = decodePixel(imageId, offset);
// TODO: bug here ?!
// if (mode == GrayCode.DECODE_REF) {
// newValue = !newValue;
// }
out.pixels[offset] = newValue ? 255 : 0;
}
}
return out;
}
示例8: KinectPoints
import processing.core.PImage; //导入依赖的package包/类
/**
* Constructs a KinectPoints object from the provided Kinect output data
*
* @param p the parent Processing applet
* @param points the Kinect 3D points
* @param rgbImg the Kinect color image
* @param depthMap the Kinect depth map
* @param reductionFactor the scale reduction factor
*/
public KinectPoints(PApplet p, PVector[] points, PImage rgbImg, int[] depthMap, int reductionFactor) {
reductionFactor = Math.max(1, reductionFactor);
this.p = p;
this.width = rgbImg.width / reductionFactor;
this.height = rgbImg.height / reductionFactor;
this.nPoints = this.width * this.height;
this.points = new PVector[this.nPoints];
this.colors = new int[this.nPoints];
this.visibilityMask = new boolean[this.nPoints];
// Populate the arrays
rgbImg.loadPixels();
for (int row = 0; row < this.height; row++) {
for (int col = 0; col < this.width; col++) {
int index = col + row * this.width;
int indexOriginal = col * reductionFactor + row * reductionFactor * rgbImg.width;
this.points[index] = points[indexOriginal].copy();
this.colors[index] = rgbImg.pixels[indexOriginal];
this.visibilityMask[index] = depthMap[indexOriginal] > 0;
}
}
rgbImg.updatePixels();
}
示例9: remapImage
import processing.core.PImage; //导入依赖的package包/类
public static void remapImage(PVector[] in, PVector[] out, opencv_core.IplImage imgIn, opencv_core.IplImage imgTmp, PImage Pout) {
opencv_core.CvMat srcPoints;
opencv_core.CvMat dstPoints;
int nbPoints = in.length;
opencv_core.CvMat homography;
// TODO: no create map
srcPoints = cvCreateMat(2, in.length, opencv_core.CV_32FC1);
dstPoints = cvCreateMat(2, in.length, opencv_core.CV_32FC1);
homography = cvCreateMat(3, 3, opencv_core.CV_32FC1);
for (int i = 0; i < in.length; i++) {
srcPoints.put(i, in[i].x);
srcPoints.put(i + nbPoints, in[i].y);
dstPoints.put(i, out[i].x);
dstPoints.put(i + nbPoints, out[i].y);
}
cvFindHomography(srcPoints, dstPoints, homography);
// It is better to use : GetPerspectiveTransform
opencv_imgproc.cvWarpPerspective(imgIn, imgTmp, homography);
// opencv_imgproc.CV_INTER_LINEAR ); // opencv_imgproc.CV_WARP_FILL_OUTLIERS);
// getFillColor());
IplImageToPImage(imgTmp, false, Pout);
}
示例10: GrayCode
import processing.core.PImage; //导入依赖的package包/类
public GrayCode(PApplet applet, int width, int height, int downScale) {
this.parent = applet;
this.width = width / downScale;
this.height = height / downScale;
this.displayWidth = width;
this.displayHeight = height;
this.downScale = downScale;
nbCols = (int) ceil(log2(width));
colShift = (int) floor((pow(2.0f, nbCols) - width) / 2);
nbRows = (int) ceil(log2(height));
rowShift = (int) floor((pow(2.0f, nbRows) - height) / 2);
nbCodes = nbCols + nbRows + 2;
grayCodesCaptures = new PImage[nbCodes];
}
示例11: apply
import processing.core.PImage; //导入依赖的package包/类
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
List<Object> params = ProcessingUtil.parseParams(stack, 3);
PGraphics pg = (PGraphics) params.get(0);
if (params.get(3) instanceof PImage) {
pg.set(
((Number) params.get(1)).intValue(),
((Number) params.get(2)).intValue(),
(PImage) params.get(3)
);
} else {
pg.set(
((Number) params.get(1)).intValue(),
((Number) params.get(2)).intValue(),
((Number) params.get(3)).intValue()
);
}
stack.push(pg);
return stack;
}
示例12: initParticleShapes
import processing.core.PImage; //导入依赖的package包/类
public void initParticleShapes(){
papplet.shapeMode(PConstants.CORNER);
shp_particlesystem = papplet.createShape(PShape.GROUP);
PImage sprite = createSprite(0);
papplet.colorMode(PConstants.HSB, 360, 100, 100);
for (int i = 0; i < PARTICLE_COUNT; i++) {
PShape shp_particle = createParticleShape(particles[i], sprite);
particles[i].setShape(shp_particle);
if(i != IDX_MOUSE_PARTICLE){
shp_particlesystem.addChild(shp_particle);
}
}
papplet.colorMode(PConstants.RGB, 255, 255, 255);
}
示例13: createImageFrom
import processing.core.PImage; //导入依赖的package包/类
public static opencv_core.IplImage createImageFrom(PImage in) {
// TODO: avoid this creation !!
opencv_core.CvSize outSize = new opencv_core.CvSize();
outSize.width(in.width);
outSize.height(in.height);
// System.out.println("inputImage to create an IPL:" + in.width + " " + in.height + " " + in.format);
opencv_core.IplImage imgOut = null;
if (in.format == PConstants.RGB) {
imgOut = cvCreateImage(outSize, opencv_core.IPL_DEPTH_8U, // depth
3);
}
if (in.format == PConstants.ALPHA || in.format == PConstants.GRAY) {
imgOut = cvCreateImage(outSize, opencv_core.IPL_DEPTH_8U, // depth
1);
}
if (in.format == PConstants.ARGB) {
imgOut = cvCreateImage(outSize, opencv_core.IPL_DEPTH_8U, // depth
4);
}
// imgIn.w
return imgOut;
}
示例14: render
import processing.core.PImage; //导入依赖的package包/类
public void render(PGraphics2D dst, PImage sprite, int display_mode){
int[] sprite_tex_handle = new int[1];
if(sprite != null){
sprite_tex_handle[0] = dst.getTexture(sprite).glName;
}
int w = dst.width;
int h = dst.height;
dst.beginDraw();
// dst.blendMode(PConstants.BLEND);
dst.blendMode(PConstants.ADD);
context.begin();
shader_particleRender.begin();
shader_particleRender.uniform2f ("wh_viewport", w, h);
shader_particleRender.uniform2i ("num_particles", particles_x, particles_y);
shader_particleRender.uniformTexture("tex_particles", tex_particles.src);
shader_particleRender.uniformTexture("tex_sprite" , sprite_tex_handle[0]);
shader_particleRender.uniform1i ("display_mode" , display_mode); // 0 ... 1px points, 1 = sprite texture, 2 ... falloff points
shader_particleRender.drawFullScreenPoints(particles_x * particles_y);
shader_particleRender.end();
context.end("ParticleSystem.render");
dst.endDraw();
}
示例15: createSprite
import processing.core.PImage; //导入依赖的package包/类
static public PImage createSprite(PApplet papplet, int size, float exp1, float exp2, float mult){
PImage pimg = papplet.createImage(size, size, PConstants.ARGB);
pimg.loadPixels();
for(int y = 0; y < size; y++){
for(int x = 0; x < size; x++){
int pid = y * size + x;
float xn = ((x + 0.5f) / (float)size) * 2f - 1f;
float yn = ((y + 0.5f) / (float)size) * 2f - 1f;
float dd = (float) Math.sqrt(xn*xn + yn*yn);
dd = clamp(dd, 0, 1);
dd = (float) Math.pow(dd, exp1);
dd = 1.0f - dd;
dd = (float) Math.pow(dd, exp2);
dd *= mult;
dd = clamp(dd, 0, 1);
pimg.pixels[pid] = ((int)(dd * 255)) << 24 | 0x00FFFFFF;
}
}
pimg.updatePixels();
return pimg;
}