From 0e5a9b4843c10be2093bf3e8468d02fdd46c353e Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Wed, 27 Dec 2017 19:48:28 +1000 Subject: [PATCH 1/4] COMMON: bump version --- ChangeLog | 5 ++++- configure.ac | 2 +- debian/changelog | 5 +++++ ide/android/AndroidManifest.xml | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e0e633fb..9f0257a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -2017-11-28 (0.12.10/11) +2017-11-28 (0.12.10) + Released 82f865d61a6eba1c017b8a58e1c892f1b7d6a0c0 + +2017-11-28 (0.12.10) COMMON: owner strings 2017-11-28 (0.12.10) diff --git a/configure.ac b/configure.ac index cb77b44b..387f49ee 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/debian/changelog b/debian/changelog index bf157a64..87eba931 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,8 @@ +smallbasic (0.12.11) unstable; urgency=low + * Various see web site + + -- Chris Warren-Smith Wed, 27 Dec 2017 09:45:25 +1000 + smallbasic (0.12.10) unstable; urgency=low * Various see web site diff --git a/ide/android/AndroidManifest.xml b/ide/android/AndroidManifest.xml index 36f13f71..6705af7a 100644 --- a/ide/android/AndroidManifest.xml +++ b/ide/android/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="26" + android:versionName="0.12.11"> From 8cc65cecbb557d490398f61697a56e3472994aab Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Wed, 27 Dec 2017 20:33:45 +1000 Subject: [PATCH 2/4] UI: fix img.save(d) to set correct indexes --- ChangeLog | 3 + .../distro-examples/graphics/img2ascii.bas | 112 ++++++++++++++++++ src/ui/image.cpp | 2 +- 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 samples/distro-examples/graphics/img2ascii.bas diff --git a/ChangeLog b/ChangeLog index 9f0257a1..2d735586 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-11-28 (0.12.11) + Fix img.save(dat) to build correct indexes + 2017-11-28 (0.12.10) Released 82f865d61a6eba1c017b8a58e1c892f1b7d6a0c0 diff --git a/samples/distro-examples/graphics/img2ascii.bas b/samples/distro-examples/graphics/img2ascii.bas new file mode 100644 index 00000000..54828662 --- /dev/null +++ b/samples/distro-examples/graphics/img2ascii.bas @@ -0,0 +1,112 @@ +#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 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) + img.save(dat) + cls + + 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) + n = 255 * (vals[i - 1] - minv) / (maxv - minv) + 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 + row = "" + for blx = 0 to blw - 1 + n = 255 * (pic[bly,blx] - minv) / (maxv - minv) + row += get_char(tbl, n) + next blx + print row + next bly +end + +imageToAscii("tree.png") diff --git a/src/ui/image.cpp b/src/ui/image.cpp index b2c8243d..867314e2 100644 --- a/src/ui/image.cpp +++ b/src/ui/image.cpp @@ -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++) { From 08ebf828371969996702432274ea6f92c41207e2 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 28 Dec 2017 08:05:05 +1000 Subject: [PATCH 3/4] UI: Fix ESCm implementation issue --- ChangeLog | 2 ++ src/ui/ansiwidget.cpp | 42 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d735586..892934af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2017-11-28 (0.12.11) Fix img.save(dat) to build correct indexes + Fix ESCm implementation bug + Implements ESCn back screen handlers 2017-11-28 (0.12.10) Released 82f865d61a6eba1c017b8a58e1c892f1b7d6a0c0 diff --git a/src/ui/ansiwidget.cpp b/src/ui/ansiwidget.cpp index 1d357f3d..1841a8a3 100755 --- a/src/ui/ansiwidget.cpp +++ b/src/ui/ansiwidget.cpp @@ -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 @@ -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; @@ -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; } } From 313d4d358c084665236d9b91ea34f654b79ae5e2 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Thu, 28 Dec 2017 13:13:32 +1000 Subject: [PATCH 4/4] SAMPLES: added img2ascii sample --- .../distro-examples/graphics/img2ascii.bas | 65 ++++++++++++++++--- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/samples/distro-examples/graphics/img2ascii.bas b/samples/distro-examples/graphics/img2ascii.bas index 54828662..31939c48 100644 --- a/samples/distro-examples/graphics/img2ascii.bas +++ b/samples/distro-examples/graphics/img2ascii.bas @@ -10,8 +10,8 @@ func calc_block(byref dat, h, y2, w, x2) 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 + r = ((c band 0xff0000) rshift 16) + g = ((c band 0xff00) rshift 8) b = (c band 0xff) n += (r + g + b) / 3 next x @@ -19,6 +19,46 @@ func calc_block(byref dat, h, y2, w, x2) 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 @@ -38,11 +78,11 @@ func create_table local w = txtw(chars) local h = txth(chars) local cw = txtw("1") - + cls: print chars - img = image(0, 0, w, h) + img = image(0, 0, w, h, 1) img.save(dat) - cls + cls: showpage local vals = [] local minv = maxint @@ -61,7 +101,8 @@ func create_table local tbl = {} for i = 1 to len(chars) ch = mid(chars, i, 1) - n = 255 * (vals[i - 1] - minv) / (maxv - minv) + diff = iff(maxv - minv == 0, 1, maxv - minv) + n = 255 * (vals[i - 1] - minv) / diff vals[i - 1] = n tbl[n] = ch next i @@ -100,13 +141,17 @@ sub imageToAscii(path) next bly for bly = 0 to blh - 1 - row = "" for blx = 0 to blw - 1 - n = 255 * (pic[bly,blx] - minv) / (maxv - minv) - row += get_char(tbl, n) + 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 row + print next bly + showpage end imageToAscii("tree.png")