Skip to content

Commit 628da62

Browse files
authored
Merge pull request #63 from chrisws/0_12_11
0 12 11
2 parents 82f865d + 313d4d3 commit 628da62

File tree

7 files changed

+212
-10
lines changed

7 files changed

+212
-10
lines changed

ChangeLog

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
2017-11-28 (0.12.10/11)
1+
2017-11-28 (0.12.11)
2+
Fix img.save(dat) to build correct indexes
3+
Fix ESCm implementation bug
4+
Implements ESC<n ESC>n back screen handlers
5+
6+
2017-11-28 (0.12.10)
7+
Released 82f865d61a6eba1c017b8a58e1c892f1b7d6a0c0
8+
9+
2017-11-28 (0.12.10)
210
COMMON: owner strings
311

412
2017-11-28 (0.12.10)

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [0.12.10])
10+
AC_INIT([smallbasic], [0.12.11])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
smallbasic (0.12.11) unstable; urgency=low
2+
* Various see web site
3+
4+
-- Chris Warren-Smith <cwarrensmith@gmail.com> Wed, 27 Dec 2017 09:45:25 +1000
5+
16
smallbasic (0.12.10) unstable; urgency=low
27
* Various see web site
38

ide/android/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="net.sourceforge.smallbasic"
44
android:installLocation="preferExternal"
5-
android:versionCode="25"
6-
android:versionName="0.12.10">
5+
android:versionCode="26"
6+
android:versionName="0.12.11">
77
<uses-sdk android:minSdkVersion="15"/>
88

99
<!-- support large + xlarge screens to avoid compatibility mode -->
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#http://mattmik.com/articles/ascii/ascii.html
2+
const chars = "~`!@#$%^&*()+-=[]\;',./_+{}|:"
3+
const block_width = 4
4+
const block_height = 6
5+
6+
func calc_block(byref dat, h, y2, w, x2)
7+
local y,x,c,r,g,b,n
8+
9+
n = 0
10+
for y = 0 to h
11+
for x = 0 to w
12+
c = -dat[y2 + y, x2 + x]
13+
r = ((c band 0xff0000) rshift 16)
14+
g = ((c band 0xff00) rshift 8)
15+
b = (c band 0xff)
16+
n += (r + g + b) / 3
17+
next x
18+
next y
19+
return n
20+
end
21+
22+
func calc_color(byref dat, h, y2, w, x2)
23+
local y,x,c
24+
local r = 0
25+
local g = 0
26+
local b = 0
27+
local wh = w * h
28+
29+
for y = 0 to h
30+
for x = 0 to w
31+
c = -dat[y2 + y, x2 + x]
32+
rx = ((c band 0xff0000) rshift 16)
33+
gx = ((c band 0xff00) rshift 8)
34+
bx= (c band 0xff)
35+
36+
r += ((c band 0xff0000) rshift 16)
37+
g += ((c band 0xff00) rshift 8)
38+
b += (c band 0xff)
39+
next x
40+
next y
41+
42+
r = r / wh
43+
g = g / wh
44+
b = b / wh
45+
46+
local minv = min(r,g,b)
47+
local maxv = max(r,g,b)
48+
49+
if (minv < maxv) then
50+
local diff = iff(maxv - minv == 0, 1, maxv - minv)
51+
r = int(255 * (r - minv) / diff)
52+
g = int(255 * (g - minv) / diff)
53+
b = int(255 * (b - minv) / diff)
54+
return rgb(r,g,b)
55+
else
56+
r = min(255, r)
57+
return rgb(r,r,r)
58+
endif
59+
60+
end
61+
62+
func get_char(byref tbl, n)
63+
local r = tbl[n]
64+
if r > 0 then return r
65+
for sn in tbl.sorted
66+
if (sn > n) then
67+
' round up to the nearest value
68+
tbl[n] = tbl[sn]
69+
return tbl[sn]
70+
endif
71+
next n
72+
return " "
73+
end
74+
75+
# analyze the graphic data corresponding to each character in the character set.
76+
func create_table
77+
local img,dat,i,ch,x2,n
78+
local w = txtw(chars)
79+
local h = txth(chars)
80+
local cw = txtw("1")
81+
82+
cls: print chars
83+
img = image(0, 0, w, h, 1)
84+
img.save(dat)
85+
cls: showpage
86+
87+
local vals = []
88+
local minv = maxint
89+
local maxv = 0
90+
91+
for i = 1 to len(chars)
92+
ch = mid(chars, i, 1)
93+
x2 = ((i - 1) * cw)
94+
n = calc_block(dat, h - 1, 0, cw - 1, x2) / (w * h)
95+
minv = min(minv, n)
96+
maxv = max(maxv, n)
97+
vals << n
98+
next i
99+
100+
' scale the values from 0:255
101+
local tbl = {}
102+
for i = 1 to len(chars)
103+
ch = mid(chars, i, 1)
104+
diff = iff(maxv - minv == 0, 1, maxv - minv)
105+
n = 255 * (vals[i - 1] - minv) / diff
106+
vals[i - 1] = n
107+
tbl[n] = ch
108+
next i
109+
110+
sort vals
111+
tbl["sorted"] = vals
112+
return tbl
113+
end
114+
115+
sub imageToAscii(path)
116+
local img,dat,pic,bly,blx,y2,x2,n,minv,maxv,row
117+
local tbl = create_table()
118+
119+
img = image(path)
120+
img.save(dat)
121+
122+
local w = img.width
123+
local h = img.height
124+
local blw = w / block_width
125+
local blh = h / block_height
126+
local vals = []
127+
local minv = maxint
128+
local maxv = 0
129+
130+
dim pic(blh, blw)
131+
132+
for bly = 0 to blh - 1
133+
for blx = 0 to blw - 1
134+
y2 = bly * block_height
135+
x2 = blx * block_width
136+
n = calc_block(dat, block_height, y2, block_width - 1, x2) / (w * h)
137+
minv = min(minv, n)
138+
maxv = max(maxv, n)
139+
pic[bly,blx] = n
140+
next blx
141+
next bly
142+
143+
for bly = 0 to blh - 1
144+
for blx = 0 to blw - 1
145+
diff = iff(maxv - minv == 0, 1, maxv - minv)
146+
n = 255 * (pic[bly, blx] - minv) / diff
147+
y2 = iff(bly==0,1,bly) * block_height
148+
x2 = iff(blx==0,1,blx) * block_width
149+
color calc_color(dat, block_height, y2, block_width - 1, x2)
150+
print get_char(tbl, n);
151+
next blx
152+
print
153+
next bly
154+
showpage
155+
end
156+
157+
imageToAscii("tree.png")

