Revision 7cb8d4b0
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.bandaged; |
21 | 21 |
|
22 |
import android.graphics.Bitmap; |
|
22 | 23 |
import android.os.Build; |
23 | 24 |
import android.os.Bundle; |
24 | 25 |
import android.util.DisplayMetrics; |
... | ... | |
186 | 187 |
|
187 | 188 |
if( mScreen==null ) mScreen = new BandagedCreatorScreen(); |
188 | 189 |
mScreen.onAttachedToWindow(this); |
190 |
|
|
191 |
BandagedCreatorWorkerThread.create(this); |
|
189 | 192 |
} |
190 | 193 |
|
191 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
231 | 234 |
|
232 | 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
233 | 236 |
|
234 |
public int getHeightBar()
|
|
237 |
public void iconCreationDone(Bitmap bmp)
|
|
235 | 238 |
{ |
236 |
return mHeightBar;
|
|
239 |
mScreen.iconCreationDone(bmp);
|
|
237 | 240 |
} |
238 | 241 |
|
239 | 242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/bandaged/BandagedCreatorObjectView.java | ||
---|---|---|
20 | 20 |
package org.distorted.bandaged; |
21 | 21 |
|
22 | 22 |
import android.view.LayoutInflater; |
23 |
import android.view.View; |
|
23 | 24 |
import android.widget.LinearLayout; |
24 | 25 |
|
25 | 26 |
import org.distorted.helpers.TransparentButton; |
... | ... | |
34 | 35 |
private final LinearLayout mPane; |
35 | 36 |
private final String mName; |
36 | 37 |
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
private void playObject() |
|
41 |
{ |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
private void deleteObject() |
|
48 |
{ |
|
49 |
|
|
50 |
} |
|
51 |
|
|
37 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 53 |
|
39 | 54 |
public BandagedCreatorObjectView(BandagedCreatorActivity act, String name, boolean leftmost) |
... | ... | |
64 | 79 |
|
65 | 80 |
bottom.addView(plaButton); |
66 | 81 |
bottom.addView(delButton); |
82 |
|
|
83 |
plaButton.setOnClickListener( new View.OnClickListener() |
|
84 |
{ |
|
85 |
@Override |
|
86 |
public void onClick(View v) |
|
87 |
{ |
|
88 |
playObject(); |
|
89 |
} |
|
90 |
}); |
|
91 |
|
|
92 |
delButton.setOnClickListener( new View.OnClickListener() |
|
93 |
{ |
|
94 |
@Override |
|
95 |
public void onClick(View v) |
|
96 |
{ |
|
97 |
deleteObject(); |
|
98 |
} |
|
99 |
}); |
|
67 | 100 |
} |
68 | 101 |
|
69 | 102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java | ||
---|---|---|
23 | 23 |
import javax.microedition.khronos.opengles.GL10; |
24 | 24 |
|
25 | 25 |
import android.app.Activity; |
26 |
import android.opengl.GLES31; |
|
26 | 27 |
import android.opengl.GLSurfaceView; |
27 | 28 |
import android.widget.Toast; |
28 | 29 |
|
29 | 30 |
import org.distorted.dialogs.RubikDialogSaveBandaged; |
31 |
import org.distorted.library.effect.PostprocessEffectBorder; |
|
32 |
import org.distorted.library.main.DistortedEffects; |
|
33 |
import org.distorted.library.main.DistortedFramebuffer; |
|
30 | 34 |
import org.distorted.library.main.DistortedLibrary; |
31 | 35 |
import org.distorted.library.main.DistortedNode; |
32 | 36 |
import org.distorted.library.main.DistortedScreen; |
33 | 37 |
|
38 |
import org.distorted.library.type.Static1D; |
|
34 | 39 |
import org.distorted.library.type.Static3D; |
35 | 40 |
import org.distorted.library.type.Static4D; |
36 | 41 |
import org.distorted.objectlib.json.JsonWriter; |
42 |
import org.distorted.objectlib.main.ObjectControl; |
|
43 |
import org.distorted.objectlib.main.ShapeHexahedron; |
|
37 | 44 |
import org.distorted.objectlib.main.TwistyObject; |
38 | 45 |
import org.distorted.objectlib.objects.TwistyBandagedGeneric; |
39 | 46 |
import org.json.JSONException; |
... | ... | |
41 | 48 |
import java.io.File; |
42 | 49 |
import java.io.FileNotFoundException; |
43 | 50 |
import java.io.IOException; |
51 |
import java.nio.ByteBuffer; |
|
52 |
import java.nio.ByteOrder; |
|
44 | 53 |
|
45 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 55 |
|
47 | 56 |
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
48 | 57 |
{ |
58 |
public static final float BRIGHTNESS = 0.333f; |
|
49 | 59 |
private static final int DURATION = 1000; |
50 | 60 |
|
51 | 61 |
static final int COLOR_DEFAULT = 0xffffff55; |
... | ... | |
95 | 105 |
private float mScaleValue; |
96 | 106 |
private float mX, mY, mZ, mW; |
97 | 107 |
private boolean mResetQuats, mSetQuatT, mResettingObject; |
108 |
private int mSaveIcon; |
|
109 |
private DistortedFramebuffer mFramebuffer; |
|
110 |
private String mPath; |
|
98 | 111 |
|
99 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 | 113 |
|
101 | 114 |
BandagedCreatorRenderer(BandagedCreatorView v) |
102 | 115 |
{ |
103 |
final float BRIGHTNESS = 0.333f; |
|
104 |
|
|
105 | 116 |
mQuatT = new Static4D(0,0,0,1); |
106 | 117 |
mQuatA = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); |
107 | 118 |
|
... | ... | |
111 | 122 |
mSetQuatT = false; |
112 | 123 |
mResettingObject= false; |
113 | 124 |
|
125 |
mSaveIcon = -1; |
|
126 |
|
|
114 | 127 |
mScreen = new DistortedScreen(); |
115 | 128 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
116 | 129 |
mScale = new Static3D(1,1,1); |
... | ... | |
216 | 229 |
boolean done = continueResetting(time); |
217 | 230 |
if( done ) mResettingObject = false; |
218 | 231 |
} |
232 |
|
|
233 |
if( mSaveIcon>=0 ) mSaveIcon++; |
|
234 |
if( mSaveIcon>=2 ) { saveIcon(); mSaveIcon = -1; } |
|
219 | 235 |
} |
220 | 236 |
|
221 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
347 | 363 |
BandagedCreatorActivity act = (BandagedCreatorActivity) mView.getContext(); |
348 | 364 |
|
349 | 365 |
boolean success = createObjectJson(obj,act); |
366 |
setupIconCreation(obj,act); |
|
350 | 367 |
|
351 | 368 |
if( success ) |
352 | 369 |
{ |
... | ... | |
411 | 428 |
} |
412 | 429 |
|
413 | 430 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
414 |
/* |
|
415 |
private void createIcon(TwistyObject object)
|
|
431 |
|
|
432 |
private void setupIconCreation(TwistyObject object, Activity act)
|
|
416 | 433 |
{ |
417 |
if( !mIconActive ) |
|
418 |
{ |
|
419 |
mIconActive = true; |
|
420 |
|
|
421 |
ObjectControl control = getControl(); |
|
422 |
DistortedEffects effects = object.getObjectEffects(); |
|
423 |
|
|
424 |
Static4D defRot = ShapeHexahedron.DEFAULT_ROT; |
|
425 |
Static1D halo = new Static1D(5); |
|
426 |
control.rotateNow(defRot); |
|
427 |
float scale = 1.15f; |
|
428 |
control.scaleNow(scale); |
|
429 |
Static4D color = new Static4D(0,0,0,1); |
|
430 |
PostprocessEffectBorder border = new PostprocessEffectBorder(halo,color); |
|
431 |
border.setHaloDepth(false); |
|
432 |
effects.apply(border); |
|
433 |
String objectName = object.getShortName(); |
|
434 |
final String name = STORAGE+objectName+".png"; |
|
435 |
renderer.setSaveIcon(name); |
|
436 |
} |
|
434 |
/* |
|
435 |
// create framebuffer, attach object's node to it |
|
436 |
|
|
437 |
ObjectControl control = getControl(); |
|
438 |
DistortedEffects effects = object.getObjectEffects(); |
|
439 |
|
|
440 |
Static4D defRot = ShapeHexahedron.DEFAULT_ROT; |
|
441 |
Static1D halo = new Static1D(5); |
|
442 |
control.rotateNow(defRot); |
|
443 |
float scale = 1.15f; |
|
444 |
control.scaleNow(scale); |
|
445 |
Static4D color = new Static4D(0,0,0,1); |
|
446 |
PostprocessEffectBorder border = new PostprocessEffectBorder(halo,color); |
|
447 |
border.setHaloDepth(false); |
|
448 |
effects.apply(border); |
|
449 |
|
|
450 |
final String name = object.getShortName()+".png"; |
|
451 |
File file = new File(act.getFilesDir(), name); |
|
452 |
String filename = file.getAbsolutePath(); |
|
453 |
|
|
454 |
mSaveIcon = 0; |
|
455 |
mPath = filename; |
|
456 |
*/ |
|
437 | 457 |
} |
438 |
*/ |
|
458 |
|
|
459 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
460 |
|
|
461 |
private void saveIcon() |
|
462 |
{ |
|
463 |
int fW = mFramebuffer.getWidth(); |
|
464 |
int fH = mFramebuffer.getHeight(); |
|
465 |
ByteBuffer buf = ByteBuffer.allocateDirect(fW*fH*4); |
|
466 |
buf.order(ByteOrder.LITTLE_ENDIAN); |
|
467 |
|
|
468 |
int textureID = mFramebuffer.getTextureID(); |
|
469 |
|
|
470 |
if( textureID>=0 ) |
|
471 |
{ |
|
472 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, textureID); |
|
473 |
GLES31.glReadPixels( 0, 0, fW, fH, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, buf); |
|
474 |
BandagedCreatorWorkerThread.newBuffer(buf,fW,fH,6,mPath); |
|
475 |
} |
|
476 |
else |
|
477 |
{ |
|
478 |
android.util.Log.e("Save", "Error trying to read from offscreen FBO, textureID="+textureID); |
|
479 |
} |
|
480 |
|
|
481 |
mSaveIcon = -1; |
|
482 |
} |
|
483 |
|
|
439 | 484 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
440 | 485 |
|
441 | 486 |
public void displaySavingDialog() |
src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.bandaged; |
21 | 21 |
|
22 |
import android.graphics.Bitmap; |
|
22 | 23 |
import android.view.View; |
24 |
import android.widget.ImageView; |
|
23 | 25 |
import android.widget.LinearLayout; |
24 | 26 |
|
25 | 27 |
import org.distorted.helpers.TransparentImageButton; |
... | ... | |
139 | 141 |
mObjectView.addView(pane); |
140 | 142 |
mNumObjects++; |
141 | 143 |
} |
144 |
|
|
145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 |
|
|
147 |
void iconCreationDone(Bitmap bmp) |
|
148 |
{ |
|
149 |
int numChildren = mObjectView.getChildCount(); |
|
150 |
LinearLayout pane = (LinearLayout)mObjectView.getChildAt(numChildren-1); |
|
151 |
ImageView view = pane.findViewById(R.id.bandagedCreatorObjectIcon); |
|
152 |
|
|
153 |
if( view!=null ) |
|
154 |
{ |
|
155 |
view.setImageBitmap(bmp); |
|
156 |
} |
|
157 |
else |
|
158 |
{ |
|
159 |
android.util.Log.e("D", "ImageView not found!"); |
|
160 |
} |
|
161 |
} |
|
142 | 162 |
} |
src/main/java/org/distorted/bandaged/BandagedCreatorWorkerThread.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2022 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.bandaged; |
|
21 |
|
|
22 |
import android.app.Activity; |
|
23 |
import android.content.Intent; |
|
24 |
import android.graphics.Bitmap; |
|
25 |
import android.net.Uri; |
|
26 |
import android.widget.Toast; |
|
27 |
|
|
28 |
import java.io.BufferedOutputStream; |
|
29 |
import java.io.File; |
|
30 |
import java.io.FileOutputStream; |
|
31 |
import java.io.IOException; |
|
32 |
import java.lang.ref.WeakReference; |
|
33 |
import java.nio.ByteBuffer; |
|
34 |
import java.nio.ByteOrder; |
|
35 |
import java.util.Vector; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
class BandagedCreatorWorkerThread extends Thread |
|
40 |
{ |
|
41 |
private static Vector<WorkLoad> mBuffers; |
|
42 |
private static BandagedCreatorWorkerThread mThis=null; |
|
43 |
private static WeakReference<Activity> mWeakAct; |
|
44 |
|
|
45 |
private static class WorkLoad |
|
46 |
{ |
|
47 |
ByteBuffer buffer; |
|
48 |
int width; |
|
49 |
int height; |
|
50 |
int numColors; |
|
51 |
String filename; |
|
52 |
|
|
53 |
WorkLoad(ByteBuffer buf, int w, int h, int n, String name) |
|
54 |
{ |
|
55 |
buffer = buf; |
|
56 |
width = w; |
|
57 |
height = h; |
|
58 |
numColors= n; |
|
59 |
filename = name; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
private BandagedCreatorWorkerThread() |
|
66 |
{ |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
static void create(Activity act) |
|
72 |
{ |
|
73 |
mWeakAct = new WeakReference<>(act); |
|
74 |
|
|
75 |
if( mThis==null ) |
|
76 |
{ |
|
77 |
mBuffers = new Vector<>(); |
|
78 |
mThis = new BandagedCreatorWorkerThread(); |
|
79 |
mThis.start(); |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
public void run() |
|
86 |
{ |
|
87 |
WorkLoad load; |
|
88 |
|
|
89 |
while(true) |
|
90 |
{ |
|
91 |
synchronized(mThis) |
|
92 |
{ |
|
93 |
while( mBuffers.size()>0 ) |
|
94 |
{ |
|
95 |
load = mBuffers.remove(0); |
|
96 |
process(load); |
|
97 |
} |
|
98 |
|
|
99 |
try { mThis.wait(); } |
|
100 |
catch(InterruptedException ex) { } |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
static void newBuffer(ByteBuffer buffer, int width, int height, int numColors, String filename) |
|
108 |
{ |
|
109 |
synchronized(mThis) |
|
110 |
{ |
|
111 |
WorkLoad load = new WorkLoad(buffer,width,height,numColors,filename); |
|
112 |
mBuffers.add(load); |
|
113 |
mThis.notify(); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
118 |
|
|
119 |
private boolean containsBlackness(byte[] tmp, int width) |
|
120 |
{ |
|
121 |
for(int i=0; i<width; i++) |
|
122 |
{ |
|
123 |
if( tmp[4*i]==0 && tmp[4*i+3]==-1 ) return true; |
|
124 |
} |
|
125 |
|
|
126 |
return false; |
|
127 |
} |
|
128 |
|
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 |
|
|
131 |
private int computeFirstRow(ByteBuffer buf, byte[] tmp, int width, int height) |
|
132 |
{ |
|
133 |
int wBytes = 4*width; |
|
134 |
|
|
135 |
for(int i=0; i<height; i++) |
|
136 |
{ |
|
137 |
buf.position(i*wBytes); |
|
138 |
buf.get(tmp); |
|
139 |
|
|
140 |
if( containsBlackness(tmp,width) ) return i; |
|
141 |
} |
|
142 |
|
|
143 |
return -1; |
|
144 |
} |
|
145 |
|
|
146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
147 |
|
|
148 |
private int computeLastRow(ByteBuffer buf, byte[] tmp, int width, int height) |
|
149 |
{ |
|
150 |
int wBytes = 4*width; |
|
151 |
|
|
152 |
for(int i=height-1; i>=0; i--) |
|
153 |
{ |
|
154 |
buf.position(i*wBytes); |
|
155 |
buf.get(tmp); |
|
156 |
|
|
157 |
if( containsBlackness(tmp,width) ) return i; |
|
158 |
} |
|
159 |
|
|
160 |
return -1; |
|
161 |
} |
|
162 |
|
|
163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
// GL uses a coordinate system from mathematics; i.e. (0,0) is in the lower-left corner. 2D stuff |
|
165 |
// has the origin on the upper-left corner; we have to flip our bitmap upside down! |
|
166 |
// |
|
167 |
// We also need to figure out the topmost and bottommost rows where the object starts and cut out |
|
168 |
// a square section from the 'input' so that the object is vertically centralized. |
|
169 |
|
|
170 |
private ByteBuffer adjustBuffer(ByteBuffer input, byte[] tmp, int width, int height) |
|
171 |
{ |
|
172 |
int wBytes = 4*width; |
|
173 |
|
|
174 |
ByteBuffer output = ByteBuffer.allocateDirect(wBytes*width); |
|
175 |
output.order(ByteOrder.LITTLE_ENDIAN); |
|
176 |
|
|
177 |
int firstRow = computeFirstRow(input,tmp,width,height); |
|
178 |
int lastRow = computeLastRow(input,tmp,width,height); |
|
179 |
|
|
180 |
int startRow = (firstRow+lastRow+width)/2; |
|
181 |
|
|
182 |
for(int i=0; i<width; i++) |
|
183 |
{ |
|
184 |
input.position((startRow-i)*wBytes); |
|
185 |
input.get(tmp); |
|
186 |
output.position(i*wBytes); |
|
187 |
output.put(tmp); |
|
188 |
} |
|
189 |
|
|
190 |
output.rewind(); |
|
191 |
return output; |
|
192 |
} |
|
193 |
|
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 |
|
|
196 |
private void replaceColor(byte[] tmp, int index, int numColors) |
|
197 |
{ |
|
198 |
byte A = (byte)0xab; |
|
199 |
int CUTOFF = 100; |
|
200 |
|
|
201 |
switch(numColors) |
|
202 |
{ |
|
203 |
case 4: if( tmp[index+1]==0 ) { tmp[index]=A; tmp[index+1]=0; tmp[index+2]=0; } |
|
204 |
else |
|
205 |
{ |
|
206 |
if( tmp[index]==tmp[index+1] ) |
|
207 |
{ |
|
208 |
if( tmp[index]<0 || tmp[index]>CUTOFF ) { tmp[index]=A; tmp[index+1]=A; tmp[index+2]=0; } |
|
209 |
} |
|
210 |
else { tmp[index]=0; tmp[index+1]=0; tmp[index+2]=A; } |
|
211 |
} |
|
212 |
break; |
|
213 |
case 6: if( tmp[index+2]!=0 ) |
|
214 |
{ |
|
215 |
if( tmp[index]==0 ) { tmp[index]=0; tmp[index+1]=0; tmp[index+2]=A; } |
|
216 |
} |
|
217 |
else |
|
218 |
{ |
|
219 |
if( tmp[index]==tmp[index+1] ) { tmp[index]=A; tmp[index+1]=A; tmp[index+2]=0; } |
|
220 |
else { tmp[index]=A; tmp[index+1]=0; tmp[index+2]=0; } |
|
221 |
} |
|
222 |
break; |
|
223 |
case 8: if( tmp[index+2]!=0 ) |
|
224 |
{ |
|
225 |
if( tmp[index+1]==0 ) { tmp[index]=A; tmp[index+1]=0; tmp[index+2]=0; } |
|
226 |
} |
|
227 |
else |
|
228 |
{ |
|
229 |
if( tmp[index+1]==0 ) { tmp[index]=0; tmp[index+1]=0; tmp[index+2]=A; } |
|
230 |
else |
|
231 |
{ |
|
232 |
if( tmp[index]==tmp[index+1] ) { tmp[index]=A; tmp[index+1]=A; tmp[index+2]=0; } |
|
233 |
else { tmp[index]=0; tmp[index+1]=A; tmp[index+2]=0; } |
|
234 |
} |
|
235 |
} |
|
236 |
break; |
|
237 |
|
|
238 |
case 12:if( tmp[index+2]==0 ) |
|
239 |
{ |
|
240 |
if( tmp[index+1]==0 ) {tmp[index]=A; tmp[index+1]=0; tmp[index+2]=0;} |
|
241 |
else {tmp[index]=0; tmp[index+1]=A; tmp[index+2]=0;} |
|
242 |
} |
|
243 |
else |
|
244 |
{ |
|
245 |
if( tmp[index]==tmp[index+1] ) |
|
246 |
{ |
|
247 |
if( tmp[index]<0 || tmp[index]>CUTOFF ) {tmp[index]=A; tmp[index+1]=A; tmp[index+2]=0;} |
|
248 |
} |
|
249 |
else {tmp[index]=0; tmp[index+1]=0; tmp[index+2]=A;} |
|
250 |
} |
|
251 |
break; |
|
252 |
} |
|
253 |
} |
|
254 |
|
|
255 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
256 |
|
|
257 |
private ByteBuffer replaceColors(ByteBuffer input, byte[] tmp, int size, int numColors) |
|
258 |
{ |
|
259 |
int marker = (int)(255*BandagedCreatorRenderer.BRIGHTNESS); |
|
260 |
int wBytes = 4*size; |
|
261 |
|
|
262 |
ByteBuffer output = ByteBuffer.allocateDirect(wBytes*size); |
|
263 |
output.order(ByteOrder.LITTLE_ENDIAN); |
|
264 |
|
|
265 |
for(int i=0; i<size; i++) |
|
266 |
{ |
|
267 |
input.position(i*wBytes); |
|
268 |
input.get(tmp); |
|
269 |
|
|
270 |
for(int j=0; j<size; j++) |
|
271 |
{ |
|
272 |
if( tmp[4*j]==marker && tmp[4*j+1]==marker && tmp[4*j+2]==marker ) |
|
273 |
{ |
|
274 |
tmp[4*j ]=0; |
|
275 |
tmp[4*j+1]=0; |
|
276 |
tmp[4*j+2]=0; |
|
277 |
tmp[4*j+3]=0; |
|
278 |
} |
|
279 |
else if( tmp[4*j]!=0 || tmp[4*j+1]!=0 || tmp[4*j+2]!=0 ) replaceColor(tmp,4*j,numColors); |
|
280 |
} |
|
281 |
|
|
282 |
output.position(i*wBytes); |
|
283 |
output.put(tmp); |
|
284 |
} |
|
285 |
|
|
286 |
output.rewind(); |
|
287 |
return output; |
|
288 |
} |
|
289 |
|
|
290 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
291 |
|
|
292 |
private void process(WorkLoad load) |
|
293 |
{ |
|
294 |
int width = load.width; |
|
295 |
int height= load.height; |
|
296 |
|
|
297 |
byte[] tmp = new byte[4*width]; |
|
298 |
ByteBuffer bufSquare = adjustBuffer(load.buffer,tmp,width,height); |
|
299 |
ByteBuffer bufTransp = replaceColors(bufSquare,tmp,width,load.numColors); |
|
300 |
|
|
301 |
final String filename = load.filename; |
|
302 |
BufferedOutputStream bos =null; |
|
303 |
final Activity act = mWeakAct.get(); |
|
304 |
|
|
305 |
try |
|
306 |
{ |
|
307 |
bos = new BufferedOutputStream(new FileOutputStream(filename)); |
|
308 |
Bitmap bmp = Bitmap.createBitmap( width, width, Bitmap.Config.ARGB_8888); |
|
309 |
bmp.copyPixelsFromBuffer(bufTransp); |
|
310 |
bmp.compress(Bitmap.CompressFormat.PNG, 90, bos); |
|
311 |
|
|
312 |
BandagedCreatorActivity cact = (BandagedCreatorActivity)act; |
|
313 |
cact.iconCreationDone(bmp); |
|
314 |
} |
|
315 |
catch(final Exception ex) |
|
316 |
{ |
|
317 |
act.runOnUiThread(new Runnable() |
|
318 |
{ |
|
319 |
public void run() |
|
320 |
{ |
|
321 |
Toast.makeText(act, |
|
322 |
"Saving to \n\n"+filename+"\n\n failed: "+"\n\n"+ex.getMessage() , |
|
323 |
Toast.LENGTH_LONG).show(); |
|
324 |
} |
|
325 |
}); |
|
326 |
} |
|
327 |
finally |
|
328 |
{ |
|
329 |
if(bos!=null) |
|
330 |
{ |
|
331 |
try { bos.close(); } |
|
332 |
catch(IOException io) {} |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
336 |
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); |
|
337 |
File f = new File(filename); |
|
338 |
Uri contentUri = Uri.fromFile(f); |
|
339 |
mediaScanIntent.setData(contentUri); |
|
340 |
act.sendBroadcast(mediaScanIntent); |
|
341 |
} |
|
342 |
} |
src/main/java/org/distorted/bandaged/BandagedCubit.java | ||
---|---|---|
79 | 79 |
mMove = new Static3D(0,0,0); |
80 | 80 |
|
81 | 81 |
FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance(); |
82 |
MeshBase mesh = factory.createMesh(mPosition); |
|
82 |
MeshBase mesh = factory.createMesh(mPosition,false);
|
|
83 | 83 |
|
84 | 84 |
mTexture = new DistortedTexture(); |
85 | 85 |
mTexture.setColorARGB(color); |
... | ... | |
114 | 114 |
mPosition = tmpPosition; |
115 | 115 |
|
116 | 116 |
FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance(); |
117 |
MeshBase mesh = factory.createMesh(mPosition); |
|
117 |
MeshBase mesh = factory.createMesh(mPosition,false);
|
|
118 | 118 |
mNode.setMesh(mesh); |
119 | 119 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
120 | 120 |
} |
... | ... | |
135 | 135 |
computeMove(mPosition); |
136 | 136 |
|
137 | 137 |
FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance(); |
138 |
MeshBase mesh = factory.createMesh(mPosition); |
|
138 |
MeshBase mesh = factory.createMesh(mPosition,false);
|
|
139 | 139 |
mNode.setMesh(mesh); |
140 | 140 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
141 | 141 |
} |
src/main/java/org/distorted/bandaged/BandagedPlayActivity.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
import com.google.firebase.analytics.FirebaseAnalytics; |
33 | 33 |
|
34 |
import org.distorted.config.ConfigSurfaceView; |
|
35 | 34 |
import org.distorted.dialogs.RubikDialogError; |
36 | 35 |
import org.distorted.library.main.DistortedLibrary; |
37 | 36 |
import org.distorted.main.R; |
38 | 37 |
import org.distorted.objectlib.main.ObjectControl; |
38 |
import org.distorted.objectlib.main.TwistyObject; |
|
39 | 39 |
import org.distorted.objects.RubikObject; |
40 | 40 |
import org.distorted.objects.RubikObjectList; |
41 | 41 |
|
... | ... | |
211 | 211 |
if( object!=null ) |
212 | 212 |
{ |
213 | 213 |
int meshState = object.getMeshState(); |
214 |
int iconMode = TwistyObject.MODE_NORM; |
|
214 | 215 |
InputStream jsonStream = object.getObjectStream(this); |
215 | 216 |
InputStream meshStream = object.getMeshStream(this); |
216 | 217 |
String name = object.getUpperName(); |
217 | 218 |
|
218 |
control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream); |
|
219 |
control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
|
|
219 | 220 |
} |
220 | 221 |
} |
221 | 222 |
|
src/main/java/org/distorted/config/ConfigActivity.java | ||
---|---|---|
35 | 35 |
import org.distorted.objectlib.main.ObjectControl; |
36 | 36 |
import org.distorted.main.R; |
37 | 37 |
import org.distorted.dialogs.RubikDialogError; |
38 |
import org.distorted.objectlib.main.TwistyObject; |
|
38 | 39 |
import org.distorted.objects.RubikObject; |
39 | 40 |
import org.distorted.objects.RubikObjectList; |
40 | 41 |
|
... | ... | |
208 | 209 |
if( object!=null ) |
209 | 210 |
{ |
210 | 211 |
int meshState = object.getMeshState(); |
212 |
int iconMode = TwistyObject.MODE_NORM; |
|
211 | 213 |
InputStream jsonStream = object.getObjectStream(this); |
212 | 214 |
InputStream meshStream = object.getMeshStream(this); |
213 | 215 |
String name = object.getUpperName(); |
214 | 216 |
|
215 |
control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream); |
|
217 |
control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
|
|
216 | 218 |
} |
217 | 219 |
} |
218 | 220 |
|
... | ... | |
239 | 241 |
ObjectControl control = view.getObjectControl(); |
240 | 242 |
|
241 | 243 |
int meshState = object.getMeshState(); |
244 |
int iconMode = TwistyObject.MODE_NORM; |
|
242 | 245 |
InputStream jsonStream = object.getObjectStream(this); |
243 | 246 |
InputStream meshStream = object.getMeshStream(this); |
244 | 247 |
|
245 |
control.changeObject(ordinal,meshState,jsonStream,meshStream); |
|
248 |
control.changeObject(ordinal,meshState,iconMode,jsonStream,meshStream);
|
|
246 | 249 |
} |
247 | 250 |
} |
248 | 251 |
|
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
490 | 490 |
{ |
491 | 491 |
RubikObject object = RubikObjectList.getObject(ordinal); |
492 | 492 |
int meshState = object!=null ? object.getMeshState() : MESH_NICE; |
493 |
int iconMode = TwistyObject.MODE_NORM; |
|
493 | 494 |
InputStream jsonStream = object==null ? null : object.getObjectStream(this); |
494 | 495 |
InputStream meshStream = object==null ? null : object.getMeshStream(this); |
495 | 496 |
String name = object==null ? "NULL" : object.getUpperName(); |
496 | 497 |
|
497 |
control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream); |
|
498 |
control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
|
|
498 | 499 |
} |
499 | 500 |
|
500 | 501 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/tutorials/TutorialActivity.java | ||
---|---|---|
34 | 34 |
|
35 | 35 |
import com.google.firebase.analytics.FirebaseAnalytics; |
36 | 36 |
|
37 |
import org.distorted.dmesh.ObjectMesh; |
|
38 |
import org.distorted.jsons.ObjectJson; |
|
39 | 37 |
import org.distorted.library.main.DistortedLibrary; |
40 | 38 |
|
41 | 39 |
import org.distorted.objectlib.main.ObjectControl; |
40 |
import org.distorted.objectlib.main.TwistyObject; |
|
42 | 41 |
|
43 | 42 |
import org.distorted.main.R; |
44 | 43 |
import org.distorted.dialogs.RubikDialogError; |
... | ... | |
232 | 231 |
{ |
233 | 232 |
RubikObject object = RubikObjectList.getObject(ordinal); |
234 | 233 |
int meshState = object!=null ? object.getMeshState() : MESH_NICE; |
234 |
int iconMode = TwistyObject.MODE_NORM; |
|
235 | 235 |
InputStream jsonStream = object==null ? null : object.getObjectStream(this); |
236 | 236 |
InputStream meshStream = object==null ? null : object.getMeshStream(this); |
237 | 237 |
String name = object==null ? "NULL" : object.getUpperName(); |
238 | 238 |
|
239 |
control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream); |
|
239 |
control.changeIfDifferent(ordinal,name,meshState,iconMode,jsonStream,meshStream);
|
|
240 | 240 |
} |
241 | 241 |
|
242 | 242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Mode the 'iconMode' from static variable in ObjectControl to member varaible in TwistyObject (safer)