Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
2017-11-28 (0.12.10/11)
2017-11-28 (0.12.11)
Fix img.save(dat) to build correct indexes
Fix ESCm implementation bug
Implements ESC<n ESC>n back screen handlers

2017-11-28 (0.12.10)
Released 82f865d61a6eba1c017b8a58e1c892f1b7d6a0c0

2017-11-28 (0.12.10)
COMMON: owner strings

2017-11-28 (0.12.10)
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
dnl Download the GNU Public License (GPL) from www.gnu.org
dnl

AC_INIT([smallbasic], [0.12.10])
AC_INIT([smallbasic], [0.12.11])
AC_CONFIG_SRCDIR([configure.ac])

AC_CANONICAL_TARGET
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
smallbasic (0.12.11) unstable; urgency=low
* Various see web site

-- Chris Warren-Smith <cwarrensmith@gmail.com> Wed, 27 Dec 2017 09:45:25 +1000

smallbasic (0.12.10) unstable; urgency=low
* Various see web site

Expand Down
4 changes: 2 additions & 2 deletions ide/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.sourceforge.smallbasic"
android:installLocation="preferExternal"
android:versionCode="25"
android:versionName="0.12.10">
android:versionCode="26"
android:versionName="0.12.11">
<uses-sdk android:minSdkVersion="15"/>

<!-- support large + xlarge screens to avoid compatibility mode -->
Expand Down
157 changes: 157 additions & 0 deletions samples/distro-examples/graphics/img2ascii.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#http://mattmik.com/articles/ascii/ascii.html
const chars = "~`!@#$%^&*()+-=[]\;',./_+{}|:"
const block_width = 4
const block_height = 6

func calc_block(byref dat, h, y2, w, x2)
local y,x,c,r,g,b,n

n = 0
for y = 0 to h
for x = 0 to w
c = -dat[y2 + y, x2 + x]
r = ((c band 0xff0000) rshift 16)
g = ((c band 0xff00) rshift 8)
b = (c band 0xff)
n += (r + g + b) / 3
next x
next y
return n
end

func calc_color(byref dat, h, y2, w, x2)
local y,x,c
local r = 0
local g = 0
local b = 0
local wh = w * h

for y = 0 to h
for x = 0 to w
c = -dat[y2 + y, x2 + x]
rx = ((c band 0xff0000) rshift 16)
gx = ((c band 0xff00) rshift 8)
bx= (c band 0xff)

r += ((c band 0xff0000) rshift 16)
g += ((c band 0xff00) rshift 8)
b += (c band 0xff)
next x
next y

r = r / wh
g = g / wh
b = b / wh

local minv = min(r,g,b)
local maxv = max(r,g,b)

if (minv < maxv) then
local diff = iff(maxv - minv == 0, 1, maxv - minv)
r = int(255 * (r - minv) / diff)
g = int(255 * (g - minv) / diff)
b = int(255 * (b - minv) / diff)
return rgb(r,g,b)
else
r = min(255, r)
return rgb(r,r,r)
endif

end

func get_char(byref tbl, n)
local r = tbl[n]
if r > 0 then return r
for sn in tbl.sorted
if (sn > n) then
' round up to the nearest value
tbl[n] = tbl[sn]
return tbl[sn]
endif
next n
return " "
end

# analyze the graphic data corresponding to each character in the character set.
func create_table
local img,dat,i,ch,x2,n
local w = txtw(chars)
local h = txth(chars)
local cw = txtw("1")

cls: print chars
img = image(0, 0, w, h, 1)
img.save(dat)
cls: showpage

local vals = []
local minv = maxint
local maxv = 0

for i = 1 to len(chars)
ch = mid(chars, i, 1)
x2 = ((i - 1) * cw)
n = calc_block(dat, h - 1, 0, cw - 1, x2) / (w * h)
minv = min(minv, n)
maxv = max(maxv, n)
vals << n
next i

' scale the values from 0:255
local tbl = {}
for i = 1 to len(chars)
ch = mid(chars, i, 1)
diff = iff(maxv - minv == 0, 1, maxv - minv)
n = 255 * (vals[i - 1] - minv) / diff
vals[i - 1] = n
tbl[n] = ch
next i

sort vals
tbl["sorted"] = vals
return tbl
end

sub imageToAscii(path)
local img,dat,pic,bly,blx,y2,x2,n,minv,maxv,row
local tbl = create_table()

img = image(path)
img.save(dat)

local w = img.width
local h = img.height
local blw = w / block_width
local blh = h / block_height
local vals = []
local minv = maxint
local maxv = 0

dim pic(blh, blw)

for bly = 0 to blh - 1
for blx = 0 to blw - 1
y2 = bly * block_height
x2 = blx * block_width
n = calc_block(dat, block_height, y2, block_width - 1, x2) / (w * h)
minv = min(minv, n)
maxv = max(maxv, n)
pic[bly,blx] = n
next blx
next bly

for bly = 0 to blh - 1
for blx = 0 to blw - 1
diff = iff(maxv - minv == 0, 1, maxv - minv)
n = 255 * (pic[bly, blx] - minv) / diff
y2 = iff(bly==0,1,bly) * block_height
x2 = iff(blx==0,1,blx) * block_width
color calc_color(dat, block_height, y2, block_width - 1, x2)
print get_char(tbl, n);
next blx
print
next bly
showpage
end

imageToAscii("tree.png")
42 changes: 37 additions & 5 deletions src/ui/ansiwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void AnsiWidget::print(const char *str) {
case '\003': // end of text
flush(true);
break;
case '\xC':
case '\xC': // form feed
clearScreen();
break;
case '\033': // ESC ctrl chars
Expand All @@ -218,9 +218,6 @@ void AnsiWidget::print(const char *str) {
case '\r': // return
_back->_curX = INITXY; // erasing the line will clear any previous text
break;
case 'm': // scroll to the top (M = scroll up one line)
_back->_scrollY = 0;
break;
default:
p += _back->print(p, lineHeight) - 1; // allow for p++
break;
Expand Down Expand Up @@ -658,11 +655,46 @@ bool AnsiWidget::drawHoverLink(MAEvent &event) {

// print() helper
void AnsiWidget::handleEscape(const char *&p, int lineHeight) {
if (*(p + 1) == '[') {
switch (*(p + 1)) {
case '[':
p += 2;
while (doEscape(p, lineHeight)) {
// continue
}
break;
case 'm':
// scroll to the top (M = scroll up one line)
p += 2;
_back->_scrollY = 0;
break;
case '<':
// select back screen
switch (*(p + 2)) {
case '1':
p += 3;
selectBackScreen(USER_SCREEN1);
break;
case '2':
p += 3;
selectBackScreen(USER_SCREEN2);
break;
}
break;
case '>':
// select front screen
switch (*(p + 2)) {
case '1':
p += 3;
selectFrontScreen(USER_SCREEN1);
break;
case '2':
p += 3;
selectFrontScreen(USER_SCREEN2);
break;
}
break;
default:
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void cmd_image_save(var_s *self) {
saved = true;
}
} else if (array != NULL) {
v_tomatrix(array, w, h);
v_tomatrix(array, h, w);
for (int y = 0; y < h; y++) {
int yoffs = (4 * y * w);
for (int x = 0; x < w; x++) {
Expand Down