Drawing pixel resolution graphics in text mode

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Aacini
Expert
Posts: 1910
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Drawing pixel resolution graphics in text mode

#16 Post by Aacini » 18 Jan 2014 18:40

einstein1969 wrote:
Ed Dyreen wrote:
einstein1969 wrote:or use colorshow.exe with is faster but has the disadvantage that is ISA(Istruction Set Architecture) dependent.
Not sure what you mean depends on x86 instruction set ??


Yes depends on x86.

einstein1969


Excuse me. I am afraid I don't understand what you intended to mean with "colorshow.exe... has the disadvantage that is ISA (Istruction Set Architecture) dependent... (depends on x86)".

Of course, colorshow.exe program requires an x86 compatible CPU (and Windows OS) in order to run, but the same "restriction" apply to thousand or perhaps millions of applications of all kinds, from small freeware programs up to several hundred dollars suites, that are distributed exclusively as .exe executable files for x86 Windows OS. Is your opinion that all these applications "have the disadvantage that depends on x86"? Or, do you have this opinion just on my colorshow.exe program?

Is your post an advice that if someone use colorshow.exe program to show text in color, he/she must be aware that this solution will not longer works if he/she later change the computer for a non-x86 compatible one?

As I said before, I don't understand what you meant...

Antonio

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Drawing pixel resolution graphics in text mode

#17 Post by einstein1969 » 20 Jan 2014 08:09

Aacini wrote:Excuse me. I am afraid I don't understand what you intended to mean with "colorshow.exe... has the disadvantage that is ISA (Istruction Set Architecture) dependent... (depends on x86)".

Of course, colorshow.exe program requires an x86 compatible CPU (and Windows OS) in order to run, but the same "restriction" apply to thousand or perhaps millions of applications of all kinds, from small freeware programs up to several hundred dollars suites, that are distributed exclusively as .exe executable files for x86 Windows OS. Is your opinion that all these applications "have the disadvantage that depends on x86"? Or, do you have this opinion just on my colorshow.exe program?

Is your post an advice that if someone use colorshow.exe program to show text in color, he/she must be aware that this solution will not longer works if he/she later change the computer for a non-x86 compatible one?

As I said before, I don't understand what you meant...

Antonio


Antonio,

I only notice the dependencies. 1) closed source 2) developed by one person 3) written in a low-level language for a particular ISA.
What does this mean? That all the work that you did not survive very long.
Of course, even if Microsoft were to remove all of the functionality we would have had problems. But in this case depends on someone else.

with respect
einstein1969 aka Francesco Poscetti

Squashman
Expert
Posts: 4485
Joined: 23 Dec 2011 13:59

Re: Drawing pixel resolution graphics in text mode

#18 Post by Squashman » 20 Jan 2014 10:43

1) I am sure if you asked nicely he would provide the source.
2) Why is a one person developer such a bad thing?
3) It's pretty much going to run on any computer running Windows which is what the utility is intended for. Are you expecting it to run on Android tablets running on ARM processors?

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Drawing pixel resolution graphics in text mode

#19 Post by einstein1969 » 23 Jan 2014 15:05

Aacini wrote:

Code: Select all

@if (@CodeSection == @Batch) @then


@echo off

rem Mandelbrot Set graphic in text mode
rem Batch-JScript hybrid version optimized for high resolution screens
rem Include "Terminal 1x1.FNT" font file and installation instructions
rem Antonio Perez Ayala

setlocal EnableDelayedExpansion
if "%~1" equ "DrawLines" goto DrawLines

rem Create "Terminal 1x1.FNT" file if not exists
if not exist "Terminal 1x1.FNT" (
   call :ExtractBinaryFile "Terminal 1x1.FNT"
   echo/
   echo In order to install a "Terminal" raster font right-click on it and select
   echo "Install", or open Fonts via Control Panel and drag^&drop the font file.
   echo/
   echo To use the installed font in a Command-line window, follow these steps:
   echo/
   echo 1. Right-click on any MS-DOS Command-line icon and select "Create shortcut"
   echo    or "Copy".
   echo 2. Open the folder that contain the programs that will be used in this window
   echo    and type Ctrl-V (paste^); a new MS-DOS shortcut icon is created.
   echo 3. Open the new icon, right-click on the title bar and select "Properties".
   echo 4. Open "Font" tab, select "Bitmap fonts" and "1x1" size.
   echo 5. Open "Layout" tab and enter a large size in Buffer and Window sizes; for
   echo    example: Width: 800, Height: 600 (same values in BOTH Buffer and Window^).
   echo 6. Click OK, type EXIT and press Enter.
   echo/
   echo After that, it is suggested to rename the new icon to include the resolution
   echo and the font size; for example: "MS-DOS 800x600 @ 1x1". To use this icon:
   echo open it, type the name of the program to execute and press Enter.
   echo/
   pause
   goto :EOF
)

rem Working values: maximum screen coordinates
rem The Command-line window MUST have the same values in BOTH Buffer and Window sizes
set /A maxY=0, maxX=0
for /F "skip=2 tokens=2" %%a in ('mode con') do (
   if !maxY! equ 0 ( set /A maxY=%%a-2
   ) else if !maxX! equ 0 ( set /A maxX=%%a-1
   )
)

