本文整理汇总了Java中processing.core.PImage.loadPixels方法的典型用法代码示例。如果您正苦于以下问题:Java PImage.loadPixels方法的具体用法?Java PImage.loadPixels怎么用?Java PImage.loadPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing.core.PImage
的用法示例。
在下文中一共展示了PImage.loadPixels方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例3: 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;
}
示例4: imgDifference
import processing.core.PImage; //导入方法依赖的package包/类
private static float imgDifference(PImage i0, PImage i1) {
float diff = 0;
i0.loadPixels();
int[] ip0 = i0.pixels;
i1.loadPixels();
int[] ip1 = i1.pixels;
for (int n = 0; n < ip0.length; n++) {
int pxl0 = ip0[n], r0, g0, b0;
int pxl1 = ip1[n], r1, g1, b1;
r0 = (pxl0 >> 20) & 0xF;
g0 = (pxl0 >> 12) & 0xF;
b0 = (pxl0 >> 4) & 0xF;
r1 = (pxl1 >> 20) & 0xF;
g1 = (pxl1 >> 12) & 0xF;
b1 = (pxl1 >> 4) & 0xF;
diff += PApplet.abs(r0 - r1) + PApplet.abs(g0 - g1) + PApplet.abs(b0 - b1);
}
// Each colour channel can have a difference 0-15
// Considering 3 colour channels (ignoring alpha)
return diff / (ip0.length * 3 * 15);
}
示例5: computeOccurencesOfColor
import processing.core.PImage; //导入方法依赖的package包/类
public int computeOccurencesOfColor(int c, int threshold) {
// TODO: Hack for noCamera, better to be done.
if (paperScreen.cameraTracking == null) {
return 0;
}
PImage out = getImage();
if (out == null) {
return 0;
}
out.loadPixels();
int pxNb = picWidth * picHeight;
int nbSameColor = 0;
for (int k = 0; k < pxNb; k++) {
int c2 = out.pixels[k];
boolean isClose = MathUtils.colorDistRGB(c, c2, threshold);
if (isClose) {
nbSameColor++;
}
}
return nbSameColor;
}
示例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: getProjectorImageScaled
import processing.core.PImage; //导入方法依赖的package包/类
public PImage getProjectorImageScaled(PApplet applet, int projWidth, int projHeight, int precision) {
PImage projectorImage = applet.createImage(projWidth / precision, projHeight / precision, 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];
x = x / precision;
y = y / precision;
int offset = y * projWidth / precision + x;
projectorImage.pixels[offset] = refImage.pixels[i];
}
}
projectorImage.updatePixels();
return projectorImage;
}
示例8: 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;
}
示例9: light
import processing.core.PImage; //导入方法依赖的package包/类
/**
* Burn lighting onto decal.
*/
public void light() {
// Generate alpha map.
PImage alpha = sprite.get();
alpha.loadPixels();
for (int i = 0; i < alpha.pixels.length; i ++) {
alpha.pixels[i] = ((alpha.pixels[i] >> 8) & 0xFFFFFF) << 8 | (alpha.pixels[i] >> 24) & 0xFF;
}
alpha.updatePixels();
// Create the light map.
PImage lightMapCopy = pie.app.createImage(sprite.width, sprite.height, PConstants.ARGB);
// Copy light map portion from main light map image.
if (!isTile) {
for (int i = 0; i <= objFrames; i++) {
lightMapCopy.copy(pie.lightMap, x, y, objWidth, objHeight, i * objWidth, 0, objWidth, objHeight);
}
} else {
lightMapCopy.copy(pie.lightMap, x, y, objWidth, objHeight, 0, 0, objWidth, objHeight);
}
// Add on ilumMap if any, using SCREEN blend mode.
if (IlumSprite != null) {
lightMapCopy.blend(IlumSprite, 0, 0, sprite.width, sprite.height, 0, 0, sprite.width, sprite.height, PConstants.SCREEN);
IlumSprite = null; // We don't need this anymore, free resources.
}
// Burn light map onto sprite.
sprite.blend(lightMapCopy, 0, 0, sprite.width, sprite.height, 0, 0, sprite.width, sprite.height, PConstants.MULTIPLY);
// Re-apply the original alpha onto the lighted sprite.
sprite.mask(alpha);
}
示例10: createGradientImg
import processing.core.PImage; //导入方法依赖的package包/类
/**
* Creates an image with a circular color gradient
*
* @param p the parent Processing applet
* @param centralColor the image central color
* @param borderColor the image border color
* @return the image with the circular color gradient
*/
public static PImage createGradientImg(PApplet p, int centralColor, int borderColor) {
// Create the image with the same dimensions as the sketch applet
PImage img = p.createImage(p.width, p.height, PApplet.RGB);
// Set the image pixel colors
float rowCenter = 0.5f * img.height;
float colCenter = 0.5f * img.width;
float maxRadiusSq = PApplet.sq(colCenter) + PApplet.sq(rowCenter);
int centralRed = (centralColor >> 16) & 0xff;
int centralGreen = (centralColor >> 8) & 0xff;
int centralBlue = centralColor & 0xff;
int borderRed = (borderColor >> 16) & 0xff;
int borderGreen = (borderColor >> 8) & 0xff;
int borderBlue = borderColor & 0xff;
img.loadPixels();
for (int row = 0; row < img.height; row++) {
for (int col = 0; col < img.width; col++) {
float relativeDist = PApplet
.sqrt((PApplet.sq(col - colCenter) + PApplet.sq(row - rowCenter)) / maxRadiusSq);
int pixelRed = Math.round((1 - relativeDist) * centralRed + relativeDist * borderRed);
int pixelGreen = Math.round((1 - relativeDist) * centralGreen + relativeDist * borderGreen);
int pixelBlue = Math.round((1 - relativeDist) * centralBlue + relativeDist * borderBlue);
img.pixels[col + row * img.width] = (pixelRed << 16) | (pixelGreen << 8) | pixelBlue | 0xff000000;
}
}
img.updatePixels();
return img;
}
示例11: computeColor
import processing.core.PImage; //导入方法依赖的package包/类
public void computeColor() {
// HACK -> TODO error management.
if (paperScreen.cameraTracking == null) {
return;
}
PImage out = getImage();
if (out == null) {
return;
}
out.loadPixels();
int avgRed = 0;
int avgGreen = 0;
int avgBlue = 0;
int pxNb = picWidth * picHeight;
for (int k = 0; k < pxNb; k++) {
int c = out.pixels[k];
avgRed += c >> 16 & 0xFF;
avgGreen += c >> 8 & 0xFF;
avgBlue += c >> 0 & 0xFF;
}
avgRed = (avgRed / pxNb) << 16;
avgGreen = (avgGreen / pxNb) << 8;
avgBlue /= pxNb;
this.col = 255 << 24 | avgRed | avgGreen | avgBlue;
}
示例12: createAnaglyph
import processing.core.PImage; //导入方法依赖的package包/类
public static void createAnaglyph(PImage imgL, PImage imgR, PImage imgOut) {
imgL.loadPixels();
imgR.loadPixels();
imgOut.loadPixels();
int[] pL = imgL.pixels;
int[] pR = imgR.pixels;
int[] pO = imgOut.pixels;
for (int i = 0; i < pL.length; i++) {
pO[i] = (pR[i] >> 16) << 16 | (pL[i] >> 8) & 255 << 8 | pL[i] & 255;
// pO[i] = pL[i];
}
imgOut.updatePixels();
// imgL.updatePixels();
}
示例13: applyTransColor
import processing.core.PImage; //导入方法依赖的package包/类
private void applyTransColor(PImage source, String c){
int trans = this.readColor(c);
source.loadPixels();
for (int p = 0; p < source.pixels.length; p++) if(source.pixels[p] == trans) source.pixels[p] = parent.color(255, 1);
source.updatePixels();
}
示例14: fastblur
import processing.core.PImage; //导入方法依赖的package包/类
/**
* Super Fast Blur (by Mario Klingemann <http://incubator.quasimondo.com>)
* @param img
* @param radius
*/
private static void fastblur(PImage img, int radius) {
if (radius < 1) {
return;
}
img.loadPixels();
int w = img.width;
int h = img.height;
int wm = w - 1;
int hm = h - 1;
int wh = w * h;
int div = radius + radius + 1;
int r[] = new int[wh];
int g[] = new int[wh];
int b[] = new int[wh];
int rsum, gsum, bsum, x, y, i, p, p1, p2, yp, yi, yw;
int vmin[] = new int[PApplet.max(w, h)];
int vmax[] = new int[PApplet.max(w, h)];
int[] pix = img.pixels;
int dv[] = new int[256 * div];
for (i = 0; i < 256 * div; i++) {
dv[i] = (i / div);
}
yw = yi = 0;
for (y = 0; y < h; y++) {
rsum = gsum = bsum = 0;
for (i = -radius; i <= radius; i++) {
p = pix[yi + PApplet.min(wm, PApplet.max(i, 0))];
rsum += (p & 0xff0000) >> 16;
gsum += (p & 0x00ff00) >> 8;
bsum += p & 0x0000ff;
}
for (x = 0; x < w; x++) {
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
if (y == 0) {
vmin[x] = PApplet.min(x + radius + 1, wm);
vmax[x] = PApplet.max(x - radius, 0);
}
p1 = pix[yw + vmin[x]];
p2 = pix[yw + vmax[x]];
rsum += ((p1 & 0xff0000) - (p2 & 0xff0000)) >> 16;
gsum += ((p1 & 0x00ff00) - (p2 & 0x00ff00)) >> 8;
bsum += (p1 & 0x0000ff) - (p2 & 0x0000ff);
yi++;
}
yw += w;
}
for (x = 0; x < w; x++) {
rsum = gsum = bsum = 0;
yp = -radius * w;
for (i = -radius; i <= radius; i++) {
yi = PApplet.max(0, yp) + x;
rsum += r[yi];
gsum += g[yi];
bsum += b[yi];
yp += w;
}
yi = x;
for (y = 0; y < h; y++) {
pix[yi] = 0xff000000 | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
if (x == 0) {
vmin[y] = PApplet.min(y + radius + 1, hm) * w;
vmax[y] = PApplet.max(y - radius, 0) * w;
}
p1 = x + vmin[y];
p2 = x + vmax[y];
rsum += r[p1] - r[p2];
gsum += g[p1] - g[p2];
bsum += b[p1] - b[p2];
yi += w;
}
}
img.updatePixels();
}