My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:HorizontalLayout />
</s:layout>
<fx:Script>
<![CDATA[
import flash.utils.setTimeout;

import mx.utils.ObjectUtil;
// http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-player-10/
protected var f:FileReference=new FileReference();
protected var bd:BitmapData;
protected var p:Point=new Point();
protected var o:Object;
protected var lines:Array;
protected var curLine:Array;
protected function onFileSelect(e:Event):void {
f.load();
}
protected function onLoadComplete(e:Event):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onDataLoadComplete);
loader.loadBytes(f.data);
}
protected function onDataLoadComplete(e:Event):void {
bd=Bitmap(e.target.content).bitmapData;
img.source=bd;
p.x=p.y=0;
o={};
lines=[];
curLine=[];
nextPoints();
}
protected function nextPoints():void {
var i:int=0;
var c:uint;
for (i=0; i<100; i++) {
c=bd.getPixel(p.x, p.y);
if (!o[c]) o[c]=1;
else o[c]++;
//
if (curLine.length==0) {
curLine.push({color:c, count:1});
} else {
var lastC:Object=curLine[curLine.length-1];
if (lastC.color==c) {
lastC.count++;
} else {
curLine.push({color:c, count:1});
}
}
//
p.x++;
if (p.x>=bd.width) {
p.x=0;
p.y++;
lines.push(curLine);
curLine=[];
if (p.y>=bd.height) {
updateCount();
ta.appendText('\n---\n');
appendLines();
return;
}
}
}
updateCount();
callLater(nextPoints);
}
protected function updateCount():void {
var s:String='';
var c:uint;
for (var k:String in o) {
s+='#'+uint(k).toString(16)+': '+o[k]+'\n';
c+=o[k];
}
s+='\n'+bd.width+'x'+bd.height+'='+c+'\n';
ta.text=s;
}
protected function appendLines():void {
var s:String='';
for (var i:int=0; i<lines.length; i++) {
s+='\n - Line '+(i+1)+'\n\n';
for (var j:int=0; j<lines[i].length; j++) {
var o:Object=lines[i][j];
s+='#'+uint(o.color).toString(16)+' × '+o.count+'\n';
}
}
ta.appendText(s);
}
]]>
</fx:Script>
<s:creationComplete>
<![CDATA[
f.addEventListener(Event.SELECT, onFileSelect);
f.addEventListener(Event.COMPLETE, onLoadComplete);
]]>
</s:creationComplete>
<s:Scroller width="60%" height="100%">
<s:Group width="100%" height="100%">
<s:BitmapImage id="img" horizontalCenter="0" verticalCenter="0"/>
</s:Group>
</s:Scroller>
<s:VGroup width="40%" height="100%" paddingLeft="10" paddingTop="10" paddingRight="10" paddingBottom="10">
<s:TextArea width="100%" height="100%" id="ta" fontFamily="Courier New"/>
<s:Button label="Load..." id="bLoad">
<s:click>
<![CDATA[
f.browse();
]]>
</s:click>
</s:Button>
</s:VGroup>
</s:Application>

Change log

r113 by quentin.t on Jun 29, 2011   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 3271 bytes, 117 lines
Powered by Google Project Hosting