if not exist ColorChar.exe call :ExtractBinaryFile ColorChar.exe
rem Create the semaphore-signal file and start the asynchronous process
echo X > Flag.out
if exist Flag.in del Flag.in
rem Get output lines from JScript section and show they with ColorChar.exe
cls
CScript //nologo //E:JScript "%~F0" %maxY% %maxX% | "%~F0" DrawLines
del Flag.out
pause
goto :EOF

:DrawLines
   rem Wait for "Data Available" signal
   if not exist Flag.in goto DrawLines
   rem Read the input line sent by JScript code
   set line=
   set /P "line="
   rem Set "Data Read" acknowledgement
   ren Flag.in Flag.out
   rem Check the standard "End Of piped File" mark
   if not defined line goto :EOF
   ColorChar %line%
goto DrawLines


rem ExtractBinaryFile from hexadecimal digits placed in a "resource" in this .bat file
:ExtractBinaryFile filename.ext
setlocal EnableDelayedExpansion
set "start="
set "end="
for /F "tokens=1,3 delims=:=>" %%a in ('findstr /N /B "</*resource" "%~F0"') do (
   if not defined start (
      if "%%~b" equ "%~1" set start=%%a
   ) else if not defined end set end=%%a
)
(for /F "skip=%start% tokens=1* delims=:" %%a in ('findstr /N "^" "%~F0"') do (
   if "%%a" == "%end%" goto decodeHexFile
   echo %%b
)) > "%~1.hex"
:decodeHexFile
< "%~1.hex" Cscript //nologo //E:JScript "%~F0" Extract "%~1"
del "%~1.hex"
exit /B


<resource id="Terminal 1x1.FNT">
00034403[2]416e746f6e696f20506572657a204179616c612028616b6120416163696e6929006163696e692900446c6c5c6e74646c6c2e646c6c[24]
9001ff010001[2]01000100207f212061[5]3b03[6]da02[3]01[29]0100da02[2]0100db02[2]0100dc02[2]0100dd02[2]0100de02[2]0100df02
[2]0100e002[2]0100e102[2]0100e202[2]0100e302[2]0100e402[2]0100e502[2]0100e602[2]0100e702[2]0100e802[2]0100e902[2]0100ea
02[2]0100eb02[2]0100ec02[2]0100ed02[2]0100ee02[2]0100ef02[2]0100f002[2]0100f102[2]0100f202[2]0100f302[2]0100f402[2]0100
f502[2]0100f602[2]0100f702[2]0100f802[2]0100f902[2]0100fa02[2]0100fb02[2]0100fc02[2]0100fd02[2]0100fe02[2]0100ff02[2]01
[2]03[2]01000103[2]01000203[2]01000303[2]01000403[2]01000503[2]01000603[2]01000703[2]01000803[2]01000903[2]01000a03[2]01
000b03[2]01000c03[2]01000d03[2]01000e03[2]01000f03[2]01001003[2]01001103[2]01001203[2]01001303[2]01001403[2]01001503[2]
01001603[2]01001703[2]01001803[2]01001903[2]01001a03[2]01001b03[2]01001c03[2]01001d03[2]01001e03[2]01001f03[2]01002003[2]
01002103[2]01002203[2]01002303[2]01002403[2]01002503[2]01002603[2]01002703[2]01002803[2]01002903[2]01002a03[2]01002b03[2]
01002c03[2]01002d03[2]01002e03[2]01002f03[2]01003003[2]01003103[2]01003203[2]01003303[2]01003403[2]01003503[2]01003603[2]
01003703[2]01003803[2]01003903[2]08003a03[3][6x80]0080[7]80[3]808080008080[3]8080[2]8000[6x80][2][9x80]00[5x80]008080[4]
[11x80]00[15x80][3]80005465726d696e616c00
</resource>

