as3corelib 0.1.0 → 0.85.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/Gemfile +1 -4
  2. data/Gemfile.lock +7 -4
  3. data/README.textile +20 -10
  4. data/Rakefile +32 -2
  5. data/as3corelib.gemspec +13 -11
  6. data/lib/as3corelib.rb +10 -4
  7. data/lib/as3corelib/version.rb +4 -0
  8. metadata +31 -121
  9. data/build/build.properties +0 -48
  10. data/build/build.xml +0 -104
  11. data/examples/JSONExample/JSONExample.mxml +0 -73
  12. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +0 -313
  13. data/src/com/adobe/air/filesystem/FileMonitor.as +0 -245
  14. data/src/com/adobe/air/filesystem/FileUtil.as +0 -63
  15. data/src/com/adobe/air/filesystem/VolumeMonitor.as +0 -184
  16. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +0 -61
  17. data/src/com/adobe/air/logging/FileTarget.as +0 -95
  18. data/src/com/adobe/air/net/ResourceCache.as +0 -165
  19. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +0 -70
  20. data/src/com/adobe/crypto/HMAC.as +0 -127
  21. data/src/com/adobe/crypto/MD5.as +0 -281
  22. data/src/com/adobe/crypto/MD5Stream.as +0 -402
  23. data/src/com/adobe/crypto/SHA1.as +0 -289
  24. data/src/com/adobe/crypto/SHA224.as +0 -257
  25. data/src/com/adobe/crypto/SHA256.as +0 -261
  26. data/src/com/adobe/crypto/WSSEUsernameToken.as +0 -114
  27. data/src/com/adobe/errors/IllegalStateError.as +0 -63
  28. data/src/com/adobe/fileformats/vcard/Address.as +0 -47
  29. data/src/com/adobe/fileformats/vcard/Email.as +0 -39
  30. data/src/com/adobe/fileformats/vcard/Phone.as +0 -39
  31. data/src/com/adobe/fileformats/vcard/VCard.as +0 -54
  32. data/src/com/adobe/fileformats/vcard/VCardParser.as +0 -246
  33. data/src/com/adobe/images/BitString.as +0 -39
  34. data/src/com/adobe/images/JPGEncoder.as +0 -648
  35. data/src/com/adobe/images/PNGEncoder.as +0 -141
  36. data/src/com/adobe/net/DynamicURLLoader.as +0 -55
  37. data/src/com/adobe/net/IURIResolver.as +0 -76
  38. data/src/com/adobe/net/MimeTypeMap.as +0 -200
  39. data/src/com/adobe/net/URI.as +0 -2466
  40. data/src/com/adobe/net/URIEncodingBitmap.as +0 -139
  41. data/src/com/adobe/net/proxies/RFC2817Socket.as +0 -198
  42. data/src/com/adobe/protocols/dict/Database.as +0 -66
  43. data/src/com/adobe/protocols/dict/Definition.as +0 -71
  44. data/src/com/adobe/protocols/dict/Dict.as +0 -360
  45. data/src/com/adobe/protocols/dict/DictionaryServer.as +0 -60
  46. data/src/com/adobe/protocols/dict/MatchStrategy.as +0 -66
  47. data/src/com/adobe/protocols/dict/Response.as +0 -71
  48. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +0 -53
  49. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +0 -67
  50. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +0 -70
  51. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +0 -69
  52. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +0 -69
  53. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +0 -55
  54. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +0 -80
  55. data/src/com/adobe/protocols/dict/events/MatchEvent.as +0 -67
  56. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +0 -70
  57. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +0 -54
  58. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +0 -68
  59. data/src/com/adobe/protocols/dict/util/SocketHelper.as +0 -81
  60. data/src/com/adobe/serialization/json/JSON.as +0 -86
  61. data/src/com/adobe/serialization/json/JSONDecoder.as +0 -327
  62. data/src/com/adobe/serialization/json/JSONEncoder.as +0 -312
  63. data/src/com/adobe/serialization/json/JSONParseError.as +0 -87
  64. data/src/com/adobe/serialization/json/JSONToken.as +0 -104
  65. data/src/com/adobe/serialization/json/JSONTokenType.as +0 -69
  66. data/src/com/adobe/serialization/json/JSONTokenizer.as +0 -702
  67. data/src/com/adobe/utils/ArrayUtil.as +0 -187
  68. data/src/com/adobe/utils/DateUtil.as +0 -701
  69. data/src/com/adobe/utils/DictionaryUtil.as +0 -87
  70. data/src/com/adobe/utils/IntUtil.as +0 -99
  71. data/src/com/adobe/utils/NumberFormatter.as +0 -74
  72. data/src/com/adobe/utils/StringUtil.as +0 -239
  73. data/src/com/adobe/utils/XMLUtil.as +0 -168
  74. data/src/com/adobe/webapis/ServiceBase.as +0 -48
  75. data/src/com/adobe/webapis/URLLoaderBase.as +0 -108
  76. data/src/com/adobe/webapis/events/ServiceEvent.as +0 -82
  77. data/tests/src/CoreLibTestRunner-app.xml +0 -135
  78. data/tests/src/CoreLibTestRunner.as +0 -138
  79. data/tests/src/CoreLibTestRunner.mxml +0 -46
  80. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +0 -176
  81. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +0 -63
  82. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +0 -57
  83. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +0 -59
  84. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +0 -72
  85. data/tests/src/com/adobe/crypto/HMACMD5Test.as +0 -134
  86. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +0 -138
  87. data/tests/src/com/adobe/crypto/MD5Test.as +0 -82
  88. data/tests/src/com/adobe/crypto/SHA1Test.as +0 -151
  89. data/tests/src/com/adobe/crypto/SHA224Test.as +0 -104
  90. data/tests/src/com/adobe/crypto/SHA256Test.as +0 -116
  91. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +0 -87
  92. data/tests/src/com/adobe/images/JPGEncoderTest.as +0 -54
  93. data/tests/src/com/adobe/images/PNGEncoderTest.as +0 -54
  94. data/tests/src/com/adobe/net/URITest.as +0 -589
  95. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +0 -59
  96. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +0 -62
  97. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +0 -61
  98. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +0 -61
  99. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +0 -61
  100. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +0 -59
  101. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +0 -63
  102. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +0 -61
  103. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +0 -61
  104. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +0 -58
  105. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +0 -60
  106. data/tests/src/com/adobe/serialization/json/JSONTest.as +0 -522
  107. data/tests/src/com/adobe/serialization/json/SimpleClass.as +0 -85
  108. data/tests/src/com/adobe/utils/ArrayUtilTest.as +0 -173
  109. data/tests/src/com/adobe/utils/DateUtilTest.as +0 -436
  110. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +0 -93
  111. data/tests/src/com/adobe/utils/IntUtilTest.as +0 -73
  112. data/tests/src/com/adobe/utils/NumberFormatterTest.as +0 -70
  113. data/tests/src/com/adobe/utils/StringUtilTest.as +0 -304
  114. data/tests/src/com/adobe/utils/XMLUtilTest.as +0 -101
  115. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +0 -66
