Skip to content

Commit 9c9900a

Browse files
hansonrhansonr
authored andcommitted
WritableRaster adds 秘pix element for direct writing
1 parent faf3724 commit 9c9900a

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

sources/net.sf.j2s.java.core/src/java/awt/image/Raster.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,12 @@ public static WritableRaster createWritableRaster(SampleModel sm,
978978
}
979979

980980
int dataType = sm.getDataType();
981+
982+
if (dataType == DataBuffer.TYPE_INT) { // SwingJS
983+
SunWritableRaster r = new SunWritableRaster(sm,db,location);
984+
r.秘pix = SunWritableRaster.stealData((DataBufferInt) db, 0);
985+
return r;
986+
}
981987
//
982988
// if (sm instanceof PixelInterleavedSampleModel) {
983989
// switch(dataType) {
@@ -1007,7 +1013,7 @@ public static WritableRaster createWritableRaster(SampleModel sm,
10071013

10081014
// we couldn't do anything special - do the generic thing
10091015

1010-
return new SunWritableRaster(sm,db,location);
1016+
return new BytePackedRaster(sm, db, location);
10111017
}
10121018

10131019
/**

sources/net.sf.j2s.java.core/src/sun/awt/image/SunWritableRaster.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
public class SunWritableRaster extends WritableRaster {
5050
private static DataStealer stealer;
51+
52+
public int[] 秘pix;
5153

5254
private static DataStealer getStealer() {
5355
return (stealer == null ? stealer = new DataStealer() {

sources/net.sf.j2s.java.core/src/swingjs/JSGraphics2D.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public class JSGraphics2D implements
9999
* ctx.backingStorePixelRatio || 1; return dpr / bsr; })() ||
100100
*/
101101
1;
102+
static {
103+
System.out.println("JSGraphics2D pixelRatio is " + pixelRatio);
104+
}
102105
// this is 1.5 for Windows
103106
// nice, but now how would be do raw pixel setting, say, from images?
104107
// can.width = w * pixelRatio;
@@ -468,6 +471,14 @@ private void doRoundRect(int x, int y, int w, int h, int aw, int ah, int mode) {
468471
draw(rrect);
469472
}
470473

474+
/**
475+
* Allows for direct image transfer by buffer
476+
* @param img
477+
* @param x
478+
* @param y
479+
* @param observer
480+
* @return
481+
*/
471482
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
472483
return drawImagePriv(img, x, y, observer);
473484
}
@@ -496,10 +507,10 @@ private void observe(Image img, ImageObserver observer, boolean isOK) {
496507
observer.imageUpdate(img, (isOK ? 0 : ImageObserver.ABORT | ImageObserver.ERROR), -1, -1, -1, -1);
497508
}
498509

499-
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
500-
// backgroundPainted = true;
501-
return drawImage(img, x, y, observer);
502-
}
510+
// public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
511+
//// backgroundPainted = true;
512+
// return drawImage(img, x, y, observer);
513+
// }
503514

504515
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
505516
if (width <= 0 || height <= 0)
@@ -563,7 +574,7 @@ public boolean drawImagePriv(Image img, int x, int y, ImageObserver observer) {
563574
/**
564575
* @j2sNative
565576
*
566-
* pixels = img.秘pix; isRGB = (img.imageType == 1);
577+
* pixels = img.raster.秘pix ||img.秘pix; isRGB = (img.imageType == 1);
567578
*
568579
*/
569580
DOMNode imgNode = null;
@@ -582,13 +593,7 @@ public boolean drawImagePriv(Image img, int x, int y, ImageObserver observer) {
582593
return true;
583594
}
584595

585-
public void drawDirectRGBA(int[] pixels) {
586-
// this can go VERY fast - for writing directly to the canvas context
587-
// backgroundPainted = true;
588-
drawDirect(pixels, 0, 0, width, height, false);
589-
}
590-
591-
private void drawDirect(int[] pixels, int x, int y, int width, int height, boolean isRGB) {
596+
public void drawDirect(int[] pixels, int x, int y, int width, int height, boolean isRGB) {
592597
if (buf8 == null || x != lastx || y != lasty || nx != width || ny != height) {
593598
imageData = ctx.getImageData(x, y, width, height);
594599
buf8 = imageData.data;

0 commit comments

Comments
 (0)