<resource id="ColorChar.exe">
4d5a900003[3]04[3]ffff[2]b8[7]40[35]b0[3]0e1fba0e00b409cd21b8014ccd21546869732070726f6772616d2063616e6e6f74206265207275
6e20696e20444f53206d6f64652e0d0d0a24[7]55b5b8fd11d4d6ae11d4d6ae11d4d6ae9fcbc5ae18d4d6aeedf4c4ae13d4d6ae5269636811d4d6ae
[8]5045[2]4c010300ff23cd52[8]e0000f010b01050c0004[3]04[7]10[3]10[3]20[4]40[2]10[3]02[2]04[7]04[8]40[3]04[6]03[5]10[2]10
[4]10[2]10[6]10[11]1c20[2]28[84]20[2]1c[27]2e74657874[3]a202[3]10[3]04[3]04[14]20[2]602e7264617461[2]ea[4]20[3]02[3]08[14]
40[2]402e64617461[3]20[4]30[3]02[3]0a[14]40[2]c0[480]e806[3]50e87302[2]558bec81c4f4dffffffc6af5e86e02[2]8945fc6800304000
ff75fce85802[2]8dbdfcdfffff89bdf8dfffffe81302[2]e83202[2]8a064684c00f846001[2]3c2f75672bbdf8dfffff74168d85f4dfffff5057ff
b5f8dfffffff75fce88b01[2]8bbdf8dfffff8a064684c00f842d01[2]2c303c0976082c073c0f76022c208a264684e40f841401[2]80fc20741286
c42c303c0976082c073c0f76022c20d51066a316304000eb853c2275208a064684c00f84e6[3]3c227405880747ebec8a06463c2274f4e961ffffff
3c300f82c9[3]3c390f87c1[3]e8e3[3]8ae080ff2a740a80ff58740580ff7875278adc468a06463c300f829d[3]3c390f8795[3]e8b7[3]0fb7c88a
c3f3aae914ffffff80fc20737780fc09751f8b0d0430400003cf2b8df8dfffff83e10783e908f7d9b020f3aae9ebfeffff2bbdf8dfffff7418508d85
f4dfffff5057ffb5f8dfffffff75fce889[3]588bbdf8dfffff88276a008d85f4dfffff506a01ffb5f8dfffffff75fce8fd[3]6800304000ff75fce8
e4[3]e998feffff882747e990feffff2bbdf8dfffff74168d85f4dfffff5057ffb5f8dfffffff75fce82f[3]33c0c9c3e8[4]6683e00f66b90a008a
3e4680ff30721480ff39770f66f7e180ef30660fb6d76603c2ebe44ec3558bec6a00ff7514ff7510ff750cff7508e880[3]8b4d10578b7d0c66a116
304000f366ab8b0d04304000ff751451ff7510ff750cff7508e85e[3]5f6800304000ff7508e83e[3]c9c21000[6xcc]e847[3]8bf08a06463c2275
098a06463c2275f9eb0c8a06463c20740484c075f54ec38a06463c2074f94ec3ccff2514204000ff2500204000ff2504204000ff2508204000ff250c
204000ff25102040[351]6e20[2]8c20[2]9c20[2]ac20[2]ca20[2]6020[6]4420[10]dc20[3]20[22]6e20[2]8c20[2]9c20[2]ac20[2]ca20[2]
6020[6]9b004578697450726f6365737300f500476574436f6e736f6c6553637265656e427566666572496e666f[2]6a0147657453746448616e646c
65[2]ee025772697465436f6e736f6c654100f2025772697465436f6e736f6c654f757470757441747472696275746500e600476574436f6d6d616e
644c696e6541006b65726e656c33322e646c6c[302]07[489]
</resource>


@end


if ( WScript.Arguments(0) != "Extract" ) {

// Calculate Mandelbrot Set points and output they to Batch section

fso = new ActiveXObject("Scripting.FileSystemObject");

// Horizontal range: for 4:3 screen use range=3 (-1,2), for 16:9 screen use range=4 (-1.5,2.5)
var           yTop=1.1250,
    xLeft=-1.0000, xRight=2.0000,
           yBottom=-1.1250,       maxLevel=32,  // larger maxLevel values produce finer image details
    maxY=parseInt(WScript.Arguments(0)), maxX=parseInt(WScript.Arguments(1)),
    xStep=(xRight-xLeft)/maxX, yStep=(yBottom-yTop)/maxY, yPos=yTop-yStep,
    color="0123456789ABCDDEEEE";

for ( var y = 0; y <= maxY; y++ ) {
   yPos+=yStep;
   var xPos=xLeft-xStep, line="", prevPixel="", count=0, pixel;
   for ( var x = 0; x <= maxX; x++ ) {
      xPos+=xStep;
      var xIter=xPos, yIter=yPos, xSquare=xIter*xIter, ySquare=yIter*yIter, root=xSquare+ySquare, level=0;
      for ( var i = 1; i <= maxLevel; i++ ) {
         if ( root < 4 ) {
            yIter=2*xIter*yIter-yPos; xIter=xSquare-ySquare-xPos; xSquare=xIter*xIter; ySquare=yIter*yIter; root=xSquare+ySquare;
         } else {
            level=i;
            break;
         }
      }
      pixel = (level<color.length) ? color.charAt(level) : "F";
   // Use next line instead of previous one when maxLevel > 500
   // pixel = (level<color.length) ? color.charAt(level) : ((level<36)?"1":"F");
      if ( pixel != prevPixel ) {
         line+=" /"+prevPixel+" 219*"+count;
         if ( line.length > 1000 ) {
            sendLine(line);
            line = "";
         }
         prevPixel=pixel;
         count=1;
      } else {
         count++;
      }
   }
   line+=" /"+prevPixel+" 219*"+count;
   sendLine(line);
}
// Wait for last "Data Read" acknowledgement
while ( ! fso.FileExists("Flag.out") ) {
      WScript.Sleep(1);
}
// Send the standard "End Of piped File" mark
WScript.Echo();
fso.MoveFile("Flag.out", "Flag.in");

} else {

// Extract a hexadecimal "resource" into a binary file

// Convert Ascii hexadecimal digits from Stdin to a binary string
var count, byte, output = "";
while ( !WScript.Stdin.AtEndOfStream ) {
   var input = WScript.Stdin.ReadLine();
   for ( var index = 0; index < input.length; ) {
      if ( input.charAt(index) == '[' ) {
         for ( count = ++index; input.charAt(index) != 'x' &&
                                input.charAt(index) != ']' ; index++ ) ;
         count = parseInt(input.slice(count,index++));
         if ( input.charAt(index-1) == 'x' ) {
            byte = String.fromCharCode(parseInt(input.substr(index,2),16));
            index += 3;
         } else {
            byte = String.fromCharCode(0);
         }
         for ( var i = 1; i <= count; i++ ) output += byte;
      } else {
         output += String.fromCharCode(parseInt(input.substr(index,2),16));
         index += 2;
      }
   }
}

// Write the binary string to the output file
var ado = WScript.CreateObject("ADODB.Stream");
ado.Type = 2;  // adTypeText = 2
ado.CharSet = "iso-8859-1";  // right code page for output (no adjustments)
ado.Open();
ado.WriteText(output);
ado.SaveToFile(WScript.Arguments(1),2); // adSaveCreateOverWrite = 2
ado.Close();

}

