Skip to content

Commit 8eba035

Browse files
committed
fix for processing#1730, also change how update/loadPixels are called in Java2D
1 parent dbecf68 commit 8eba035

4 files changed

Lines changed: 87 additions & 43 deletions

File tree

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,13 @@ public void endDraw() {
353353
loadPixels();
354354
}
355355

356-
// Marking as modified, and then calling updatePixels() in
357-
// the super class, which just sets the mx1, my1, mx2, my2
358-
// coordinates of the modified area. This avoids doing the
359-
// full copy of the pixels to the surface in this.updatePixels().
360-
setModified();
361-
super.updatePixels();
356+
// // Marking as modified, and then calling updatePixels() in
357+
// // the super class, which just sets the mx1, my1, mx2, my2
358+
// // coordinates of the modified area. This avoids doing the
359+
// // full copy of the pixels to the surface in this.updatePixels().
360+
// setModified();
361+
// super.updatePixels();
362+
setModified(); // marks pixels as modified so that the pixels will be updated
362363
}
363364

364365

@@ -1253,7 +1254,7 @@ protected void imageImpl(PImage who,
12531254
if ((tint && !cash.tinted) ||
12541255
(tint && (cash.tintedColor != tintColor)) ||
12551256
(!tint && cash.tinted)) {
1256-
// for tint change, mark all pixels as needing update
1257+
// For tint change, mark all pixels as needing update.
12571258
who.updatePixels();
12581259
}
12591260

@@ -1602,13 +1603,16 @@ protected float textWidthImpl(char buffer[], int start, int stop) {
16021603
return super.textWidthImpl(buffer, start, stop);
16031604
}
16041605

1605-
protected void beginTextScreenMode() {
1606-
loadPixels();
1607-
}
16081606

1609-
protected void endTextScreenMode() {
1610-
updatePixels();
1611-
}
1607+
// protected void beginTextScreenMode() {
1608+
// loadPixels();
1609+
// }
1610+
1611+
1612+
// protected void endTextScreenMode() {
1613+
// updatePixels();
1614+
// }
1615+
16121616

16131617
//////////////////////////////////////////////////////////////
16141618

@@ -2308,19 +2312,19 @@ public void loadPixels() {
23082312
}
23092313

23102314

2311-
/**
2312-
* Update the pixels[] buffer to the PGraphics image.
2313-
* <P>
2314-
* Unlike in PImage, where updatePixels() only requests that the
2315-
* update happens, in PGraphicsJava2D, this will happen immediately.
2316-
*/
2317-
@Override
2318-
public void updatePixels() {
2319-
//updatePixels(0, 0, width, height);
2320-
// WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
2321-
// WritableRaster raster = image.getRaster();
2322-
getRaster().setDataElements(0, 0, width, height, pixels);
2323-
}
2315+
// /**
2316+
// * Update the pixels[] buffer to the PGraphics image.
2317+
// * <P>
2318+
// * Unlike in PImage, where updatePixels() only requests that the
2319+
// * update happens, in PGraphicsJava2D, this will happen immediately.
2320+
// */
2321+
// @Override
2322+
// public void updatePixels() {
2323+
// //updatePixels(0, 0, width, height);
2324+
//// WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
2325+
//// WritableRaster raster = image.getRaster();
2326+
// updatePixels(0, 0, width, height);
2327+
// }
23242328

23252329

23262330
/**
@@ -2336,9 +2340,27 @@ public void updatePixels(int x, int y, int c, int d) {
23362340
// Show a warning message, but continue anyway.
23372341
showVariationWarning("updatePixels(x, y, w, h)");
23382342
}
2339-
updatePixels();
2343+
// updatePixels();
2344+
if (pixels != null) {
2345+
getRaster().setDataElements(0, 0, width, height, pixels);
2346+
}
2347+
modified = true;
23402348
}
23412349

2350+
2351+
// @Override
2352+
// protected void updatePixelsImpl(int x, int y, int w, int h) {
2353+
// super.updatePixelsImpl(x, y, w, h);
2354+
//
2355+
// if ((x != 0) || (y != 0) || (w != width) || (h != height)) {
2356+
// // Show a warning message, but continue anyway.
2357+
// showVariationWarning("updatePixels(x, y, w, h)");
2358+
// }
2359+
// getRaster().setDataElements(0, 0, width, height, pixels);
2360+
// }
2361+
2362+
2363+
23422364
//////////////////////////////////////////////////////////////
23432365

23442366
// GET/SET

core/src/processing/core/PGraphicsRetina2D.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,31 @@ public void loadPixels() {
263263
}
264264

265265

266+
@Override
267+
public void updatePixels() {
268+
if (hints[ENABLE_RETINA_PIXELS]) {
269+
updatePixels(0, 0, retina.width, retina.height);
270+
} else {
271+
updatePixels(0, 0, width, height);
272+
}
273+
}
274+
275+
266276
/**
267277
* Update the pixels[] buffer to the PGraphics image.
268278
* <P>
269279
* Unlike in PImage, where updatePixels() only requests that the
270280
* update happens, in PGraphicsJava2D, this will happen immediately.
271281
*/
272282
@Override
273-
public void updatePixels() {
283+
public void updatePixels(int ux, int uy, int uw, int uh) {
284+
int wide = hints[ENABLE_RETINA_PIXELS] ? retina.width : width;
285+
int high = hints[ENABLE_RETINA_PIXELS] ? retina.height : height;
286+
if ((ux != 0) || (uy != 0) || (uw != wide) || (uh != high)) {
287+
// Show a warning message, but continue anyway.
288+
showVariationWarning("updatePixels(x, y, w, h)");
289+
}
290+
// If not using retina pixels, will need to first downsample
274291
if (!hints[ENABLE_RETINA_PIXELS]) {
275292
int offset = 0;
276293
int roffset = 0;
@@ -286,13 +303,10 @@ public void updatePixels() {
286303
}
287304
}
288305
getRaster().setDataElements(0, 0, retina.width, retina.height, retina.pixels);
306+
modified = true;
289307
}
290308

291309

292-
// No override necessary, just prints a warning and calls updatePixels()
293-
//public void updatePixels(int x, int y, int c, int d);
294-
295-
296310
static int rgetset[] = new int[4];
297311

298312
@Override

core/src/processing/core/PImage.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ public void loadPixels() { // ignore
494494

495495

496496
public void updatePixels() { // ignore
497-
updatePixelsImpl(0, 0, width, height);
497+
// updatePixelsImpl(0, 0, width, height);
498+
updatePixels(0, 0, width, height);
498499
}
499500

500501

@@ -530,11 +531,15 @@ public void updatePixels() { // ignore
530531
* @param h height
531532
*/
532533
public void updatePixels(int x, int y, int w, int h) { // ignore
533-
updatePixelsImpl(x, y, w, h);
534-
}
535-
536-
537-
protected void updatePixelsImpl(int x, int y, int w, int h) {
534+
// updatePixelsImpl(x, y, w, h);
535+
// }
536+
//
537+
//
538+
// /**
539+
// * Broken out as separate impl to signify that the w/y/w/h numbers have
540+
// * already been tested and their bounds set properly.
541+
// */
542+
// protected void updatePixelsImpl(int x, int y, int w, int h) {
538543
int x2 = x + w;
539544
int y2 = y + h;
540545

@@ -896,7 +901,8 @@ protected void getImpl(int sourceX, int sourceY,
896901
public void set(int x, int y, int c) {
897902
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return;
898903
pixels[y*width + x] = c;
899-
updatePixelsImpl(x, y, 1, 1); // slow?
904+
//updatePixelsImpl(x, y, 1, 1); // slow?
905+
updatePixels(x, y, 1, 1); // slow?
900906
}
901907

902908

@@ -955,7 +961,8 @@ protected void setImpl(PImage sourceImage,
955961
targetOffset += width;
956962
}
957963

958-
updatePixelsImpl(targetX, targetY, sourceWidth, sourceHeight);
964+
//updatePixelsImpl(targetX, targetY, sourceWidth, sourceHeight);
965+
updatePixels(targetX, targetY, sourceWidth, sourceHeight);
959966
}
960967

961968

core/todo.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ o JAI handles setting image size for png (check javax.imageio?)
1818
o PNGEncodeParam png = PNGEncodeParam.getDefaultEncodeParam(bufImage);
1919
o png.setPhysicalDimension(round(dpi*39.370079), round(dpi*39.370079), 1);
2020
o JAI.create("filestore", bufImage, filename+".png", "PNG");
21+
X tint() with JAVA2D does not automatically refresh (with possible fix)
22+
X https://github.com/processing/processing/issues/1730
23+
X change how updatePixels() is called in PGraphicsJava2D
24+
X only call setModified(), not updatePixels() in endDraw()
2125

2226
mouse wheel
2327
X add mouse wheel support to 2.0 event system
@@ -64,9 +68,6 @@ _ "deleted n framebuffer objects"
6468
_ draw() called again before finishing on OS X (retina issue)
6569
_ https://github.com/processing/processing/issues/1709
6670

67-
_ tint() with JAVA2D does not automatically refresh (with possible fix)
68-
_ https://github.com/processing/processing/issues/1730
69-
7071
_ Linux sometimes not responding correctly w/ the size() command
7172
_ https://github.com/processing/processing/issues/1672
7273

0 commit comments

Comments
 (0)