Skip to content

Commit 0e2d2ef

Browse files
inoookinoook
authored andcommitted
use LoadRawTextureData
1 parent 9482f8e commit 0e2d2ef

File tree

13 files changed

+435
-1369
lines changed

13 files changed

+435
-1369
lines changed

Assets/Flash/Flash.cs

Lines changed: 0 additions & 535 deletions
This file was deleted.
Lines changed: 150 additions & 183 deletions
Large diffs are not rendered by default.

Assets/Flash/FlashInt.cs

Lines changed: 0 additions & 633 deletions
This file was deleted.

Assets/Flash/FlashInt.cs.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Assets/Flash/FlashUtils.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,52 @@ public ColorTransform( float redMultiplier = 1.0f, float greenMultiplier = 1.0f
238238
this.alphaOffset = alphaOffset;
239239
}
240240
}
241+
242+
//
243+
public class Utils
244+
{
245+
#region utils
246+
public static uint ColorToUint(Color32 c)
247+
{
248+
return (uint)(c.a << 24 | c.r << 16 | c.g << 8 | c.b);
249+
}
250+
251+
public static Color32 UintToColor(uint uintColor)
252+
{
253+
uint a = (uintColor >> 24 & 0xFF);
254+
uint r = (uintColor >> 16 & 0xFF);
255+
uint g = (uintColor >> 8 & 0xFF);
256+
uint b = (uintColor & 0xFF);
257+
return new Color32((byte)r, (byte)g, (byte)b, (byte)a);
258+
}
259+
260+
public static Color32[] ConvColorsInt(uint[] intColors)
261+
{
262+
Color32[] colors = new Color32[intColors.Length];
263+
for(int i = 0; i < intColors.Length; i++){
264+
uint intColor = intColors[i];
265+
colors[i] = UintToColor(intColor);
266+
}
267+
return colors;
268+
}
269+
270+
public static byte[] ConvColorsToBytes(uint[] intColors)
271+
{
272+
byte[] bytes = new byte[intColors.Length*4];
273+
for(int i = 0; i < intColors.Length; i++){
274+
uint uintColor = intColors[i];
275+
byte a = (byte)(uintColor >> 24 & 0xFF);
276+
byte r = (byte)(uintColor >> 16 & 0xFF);
277+
byte g = (byte)(uintColor >> 8 & 0xFF);
278+
byte b = (byte)(uintColor & 0xFF);
279+
280+
bytes[i*4+0] = r;
281+
bytes[i*4+1] = g;
282+
bytes[i*4+2] = b;
283+
bytes[i*4+3] = a;
284+
}
285+
return bytes;
286+
}
287+
#endregion
288+
}
241289
}

Assets/Test.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
using System.Collections;
33

44
using FlashClass;
5-
// namespaceで切換え。動作比較用 内部のデータの持ち方が違うのみ Flash, FlashInt, FlashIntData
6-
// bitmapdata.colorTransformはFlashが一番はやく動作する。それ以外は、FlashIntもFlashIntDataが若干速い。
7-
// 、、、が、それほどの差ではない。総合的にみるとFlashがベストかもしれない。colorTransformを使用しないならば、FlashIntData.
8-
using Flash;
5+
using FlashBytes;
96

