21
21
Boston, MA 02111-1307 USA
22
22
*/
23
23
24
- package processing . core ;
24
+ package procesing . a2d ;
25
25
26
26
import java .io .InputStream ;
27
27
import java .util .zip .GZIPInputStream ;
28
28
29
29
import processing .android .AppComponent ;
30
+ import processing .core .PApplet ;
31
+ import processing .core .PFont ;
32
+ import processing .core .PGraphics ;
33
+ import processing .core .PImage ;
34
+ import processing .core .PMatrix ;
35
+ import processing .core .PMatrix2D ;
36
+ import processing .core .PMatrix3D ;
37
+ import processing .core .PShape ;
38
+ import processing .core .PShapeSVG ;
39
+ import processing .core .PSurface ;
30
40
import processing .data .XML ;
31
41
import android .app .Activity ;
32
42
import android .app .ActivityManager ;
@@ -1045,20 +1055,23 @@ public void noSmooth() {
1045
1055
protected void imageImpl (PImage src ,
1046
1056
float x1 , float y1 , float x2 , float y2 ,
1047
1057
int u1 , int v1 , int u2 , int v2 ) {
1048
- if (src .bitmap != null && src .bitmap .isRecycled ()) {
1058
+ Bitmap bitmap = (Bitmap )src .getNative ();
1059
+
1060
+ if (bitmap != null && bitmap .isRecycled ()) {
1049
1061
// Let's make sure it is recreated
1050
- src . bitmap = null ;
1062
+ bitmap = null ;
1051
1063
}
1052
1064
1053
- if (src . bitmap == null && src .format == ALPHA ) {
1065
+ if (bitmap == null && src .format == ALPHA ) {
1054
1066
// create an alpha bitmap for this feller
1055
- src . bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
1067
+ bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
1056
1068
int [] px = new int [src .pixels .length ];
1057
1069
for (int i = 0 ; i < px .length ; i ++) {
1058
1070
px [i ] = src .pixels [i ] << 24 | 0xFFFFFF ;
1059
1071
}
1060
- src .bitmap .setPixels (px , 0 , src .width , 0 , 0 , src .width , src .height );
1061
- src .modified = false ;
1072
+ bitmap .setPixels (px , 0 , src .width , 0 , 0 , src .width , src .height );
1073
+ modified = false ;
1074
+ src .setNative (bitmap );
1062
1075
}
1063
1076
1064
1077
// this version's not usable because it doesn't allow you to set output w/h
@@ -1069,23 +1082,26 @@ protected void imageImpl(PImage src,
1069
1082
// src.format == ARGB, tint ? tintPaint : null);
1070
1083
// } else {
1071
1084
1072
- if (src .bitmap == null ||
1073
- src .width != src .bitmap .getWidth () ||
1074
- src .height != src .bitmap .getHeight ()) {
1075
- if (src .bitmap != null ) src .bitmap .recycle ();
1076
- src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
1077
- src .modified = true ;
1085
+ if (bitmap == null ||
1086
+ src .width != bitmap .getWidth () ||
1087
+ src .height != bitmap .getHeight ()) {
1088
+ if (bitmap != null ) bitmap .recycle ();
1089
+ bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
1090
+ modified = true ;
1091
+ src .setNative (bitmap );
1078
1092
}
1079
- if (src .modified ) {
1093
+
1094
+ if (src .isModified ()) {
1080
1095
//System.out.println("mutable, recycled = " + who.bitmap.isMutable() + ", " + who.bitmap.isRecycled());
1081
- if (!src .bitmap .isMutable ()) {
1082
- src .bitmap .recycle ();
1083
- src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
1096
+ if (!bitmap .isMutable ()) {
1097
+ bitmap .recycle ();
1098
+ bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
1099
+ src .setNative (bitmap );
1084
1100
}
1085
1101
if (src .pixels != null ) {
1086
- src . bitmap .setPixels (src .pixels , 0 , src .width , 0 , 0 , src .width , src .height );
1102
+ bitmap .setPixels (src .pixels , 0 , src .width , 0 , 0 , src .width , src .height );
1087
1103
}
1088
- src .modified = false ;
1104
+ src .setModified ( false ) ;
1089
1105
}
1090
1106
1091
1107
if (imageImplSrcRect == null ) {
@@ -1099,7 +1115,7 @@ protected void imageImpl(PImage src,
1099
1115
//System.out.println(PApplet.hex(fillPaint.getColor()));
1100
1116
//canvas.drawBitmap(who.bitmap, imageImplSrcRect, imageImplDstRect, fillPaint);
1101
1117
// System.out.println("drawing lower, tint = " + tint + " " + PApplet.hex(tintPaint.getColor()));
1102
- canvas .drawBitmap (src . bitmap , imageImplSrcRect , imageImplDstRect , tint ? tintPaint : null );
1118
+ canvas .drawBitmap (bitmap , imageImplSrcRect , imageImplDstRect , tint ? tintPaint : null );
1103
1119
1104
1120
// If the OS things the memory is low, then recycles bitmaps automatically...
1105
1121
// but I don't think it is particularly efficient, as the bitmaps are stored
@@ -1110,8 +1126,8 @@ protected void imageImpl(PImage src,
1110
1126
ActivityManager activityManager = (ActivityManager ) activity .getSystemService (android .content .Context .ACTIVITY_SERVICE );
1111
1127
activityManager .getMemoryInfo (mi );
1112
1128
if (mi .lowMemory ) {
1113
- src . bitmap .recycle ();
1114
- src .bitmap = null ;
1129
+ bitmap .recycle ();
1130
+ src .setNative ( null ) ;
1115
1131
}
1116
1132
}
1117
1133
@@ -1339,7 +1355,7 @@ protected void textLineImpl(char buffer[], int start, int stop,
1339
1355
// textFont.smooth ?
1340
1356
// RenderingHints.VALUE_ANTIALIAS_ON :
1341
1357
// RenderingHints.VALUE_ANTIALIAS_OFF);
1342
- fillPaint .setAntiAlias (textFont .smooth );
1358
+ fillPaint .setAntiAlias (textFont .isSmooth () );
1343
1359
1344
1360
//System.out.println("setting frac metrics");
1345
1361
//g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
@@ -2067,28 +2083,32 @@ public void set(int x, int y, PImage src) {
2067
2083
throw new RuntimeException ("set() not available for ALPHA images" );
2068
2084
}
2069
2085
2070
- if (src .bitmap == null ) {
2071
- src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2072
- src .modified = true ;
2086
+ Bitmap bitmap = (Bitmap )src .getNative ();
2087
+ if (bitmap == null ) {
2088
+ bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2089
+ src .setNative (bitmap );
2090
+ src .setModified ();
2073
2091
}
2074
- if (src .width != src .bitmap .getWidth () ||
2075
- src .height != src .bitmap .getHeight ()) {
2076
- src .bitmap .recycle ();
2077
- src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2078
- src .modified = true ;
2092
+ if (src .width != bitmap .getWidth () ||
2093
+ src .height != bitmap .getHeight ()) {
2094
+ bitmap .recycle ();
2095
+ bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2096
+ src .setNative (bitmap );
2097
+ src .setModified ();
2079
2098
}
2080
- if (src .modified ) {
2081
- if (!src .bitmap .isMutable ()) {
2082
- src .bitmap .recycle ();
2083
- src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2099
+ if (src .isModified ()) {
2100
+ if (!bitmap .isMutable ()) {
2101
+ bitmap .recycle ();
2102
+ bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2103
+ setNative (bitmap );
2084
2104
}
2085
- src . bitmap .setPixels (src .pixels , 0 , src .width , 0 , 0 , src .width , src .height );
2086
- src .modified = false ;
2105
+ bitmap .setPixels (src .pixels , 0 , src .width , 0 , 0 , src .width , src .height );
2106
+ src .setModified ( false ) ;
2087
2107
}
2088
2108
// set() happens in screen coordinates, so need to clear the ctm
2089
2109
canvas .save (Canvas .MATRIX_SAVE_FLAG );
2090
2110
canvas .setMatrix (null ); // set to identity
2091
- canvas .drawBitmap (src . bitmap , x , y , null );
2111
+ canvas .drawBitmap (bitmap , x , y , null );
2092
2112
canvas .restore ();
2093
2113
}
2094
2114
0 commit comments