Solved

Dimming a monitor/colours

Posted on 2001-06-06
6
371 Views
Last Modified: 2010-04-06
Help.

Does anyone know of a way to dim the monitor through code.

0
Comment
Question by:dvk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6158878
hi,
do you mean the actual brightness of the moniter/display?
i would think that would be a hardware issue specific to your graphics card.my nvidea geforce2 has a slider (in color correction control panel)to do this but the software came specific for the card.
0
 

Author Comment

by:dvk
ID: 6159650
If it can be done, then yes through the brightness.  Or another way would be to have a component that would invert colours to simulate night time - is there something out there.

I have thougth about using colours, but this would be very time consuming and would prefer it if there was already a component that did this.

0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6162370
I can help you for an image brightness :(

The code fragment below converts colors between RGB (Red, Green, Blue) and
HLS/HBS (Hue, Lightness, Saturation/Hue, Brightness, Saturation).


MORE INFORMATION


/* Color Conversion Routines --

RGBtoHLS() takes a DWORD RGB value, translates it to HLS, and stores the
results in the global vars H, L, and S. HLStoRGB takes the current values of
H, L, and S and returns the equivalent value in an RGB DWORD. The vars H, L,
and S are only written to by:


   1. RGBtoHLS (initialization)
   2. The scroll bar handlers
A point of reference for the algorithms is Foley and Van Dam, "Fundamentals
of Interactive Computer Graphics," Pages 618-19. Their algorithm is in
floating point. CHART implements a less general (hardwired ranges) integral
algorithm.
There are potential round-off errors throughout this sample. ((0.5 + x)/y)
without floating point is phrased ((x + (y/2))/y), yielding a very small
round-off error. This makes many of the following divisions look strange. */

*************************************************************************)
const
  HLSMAX = 240;         (* H,L, and S vary over 0-HLSMAX *)
  RGBMAX = 255;         (* R,G, and B vary over 0-RGBMAX *)
                        (* HLSMAX BEST IF DIVISIBLE BY 6 *)
                        (* RGBMAX, HLSMAX must each fit in a byte. *)
(* Hue is undefined if Saturation is 0 (grey-scale) *)
(* This value determines where the Hue scrollbar is *)
(* initially set for achromatic colors *)
  UNDEFINED = HLSMAX*2 div 3;

function RGBtoHLS(RGBColor: DWORD): THLSVector;
var
   R, G, B: Word;              (* input RGB values *)
   cMax, cMin: Byte;           (* max and min RGB values *)
   Rdelta,Gdelta,Bdelta: Word; (* intermediate value: % of spread from max*)
begin
   (* get R, G, and B out of DWORD *)
   R := GetRValue(RGBColor);
   G := GetGValue(RGBColor);
   B := GetBValue(RGBColor);

   (* calculate lightness *)
   cMax := UMax( UMax(R,G), B);
   cMin := UMin( UMin(R,G), B);
   with Result do
   begin
      Luminance := ( ((cMax+cMin)*HLSMAX) + RGBMAX ) div (2*RGBMAX);

      if (cMax = cMin) then          (* r:=g:=b --> achromatic case *)
      begin
         Saturation := 0;                     (* saturation *)
         Hue := UNDEFINED;             (* hue *)
      end else
      begin                        (* chromatic case *)
         (* saturation *)
         if Luminance <= (HLSMAX div 2) then
            Saturation := ( ((cMax-cMin)*HLSMAX) + ((cMax+cMin) div 2) )
div  (cMax+cMin)
         else
            Saturation := ( ((cMax-cMin)*HLSMAX) + ((2*RGBMAX-cMax-cMin) div
2) )
                div  (2*RGBMAX-cMax-cMin);

         (* hue *)
         Rdelta := ( ((cMax-R)*(HLSMAX div 6)) + ((cMax-cMin) div 2) ) div
(cMax-cMin);
         Gdelta := ( ((cMax-G)*(HLSMAX div 6)) + ((cMax-cMin) div 2) ) div
(cMax-cMin);
         Bdelta := ( ((cMax-B)*(HLSMAX div 6)) + ((cMax-cMin) div 2) ) div
(cMax-cMin);

         if R = cMax then
            Hue := Bdelta - Gdelta
         else if G = cMax then
            Hue := (HLSMAX div 3) + Rdelta - Bdelta
         else (* B = cMax *)
            Hue := ((2*HLSMAX) div 3) + Gdelta - Rdelta;

         if Hue < 0 then
            Inc(Hue, HLSMAX);
         if Hue > HLSMAX then
            Dec(Hue, HLSMAX);
      end;
   end;
end;

