color RGB/HSV

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

color RGB/HSV

#1 Post by einstein1969 » 08 Apr 2016 18:55

This work show how to use color.
You can use to load an image and show simple.

Sorry for delay in this release (three years :( )

- Use Lucida console font 5
- Disable ClearType
- Enable "Smooth Edges of Screen Fonts"


Code: Select all

:::::::::::::::::::::::::::::::::::::::::::::
::
:: By einstein1969. ColorsHSV.cmd
::
:: Ver. 0.0.2 09-04-2016 alpha release
::  - Reduce size of environment for speedup.
::  - Auto load Lucida console font size 5
::
:: Ver. 0.0.1 21-10-2013 alpha
::  - Initial version. Too slow to release.
:::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal enabledelayedexpansion

mode 90,60
chcp 437

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:00050000
                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\ColorsHSV /v %%b /t reg_dword /d 0x%%c /f
  )
  >nul reg add HKCU\Console\ColorsHSV /v FaceName /t reg_sz /d "Lucida Console" /f
  start "ColorsHSV" /max "%ComSpec%" /c "%~f0" 1&goto:eof

) else ( >nul reg delete HKCU\Console\ColorsHSV /f )


pushd %tmp%

:: prepare for color function
  for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
    set "DEL=%%a"
  )
  <nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" > "'"
  <nul > X set /p ".=."


:: Set the 16 color standard palette
  set /a i=0
  for %%c in (   000000 000080 008000 008080 800000 800080 808000 C0C0C0
      808080 0000FF 00FF00 00FFFF FF0000 FF00FF FFFF00 FFFFFF) do (
      set p16[!i!]=%%c
      set /a i=i+1
  )

  :: gamma 2.2
  set /a i=0
  for %%c in (   000000 000037 003700 003737 370000 370037 373700 898989
      373737 0000FF 00FF00 00FFFF FF0000 FF00FF FFFF00 FFFFFF) do (
      set p16[!i!]=%%c
      set /a i=i+1
  )