@@ -1,39 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
- package com.adobe.fileformats.vcard
33
- {
34
- public class Email
35
- {
36
- public var type:String;
37
- public var address:String;
38
- }
39
- }
@@ -1,39 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
- package com.adobe.fileformats.vcard
33
- {
34
- public class Phone
35
- {
36
- public var type:String;
37
- public var number:String;
38
- }
39
- }
@@ -1,54 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
- package com.adobe.fileformats.vcard
33
- {
34
- import flash.utils.ByteArray;
35
-
36
- public class VCard
37
- {
38
- public var fullName:String;
39
- public var orgs:Array;
40
- public var title:String;
41
- public var image:ByteArray;
42
- public var phones:Array;
43
- public var emails:Array;
44
- public var addresses:Array;
45
-
46
- public function VCard()
47
- {
48
- orgs = new Array();
49
- phones = new Array();
50
- emails = new Array();
51
- addresses = new Array();
52
- }
53
- }
54
- }
@@ -1,246 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
- package com.adobe.fileformats.vcard
33
- {
34
- import mx.utils.Base64Decoder;
35
- import mx.utils.StringUtil;
36
-
37
- public class VCardParser
38
- {
39
- public static function parse(vcardStr:String):Array
40
- {
41
- var vcards:Array = new Array();
42
- var lines:Array = vcardStr.split(/\r\n/);
43
- var vcard:VCard;
44
- var type:String;
45
- var typeTmp:String;
46
- var line:String;
47
-
48
- for (var i:uint = 0; i < lines.length; ++i)
49
- {
50
- line = lines[i];
51
- if (line == "BEGIN:VCARD")
52
- {
53
- vcard = new VCard();
54
- }
55
- else if (line == "END:VCARD")
56
- {
57
- if (vcard != null)
58
- {
59
- vcards.push(vcard);
60
- }
61
- }
62
- else if(line.search(/^ORG/i) != -1)
63
- {
64
- var org:String = line.substring(4, line.length);
65
- var orgArray:Array = org.split(";");
66
- for each (var orgToken:String in orgArray)
67
- {
68
- if (StringUtil.trim(orgToken).length > 0)
69
- {
70
- vcard.orgs.push(orgToken);
71
- }
72
- }
73
- }
74
- else if(line.search(/^TITLE/i) != -1)
75
- {
76
- var title:String = line.substring(6, line.length);
77
- vcard.title = title;
78
- }
79
- else if (line.search(/^FN:/i) != -1)
80
- {
81
- var fullName:String = line.substring(3, line.length);
82
- vcard.fullName = fullName;
83
- }
84
- else if (line.search(/^TEL/i) != -1)
85
- {
86
- type = new String();
87
- typeTmp = new String();
88
- var phone:Phone = new Phone();
89
- var number:String;
90
- var phoneTokens:Array = line.split(";");
91
- for each (var phoneToken:String in phoneTokens)
92
- {
93
- if (phoneToken.search(/^TYPE=/i) != -1)
94
- {
95
- if (phoneToken.indexOf(":") != -1)
96
- {
97
- typeTmp = phoneToken.substring(5, phoneToken.indexOf(":"));
98
- number = phoneToken.substring(phoneToken.indexOf(":")+1, phoneToken.length);
99
- }
100
- else
101
- {
102
- typeTmp = phoneToken.substring(5, phoneToken.length);
103
- }
104
-
105
- typeTmp = typeTmp.toLocaleLowerCase();
106
-
107
- if (typeTmp == "pref")
108
- {
109
- continue;
110
- }
111
- if (type.length != 0)
112
- {
113
- type += (" ");
114
- }
115
- type += typeTmp;
116
- }
117
- }
118
- if (type.length > 0 && number != null)
119
- {
120
- phone.type = type;
121
- phone.number = number;
122
- }
123
- vcard.phones.push(phone);
124
- }
125
- else if (line.search(/^EMAIL/i) != -1)
126
- {
127
- type = new String();
128
- typeTmp = new String();
129
- var email:Email = new Email();
130
- var emailAddress:String;
131
- var emailTokens:Array = line.split(";");
132
- for each (var emailToken:String in emailTokens)
133
- {
134
- if (emailToken.search(/^TYPE=/i) != -1)
135
- {
136
- if (emailToken.indexOf(":") != -1)
137
- {
138
- typeTmp = emailToken.substring(5, emailToken.indexOf(":"));
139
- emailAddress = emailToken.substring(emailToken.indexOf(":")+1, emailToken.length);
140
- }
141
- else
142
- {
143
- typeTmp = emailToken.substring(5, emailToken.length);
144
- }
145
-
146
- typeTmp = typeTmp.toLocaleLowerCase();
147
-
148
- if (typeTmp == "pref" || typeTmp == "internet")
149
- {
150
- continue;
151
- }
152
- if (type.length != 0)
153
- {
154
- type += (" ");
155
- }
156
- type += typeTmp;
157
- }
158
- }
159
- if (type.length > 0 && emailAddress != null)
160
- {
161
- email.type = type;
162
- email.address = emailAddress;
163
- }
164
- vcard.emails.push(email);
165
- }
166
- else if (line.indexOf("ADR;") != -1)
167
- {
168
- var addressTokens:Array = line.split(";");
169
- var address:Address = new Address();
170
- for (var j:uint = 0; j < addressTokens.length; ++j)
171
- {
172
- var addressToken:String = addressTokens[j];
173
- if (addressToken.search(/^home:+$/i) != -1) // For Outlook, which uses non-standard vCards.
174
- {
175
- address.type = "home";
176
- }
177
- else if (addressToken.search(/^work:+$/i) != -1) // For Outlook, which uses non-standard vCards.
178
- {
179
- address.type = "work";
180
- }
181
- if (addressToken.search(/^type=/i) != -1) // The "type" parameter is the standard way (which Address Book uses)
182
- {
183
- // First, remove the optional ":" character.
184
- addressToken = addressToken.replace(/:/,"");
185
- var addressType:String = addressToken.substring(5, addressToken.length).toLowerCase();
186
- if (addressType == "pref") // Not interested in which one is preferred.
187
- {
188
- continue;
189
- }
190
- else if (addressType.indexOf("home") != -1) // home
191
- {
192
- addressType = "home";
193
- }
194
- else if (addressType.indexOf("work") != -1) // work
195
- {
196
- addressType = "work";
197
- }
198
- else if (addressType.indexOf(",") != -1) // if the comma technique is used, just use the first one
199
- {
200
- var typeTokens:Array = addressType.split(",");
201
- for each (var typeToken:String in typeTokens)
202
- {
203
- if (typeToken != "pref")
204
- {
205
- addressType = typeToken;
206
- break;
207
- }
208
- }
209
- }
210
- address.type = addressType;
211
- }
212
- else if (addressToken.search(/^\d/) != -1 && address.street == null)
213
- {
214
- address.street = addressToken.replace(/\\n/, "");
215
- address.city = addressTokens[j+1];
216
- address.state = addressTokens[j+2];
217
- address.postalCode = addressTokens[j+3];
218
- }
219
- }
220
- if (address.type != null && address.street != null)
221
- {
222
- vcard.addresses.push(address);
223
- }
224
-
225
- }
226
- else if (line.search(/^PHOTO;BASE64/i) != -1)
227
- {
228
- var imageStr:String = new String();
229
- for (var k:uint = i+1; k < lines.length; ++k)
230
- {
231
- imageStr += lines[k];
232
- //if (lines[k].search(/.+\=$/) != -1) // Very slow in Mac due to RegEx bug
233
- if (lines[k].indexOf('=') != -1)
234
- {
235
- var decoder:Base64Decoder = new Base64Decoder();
236
- decoder.decode(imageStr);
237
- vcard.image = decoder.flush();
238
- break;
239
- }
240
- }
241
- }
242
- }
243
- return vcards;
244
- }
245
- }
246
- }
@@ -1,39 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
- package com.adobe.images
33
- {
34
- public class BitString
35
- {
36
- public var len:int = 0;
37
- public var val:int = 0;
38
- }
39
- }
@@ -1,648 +0,0 @@
1
- /*
2
- Copyright (c) 2008, Adobe Systems Incorporated
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are
7
- met:
8
-
9
- * Redistributions of source code must retain the above copyright notice,
10
- this list of conditions and the following disclaimer.
11
-
12
- * Redistributions in binary form must reproduce the above copyright
13
- notice, this list of conditions and the following disclaimer in the
14
- documentation and/or other materials provided with the distribution.
15
-
16
- * Neither the name of Adobe Systems Incorporated nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- */
32
- package com.adobe.images
33
- {
34
- import flash.geom.*;
35
- import flash.display.*;
36
- import flash.utils.*;
37
-
38
- /**
39
- * Class that converts BitmapData into a valid JPEG
40
- */
41
- public class JPGEncoder
42
- {
43
-
44
- // Static table initialization
45
-
46
- private var ZigZag:Array = [
47
- 0, 1, 5, 6,14,15,27,28,
48
- 2, 4, 7,13,16,26,29,42,
49
- 3, 8,12,17,25,30,41,43,
50
- 9,11,18,24,31,40,44,53,
51
- 10,19,23,32,39,45,52,54,
52
- 20,22,33,38,46,51,55,60,
53
- 21,34,37,47,50,56,59,61,
54
- 35,36,48,49,57,58,62,63
55
- ];
56
-
57
- private var YTable:Array = new Array(64);
58
- private var UVTable:Array = new Array(64);
59
- private var fdtbl_Y:Array = new Array(64);
60
- private var fdtbl_UV:Array = new Array(64);
61
-
62
- private function initQuantTables(sf:int):void
63
- {
64
- var i:int;
65
- var t:Number;
66
- var YQT:Array = [
67
- 16, 11, 10, 16, 24, 40, 51, 61,
68
- 12, 12, 14, 19, 26, 58, 60, 55,
69
- 14, 13, 16, 24, 40, 57, 69, 56,
70
- 14, 17, 22, 29, 51, 87, 80, 62,
71
- 18, 22, 37, 56, 68,109,103, 77,
72
- 24, 35, 55, 64, 81,104,113, 92,
73
- 49, 64, 78, 87,103,121,120,101,
74
- 72, 92, 95, 98,112,100,103, 99
75
- ];
76
- for (i = 0; i < 64; i++) {
77
- t = Math.floor((YQT[i]*sf+50)/100);
78
- if (t < 1) {
79
- t = 1;
80
- } else if (t > 255) {
81
- t = 255;
82
- }
83
- YTable[ZigZag[i]] = t;
84
- }
85
- var UVQT:Array = [
86
- 17, 18, 24, 47, 99, 99, 99, 99,
87
- 18, 21, 26, 66, 99, 99, 99, 99,
88
- 24, 26, 56, 99, 99, 99, 99, 99,
89
- 47, 66, 99, 99, 99, 99, 99, 99,
90
- 99, 99, 99, 99, 99, 99, 99, 99,
91
- 99, 99, 99, 99, 99, 99, 99, 99,
92
- 99, 99, 99, 99, 99, 99, 99, 99,
93
- 99, 99, 99, 99, 99, 99, 99, 99
94
- ];
95
- for (i = 0; i < 64; i++) {
96
- t = Math.floor((UVQT[i]*sf+50)/100);
97
- if (t < 1) {
98
- t = 1;
99
- } else if (t > 255) {
100
- t = 255;
101
- }
102
- UVTable[ZigZag[i]] = t;
103
- }
104
- var aasf:Array = [
105
- 1.0, 1.387039845, 1.306562965, 1.175875602,
106
- 1.0, 0.785694958, 0.541196100, 0.275899379
107
- ];
108
- i = 0;
109
- for (var row:int = 0; row < 8; row++)
110
- {
111
- for (var col:int = 0; col < 8; col++)
112
- {
113
- fdtbl_Y[i] = (1.0 / (YTable [ZigZag[i]] * aasf[row] * aasf[col] * 8.0));
114
- fdtbl_UV[i] = (1.0 / (UVTable[ZigZag[i]] * aasf[row] * aasf[col] * 8.0));
115
- i++;
116
- }
117
- }
118
- }
119
-
120
- private var YDC_HT:Array;
121
- private var UVDC_HT:Array;
122
- private var YAC_HT:Array;
123
- private var UVAC_HT:Array;
124
-
125
- private function computeHuffmanTbl(nrcodes:Array, std_table:Array):Array
126
- {
127
- var codevalue:int = 0;
128
- var pos_in_table:int = 0;
129
- var HT:Array = new Array();
130
- for (var k:int=1; k<=16; k++) {
131
- for (var j:int=1; j<=nrcodes[k]; j++) {
132
- HT[std_table[pos_in_table]] = new BitString();
133
- HT[std_table[pos_in_table]].val = codevalue;
134
- HT[std_table[pos_in_table]].len = k;
135
- pos_in_table++;
136
- codevalue++;
137
- }
138
- codevalue*=2;
139
- }
140
- return HT;
141
- }
142
-
143
- private var std_dc_luminance_nrcodes:Array = [0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0];
144
- private var std_dc_luminance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
145
- private var std_ac_luminance_nrcodes:Array = [0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d];
146
- private var std_ac_luminance_values:Array = [
147
- 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,
148
- 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,
149
- 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
150
- 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,
151
- 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,
152
- 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
153
- 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,
154
- 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
155
- 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
156
- 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
157
- 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,
158
- 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
159
- 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
160
- 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
161
- 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
162
- 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,
163
- 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,
164
- 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
165
- 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,
166
- 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
167
- 0xf9,0xfa
168
- ];
169
-
170
- private var std_dc_chrominance_nrcodes:Array = [0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0];
171
- private var std_dc_chrominance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
172
- private var std_ac_chrominance_nrcodes:Array = [0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77];
173
- private var std_ac_chrominance_values:Array = [
174
- 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,
175
- 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
176
- 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
177
- 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,
178
- 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,
179
- 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
180
- 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,
181
- 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,
182
- 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
183
- 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,
184
- 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,
185
- 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
186
- 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,
187
- 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,
188
- 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
189
- 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,
190
- 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,
191
- 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
192
- 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,
193
- 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
194
- 0xf9,0xfa
195
- ];
196
-
197
- private function initHuffmanTbl():void
198
- {
199
- YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values);
200
- UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values);
201
- YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values);
202
- UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values);
203
- }
204
-
205
- private var bitcode:Array = new Array(65535);
206
- private var category:Array = new Array(65535);
207
-
208
- private function initCategoryNumber():void
209
- {
210
- var nrlower:int = 1;
211
- var nrupper:int = 2;
212
- var nr:int;
213
- for (var cat:int=1; cat<=15; cat++) {
214
- //Positive numbers
215
- for (nr=nrlower; nr<nrupper; nr++) {
216
- category[32767+nr] = cat;
217
- bitcode[32767+nr] = new BitString();
218
- bitcode[32767+nr].len = cat;
219
- bitcode[32767+nr].val = nr;
220
- }
221
- //Negative numbers
222
- for (nr=-(nrupper-1); nr<=-nrlower; nr++) {
223
- category[32767+nr] = cat;
224
- bitcode[32767+nr] = new BitString();
225
- bitcode[32767+nr].len = cat;
226
- bitcode[32767+nr].val = nrupper-1+nr;
227
- }
228
- nrlower <<= 1;
229
- nrupper <<= 1;
230
- }
231
- }
232
-
233
- // IO functions
234
-
235
- private var byteout:ByteArray;
236
- private var bytenew:int = 0;
237
- private var bytepos:int = 7;
238
-
239
- private function writeBits(bs:BitString):void
240
- {
241
- var value:int = bs.val;
242
- var posval:int = bs.len-1;
243
- while ( posval >= 0 ) {
244
- if (value & uint(1 << posval) ) {
245
- bytenew |= uint(1 << bytepos);
246
- }
247
- posval--;
248
- bytepos--;
249
- if (bytepos < 0) {
250
- if (bytenew == 0xFF) {
251
- writeByte(0xFF);
252
- writeByte(0);
253
- }
254
- else {
255
- writeByte(bytenew);
256
- }
257
- bytepos=7;
258
- bytenew=0;
259
- }
260
- }
261
- }
262
-
263
- private function writeByte(value:int):void
264
- {
265
- byteout.writeByte(value);
266
- }
267
-
268
- private function writeWord(value:int):void
269
- {
270
- writeByte((value>>8)&0xFF);
271
- writeByte((value )&0xFF);
272
- }
273
-
274
- // DCT & quantization core
275
-
276
- private function fDCTQuant(data:Array, fdtbl:Array):Array
277
- {
278
- var tmp0:Number, tmp1:Number, tmp2:Number, tmp3:Number, tmp4:Number, tmp5:Number, tmp6:Number, tmp7:Number;
279
- var tmp10:Number, tmp11:Number, tmp12:Number, tmp13:Number;
280
- var z1:Number, z2:Number, z3:Number, z4:Number, z5:Number, z11:Number, z13:Number;
281
- var i:int;
282
- /* Pass 1: process rows. */
283
- var dataOff:int=0;
284
- for (i=0; i<8; i++) {
285
- tmp0 = data[dataOff+0] + data[dataOff+7];
286
- tmp7 = data[dataOff+0] - data[dataOff+7];
287
- tmp1 = data[dataOff+1] + data[dataOff+6];
288
- tmp6 = data[dataOff+1] - data[dataOff+6];
289
- tmp2 = data[dataOff+2] + data[dataOff+5];
290
- tmp5 = data[dataOff+2] - data[dataOff+5];
291
- tmp3 = data[dataOff+3] + data[dataOff+4];
292
- tmp4 = data[dataOff+3] - data[dataOff+4];
293
-
294
- /* Even part */
295
- tmp10 = tmp0 + tmp3; /* phase 2 */
296
- tmp13 = tmp0 - tmp3;
297
- tmp11 = tmp1 + tmp2;
298
- tmp12 = tmp1 - tmp2;
299
-
300
- data[dataOff+0] = tmp10 + tmp11; /* phase 3 */
301
- data[dataOff+4] = tmp10 - tmp11;
302
-
303
- z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */
304
- data[dataOff+2] = tmp13 + z1; /* phase 5 */
305
- data[dataOff+6] = tmp13 - z1;
306
-
307
- /* Odd part */
308
- tmp10 = tmp4 + tmp5; /* phase 2 */
309
- tmp11 = tmp5 + tmp6;
310
- tmp12 = tmp6 + tmp7;
311
-
312
- /* The rotator is modified from fig 4-8 to avoid extra negations. */
313
- z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */
314
- z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */
315
- z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */
316
- z3 = tmp11 * 0.707106781; /* c4 */
317
-
318
- z11 = tmp7 + z3; /* phase 5 */
319
- z13 = tmp7 - z3;
320
-
321
- data[dataOff+5] = z13 + z2; /* phase 6 */
322
- data[dataOff+3] = z13 - z2;
323
- data[dataOff+1] = z11 + z4;
324
- data[dataOff+7] = z11 - z4;
325
-
326
- dataOff += 8; /* advance pointer to next row */
327
- }
328
-
329
- /* Pass 2: process columns. */
330
- dataOff = 0;
331
- for (i=0; i<8; i++) {
332
- tmp0 = data[dataOff+ 0] + data[dataOff+56];
333
- tmp7 = data[dataOff+ 0] - data[dataOff+56];
334
- tmp1 = data[dataOff+ 8] + data[dataOff+48];
335
- tmp6 = data[dataOff+ 8] - data[dataOff+48];
336
- tmp2 = data[dataOff+16] + data[dataOff+40];
337
- tmp5 = data[dataOff+16] - data[dataOff+40];
338
- tmp3 = data[dataOff+24] + data[dataOff+32];
339
- tmp4 = data[dataOff+24] - data[dataOff+32];
340
-
341
- /* Even part */
342
- tmp10 = tmp0 + tmp3; /* phase 2 */
343
- tmp13 = tmp0 - tmp3;
344
- tmp11 = tmp1 + tmp2;
345
- tmp12 = tmp1 - tmp2;
346
-
347
- data[dataOff+ 0] = tmp10 + tmp11; /* phase 3 */
348
- data[dataOff+32] = tmp10 - tmp11;
349
-
350
- z1 = (tmp12 + tmp13) * 0.707106781; /* c4 */
351
- data[dataOff+16] = tmp13 + z1; /* phase 5 */
352
- data[dataOff+48] = tmp13 - z1;
353
-
354
- /* Odd part */
355
- tmp10 = tmp4 + tmp5; /* phase 2 */
356
- tmp11 = tmp5 + tmp6;
357
- tmp12 = tmp6 + tmp7;
358
-
359
- /* The rotator is modified from fig 4-8 to avoid extra negations. */
360
- z5 = (tmp10 - tmp12) * 0.382683433; /* c6 */
361
- z2 = 0.541196100 * tmp10 + z5; /* c2-c6 */
362
- z4 = 1.306562965 * tmp12 + z5; /* c2+c6 */
363
- z3 = tmp11 * 0.707106781; /* c4 */
364
-
365
- z11 = tmp7 + z3; /* phase 5 */
366
- z13 = tmp7 - z3;
367
-
368
- data[dataOff+40] = z13 + z2; /* phase 6 */
369
- data[dataOff+24] = z13 - z2;
370
- data[dataOff+ 8] = z11 + z4;
371
- data[dataOff+56] = z11 - z4;
372
-
373
- dataOff++; /* advance pointer to next column */
374
- }
375
-
376
- // Quantize/descale the coefficients
377
- for (i=0; i<64; i++) {
378
- // Apply the quantization and scaling factor & Round to nearest integer
379
- data[i] = Math.round((data[i]*fdtbl[i]));
380
- }
381
- return data;
382
- }
383
-
384
- // Chunk writing
385
-
386
- private function writeAPP0():void
387
- {
388
- writeWord(0xFFE0); // marker
389
- writeWord(16); // length
390
- writeByte(0x4A); // J
391
- writeByte(0x46); // F
392
- writeByte(0x49); // I
393
- writeByte(0x46); // F
394
- writeByte(0); // = "JFIF",'\0'
395
- writeByte(1); // versionhi
396
- writeByte(1); // versionlo
397
- writeByte(0); // xyunits
398
- writeWord(1); // xdensity
399
- writeWord(1); // ydensity
400
- writeByte(0); // thumbnwidth
401
- writeByte(0); // thumbnheight
402
- }
403
-
404
- private function writeSOF0(width:int, height:int):void
405
- {
406
- writeWord(0xFFC0); // marker
407
- writeWord(17); // length, truecolor YUV JPG
408
- writeByte(8); // precision
409
- writeWord(height);
410
- writeWord(width);
411
- writeByte(3); // nrofcomponents
412
- writeByte(1); // IdY
413
- writeByte(0x11); // HVY
414
- writeByte(0); // QTY
415
- writeByte(2); // IdU
416
- writeByte(0x11); // HVU
417
- writeByte(1); // QTU
418
- writeByte(3); // IdV
419
- writeByte(0x11); // HVV
420
- writeByte(1); // QTV
421
- }
422
-
423
- private function writeDQT():void
424
- {
425
- writeWord(0xFFDB); // marker
426
- writeWord(132); // length
427
- writeByte(0);
428
- var i:int;
429
- for (i=0; i<64; i++) {
430
- writeByte(YTable[i]);
431
- }
432
- writeByte(1);
433
- for (i=0; i<64; i++) {
434
- writeByte(UVTable[i]);
435
- }
436
- }
437
-
438
- private function writeDHT():void
439
- {
440
- writeWord(0xFFC4); // marker
441
- writeWord(0x01A2); // length
442
- var i:int;
443
-
444
- writeByte(0); // HTYDCinfo
445
- for (i=0; i<16; i++) {
446
- writeByte(std_dc_luminance_nrcodes[i+1]);
447
- }
448
- for (i=0; i<=11; i++) {
449
- writeByte(std_dc_luminance_values[i]);
450
- }
451
-
452
- writeByte(0x10); // HTYACinfo
453
- for (i=0; i<16; i++) {
454
- writeByte(std_ac_luminance_nrcodes[i+1]);
455
- }
456
- for (i=0; i<=161; i++) {
457
- writeByte(std_ac_luminance_values[i]);
458
- }
459
-
460
- writeByte(1); // HTUDCinfo
461
- for (i=0; i<16; i++) {
462
- writeByte(std_dc_chrominance_nrcodes[i+1]);
463
- }
464
- for (i=0; i<=11; i++) {
465
- writeByte(std_dc_chrominance_values[i]);
466
- }
467
-
468
- writeByte(0x11); // HTUACinfo
469
- for (i=0; i<16; i++) {
470
- writeByte(std_ac_chrominance_nrcodes[i+1]);
471
- }
472
- for (i=0; i<=161; i++) {
473
- writeByte(std_ac_chrominance_values[i]);
474
- }
475
- }
476
-
477
- private function writeSOS():void
478
- {
479
- writeWord(0xFFDA); // marker
480
- writeWord(12); // length
481
- writeByte(3); // nrofcomponents
482
- writeByte(1); // IdY
483
- writeByte(0); // HTY
484
- writeByte(2); // IdU
485
- writeByte(0x11); // HTU
486
- writeByte(3); // IdV
487
- writeByte(0x11); // HTV
488
- writeByte(0); // Ss
489
- writeByte(0x3f); // Se
490
- writeByte(0); // Bf
491
- }
492
-
493
- // Core processing
494
- private var DU:Array = new Array(64);
495
-
496
- private function processDU(CDU:Array, fdtbl:Array, DC:Number, HTDC:Array, HTAC:Array):Number
497
- {
498
- var EOB:BitString = HTAC[0x00];
499
- var M16zeroes:BitString = HTAC[0xF0];
500
- var i:int;
501
-
502
- var DU_DCT:Array = fDCTQuant(CDU, fdtbl);
503
- //ZigZag reorder
504
- for (i=0;i<64;i++) {
505
- DU[ZigZag[i]]=DU_DCT[i];
506
- }
507
- var Diff:int = DU[0] - DC; DC = DU[0];
508
- //Encode DC
509
- if (Diff==0) {
510
- writeBits(HTDC[0]); // Diff might be 0
511
- } else {
512
- writeBits(HTDC[category[32767+Diff]]);
513
- writeBits(bitcode[32767+Diff]);
514
- }
515
- //Encode ACs
516
- var end0pos:int = 63;
517
- for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {
518
- };
519
- //end0pos = first element in reverse order !=0
520
- if ( end0pos == 0) {
521
- writeBits(EOB);
522
- return DC;
523
- }
524
- i = 1;
525
- while ( i <= end0pos ) {
526
- var startpos:int = i;
527
- for (; (DU[i]==0) && (i<=end0pos); i++) {
528
- }
529
- var nrzeroes:int = i-startpos;
530
- if ( nrzeroes >= 16 ) {
531
- for (var nrmarker:int=1; nrmarker <= nrzeroes/16; nrmarker++) {
532
- writeBits(M16zeroes);
533
- }
534
- nrzeroes = int(nrzeroes&0xF);
535
- }
536
- writeBits(HTAC[nrzeroes*16+category[32767+DU[i]]]);
537
- writeBits(bitcode[32767+DU[i]]);
538
- i++;
539
- }
540
- if ( end0pos != 63 ) {
541
- writeBits(EOB);
542
- }
543
- return DC;
544
- }
545
-
546
- private var YDU:Array = new Array(64);
547
- private var UDU:Array = new Array(64);
548
- private var VDU:Array = new Array(64);
549
-
550
- private function RGB2YUV(img:BitmapData, xpos:int, ypos:int):void
551
- {
552
- var pos:int=0;
553
- for (var y:int=0; y<8; y++) {
554
- for (var x:int=0; x<8; x++) {
555
- var P:uint = img.getPixel32(xpos+x,ypos+y);
556
- var R:Number = Number((P>>16)&0xFF);
557
- var G:Number = Number((P>> 8)&0xFF);
558
- var B:Number = Number((P )&0xFF);
559
- YDU[pos]=((( 0.29900)*R+( 0.58700)*G+( 0.11400)*B))-128;
560
- UDU[pos]=(((-0.16874)*R+(-0.33126)*G+( 0.50000)*B));
561
- VDU[pos]=((( 0.50000)*R+(-0.41869)*G+(-0.08131)*B));
562
- pos++;
563
- }
564
- }
565
- }
566
-
567
- /**
568
- * Constructor for JPEGEncoder class
569
- *
570
- * @param quality The quality level between 1 and 100 that detrmines the
571
- * level of compression used in the generated JPEG
572
- * @langversion ActionScript 3.0
573
- * @playerversion Flash 9.0
574
- * @tiptext
575
- */
576
- public function JPGEncoder(quality:Number = 50)
577
- {
578
- if (quality <= 0) {
579
- quality = 1;
580
- }
581
- if (quality > 100) {
582
- quality = 100;
583
- }
584
- var sf:int = 0;
585
- if (quality < 50) {
586
- sf = int(5000 / quality);
587
- } else {
588
- sf = int(200 - quality*2);
589
- }
590
- // Create tables
591
- initHuffmanTbl();
592
- initCategoryNumber();
593
- initQuantTables(sf);
594
- }
595
-
596
- /**
597
- * Created a JPEG image from the specified BitmapData
598
- *
599
- * @param image The BitmapData that will be converted into the JPEG format.
600
- * @return a ByteArray representing the JPEG encoded image data.
601
- * @langversion ActionScript 3.0
602
- * @playerversion Flash 9.0
603
- * @tiptext
604
- */
605
- public function encode(image:BitmapData):ByteArray
606
- {
607
- // Initialize bit writer
608
- byteout = new ByteArray();
609
- bytenew=0;
610
- bytepos=7;
611
-
612
- // Add JPEG headers
613
- writeWord(0xFFD8); // SOI
614
- writeAPP0();
615
- writeDQT();
616
- writeSOF0(image.width,image.height);
617
- writeDHT();
618
- writeSOS();
619
-
620
-
621
- // Encode 8x8 macroblocks
622
- var DCY:Number=0;
623
- var DCU:Number=0;
624
- var DCV:Number=0;
625
- bytenew=0;
626
- bytepos=7;
627
- for (var ypos:int=0; ypos<image.height; ypos+=8) {
628
- for (var xpos:int=0; xpos<image.width; xpos+=8) {
629
- RGB2YUV(image, xpos, ypos);
630
- DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
631
- DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
632
- DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
633
- }
634
- }
635
-
636
- // Do the bit alignment of the EOI marker
637
- if ( bytepos >= 0 ) {
638
- var fillbits:BitString = new BitString();
639
- fillbits.len = bytepos+1;
640
- fillbits.val = (1<<(bytepos+1))-1;
641
- writeBits(fillbits);
642
- }
643
-
644
- writeWord(0xFFD9); //EOI
645
- return byteout;
646
- }
647
- }
648
- }