🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.basm
2 messages
2 total messages Started by ADS Wed, 11 Sep 2002 08:49
Lighter and darker a pixel
#241
Author: ADS
Date: Wed, 11 Sep 2002 08:49
103 lines
4016 bytes
Hello,

I have to lighter or darker  a pixel depending of a coeff.

my problem is to do it correctly I have to convert the RGB value to HSV,
aplly the coff to the V and then back to RGB.

the code that I have in object pascal is pretty long when doing it on all
pixels of a bitmap.

Do someone has a routine in assembly for fast conversion of RGB <-> HSV?

thanks

Armindo


//
============================================================================
=======
//
============================================================================
=======



procedure RGBToHSV (const R,G,B: single; var H,S,V: single);
var Delta, Min: single;
begin
  Min := MinValue( [R, G, B] );    // USES Math
  V := MaxValue( [R, G, B] );

  Delta := V - Min;

  // Calculate saturation: saturation is 0 if r, g and b are all 0
  if V = 0.0 then S := 0 else S := Delta / V;

  if S = 0.0 then H := NaN                                   // Achromatic:
When s = 0, h is undefined
  else begin                                                 // Chromatic
    if R = V then H := 60.0 * (G - B) / Delta                // between
yellow and magenta [degrees]
    else
      if G = V then H := 120.0 + 60.0 * (B - R) / Delta      // between cyan
and yellow
      else
        if B = V then H := 240.0 + 60.0 * (R - G) / Delta;   // between
magenta and cyan
    if H < 0.0 then H := H + 360.0
  end
end ;

//
============================================================================
=======
//
============================================================================
=======

procedure HSVtoRGB (const H,S,V: single; var R,G,B: single);
var f, p, q, t, hTemp : single;                             // since H is
CONST parameter
    i : INTEGER;
begin
  if S = 0.0 then begin                                     // color is on
black-and-white center line
    if IsNaN(H) then begin
      R := V;                                               // achromatic:
shades of gray
      G := V;
      B := V
    end else raise EColorError.Create('HSVtoRGB: S = 0 and H has a value');
  end else begin                                            // chromatic
color
    if H = 360.0 then hTemp := 0.0                          // 360 degrees
same as 0 degrees
    else hTemp := H;

    hTemp := hTemp / 60;     // h is now IN [0,6[
    i := TRUNC(hTemp);        // largest integer <= h
    f := hTemp - i;                  // fractional part of h

    p := V * (1.0 - S);
    q := V * (1.0 - (S * f));
    t := V * (1.0 - (S * (1.0 - f)));

    case i of
      0: begin R := V; G := t; B := p end;
      1: begin R := q; G := V; B := p end;
      2: begin R := p; G := V; B := t end;
      3: begin R := p; G := q; B := V end;
      4: begin R := t; G := p; B := V end;
      5: begin R := V; G := p; B := q end
    end
  end
end ;

//
============================================================================
=======
//
============================================================================
=======
Re: Lighter and darker a pixel
#145
Author: ADS
Date: Thu, 12 Sep 2002 08:59
14 lines
1247 bytes

> Hi
> What version of Delphi do you use?
>
> Delphi 6 or Delphi 7 ?

D6

> Then look on the GraphUtil unit.
>
Thanks

Armindo
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads