Image/Pixel-Color Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Image/Pixel-Color Operations > Additional Commands >

Image/Pixel-Color Operations

CCV. - Color Conversion

Previous Top Next


MiniRobotLanguage (MRL)

 

CCV. Command

Convert and split RGB/BGR Color

 

 

Intention

 

This command will help you to handle the Red,Green and Blue Values of 24/32 bit Colors.

There are several Modes of operation for the CCV.-Command.

 

Using the "H" and "K"-Modes, you can use the command to convert a decimal number to Hexadezimal (HEX) Color values.

 

Using other Modes (X,Y,U and V) you can use the command to generate random numbers and colors.

 

1. Convert RGB-Color to BGR Color

CCV.BGR|$$RGB|$$BGR

 

2. Convert BGR-Color to RGB Color

CCV.RGB|$$BGB|$$RGR

 

3.Convert Color value into Hexadezimal

CCV.H|$$COL|$$HEX

 

4.Swap R/B Color value and convert into Hexadezimal

CCV.K|$$COL|$$HEX

 

Here is  a Sample script, using both features:

 

$$RGB=&H00FF10

CCV.BGR|$$RGB|$$BGR

CCV.H|$$BGR|$$RES

DBP.$$RES

ENR.

' Result is: &H10FF00

 

Also you can use the CCV. command to mix the RGB-parts into one color value.

 

5. Convert RGB-Color parts to BGR Color

CCV.BGR|$$RED,$$GRN,$$BLU|$$BGR

 

6. Convert BGR-Color parts to RGB Color

CCV.RGB|$$RED,$$GRN,$$BLU|$$RGR

 

Here is  a Sample script, using this features:

 

$$RED=&H00

$$GRN=&HFF

$$BLU=&H10

CCV.BGR|$$RED,$$GRN,$$BLU|$$BGR

CCV.K|$$BGR|$$RES

DBP.$$RES

ENR.

' Result is: &H10FF00

 

Third you can use the CCV. command to split a color value into its R,G and B part.

 

7.Split Color value into RGB values

CCV.Split|$$COL|$$RED,$$GRN,$$BLU

 

8.Split Color value into BGR values

CCV.T|$$COL|$$RED,$$GRN,$$BLU

 

Here is  a Sample script, using this features:

 

$$RGB=&H00FF10

CCV.T|$$RGB|$$RED,$$GRN,$$BLU

$$RES=$$RED-$$GRN-$$BLU

DBP.$$RES

ENR.

' Result is: 0-255-16

 

Fourth CCV. can be used to generate Random colors. There are are two random-number algorithms. The results are best described with these two pictures.

 

graphic

 

Algo 1 will use total random colors that are in no relation to the previous color.

 

Here is thesample program for algo 1:

 

UCV.nbi

UCV.cov

FOR.$$Y00|1|500

 CCV.x|$$RED,$$GRN,$$BLU

 CCV.r|$$RED,$$GRN,$$BLU|$$RGB

 UCV.fgr|$$RGB

 UCV.Line|0,$$Y00|500,$$Y00

NEX.

PAU.3

ENR.

 

 

graphic

 

Algo 2 will generate random numbers that are near the previous random number by the given additional value. Here a value of 25 was used.

 

Here is the sample program for algo 2, change the value of $$VAL to see the differences:

 

'#SPI:forcewrite

$$VAL=25

UCV.nbi

UCV.cov

FOR.$$Y00|1|500

' CCV.x|$$RED,$$GRN,$$BLU

 CCV.y|$$VAL|$$RED,$$GRN,$$BLU

 CCV.r|$$RED,$$GRN,$$BLU|$$RGB

 UCV.fgr|$$RGB

 UCV.Line|0,$$Y00|500,$$Y00

NEX.

PAU.3

ENR.

 

 

graphic

 

Here a value of 35 was used.

 

 

 

 

 

Syntax

 

CCV.[P1][|P2][,P3]

 

Parameter Explanation

 

P1 - prototypes

 

RGB - convert input to RGB

    CCV.RGB|$$RED,$$GRN,$$BLU|$$COL    

    CCV.RGB|$$INP|$$COL

    You can use 3.4 System-Colors values like S1,S2 etc.

 

BGR - convert input to BGR

    CCV.BGR|$$RED,$$GRN,$$BLU|$$COL

    CCV.BGR|$$INP|$$COL

    You can use 3.4 System-Colors values like S1,S2 etc.

 

Split - Split Input into RGB-values

    CCV.Split|$$COL|$$RED,$$GRN,$$BLU

 

T - Split into RGB and Swap R and B value

    CCV.Split|$$COL|$$RED,$$GRN,$$BLU

 

H - Convert number to Hexadezimal

    CCV.H|$$NUM|$$RES

    You can use this to see the values of 3.4 System-Colors

    like S1,S2 etc. Example:

    ' Show value od System color S2

    CCV.H|S2|$$HEX

    DBP.$$HEX

 

K - Swap R and B value and Convert number to Hexadezimal

    CCV.K|$$NUM|$$RES

 

X - Generate random color (algo 1)

    CCV.X|$$RED,$$GRN,$$BLU

 

Y - Generate random color (algo 2 using $$VAL)

    CCV.Y|$$VAL|$$RED,$$GRN,$$BLU

 

U - Generate random color (algo 1)

    CCV.U|$$COL

 

V - Generate random color (algo 2 using $$VAL)

    CCV.U|$$VAL|$$COL

 

 

The parameters P2 and P3 depend on the mode of operation.

 

 

 

Example

 

'***********************************

' CCV.-Sample

'***********************************

'

CCV.RGB|&HFF,&H00,&HFF|$$RES

DBP.$$RES

CCV.S|16711935|$$RED,$$GRN,$$BLU

DBP.$$RED,$$GRN,$$BLU

ENR.

 

'***********************************

' CCV.-Sample

'***********************************

'

$$RGB=16711939

CCV.RGB|$$RGB|$$BGR

DBP.$$BGR

ENR.

 

'***********************************

' CCV.-Sample

'***********************************

'

'#SPI:forcewrite

$$VAL=35

UCV.nbi

UCV.cov

FOR.$$Y00|1|500

' CCV.x|$$RED,$$GRN,$$BLU

 CCV.y|$$VAL|$$RED,$$GRN,$$BLU

 CCV.r|$$RED,$$GRN,$$BLU|$$RGB

 UCV.fgr|$$RGB

 UCV.Line|0,$$Y00|500,$$Y00

NEX.

PAU.3

ENR.

 

 

 

 

Remarks

 

When specifying Colors as hexadecimal values, prefer using this format:

&H0FFFFFF.

  RRGGBB

If you omit the "&H0" or just use the "&H"  this may lead to strange results when the values is converted to decimal. The reason for this is::

&HFFFF is -1 (conversion to signed number using "&H")

while

&H0FFFF is 65535 (conversion to unsigned number using "&H0")

as expected.

 

 

 

Limitations:

 

-

 

 

 

See also:

 

    ! Smart Package Robot 's Pixel-Operations

    ! UCV. - Undercover Graphics

    IDP. / NDP. - If desktop dpi Setting

    IPC. / NPC. - If-Pixel-Colour

    GPC. - Get-Pixel-Colour

    ! UCV. - Undercover Graphics