function sendLine ( line ) {
   // Wait for "Data Read" acknowledgement
   while ( ! fso.FileExists("Flag.out") ) {
      WScript.Sleep(1);
   }
   // Send the line to Batch code
   WScript.Echo(line);
   // Set "Data Available" signal
   fso.MoveFile("Flag.out", "Flag.in");
}


Enjoy! :D

Antonio


I have tried this code, but at resolution 512x384 and above the result is broken

Image

for resolution 320x200 i have no prolem.
Image

I have tried a very simple dithering and the font 1x1 look very good!

Image

on windows 7 32 bit

einstein1969

Aacini
Expert
Posts: 1910
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Drawing pixel resolution graphics in text mode

#20 Post by Aacini » 23 Jan 2014 16:05

einstein1969 wrote:I have tried this code, but at resolution 512x384 and above the result is broken

for resolution 320x200 i have no prolem.

einstein1969


Yes, the problem is caused by a small bug in ColorChar.exe program. The original output buffer size was 1024 characters, but when the number of adjacent pixels of same color was larger, the bug appear. I changed that size by 8192, but obviously I used the previous version when I posted the code here... :oops:

Just change the ColorChar.exe resource section by this one:

Code: Select all

<resource id="ColorChar.exe">
4d5a900003[3]04[3]ffff[2]b8[7]40[35]b0[3]0e1fba0e00b409cd21b8014ccd21546869732070726f6772616d2063616e6e6f74206265207275
6e20696e20444f53206d6f64652e0d0d0a24[7]55b5b8fd11d4d6ae11d4d6ae11d4d6ae9fcbc5ae18d4d6aeedf4c4ae13d4d6ae5269636811d4d6ae
[8]5045[2]4c010300ff23cd52[8]e0000f010b01050c0004[3]04[7]10[3]10[3]20[4]40[2]10[3]02[2]04[7]04[8]40[3]04[6]03[5]10[2]10
[4]10[2]10[6]10[11]1c20[2]28[84]20[2]1c[27]2e74657874[3]a202[3]10[3]04[3]04[14]20[2]602e7264617461[2]ea[4]20[3]02[3]08[14]
40[2]402e64617461[3]20[4]30[3]02[3]0a[14]40[2]c0[480]e806[3]50e87302[2]558bec81c4f4dffffffc6af5e86e02[2]8945fc6800304000
ff75fce85802[2]8dbdfcdfffff89bdf8dfffffe81302[2]e83202[2]8a064684c00f846001[2]3c2f75672bbdf8dfffff74168d85f4dfffff5057ff
b5f8dfffffff75fce88b01[2]8bbdf8dfffff8a064684c00f842d01[2]2c303c0976082c073c0f76022c208a264684e40f841401[2]80fc20741286
c42c303c0976082c073c0f76022c20d51066a316304000eb853c2275208a064684c00f84e6[3]3c227405880747ebec8a06463c2274f4e961ffffff
3c300f82c9[3]3c390f87c1[3]e8e3[3]8ae080ff2a740a80ff58740580ff7875278adc468a06463c300f829d[3]3c390f8795[3]e8b7[3]0fb7c88a
c3f3aae914ffffff80fc20737780fc09751f8b0d0430400003cf2b8df8dfffff83e10783e908f7d9b020f3aae9ebfeffff2bbdf8dfffff7418508d85
f4dfffff5057ffb5f8dfffffff75fce889[3]588bbdf8dfffff88276a008d85f4dfffff506a01ffb5f8dfffffff75fce8fd[3]6800304000ff75fce8
e4[3]e998feffff882747e990feffff2bbdf8dfffff74168d85f4dfffff5057ffb5f8dfffffff75fce82f[3]33c0c9c3e8[4]6683e00f66b90a008a
3e4680ff30721480ff39770f66f7e180ef30660fb6d76603c2ebe44ec3558bec6a00ff7514ff7510ff750cff7508e880[3]8b4d10578b7d0c66a116
304000f366ab8b0d04304000ff751451ff7510ff750cff7508e85e[3]5f6800304000ff7508e83e[3]c9c21000[6xcc]e847[3]8bf08a06463c2275
098a06463c2275f9eb0c8a06463c20740484c075f54ec38a06463c2074f94ec3ccff2514204000ff2500204000ff2504204000ff2508204000ff250c
204000ff25102040[351]6e20[2]8c20[2]9c20[2]ac20[2]ca20[2]6020[6]4420[10]dc20[3]20[22]6e20[2]8c20[2]9c20[2]ac20[2]ca20[2]
6020[6]9b004578697450726f6365737300f500476574436f6e736f6c6553637265656e427566666572496e666f[2]6a0147657453746448616e646c
65[2]ee025772697465436f6e736f6c654100f2025772697465436f6e736f6c654f757470757441747472696275746500e600476574436f6d6d616e
644c696e6541006b65726e656c33322e646c6c[302]07[489]
</resource>

