Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Re: RGB function

Jugoslav_Dujic
Valued Contributor II
1,130 Views
- You can "roll your own":
integer function MyRGB(iR, iG, iB)
integer, intent(in):: iR, iG, iB
MyRGB = ISHL(iB,16) + ISHL(iG,8) + iR
end function MyRGB


- or use explicit conversion at input, e.g. RGB(90_1, 90_1, 90_1) or RGB(INT1(iR), INT1(iG), INT1(iB))

- or, as I prefer, simply use hex-form instead (#BBGGRR). That won't make fortran-95 standards checking happy though. IIRC form Z'BBGGRR' is also not allowed in expressions.

Just to remind Steve about "stylesheet" thingo ;-). ("Stylesheets" are user-defined subsets of language extensions, where user can control what compiler will complain about. That's on users' wish list for quite a time).
0 Kudos
3 Replies
david_jones
Beginner
1,130 Views
There is the function RGBTOINTEGER in DFLIB that may be of some help, as it takes integer*4 arguments to generate the single RGB value. It is doc'd in the usual online help.

David Jones
0 Kudos
Intel_C_Intel
Employee
1,130 Views
If it doesn't like 255, try -1. I think that works
out to be all 1's in binary based on 2's complement
representation: 01 becomes FE, plus 1 becomes FF.
0 Kudos
llynisa
Beginner
1,130 Views
FWIW (and it may not be directly relevant to this topic, where custom colours are probably what is wanted), I got fed up with hacking around the hexadecimals. Because I normally want standard colours, but with a wider range than those from DFlib, I took the HTML Color Table and derived a CVF-compatible list (I still do not understand why CVF refers to RGB colours when they use BGR). So now I can use WHITE as a colour name instead of $HIWHITE.

The module is too long to post here, so I just give some parts of it below. If anyone would like the complete module, E-mail me at:
alan.cruttenden@baesystems.com

Alan
MODULE CVFColours
!
! This module declares and sets the 140 colours used in the HTML Color Table,
! and has reset the colour values for CVF in B, G, R order, compared to the
! order for HTML Color Table, where they are R, G, B.  Colour names are
! the same as for HTML.
! Contents are:
! 1. Integer(4)   Colour Names and values
! 2. Character*20 ColourNames array
! 3, Integer(4)   ColourNumbers array
! 4. Integer(4)   TextBorW array indicating whether Black or White displays
!                 text better on a background of the ColourNumber colour.
! 
integer(4), parameter :: ALICEBLUE            = #FFF8F0
integer(4), parameter :: ANTIQUEWHITE         = #D7EBFA
integer(4), parameter :: AQUA                 = #FFFF00
integer(4), parameter :: AQUAMARINE           = #D4FF7F
integer(4), parameter :: AZURE                = #FFFFF0
!
!
character*20, parameter :: ColourNames(140) = (/  &
'ALICEBLUE           ', & ! ColourNumber(  1) = #FFF8F0
'ANTIQUEWHITE        ', & ! ColourNumber(  2) = #D7EBFA
'AQUA                ', & ! ColourNumber(  3) = #FFFF00
'AQUAMARINE          ', & ! ColourNumber(  4) = #D4FF7F
'AZURE               ', & ! ColourNumber(  5) = #FFFFF0
!
!
integer(4), parameter :: ColourNumbers(140) = (/ &
#FFF8F0, & !ColourName(  1) = 'ALICEBLUE           '
#D7EBFA, & !ColourName(  2) = 'ANTIQUEWHITE        '
#FFFF00, & !ColourName(  3) = 'AQUA                '
#D4FF7F, & !ColourName(  4) = 'AQUAMARINE          '
#FFFFF0, & !ColourName(  5) = 'AZURE               '
!
! 0 = Black, 1 = White
integer(4), parameter :: TextBorW(140) = (/ &
0,0,0,0,0,0,0,1,0,1, 1,1,0,0,0,0,0,0,0,0, 0,1,0,0,0,1,0,1,1,0, &
1,0,0,0,1,1,0,1,0,0, 0,1,1,0,0,0,0,0,0,0, 0,0,0,0,0,0,1,0,0,0, &
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 1,0,1,1,1,0,1,0,0,0, &
1,0,0,0,0,1,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,1,0,0,1,1,0,0,0, &
0,0,0,0,1,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0 /)
0 Kudos
Reply