function HueToRGB(n1,n2,hue: Word): Word;
(* utility routine for HLStoRGB *)
begin
   (* range check: note values passed add div subtract thirds of range *)
   if hue < 0 then
      Inc(hue, HLSMAX);

   if hue > HLSMAX then
      Dec(hue, HLSMAX);

   (* return r,g, or b value from this tridrant *)
   if hue < (HLSMAX div 6) then
      Result := ( n1 + (((n2-n1)*hue+(HLSMAX div 12)) div (HLSMAX div 6)) )
else
   if hue < (HLSMAX div 2) then
      Result := n2 else
   if hue < ((HLSMAX*2) div 3) then
      Result := ( n1 + (((n2-n1)*(((HLSMAX*2) div 3)-hue)+(HLSMAX div 12))
div (HLSMAX div 6)))
   else
      Result := n1;
end;

function HLStoRGB(Hue, Luminance, Saturation: Word): TColor;
var
   R, G, B: Word;              (* RGB component values *)
   Magic1, Magic2: Word;       (* calculated magic numbers (really!) *)
begin
   if Saturation = 0 then             (* achromatic case *)
   begin
      R :=(Luminance*RGBMAX) div HLSMAX;
      G := R;
      B := R;
      if Hue <> UNDEFINED then
      begin
         (* ERROR *)
      end
   end else
   begin                    (* chromatic case *)
      (* set up magic numbers *)
      if (Luminance <= (HLSMAX div 2)) then
         Magic2 := (Luminance*(HLSMAX + Saturation) + (HLSMAX div 2)) div
HLSMAX
      else
         Magic2 := Luminance + Saturation - ((Luminance*Saturation) +
(HLSMAX div 2)) div HLSMAX;
      Magic1 := 2*Luminance-Magic2;
      (* get RGB, change units from HLSMAX to RGBMAX *)
      R := (HueToRGB(Magic1,Magic2,Hue+(HLSMAX div 3))*RGBMAX +(HLSMAX div
2)) div HLSMAX;
      G := (HueToRGB(Magic1,Magic2,Hue)               *RGBMAX +(HLSMAX div
2)) div HLSMAX;
      B := (HueToRGB(Magic1,Magic2,Hue-(HLSMAX div 3))*RGBMAX +(HLSMAX div
2)) div HLSMAX;
   end;
   Result :=  RGB(R,G,B);
end;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
f15iaf earned 100 total points
ID: 6165164
I've used a ginsonic code:
Here is the example of what you need.
This program brightens the screen.

here is unit2

unit Unit2;
interface
uses windows,math,graphics;
const
 HLSMAX = 240;         (* H,L, and S vary over 0-HLSMAX *)
 RGBMAX = 255;         (* R,G, and B vary over 0-RGBMAX *)
                       (* HLSMAX BEST IF DIVISIBLE BY 6 *)
                       (* RGBMAX, HLSMAX must each fit in a byte. *)
(* Hue is undefined if Saturation is 0 (grey-scale) *)
(* This value determines where the Hue scrollbar is *)
(* initially set for achromatic colors *)
 UNDEFINED = HLSMAX*2 div 3;
type
        THLSVector=record
                Hue,Luminance,Saturation:Word;
        end;
function RGBtoHLS(RGBColor: DWORD): THLSVector;
function HLStoRGB(Hue, Luminance, Saturation: Word): TColor;
implementation
function RGBtoHLS(RGBColor: DWORD): THLSVector;
var
  R, G, B: Word;              (* input RGB values *)
  cMax, cMin: Byte;           (* max and min RGB values *)
  Rdelta,Gdelta,Bdelta: Word; (* intermediate value: % of spread from max*)
begin
  (* get R, G, and B out of DWORD *)
  R := GetRValue(RGBColor);
  G := GetGValue(RGBColor);
  B := GetBValue(RGBColor);

  (* calculate lightness *)
  cMax := Max( Max(R,G), B);
  cMin := Min( Min(R,G), B);
  with Result do
  begin
     Luminance := ( ((cMax+cMin)*HLSMAX) + RGBMAX ) div (2*RGBMAX);

     if (cMax = cMin) then          (* r:=g:=b --> achromatic case *)
     begin
        Saturation := 0;                     (* saturation *)
        Hue := UNDEFINED;             (* hue *)
     end else
     begin                        (* chromatic case *)
        (* saturation *)
        if Luminance <= (HLSMAX div 2) then
           Saturation := ( ((cMax-cMin)*HLSMAX) + ((cMax+cMin) div 2) )