Then delete ColorChar.exe file from disk and run the program again.

I also fixed the code in the original post.

Antonio

PS - That color dithering is amazing! :D

Aacini
Expert
Posts: 1910
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Drawing pixel resolution graphics in text mode

#21 Post by Aacini » 25 Jan 2014 22:43

If you want to display text in the 1x1 pixel resolution "graphics" screen, a method to map a font definition table into pixels in the screen is needed. I developed a preliminary Batch-JScript hybrid version of such method as a prototype before write the assembler .exe final version. The result is very good:


Image


The prototype version use a simple one-byte wide table for the font definition, so all characters are 8-pixels wide although they may have any height size. Joseph Gil's fntcol16.zip package is a collection with 280 files of such simple font definition tables, although many of them have the same characters in 32-127 range and just a few different characters in the high range; previous image was created using VGA-ROM.F08, VGA-ROM.F14 and VGA-ROM.F16 files from such collection. The final version of the show text routine will use .FNT format files instead that have not restrictions in the font size. Currently exist programs to convert .FON and .TTF files into .FNT ones. DaFont.com is a site with more than 23,000 fonts divided in a large range of themes where you can download .FON and .TTF font files.

The image below show a few of the fonts included in fntcol16.zip collection.


Image


The code of the program that create previous images is included below. Of course, you must previously download and extract the *.F## files from fntcol16.zip collection in order for this program to work.

Code: Select all

@if (@CodeSection == @Batch) @then


@echo off

REM Example of LoadFont and ShowText prototype subroutines
REM Antonio Perez Ayala

setlocal DisableDelayedExpansion
set text= !"#$%%&'()*+,-./0123456789:;<=>?[\]^_{|}~
setlocal EnableDelayedExpansion

rem Define colors for Rainbow Bands
set prev=1
for %%a in (F E D C B A 9 8 7 6 5 4 3 2 1) do (
   set "band[/!prev!]=/%%a"
   set "prev=%%a"
)
set "myself=%~F0"

if not exist CursorPos.exe call :ExtractBinaryFile CursorPos.exe

rem Draw first example screen (sizes and colors)
cls

call :LoadFont VGA-ROM.F16 32 127
call :ShowText "You may show text in the 1x1 pixel size text screen: "
call :ShowText V:text
for /L %%i in (1,1,%fontSize%) do echo/
call :ShowText "The size of the text may be adjusted by an horizontal and"
call :ShowText "vertical factors that are applied to the base font size:"
for /L %%i in (1,1,8) do echo/
call :ShowText /S:3x4 "16:3x4" /S:2x4 " 2x4" /S:1x4 " 1x4 " /S:3x3 "3x3" /S:2x3 " 2x3" /S:1x3 " 1x3 " /S:2x2 "2x2" /S:1x2 " 1x2"
set /A adjust=fontSize*3/2
CursorPos 480 -%adjust%
call :ShowText /S:1x1 "1x1"
CursorPos 0 +6

call :LoadFont VGA-ROM.F14 48 120
call :ShowText /S:3x4 "14:3x4" /S:2x4 " 2x4" /S:1x4 " 1x4 " /S:3x3 "3x3" /S:2x3 " 2x3" /S:1x3 " 1x3 " /S:2x2 "2x2" /S:1x2 " 1x2"
set /A adjust=fontSize*3/2
CursorPos 480 -%adjust%
call :ShowText /S:1x1 "1x1"
CursorPos 0 +12

call :LoadFont VGA-ROM.F08 48 120
call :ShowText /S:3x4 "08:3x4" /S:2x4 " 2x4" /S:1x4 " 1x4 " /S:3x3 "3x3" /S:2x3 " 2x3" /S:1x3 " 1x3 " /S:2x2 "2x2" /S:1x2 " 1x2"
set /A adjust=fontSize*3/2
CursorPos 480 -%adjust%
call :ShowText /S:1x1 "1x1"
CursorPos 0 +16

call :LoadFont VGA-ROM.F14 65 122
call :ShowText /S:2x3 "You may also show text with"
call :ShowText /E "D" /1 "I" /D "F" /2 "F" /C "E" /3 "R" /B "E" /4 "N" /A "T " /7 "C" /5 "O" /9 "L" /6 "O" /8 "R" /F "S" /S:1x3 /7 " or " /S:2x3 /RB "RAINBOW " "BANDS"

for /L %%i in (1,1,4) do echo/
call :ShowText /S:1x1 /7 "Press any key when ready . . ."
pause > NUL

rem Draw second example screen (fonts)
cls

call :LoadFont INVERTED.F14 32 116
CursorPos 50 0
call :ShowText /S:2x2 "41F.DETREVNI si tnof sihT"

call :LoadFont COMPUTER.F14 32 116
CursorPos 30 30
call :ShowText /S:2x2 "This font is COMPUTER.F14"

