Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F946741
colors3.html
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
colors3.html
View Options
<
html
>
<
head
>
<
title
>
Compress colors
</
title
>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=utf-8"
/>
<
style
type
=
"text/css"
>
@
import
"../../../dojo/resources/dojo.css"
;
@
import
"../../../dijit/tests/css/dijitTests.css"
;
.
pane
{
margin-top
:
2
em
;
}
</
style
>
<
script
type
=
"text/javascript"
src
=
"../../../dojo/dojo.js"
djConfig
=
"isDebug: true"
></
script
>
<
script
type
=
"text/javascript"
>
dojo
.
require
(
"dojox.encoding.tests.colors"
);
dojo
.
require
(
"dojox.encoding.easy64"
);
dojo
.
require
(
"dojox.encoding.bits"
);
dojo
.
require
(
"dojox.encoding.splay"
);
dojo
.
require
(
"dojox.encoding.lzw"
);
var
dc
=
dojox
.
encoding
,
colors
=
dc
.
tests
.
colors
;
var
run
=
function
(){
var
empty
=
{},
names
=
[];
for
(
var
i
in
colors
){
if
(
i
in
empty
){
continue
;
}
names
.
push
(
i
);
}
names
.
sort
();
var
output
=
new
dc
.
bits
.
OutputStream
(),
result
=
[];
// encode names
var
s
=
names
.
join
(
"{"
),
encoder
=
new
dc
.
lzw
.
Encoder
(
27
);
result
.
push
(
"<div>Input is "
+
s
.
length
+
" bytes long.</div>"
);
result
.
push
(
"<div>Input: "
+
s
+
".</div>"
);
for
(
var
i
=
0
;
i
<
s
.
length
;
++
i
){
var
v
=
s
.
charCodeAt
(
i
)
-
97
;
if
(
v
<
0
||
v
>
26
)
console
.
debug
(
"error!"
,
v
);
encoder
.
encode
(
v
,
output
);
}
encoder
.
flush
(
output
);
var
w
=
output
.
getWidth
();
result
.
push
(
"<div>Output is "
+
Math
.
ceil
(
w
/
8
)
+
" bytes ("
+
w
+
" bits) long.</div>"
);
var
buf
=
output
.
getBuffer
();
{
var
input
=
new
dc
.
bits
.
InputStream
(
buf
,
buf
.
length
*
8
),
decoder
=
new
dc
.
lzw
.
Decoder
(
27
);
var
t
=
[];
for
(
var
w
=
0
;
w
<
s
.
length
;){
var
v
=
decoder
.
decode
(
input
);
t
.
push
(
v
);
w
+=
v
.
length
;
}
t
=
t
.
join
(
""
);
var
p
=
[];
for
(
var
i
=
0
;
i
<
t
.
length
;
++
i
){
p
.
push
(
String
.
fromCharCode
(
t
.
charCodeAt
(
i
)
+
97
));
}
p
=
p
.
join
(
""
);
result
.
push
(
"<div>Control: "
+
p
+
".</div>"
);
}
while
(
buf
.
length
%
3
){
buf
.
push
(
0
);
}
var
e64
=
dc
.
easy64
.
encode
(
buf
);
result
.
push
(
"<div>Encoded output is "
+
e64
.
length
+
" bytes.</div>"
);
result
.
push
(
"<div><textarea>"
+
e64
+
"</textarea></div>"
);
// test
{
var
buf
=
dc
.
easy64
.
decode
(
e64
);
var
input
=
new
dc
.
bits
.
InputStream
(
buf
,
buf
.
length
*
8
),
decoder
=
new
dc
.
lzw
.
Decoder
(
27
);
var
t
=
[];
for
(
var
w
=
0
;
w
<
s
.
length
;){
var
v
=
decoder
.
decode
(
input
);
t
.
push
(
v
);
w
+=
v
.
length
;
}
t
=
t
.
join
(
""
);
var
p
=
[];
for
(
var
i
=
0
;
i
<
t
.
length
;
++
i
){
p
.
push
(
String
.
fromCharCode
(
t
.
charCodeAt
(
i
)
+
97
));
}
p
=
p
.
join
(
""
);
result
.
push
(
"<div>Control: "
+
p
+
".</div>"
);
}
// encode values
buf
=
[];
for
(
var
i
=
0
;
i
<
names
.
length
;
++
i
){
var
c
=
colors
[
names
[
i
]];
buf
.
push
(
c
[
0
],
c
[
1
],
c
[
2
]);
}
result
.
push
(
"<div>Output is "
+
buf
.
length
+
" bytes long.</div>"
);
while
(
buf
.
length
%
4
){
buf
.
push
(
0
);
}
e64
=
dc
.
easy64
.
encode
(
buf
);
result
.
push
(
"<div>Encoded output is "
+
e64
.
length
+
" bytes.</div>"
);
result
.
push
(
"<div><textarea>"
+
e64
+
"</textarea></div>"
);
dojo
.
byId
(
"status"
).
innerHTML
=
result
.
join
(
"\n"
);
};
dojo
.
addOnLoad
(
function
(){
dojo
.
connect
(
dojo
.
byId
(
"run"
),
"onclick"
,
run
);
});
</
script
>
</
head
>
<
body
>
<
h1
>
Compress colors
</
h1
>
<
p
><
button
id
=
"run"
>
Run
</
button
></
p
>
<
div
id
=
"status"
class
=
"pane"
><
em
>
No status yet.
</
em
></
div
>
</
body
>
</
html
>
File Metadata
Details
Attached
Mime Type
text/html
Expires
Sat, Apr 26, 08:44 (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26943
Default Alt Text
colors3.html (3 KB)
Attached To
rZEDHG ZedLegacy
Event Timeline
Log In to Comment