107
public class Test : MonoBehaviour {
118

@@ -21,8 +18,10 @@ public class Test : MonoBehaviour {
2118

2219
// Use this for initialization
2320
void Start () {
21+
2422
srcBmp = new BitmapData();
2523
srcBmp.SetTexture2D(texture);
24+
srcBmp.unlock();
2625

2726
distBmp = new BitmapData(srcBmp.width, srcBmp.height, Color.black);
2827

@@ -82,20 +81,23 @@ void Start () {
8281
// Update is called once per frame
8382
void Update () {
8483
/*
85-
//distBmp.fastblur(srcBmp, blur);
84+
distBmp.fastblur(srcBmp, blur);
85+
distBmp.unlock();// apply texture2D
86+
*/
87+
/*
8688
split = Mathf.Clamp(split, 1, 256);
8789
distBmp.resolution(srcBmp, 256/split, 256/split);
88-
8990
distBmp.unlock();// apply texture2D
9091
*/
92+
9193
}
9294

9395
public int split = 1;
9496
public int blur = 3;
9597

9698
void OnGUI()
9799
{
98-
GUILayout.BeginArea(new Rect(10,10, 600,800));
100+
GUILayout.BeginArea(new Rect(10,10, 1100,800));
99101
GUILayout.BeginHorizontal();
100102
GUILayout.Label(srcBmp.texture);
101103
GUILayout.Label(distBmp.texture);
@@ -128,11 +130,14 @@ void OnGUI()
128130
distBmp.unlock();// apply texture2D
129131
}
130132
if(GUILayout.Button("Apply ColorTransform")){
133+
// distBmp.colorTransform(new Rectangle(0, 0, distBmp.width, distBmp.height), new ColorTransform(-1, -1, -1, 1, 255, 255, 255, 0));
134+
// distBmp.unlock();// apply texture2D
135+
131136
srcBmp.colorTransform(new Rectangle(0, 0, distBmp.width, distBmp.height), new ColorTransform(-1, -1, -1, 1, 255, 255, 255, 0));
132137
srcBmp.unlock();// apply texture2D
133138
}
134139
if(GUILayout.Button("Apply Fill")){
135-
distBmp.fillRect(new Rectangle(0,0,distBmp.width, distBmp.height), Color.green);
140+
distBmp.fillRect(new Rectangle(0,0,distBmp.width/2, distBmp.height/2), Color.green);
136141
distBmp.unlock();// apply texture2D
137142
}
138143

Assets/Utils/AllocMem.cs

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// http://wiki.unity3d.com/index.php/AllocationStats
2+
using UnityEngine;
3+
using System.Collections;
4+
using System.Text;
5+
6+
//[ExecuteInEditMode ()]
7+
public class AllocMem : MonoBehaviour {
8+
9+
public bool showFPS = false;
10+
11+
private float lastCollect = 0;
12+
private float lastCollectNum = 0;
13+
private float delta = 0;
14+
private float lastDeltaTime = 0;
15+
private int allocRate = 0;
16+
private int lastAllocMemory = 0;
17+
private float lastAllocSet = -9999;
18+
private int allocMem = 0;
19+
private int collectAlloc = 0;
20+
private int peakAlloc = 0;
21+
22+
public Color color = Color.green;
23+
24+
void Start () {
25+
26+
}
27+
28+
public Rect drawRect = new Rect(10, 10, 400, 300);
29+
public bool debug = false;
30+
31+
// public CheckBattery battery;
32+
33+
void OnGUI()
34+
{
35+
if(!debug){ return; }
36+
37+
//windowRect = GUILayout.Window(2, windowRect, DoMyWindow, "Memory debug");
38+
39+
int mb = 1048576;
40+
string str = "Total allocated memory : " + ((float)(System.GC.GetTotalMemory(false) / (float)mb)).ToString("0.00") + " / " + (SystemInfo.systemMemorySize) + " MB";
41+
42+
if(Debug.isDebugBuild){
43+
str += "\nHeapSize: "+ (Profiler.usedHeapSize / mb) + " Mb";
44+
}
45+
if (showFPS) {
46+
str += ("\n"+(1f/Time.deltaTime).ToString ("0.0")+" fps");
47+
}
48+
49+
str += ("\nInput.gyro.enabled: "+Input.gyro.enabled);
50+
51+
// if(battery != null){
52+
// if(battery.isEnableCheckBattery){
53+
// str += ("\nBattery: "+battery.GetBatteryLevel());
54+
// }else{
55+
// str += ("\nDisableCheckBattery");
56+
// }
57+
// }
58+
59+
GUILayout.BeginArea(drawRect);
60+
GUI.color = color;
61+
GUILayout.Label(str);
62+
if(GUILayout.Button("System.GC.Collect")){
63+
System.GC.Collect();
64+
}
65+
GUILayout.EndArea();
66+
67+
}
68+
void DoMyWindow(int windowID) {
69+
70+
int mb = 1048576;
71+
string str = "Total allocated memory : " + ((float)(System.GC.GetTotalMemory(false) / (float)mb)).ToString("0.00") + " / " + (SystemInfo.systemMemorySize) + " MB";
72+
73+
if(Debug.isDebugBuild){
74+
str += " HeapSize: "+ (Profiler.usedHeapSize / mb) + " Mb" + "\n";
75+
}
76+
77+
GUILayout.Label(str);
78+
79+
int collCount = System.GC.CollectionCount (0);
80+
81+
if (lastCollectNum != collCount) {
82+
lastCollectNum = collCount;
83+
delta = Time.realtimeSinceStartup-lastCollect;
84+
lastCollect = Time.realtimeSinceStartup;
85+
lastDeltaTime = Time.deltaTime;
86+
collectAlloc = allocMem;
87+
}
88+
89+
allocMem = (int)System.GC.GetTotalMemory (false);
90+
91+
peakAlloc = allocMem > peakAlloc ? allocMem : peakAlloc;
92+
93+
if (Time.realtimeSinceStartup - lastAllocSet > 0.3F) {
94+
int diff = allocMem - lastAllocMemory;
95+
lastAllocMemory = allocMem;
96+
lastAllocSet = Time.realtimeSinceStartup;
97+
98+
if (diff >= 0) {
99+
allocRate = diff;
100+
}
101+
}
102+
103+
StringBuilder text = new StringBuilder ();
104+
105+
// add inok
106+
text.Append("SystemMemorySize ");
107+
text.Append (SystemInfo.systemMemorySize);
108+
text.Append ("mb\n");
109+
110+
if(Debug.isDebugBuild){
111+
text.Append ("HeapSize ");
112+
text.Append ((Profiler.usedHeapSize/1000000F).ToString ("0.0"));
113+
text.Append ("mb\n");
114+
}
115+
//
116+
117+
text.Append ("Currently allocated ");
118+
text.Append ((allocMem/1000000F).ToString ("0"));
119+
text.Append ("mb\n");
120+
121+
text.Append ("Peak allocated ");
122+
text.Append ((peakAlloc/1000000F).ToString ("0"));
123+
text.Append ("mb (last collect ");
124+
text.Append ((collectAlloc/1000000F).ToString ("0"));
125+
text.Append (" mb)\n");
126+
127+
128+
text.Append ("Allocation rate ");
129+
text.Append ((allocRate/1000000F).ToString ("0.0"));
130+
text.Append ("mb\n");
131+
132+
text.Append ("Collection frequency ");
133+
text.Append (delta.ToString ("0.00"));
134+
text.Append ("s\n");
135+
136+
text.Append ("Last collect delta ");
137+
text.Append (lastDeltaTime.ToString ("0.000"));
138+
text.Append ("s (");
139+
text.Append ((1F/lastDeltaTime).ToString ("0.0"));
140+
141+
text.Append (" fps)");
142+
143+
if (showFPS) {
144+
text.Append ("\n"+(1F/Time.deltaTime).ToString ("0.0")+" fps");
145+
}
146+
147+
GUILayout.Label(text.ToString ());
148+
149+
if(GUILayout.Button("System.GC.Collect")){
150+
System.GC.Collect();
151+
}
152+
153+
GUI.DragWindow();
154+
}
155+
156+
157+
}
Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/image.jpg.meta

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)