call :LoadFont FRACTUR.F14 32 116
CursorPos 50 +8
call :ShowText /S:2x2 "This font is FRACTUR.F14"

call :LoadFont ITALICS.F14 32 116
CursorPos 75 +8
call :ShowText /S:2x2 "This font is ITALICS.F14"

call :LoadFont THAI.F14 32 116
CursorPos 100 +8
call :ShowText /S:2x2 "This font is THAI.F14"

call :LoadFont THIN.F10 32 122
CursorPos 100 +0
call :ShowText "(Previous font is THAI.F14, this one is THIN.F10)"

call :LoadFont PC.F24 32 116
CursorPos 150 +8
call :ShowText /S:2x2 "This font is PC.F24"

call :LoadFont SCRIPT.F14 32 116
CursorPos 125 +8
call :ShowText /S:2x2 "This font is SCRIPT.F14"

call :LoadFont SQUARE.F12 32 116
CursorPos 100 +8
call :ShowText /S:2x2 "This font is SQUARE.F12"

call :LoadFont MEDIEVAL.F14 32 116
CursorPos 75 +8
call :ShowText /S:2x2 "This font is MEDIEVAL.F14"

call :LoadFont BACKWARD.F14 32 116
CursorPos 50 +8
call :ShowText /S:2x2 "41F.DRAWKCAB si tnof sihT"

call :LoadFont SIDE.F10 32 116
CursorPos 8 2
call :ShowText /S:2x2
for %%a in (0 1 F . E D I S " " t n o f " " s i h T) do (
   CursorPos 8 +0
   call :ShowText "%%~a"
)

pause > NUL
cls
goto :EOF


:LoadFont fontFile.F## firstChar lastChar

if "%~3" equ "" echo ERROR - Bad syntax, should be: :LoadFont fontFile.F## firstChar lastChar & exit /B 1
if not exist "%~1" echo ERROR - Font file not found: %1 & exit /B 2
set fontSize=%~1
set fontSize=%fontSize:~-2%
if %fontSize:~0,1% equ 0 set fontSize=%fontSize:~1%
set /A char=%2, byte=1
for /F %%a in ('Cscript //nologo //E:JScript "%~F0" LoadFont "%~1" %fontSize% %2 %3') do (
   set "font[!char!][!byte!]=%%a"
   set /A byte+=1
   if !byte! gtr %fontSize% set /A char+=1, byte=1
)
rem Reset global font parameters
set "color="
set "rb="
set /A horSize=verSize=1
exit /B


ShowText [/S:hXv] [/bf] "Text"

[/S:hXv]  Font size: horizontal pixels are displayed H times, vertical pixels V times.
[/bf]     Color attribute, see: COLOR /? You may use /RB for Rainbow Bands.
"Text"    String to show in quotes, or V:varName with no quotes.

Several groups of {[/Size] [/BF] "Text"} may be given in the same :ShowText invocation,
in this case all Text's are displayed in the same "line".
When :ShowText ends, the cursor is placed at beginning of the "next line" (like ECHO command).
The last Size/Color values are preserved between :ShowText invocations.

:ShowText [/S:hXv] [/bf] "Text"

set lastPos=0
:nextParam

   rem Process /Size switch
   set "param=%~1"
   if /I "%param:~0,2%" equ "/S" (
      for /F "tokens=2,3 delims=:X" %%a in ("%param:x=X%") do set /A horSize=%%a, verSize=%%b
      shift
   )

   rem Process /BF color switch
   set "param=%~1"
   if "%param:~0,1%" equ "/" (
      set "color=%~1"
      if /I "%~1" equ "/RB" (
         set "color=/1"
         set rb=true
      ) else (
         set "rb="
      )
      shift
   )

   rem Get the start position of first scan line
   CursorPos
   set startPos=%errorlevel%
   set "endPos="
   rem Show each font scan line of the string, from top to bottom
   for /F "delims=" %%a in ('Cscript //nologo //E:JScript "%myself%" StringFontLines "%~1"') do (
      for /L %%i in (1,1,%verSize%) do (
         ColorChar !color! "%%a"
         if not defined endPos (
            rem Get the end position of (first scan line of) this string
            CursorPos
            set endPos=!errorlevel!
         )
         rem Set cursor position to start point of next scan line
         set /A "startPos+=1<<16"
         CursorPos !startPos!
      )
      if defined rb for %%c in ("!color!") do set "color=!band[%%~c]!"
   )
   if %startPos% gtr %lastPos% set lastPos=%startPos%
   rem Set cursor position to end of this string
   CursorPos %endPos%

   shift
if "%~1" neq "" goto nextParam

rem Set cursor position to beginning of "next line"
CursorPos %lastPos%
echo/

exit /B


rem Extract Binary File from hexadecimal digits placed in a "resource" in this .bat file

:ExtractBinaryFile filename.ext
setlocal EnableDelayedExpansion
set "start="
set "end="
for /F "tokens=1,3 delims=:=>" %%a in ('findstr /N /B "</*resource" "%~F0"') do (
   if not defined start (
      if "%%~b" equ "%~1" set start=%%a
   ) else if not defined end set end=%%a
)
(for /F "skip=%start% tokens=1* delims=:" %%a in ('findstr /N "^" "%~F0"') do (
   if "%%a" == "%end%" goto decodeHexFile
   echo %%b
)) > "%~1.hex"
:decodeHexFile
< "%~1.hex" Cscript //nologo //E:JScript "%~F0" Extract "%~1"
del "%~1.hex"
exit /B


