Okay, so I saw this topic: viewtopic.php?f=3&t=8087
...and I thought, well that's nice, but it only works on Win10. And, it's kind of slow...
So... can't I do that with cmdgfx_gdi? Well, no not exactly, because cmdgfx only has a 16-color buffer, and to actually support 32-bit RGB would take a major rewrite of the whole thing.
However, I realized that I can set the 16 color palette to any colors I want using cmdgfx_gdi. Perhaps that and some dithering with block characters would work?
Some results:
Emulating Truecolor with dithering and 16 color palette
Moderator: DosItHelp
Re: Emulating Truecolor with dithering and 16 color palette
The archive with this stuff and many more converted pictures are here: http://www.mediafire.com/file/mlw3n6divau03mv/ditherGxy.zip
It's a bit big (2Mb) because it includes the original jpg images for reference.
Please run _showall.bat and you will see all the converted images, plus the rotating zoomer in the end.
Rotating zoomer? Yes, since the resulting files here are just gxy files (with a custom palette), they can be used straight as-is for cmdgfx_gdi effects. So I took the zoomer from the cmdgfx archive, just changed the palette and the texture and that's it!
It's a bit big (2Mb) because it includes the original jpg images for reference.
Please run _showall.bat and you will see all the converted images, plus the rotating zoomer in the end.
Rotating zoomer? Yes, since the resulting files here are just gxy files (with a custom palette), they can be used straight as-is for cmdgfx_gdi effects. So I took the zoomer from the cmdgfx archive, just changed the palette and the texture and that's it!
Re: Emulating Truecolor with dithering and 16 color palette
Pros
1. Very fast (in fact, realtime fast). Conversion from jpg to gxy is also very fast, takes perhaps 1s.
2. Works on all Windows versions (well, ok maybe not "all" but Win7 and up a least)
3. Can be used for all kinds of effects with cmdgfx
Cons
1. The end result will never be as good as real 32 bit RGB of course. For reference, I also converted the Pink Floyd cover that IcarusLives did (it's in the archive above), and the difference is obvious (of course). If I had hand crafted the palette I believe the results could be better, but still not as good.
2. misol101's infamous external tools needed
1. Very fast (in fact, realtime fast). Conversion from jpg to gxy is also very fast, takes perhaps 1s.
2. Works on all Windows versions (well, ok maybe not "all" but Win7 and up a least)
3. Can be used for all kinds of effects with cmdgfx
Cons
1. The end result will never be as good as real 32 bit RGB of course. For reference, I also converted the Pink Floyd cover that IcarusLives did (it's in the archive above), and the difference is obvious (of course). If I had hand crafted the palette I believe the results could be better, but still not as good.
2. misol101's infamous external tools needed
Re: Emulating Truecolor with dithering and 16 color palette
The command used to convert a jpg to gxy is called convsingle.bat. It takes only JPG files and has to be run from command prompt.
It is also *required* to have ImageMagick installed and in the path.
Usage: convsingle imgfile [/W width] [/H height] [/CS altcharset1-4 nofBlack nofWhite] [/COLOR colormode cleanColorTreshold] [/FNT outFontNumber] [/NOPAL] [/EXTRAS extras] [/FORCEPAL RRGGBB[_RRGGBB...]] [/BGCOL index] [/RED] [/GREEN] [/BLUE] [/COLNOF nofcols] [/NO_GDI]
That's a lot of arguments and I don't plan to explain them all unless there is some interest Anyway, basic usage is:
convsingle file.jpg
This creates both a gxy file with the same name, and a bat file with the same name which shows the image.
To see exactly how an already existing gxy file was created, take a look inside the corresponding bat file that shows the gxy. They include the exact usage of convsingle that created them.
Unfortunately, the /W (width) and /H (height) parameters are majorly messed up, and it will take some experimentation to get good results. The binary (jp2amod.exe) is a modification of jp2a, and I suspect that the aspect ratio calculation or something like that is majorly messed up in jp2a, but I haven't looked at the actual cause yet.
It is also *required* to have ImageMagick installed and in the path.
Usage: convsingle imgfile [/W width] [/H height] [/CS altcharset1-4 nofBlack nofWhite] [/COLOR colormode cleanColorTreshold] [/FNT outFontNumber] [/NOPAL] [/EXTRAS extras] [/FORCEPAL RRGGBB[_RRGGBB...]] [/BGCOL index] [/RED] [/GREEN] [/BLUE] [/COLNOF nofcols] [/NO_GDI]
That's a lot of arguments and I don't plan to explain them all unless there is some interest Anyway, basic usage is:
convsingle file.jpg
This creates both a gxy file with the same name, and a bat file with the same name which shows the image.
To see exactly how an already existing gxy file was created, take a look inside the corresponding bat file that shows the gxy. They include the exact usage of convsingle that created them.
Unfortunately, the /W (width) and /H (height) parameters are majorly messed up, and it will take some experimentation to get good results. The binary (jp2amod.exe) is a modification of jp2a, and I suspect that the aspect ratio calculation or something like that is majorly messed up in jp2a, but I haven't looked at the actual cause yet.
Last edited by misol101 on 09 Sep 2017 06:28, edited 2 times in total.
-
- Posts: 175
- Joined: 17 Jan 2016 23:55
Re: Emulating Truecolor with dithering and 16 color palette
I truly appreciate your work and appreciation for cmd graphics! I love animations and pattern design myself. Keep it up!
I would use your tools, but I really like pure batch methods, and working to make them fast!
I would use your tools, but I really like pure batch methods, and working to make them fast!
-
- Expert
- Posts: 960
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: Emulating Truecolor with dithering and 16 color palette
this is for windows 7 pure batch dithering. show usage for sierra lite or floyd dithering using fonts 2x1
Code: Select all
@echo off & setlocal EnableDelayedExpansion
mode 330,145 & cls
echo Use Lucida console font 5
echo Disable ClearType
echo Enable "Smooth Edges of Screen Fonts"
ping -n 5 localhost >nul
if "%1"=="" (
for %%a in ( FontSize:00020000
FontFamily:00000036
WindowSize:003c005a
ScreenColors:0000000f
CodePage:000001b5
ScreenBufferSize:003c005a
FontWeight:00000190
) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
>nul reg add HKCU\Console\dither /v %%b /t reg_dword /d 0x%%c /f
)
>nul reg add HKCU\Console\dither /v FaceName /t reg_sz /d "Lucida Console" /f
start "dither" /max "%ComSpec%" /c "%~f0" 1&goto:eof
) else ( >nul reg delete HKCU\Console\dither /f )
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
set "color1=77870788088088000000000"
set "color2=FFFFFFF7F7F7777F8878888"
set "char=Û²²±²°±Û±²°²±°±°Û²°±° "
set numshadesH=23
rem call :color_sdown 07 " ...... " 04 "°±²Û" 4C "°±²Û" CE "°±²Û" EA "°±²Û" A2 "°±²Û" 21 "°±²Û" 15 "°±²Û" 50 "°±²Û"
set "color1=00004444cccceeeeaaaa2222111155550"
set "color2=4444cccceeeeaaaa22221111555500008"
set "char=°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û°±²Û "
pushd %temp%
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" > "'"
rem floyd-steinberg dither
rem l'immagine e' virtuale ed e' un gradiente verticale con pixel con colore da 0 a 255.
goto :veloce
For /L %%y in (0,1,140) do (
for /L %%x in (0,1,320) do (
set /a "pixel[%%x][%%y]=(%%x*255/320+%%y*255/140)/2"
title %%x %%y
)
)
for /L %%y in (0,1,140) do (
for /L %%x in (1,1,320) do (
set /a oldpixel=pixel[%%x][%%y]
rem rem if !oldpixel! gtr 127 (set /a newpixel=255) else (set /a newpixel=0)
rem set /a newpixel=oldpixel*21/255
set /a newpixel=oldpixel*32/255
rem if !newpixel! equ 255 (call :color 7f "Û") else (call :color 7f "²")
call :rainbow !newpixel!
rem call :shadow !newpixel!
rem set /a newpixel=newpixel*255/21
set /a newpixel=newpixel*255/32
set /a "quant_error=oldpixel - newpixel, x1=%%x+1, x10=%%x-1, y1=%%y+1"
set /a pixel[!x1!][%%y] = pixel[!x1!][%%y] + 7 * quant_error/16
set /a pixel[!x10!][!y1!] = pixel[!x10!][!y1!] + 3 * quant_error/16
set /a pixel[%%x][!y1!] = pixel[%%x][!y1!] + 5 * quant_error/16
set /a pixel[!x1!][!y1!] = pixel[!x1!][!y1!] + 1 * quant_error/16
)
echo(
)
goto :eof
:veloce
rem per fare veloce non definisco tutta la matrice 320x140
for /L %%y in (0,1,140) do (
for /L %%x in (1,1,320) do (
rem set /a "pixel[%%x][%%y]=pixel[%%x][%%y]+(%%x*255/320+%%y*255/140)/2"
rem set /a oldpixel=pixel[%%x][%%y]
rem combino le due precedenti. Provare con scala a 4096 invece che 256
set /a "oldpixel=pixel[%%x][%%y]+(%%x*4095/320+%%y*4095/140)/2, newpixel=oldpixel*32/4095"
call :rainbow !newpixel!
set /a "newpixel=newpixel*4095/32 , quant_error=oldpixel - newpixel, x1=%%x+1, x10=%%x-1, y1=%%y+1, ym1=%%y-1"
rem set /a pixel[!x1!][%%y] = pixel[!x1!][%%y] + 7 * quant_error/16
rem set /a pixel[!x10!][!y1!] = pixel[!x10!][!y1!] + 3 * quant_error/16
rem set /a pixel[%%x][!y1!] = pixel[%%x][!y1!] + 5 * quant_error/16
rem set /a pixel[!x1!][!y1!] = pixel[!x1!][!y1!] + 1 * quant_error/16
rem floyd-steinberg
rem set /a pixel[!x1!][%%y] = pixel[!x1!][%%y] + 7 * quant_error/16 , pixel[!x10!][!y1!] = pixel[!x10!][!y1!] + 3 * quant_error/16, pixel[%%x][!y1!] = pixel[%%x][!y1!] + 5 * quant_error/16, pixel[!x1!][!y1!] = pixel[!x1!][!y1!] + 1 * quant_error/16
rem sierra lite
set /a pixel[!x1!][%%y] = pixel[!x1!][%%y] + 2 * quant_error/4, pixel[%%x][!y1!] = pixel[%%x][!y1!] + 1 * quant_error/4, pixel[!x10!][!y1!] = pixel[!x10!][!y1!] + 1 * quant_error/4
if !ym1! geq 0 set pixel[%%x][!ym1!]=
)
echo(
)
popd
goto :eof
:color
(echo %~2\..\'
) > $$$.color.txt && findstr /a:%~1 /f:$$$.color.txt "."
Shift
Shift
If ""=="%~1" Goto :Eof
goto :color
goto :eof
:shadow
rem call :color !color1:~%1,1!!color2:~%1,1! "!char:~%1,1!"
(echo !char:~%1,1!\..\'
) > $$$.color.txt && findstr /a:!color1:~%1,1!!color2:~%1,1! /f:$$$.color.txt "."
rem call :color 08 " °±²Û" 87 "°±²Û" 7f "°±²Û"
goto :eof
:rainbow
(echo !char:~%1,1!\..\'
) > $$$.color.txt && findstr /a:!color1:~%1,1!!color2:~%1,1! /f:$$$.color.txt "."
goto :eof
:ColorText
echo off
<nul set /p .=%DEL%> "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
Re: Emulating Truecolor with dithering and 16 color palette
IcarusLives:Thanks, good to hear!
einstein1969: thanks, nice but a tad slow Anyway that script got me checking how to actually set the palette for a cmd window.
Updated archive, now accepts /NO_GDI as parameter, which will produce a viewer batch script that uses cmdgfx instead of cmdgfx_gdi (and opens a new window).
This has the advantage that text is actually written into the buffer, which also means it's possible to scroll properly in the buffer (in case the image is too big too fit on one screen, for example)
au.bat and pepper2.bat in the new archive were made using this new option.
einstein1969: thanks, nice but a tad slow Anyway that script got me checking how to actually set the palette for a cmd window.
Updated archive, now accepts /NO_GDI as parameter, which will produce a viewer batch script that uses cmdgfx instead of cmdgfx_gdi (and opens a new window).
This has the advantage that text is actually written into the buffer, which also means it's possible to scroll properly in the buffer (in case the image is too big too fit on one screen, for example)
au.bat and pepper2.bat in the new archive were made using this new option.