div  (cMax+cMin)
        else
           Saturation := ( ((cMax-cMin)*HLSMAX) + ((2*RGBMAX-cMax-cMin) div
2) )
               div  (2*RGBMAX-cMax-cMin);

        (* hue *)
        Rdelta := ( ((cMax-R)*(HLSMAX div 6)) + ((cMax-cMin) div 2) ) div
(cMax-cMin);
        Gdelta := ( ((cMax-G)*(HLSMAX div 6)) + ((cMax-cMin) div 2) ) div
(cMax-cMin);
        Bdelta := ( ((cMax-B)*(HLSMAX div 6)) + ((cMax-cMin) div 2) ) div
(cMax-cMin);

        if R = cMax then
           Hue := Bdelta - Gdelta
        else if G = cMax then
           Hue := (HLSMAX div 3) + Rdelta - Bdelta
        else (* B = cMax *)
           Hue := ((2*HLSMAX) div 3) + Gdelta - Rdelta;

        if Hue < 0 then
           Inc(Hue, HLSMAX);
        if Hue > HLSMAX then
           Dec(Hue, HLSMAX);
     end;
  end;
end;

function HueToRGB(n1,n2,hue: Word): DWord;
(* utility routine for HLStoRGB *)
begin
  (* range check: note values passed add div subtract thirds of range *)
  if hue < 0 then
     Inc(hue, HLSMAX);

  if hue > HLSMAX then
     Dec(hue, HLSMAX);

  (* return r,g, or b value from this tridrant *)
  if hue < (HLSMAX div 6) then
     Result := ( n1 + (((n2-n1)*hue+(HLSMAX div 12)) div (HLSMAX div 6)) )
else
  if hue < (HLSMAX div 2) then
     Result := n2 else
  if hue < ((HLSMAX*2) div 3) then
     Result := ( n1 + (((n2-n1)*(((HLSMAX*2) div 3)-hue)+(HLSMAX div 12))
div (HLSMAX div 6)))
  else
     Result := n1;
end;

function HLStoRGB(Hue, Luminance, Saturation: Word): TColor;
var
  R, G, B: Word;              (* RGB component values *)
  Magic1, Magic2: Word;       (* calculated magic numbers (really!) *)
begin
  if Saturation = 0 then             (* achromatic case *)
  begin
     R :=(Luminance*RGBMAX) div HLSMAX;
     G := R;
     B := R;
     if Hue <> UNDEFINED then
     begin
        (* ERROR *)
     end
  end else
  begin                    (* chromatic case *)
     (* set up magic numbers *)
     if (Luminance <= (HLSMAX div 2)) then
        Magic2 := (Luminance*(HLSMAX + Saturation) + (HLSMAX div 2)) div
HLSMAX
     else
        Magic2 := Luminance + Saturation - ((Luminance*Saturation) +
(HLSMAX div 2)) div HLSMAX;
     Magic1 := 2*Luminance-Magic2;
     (* get RGB, change units from HLSMAX to RGBMAX *)
     R := (HueToRGB(Magic1,Magic2,Hue+(HLSMAX div 3))*RGBMAX +(HLSMAX div
2)) div HLSMAX;
     G := (HueToRGB(Magic1,Magic2,Hue)               *RGBMAX +(HLSMAX div
2)) div HLSMAX;
     B := (HueToRGB(Magic1,Magic2,Hue-(HLSMAX div 3))*RGBMAX +(HLSMAX div
2)) div HLSMAX;
  end;
  Result :=  RGB(R,G,B);
end;

end.
 

Here is the main unit:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);stdcall;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
uses unit2;
procedure TForm1.Button1Click(Sender: TObject);stdcall;
var
        elem:array [1..28]of integer;
        col:array[1..28]of dword;
        hls:Thlsvector;
        tempr:dword;
        lm:integer;
        i:integer;
begin
        for i:=1 to 28 do
        begin
                tempr:=getsyscolor(i);
                elem[i]:=i;
                hls:=rgbtohls(tempr);
                lm:=hls.Luminance;
                lm:=lm+5;
                if(lm>240)then
                lm:=240;
                if(lm<0)then
                lm:=0;
                hls.Luminance:=lm;
                tempr:=hlstorgb(hls.Hue,hls.Luminance,hls.Saturation);
                col[i]:=tempr;
        end;
        setsyscolors(28,elem,col);
end;

end.
0
 
LVL 3

Expert Comment

by:f15iaf
ID: 6166845
if you want to dim monitor then instead of making lm:=lm+5
lm:=lm-5;
0
 

Author Comment

by:dvk
ID: 6167074
Absolutely marvellous, with a slight alteration for restoring back to default, it worked a treat.

Thanx a million.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question