<resource id="CursorPos.exe">
4d5a900003[3]04[3]ffff[2]b8[7]40[35]b0[3]0e1fba0e00b409cd21b8014ccd21546869732070726f6772616d2063616e6e6f74206265207275
6e20696e20444f53206d6f64652e0d0d0a24[7]55b5b8fd11d4d6ae11d4d6ae11d4d6ae9fcbc5ae18d4d6aeedf4c4ae13d4d6ae5269636811d4d6ae
[8]5045[2]4c010200eb84e24f[8]e0000f010b01050c0002[3]02[7]10[3]10[3]20[4]40[2]10[3]02[2]04[7]04[8]30[3]02[6]03[5]10[2]10
[4]10[2]10[6]10[11]1c20[2]28[84]20[2]1c[27]2e74657874[3]4201[3]10[3]02[3]02[14]20[2]602e7264617461[2]f6[4]20[3]02[3]04[14]
40[2]40[8]e806[3]50e81301[2]558bec83c4e06af5e81201[2]8945fc8d45e650ff75fce8fd[3]668b45ec668945e4e8bc[3]e8db[3]803e007505
8b45eaeb5c803e3d750646e8c6[3]668b4deae84a[3]8945eae8b5[3]803e007418803e2c750646e8a5[3]668b4de4e829[3]668945ec8b5dea53ff
75fce8ae[3]8d45e650536a018d45e350ff75fce895[3]0fb645e3c9c333c032db33d28a164680fa2b740880fa2d750980cb0280cb018a164680fa30
720f80fa39770a80ea306bc00a03c2ebe9f6c301740bf6c302740366f7d86603c14ec3[13xcc]e847[3]8bf08a06463c2275098a06463c2275f9eb0c
8a06463c20740484c075f54ec38a06463c2074f94ec3ccff2514204000ff2500204000ff2504204000ff2508204000ff250c204000ff25102040[191]
6e20[2]8c20[2]9c20[2]ba20[2]d620[2]6020[6]4420[10]e820[3]20[22]6e20[2]8c20[2]9c20[2]ba20[2]d620[2]6020[6]9b004578697450
726f6365737300f500476574436f6e736f6c6553637265656e427566666572496e666f[2]6a0147657453746448616e646c65[2]380252656164436f
6e736f6c654f757470757443686172616374657241006d02536574436f6e736f6c65437572736f72506f736974696f6e[2]e600476574436f6d6d61
6e644c696e6541006b65726e656c33322e646c6c[268]
</resource>


@end


// JScript section


if ( WScript.Arguments(0) == "LoadFont" ) {


// LoadFont fontFile.F## fontSize firstChar lastChar

var adjustment = "\u20AC\u0081\u201A\u0192\u201E\u2026\u2020\u2021" +
                 "\u02C6\u2030\u0160\u2039\u0152\u008D\u017D\u008F" +
                 "\u0090\u2018\u2019\u201C\u201D\u2022\u2013\u2014" +
                 "\u02DC\u2122\u0161\u203A\u0153\u009D\u017E\u0178" ;

ado = WScript.CreateObject("ADODB.Stream");
ado.Type = 2;  // adTypeText = 2
ado.CharSet = "iso-8859-1";  // code page with minimum adjustments for input
ado.Open();
ado.LoadFromFile(WScript.Arguments(1));

var font = ado.ReadText(),
    fontSize  = parseInt(WScript.Arguments(2)),
    firstChar = parseInt(WScript.Arguments(3)) * fontSize,
    lastChar  = (parseInt(WScript.Arguments(4))+1) * fontSize;

for ( var i = firstChar; i < lastChar; i++ ) {
   var code = font.charCodeAt(i);
   if ( code > 255 ) code = 128 + adjustment.indexOf(font.charAt(i));
   WScript.Stdout.WriteLine(code);
}


} else if ( WScript.Arguments(0) == "StringFontLines" ) {


// StringFontLines string

var string = WScript.Arguments(1),
    EnvVar = WScript.CreateObject("WScript.Shell").Environment("PROCESS"),
    fontSize = parseInt(EnvVar("fontSize")),
    horSize = parseInt(EnvVar("horSize"));

if ( string.substr(0,2) == "V:" ) string = EnvVar(string.substr(2));

// Assemble and output each font scan line of the string, from top to bottom
for ( var y = 1; y <= fontSize; y++ ) {
   // Each scan line is comprised of all characters in the string
   var line = "";
   for ( var x = 0; x < string.length; x++ ) {
      // Get the font byte of this character and scan line
      var byte = EnvVar("font["+string.charCodeAt(x)+"]["+y+"]");
      // Each byte contain 8 pixels (bits), from MSB to LSB
      for ( var bit = 1<<7; bit; bit >>= 1 ) {
         var pixel = (byte&bit) ? "X" : " ";
         for ( var i = 1; i <= horSize; i++ ) line += pixel;
      }
   }
   WScript.Stdout.WriteLine(line);
}


} else if ( WScript.Arguments(0) == "Extract" ) {


// Extract a hexadecimal "resource" into a binary file

// Convert Ascii hexadecimal digits from Stdin to a binary string
var count, byte, output = "";
while ( !WScript.Stdin.AtEndOfStream ) {
   var input = WScript.Stdin.ReadLine();
   for ( var index = 0; index < input.length; ) {
      if ( input.charAt(index) == '[' ) {
         for ( count = ++index; input.charAt(index) != 'x' &&
                                input.charAt(index) != ']' ; index++ ) ;
         count = parseInt(input.slice(count,index++));
         if ( input.charAt(index-1) == 'x' ) {
            byte = String.fromCharCode(parseInt(input.substr(index,2),16));
            index += 3;
         } else {
            byte = String.fromCharCode(0);
         }
         for ( var i = 1; i <= count; i++ ) output += byte;
      } else {
         output += String.fromCharCode(parseInt(input.substr(index,2),16));
         index += 2;
      }
   }
}

// Write the binary string to the output file
var ado = WScript.CreateObject("ADODB.Stream");
ado.Type = 2;  // adTypeText = 2
ado.CharSet = "iso-8859-1";  // right code page for output (no adjustments)
ado.Open();
ado.WriteText(output);
ado.SaveToFile(WScript.Arguments(1),2); // adSaveCreateOverWrite = 2
ado.Close();


}