src/ui/ansiwidget.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void AnsiWidget::print(const char *str) {
203203
case '\003': // end of text
204204
flush(true);
205205
break;
206-
case '\xC':
206+
case '\xC': // form feed
207207
clearScreen();
208208
break;
209209
case '\033': // ESC ctrl chars
@@ -218,9 +218,6 @@ void AnsiWidget::print(const char *str) {
218218
case '\r': // return
219219
_back->_curX = INITXY; // erasing the line will clear any previous text
220220
break;
221-
case 'm': // scroll to the top (M = scroll up one line)
222-
_back->_scrollY = 0;
223-
break;
224221
default:
225222
p += _back->print(p, lineHeight) - 1; // allow for p++
226223
break;
@@ -658,11 +655,46 @@ bool AnsiWidget::drawHoverLink(MAEvent &event) {
658655

659656
// print() helper
660657
void AnsiWidget::handleEscape(const char *&p, int lineHeight) {
661-
if (*(p + 1) == '[') {
658+
switch (*(p + 1)) {
659+
case '[':
662660
p += 2;
663661
while (doEscape(p, lineHeight)) {
664662
// continue
665663
}
664+
break;
665+
case 'm':
666+
// scroll to the top (M = scroll up one line)
667+
p += 2;
668+
_back->_scrollY = 0;
669+
break;
670+
case '<':
671+
// select back screen
672+
switch (*(p + 2)) {
673+
case '1':
674+
p += 3;
675+
selectBackScreen(USER_SCREEN1);
676+
break;
677+
case '2':
678+
p += 3;
679+
selectBackScreen(USER_SCREEN2);
680+
break;
681+
}
682+
break;
683+
case '>':
684+
// select front screen
685+
switch (*(p + 2)) {
686+
case '1':
687+
p += 3;
688+
selectFrontScreen(USER_SCREEN1);
689+
break;
690+
case '2':
691+
p += 3;
692+
selectFrontScreen(USER_SCREEN2);
693+
break;
694+
}
695+
break;
696+
default:
697+
break;
666698
}
667699
}
668700

src/ui/image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void cmd_image_save(var_s *self) {
391391
saved = true;
392392
}
393393
} else if (array != NULL) {
394-
v_tomatrix(array, w, h);
394+
v_tomatrix(array, h, w);
395395
for (int y = 0; y < h; y++) {
396396
int yoffs = (4 * y * w);
397397
for (int x = 0; x < w; x++) {

0 commit comments

Comments
 (0)