rgbmono Subroutine

public subroutine rgbmono(rr, rg, rb, ri, status)

NAME

RGBMONO(3f) - [M_color] converts RGB colors to a reasonable grayscale
intensity
(LICENSE:PD)

SYNOPSIS

subroutine rgbmono(rr,rg,rb,ri,status)

 real, intent(in)  :: RR
 real, intent(in)  :: RG
 real, intent(in)  :: RB
 real, intent(out) :: RI
 integer           :: status

DESCRIPTION

RGBMONO(3f) converts RGB colors to a reasonable grayscale intensity.
This can be used to produce monochrome images from color images.
Intensity is calculated from the specified Red, Green, Blue intensities
as 0.30*R + 0.59*G + 0.11*B, as in U.S. color television systems,
NTSC encoding. Note that most devices do not have an infinite range
of monochrome intensities available.

OPTIONS

 RR      red component of the input color in the range 0 to 100
 RG      green component of the input color in the range 0 to 100
 RB      blue component of the input color in the range 0 to 100

RETURNS

 RI      grayscale intensity calculated in the range 0 to 100
 status  zero (0) if no error occurred, otherwise result is out
         of bounds

EXAMPLES

Sample:

program demo_rgbmono
use M_color, only : rgbmono
implicit none
real    :: gray
integer :: ierr
call rgbmono(100.0,  0.0,  0.0,gray,ierr); write(*,*)'red     ',gray
call rgbmono(  0.0,100.0,  0.0,gray,ierr); write(*,*)'green   ',gray
call rgbmono(  0.0,  0.0,100.0,gray,ierr); write(*,*)'blue    ',gray
call rgbmono(100.0,100.0,  0.0,gray,ierr); write(*,*)'Yellow  ',gray
call rgbmono(  0.0,100.0,100.0,gray,ierr); write(*,*)'Cyan    ',gray
call rgbmono(100.0,  0.0,100.0,gray,ierr); write(*,*)'Magenta ',gray
call rgbmono(100.0,100.0,100.0,gray,ierr); write(*,*)'White   ',gray
call rgbmono( 00.0,  0.0,  0.0,gray,ierr); write(*,*)'Black   ',gray
call rgbmono( 50.0,  0.0,  0.0,gray,ierr); write(*,*)'Maroon  ',gray
call rgbmono(100.0, 50.0, 50.0,gray,ierr); write(*,*)'Pink    ',gray
end program demo_rgbmono

Results:

 red        30.0000019
 green      58.9999962
 blue       11.0000000
 Yellow     89.0000000
 Cyan       70.0000000
 Magenta    41.0000000
 White      100.000000
 Black      0.00000000
 Maroon     15.0000010
 Pink       65.0000000

AUTHOR

John S. Urban

LICENSE

Public Domain

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: rr
real, intent(in) :: rg
real, intent(in) :: rb
real, intent(out) :: ri
integer, intent(out) :: status

Contents

Source Code


Source Code

subroutine rgbmono(rr,rg,rb,ri,status)

! ident_7="@(#) M_color rgbmono(3f) convert RGB colors to a reasonable grayscale"

! monochrome devices that support intensity can have intensity calculated from the specified Red, Green, Blue
! intensities as 0.30*R + 0.59*G + 0.11*B, as in US color television systems, NTSC encoding.
! Note that most devices do not have an infinite range of monochrome intensities available.

real,intent(in)      :: rr,rg,rb                ! red, green, blue, & intensity range from 0 to 100
real,intent(out)     :: ri
integer,intent(out)  :: status
   status=0
   if(rr  <  0.0 .or. rr  >  100.0 ) status = 1 !---- passive check for valid range of values.
   if(rg  <  0.0 .or. rg  >  100.0 ) status = 1 !---- passive check for valid range of values.
   if(rb  <  0.0 .or. rb  >  100.0 ) status = 1 !---- passive check for valid range of values.
   ri = 0.30*rr + 0.59*rg + 0.11*rb
end subroutine rgbmono