IMPORTANT: Previous program must run in a MS-DOS command-line window with the Terminal 1x1 font installed and requires ColorChar.exe auxiliary program, as described in the first post of this thread; these requirements will be fulfilled when you successfully draw the Mandelbrot Set at any resolution. This example program was adjusted for 512x384 screen resolution, but it will also show correct results in larger resolutions although with apparently smaller characters.

Antonio

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Drawing pixel resolution graphics in text mode

#22 Post by einstein1969 » 04 Feb 2014 13:38

Hi Antonio,

The work done with the font is gigantic and fantastic! 8)

I'm surprised your ability to synthesize and speed of execution. :shock:

I, unfortunately I have not yet mastered what have you and go slow with color management.

Now I'm working on the luminance and the distribution of pixels, an old job I had started to do that but I stopped because I did not know how to overcome the problem of large env. I had opened a thread but remained unanswered.

These are just studies and I still have nothing ready and fully automated.

This is achieved by using only findstr.exe, reads images directly without external tools. Unfortunately, even though I created a queue to optimize call findstr is still a little slow.

In addition, not having the possibility of a multicore can not use this option together with "mode" trick.

Work proceeds on the quantization :evil:

using only 14 colors and no dithering, using your font 1x1 (this is not colored version!)

On the right the original image, on left pure batch image viever:
Image


einstein1969

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Drawing pixel resolution graphics in text mode

#23 Post by einstein1969 » 29 Mar 2014 16:09

Hi to all,

I do not know if anyone will go in using the text mode to draw in colors. I just wanted to show what you get with a batch basis.

I believe that it is necessary to make some animation, however, the assembler or something that does not exist yet.

Previus result with Lucida 5: (we can use over 300 simultaneous uniform colors!)

Image


However, I used the font Lucida Console size 2 (I think I found a bug that allows you to do that, at least on my windows 7 32bit). The font size is 1x2.

The colors are unfortunately not uniform. But it has a very interesting hardware dithering. Look the sphere in the next picture. The code is the same of above picture. We should not implement dithering and run it in batch software.

New results with raster 1x1 e Lucida 2:

Image

In this above image I have tested also with lines and antialiasing in Lucida Console 2.

Click on image and look at full size or expand with zoom graphics software.

einstein1969

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Drawing pixel resolution graphics in text mode

#24 Post by carlos » 10 Feb 2015 07:16

Aacini I found a way of load automatically the font without install it permanently. No manual installation is needed, and works with non admin accounts.

See this: Pixelfnt v1.21 set a font of 1x1

Aacini
Expert
Posts: 1910
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Drawing pixel resolution graphics in text mode

#25 Post by Aacini » 10 Feb 2015 09:27

carlos wrote:Aacini I found a way of load automatically the font without install it permanently. No manual installation is needed, and works with non admin accounts.

See this: Pixelfnt v1.21 set a font of 1x1


Yes, carlos, I saw that post. I think that that method is very good (currently I have some old fonts installed in my computer that remains from my first tests :? ).

Why did you deleted the link to your source code? Perhaps you may send me the link via PM.

Gracias Carlos! :D

Antonio

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Drawing pixel resolution graphics in text mode

#26 Post by carlos » 10 Feb 2015 09:40

Aacini wrote:
carlos wrote:Aacini I found a way of load automatically the font without install it permanently. No manual installation is needed, and works with non admin accounts.

See this: Pixelfnt v1.21 set a font of 1x1


Yes, carlos, I saw that post. I think that that method is very good (currently I have some old fonts installed in my computer that remains from my first tests :? ).

Why did you deleted the link to your source code? Perhaps you may send me the link via PM.

Gracias Carlos! :D

Antonio


Aacini, I add the link in the comments:
Rem PixelFnt v1.21
Rem Source code of pixelfnt.exe at consolesoft.com/p/bg

Post Reply