:: Calculate all colors

  set "map=0123456789ABCDEF"

  set cont=-1
  For /L %%i in (0,1,15) do (

   set /a bg=%%i, fg=%%i
   for %%D in (!bg!) do (set bg=!map:~%%D,1!)
        for %%D in (!fg!) do (set fg=!map:~%%D,1!)

   set /a "rgb=0x!p16[%%i]!, rri=rgb >> 16, ggi=(rgb >> 8) & 0xFF, bbi=rgb & 0xFF"

   set /a cont+=1

   set "pRGB!cont!=!p16[%%i]!"

   set "z!cont!=!bg!!fg! !"

   set /a si=%%i+1
      For /L %%j in (!si!,1,15) do (

      set fg=%%j
           for %%D in (!fg!) do (set fg=!map:~%%D,1!)

      set /a "rgb=0x!p16[%%j]!, rrj=rgb >> 16, ggj=(rgb >> 8) & 0xFF, bbj=rgb & 0xFF"

      set /a cont+=1
             set /a "pR=(ddr=rrj-rri)/4+rri, pG=(ddg=ggj-ggi)/4+ggi, pB=(ddb=bbj-bbi)/4+bbi"
      call :RGBHex
      set "z!cont!=!bg!!fg!°"
   
           set /a cont+=1
           Set /a "pR=ddr/2+rri, pG=ddg/2+ggi, pB=ddb/2+bbi"
      call :RGBHex
      set "z!cont!=!bg!!fg!±"

      set /a cont+=1
      Set /a "pR=ddr*3/4+rri, pG=ddg*3/4+ggi, pB=ddb*3/4+bbi"
      call :RGBHex
      set "z!cont!=!bg!!fg!²"

   )
  )

  set pal16_4.size=!cont!

  for /L %%i in (0,1,15) do set "p16[%%i]="


  :: Demo of colors. This show HALF number of colors. The WHITE colors are not show!

  Set /a s=10000, v1=10000

  For /L %%h in (0,15,360) do (
   For /L %%v in (10000,-400,0) do call :plot_HSV_RGB %%h !s! %%v
   if !v1! geq 0 (   call :plot 0 0 0
         call :plot 0 0 0
         For /L %%l in (0,8,360) do call :plot_HSV_RGB %%l !s! !v1!
         set /a v1=v1-500 )
   echo(
  )

  echo(

  popd
  pause

exit /b

:::::::::::::::::::::::::::::::::::::::::::
:Plot_HSV_RGB H S V

rem H=0..360 S=0..10000 V=0..10000

set /a H=%1, S=%2, V=%3

rem When 0 <= H < 360, 0 <= S <= 1 and 0 <= V <= 1:

if !H! equ 360 set /a H=0

if !H! lss 0 echo ERROR! & goto :EOF

set /a "h1=h*10000/60, mm = (h1 %% 20000) - 10000"

if !mm! lss 0 set /a mm=-mm

set /a C = (V * S) / 10000

set /a "X = C *(10000 - mm)/10000 , m = V - C"

rem (R,G,B) = (R'+m, G'+m, B'+m)

if !H! lss 60 (set /a R=C+m, G=X+m, B=0+m) else (
   if !H! lss 120 (set /a R=X+m, G=C+m, B=0+m) else (
      if !H! lss 180 (set /a R=0+m, G=C+m, B=X+m) else (
         if !H! lss 240 (set /a R=0+m, G=X+m, B=C+m) else (
            if !H! lss 300 (set /a R=X+m, G=0+m, B=C+m) else (
               if !H! lss 360 (set /a R=C+m, G=0+m, B=X+m) else (echo ERROR!)
            )
         )
      )
   )
)

set /a "R=R*255/10000, G=G*255/10000, B=B*255/10000"

call :Plot !R! !G! !B!

exit /b

:::::::::::::::::::::::::::::::::::::::::::
:plot R G B
  set /a "AArt=%1, AAgt=%2, AAbt=%3"
  set /a dm=256*256*256, fg=-1, bg=-1, ind=-1

  For /L %%i in (0,1,!pal16_4.size!) do (

   set /a "AAArgb=0x!pRGB%%i!, d=(AArt-(AAArgb >> 16))*(AArt-(AAArgb >> 16))+(AAgt-((AAArgb >> 8) & 0xFF))*(AAgt-((AAArgb >> 8) & 0xFF))+(AAbt-(AAArgb & 0xFF))*(AAbt-(AAArgb & 0xFF))"

   if !dm! gtr !d! set /a dm=d, ind=%%i
  )

  for %%i in (!ind!) do (
   set bg=!z%%i:~0,1!
   set fg=!z%%i:~1,1!
   set "char=!z%%i:~2,1!"
  )

  rem Carlos color version 23c. Use for compatibilty with XP
  rem call :color !bg!!fg! "!char!"

  rem jeb version don't work :(
  rem call :color_jeb !bg!!fg! "!char!"

  rem Fast color
  > colorPrint.txt (echo !char!\..\') && findstr /a:!bg!!fg! /f:colorPrint.txt "."

exit/b

:::::::::::::::::::::::::::::::::::::::::::
:RGBhex

set /a "d=pR&15,pR>>=4"
for %%D in (!d!) do set "LH=!map:~%%D,1!"
for %%D in (!pR!) do set "HH=!map:~%%D,1!"

set pRGB=!HH!!LH!

set /a "d=pG&15,pG>>=4"
for %%D in (!d!) do set "LH=!map:~%%D,1!"
for %%D in (!pG!) do set "HH=!map:~%%D,1!"

set pRGB=!pRGB!!HH!!LH!

set /a "d=pB&15,pB>>=4"
for %%D in (!d!) do set "LH=!map:~%%D,1!"
for %%D in (!pB!) do set "HH=!map:~%%D,1!"

set pRGB!cont!=!pRGB!!HH!!LH!

exit/b

:::::::::::::::::::::::::::::::::::::::::::
:color_jeb
set "param=^%~2" !
set "param=!param:"=\"!"
findstr /p /A:%1 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
exit /b

:::::::::::::::::::::::::::::::::::::::::::
:Color
:: v23c
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: This version works using Cmd /U
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
Echo(|(Pause >Nul &Findstr "^" >`)
Cmd /A /D /C Set /P "=." >>` <Nul
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do (
Cmd /A /D /C Set /P "=%%# %%#" <Nul >`.1
Copy /Y `.1 /B + `.1 /B + `.1 /B `.3 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.3 /B `.5 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.5 /B `.7 /B >Nul
)
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
For %%_ In ("&" "|" ">" "<"
) Do Set "Text=!Text:%%~_=^%%~_!"
Set /P "LF=" <` &Set "LF=!LF:~0,1!"
For %%# in ("!LF!") Do For %%_ In (
\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
For /F delims^=^ eol^= %%# in ("!Text!") Do (
If #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Cmd /A /D /C Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Del ` `.1 `.3 `.5 `.7 `.dat &Goto :Eof
Goto :__Color


Enjoy!

result:
Image

einstein1969

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: color RGB/HSV

#2 Post by npocmaka_ » 09 Apr 2016 06:50

http://blogs.microsoft.co.il/pavely/200 ... ole-fonts/
It will require native calls but console font can be changed with c#/powershell.

May be clear type can be disabled too -> https://msdn.microsoft.com/en-us/library/dd183433.aspx

I have no idea how "Smooth Edges of Screen Fonts" can be handled programmaticaly.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: color RGB/HSV

#3 Post by foxidrive » 09 Apr 2016 08:26

That's neat colouring there in the cmd window, Einstein.

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

Re: color RGB/HSV

#4 Post by einstein1969 » 27 Apr 2016 02:24

npocmaka_ wrote:http://blogs.microsoft.co.il/pavely/2009/07/23/changing-console-fonts/
It will require native calls but console font can be changed with c#/powershell.

May be clear type can be disabled too -> https://msdn.microsoft.com/en-us/library/dd183433.aspx

I have no idea how "Smooth Edges of Screen Fonts" can be handled programmaticaly.


It seem that if I enable "Clear type" automatically enable "Smooth Edges of Screen Fonts"

I haven't probed but seem that enable and disable Clear Type leave "Smooth Edges of Screen Fonts" on enable/TRUE.

Post Reply