Solved

Some questions about graphics!

Posted on 2000-05-08
15
149 Views
Last Modified: 2010-04-04
1.How to change RGB color value to HSL color value?

2.How to reality photoshop's color effect, like "mergy" "screen" "darkness" "hard light" "soft light" etc...

I couldn't do it perfect like photoshop does when I use bitblt API's mode.

Pls some advicesor relative URL.
0
Comment
Question by:Venne
  • 3
  • 3
  • 2
  • +7
15 Comments
 

Author Comment

by:Venne
ID: 2787927
it's very urgent! pls!
if I solve this problem ,i can give you 500 points more.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2787947
hi venne,

see at
http://www.efg2.com/Lab/


specially your color conversion
http://www.efg2.com/Lab/Graphics/Colors/ShowImage.htm

meikl
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2788047
You're going to have to go down to a pixel level and modify the images directly (BitBlt's won't do the job). To keep things fast, use scanlines. As for individual effects then it all depends on what you want to do.

Let me know what you want and I'll see what I can do

The Neil =:)
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2788057
You're going to have to go down to a pixel level and modify the images directly (BitBlt's won't do the job). To keep things fast, use scanlines. As for individual effects then it all depends on what you want to do.

Let me know what you want and I'll see what I can do

The Neil =:)
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2788115
to expensive to miss, listening...
0
 
LVL 1

Expert Comment

by:bogieman_
ID: 2788338
Listening...
0
 

Expert Comment

by:ellessar
ID: 2788440
listening....
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:gallaghe
ID: 2788465
Take a look at the component at http://www.jps.net/gfody/

Goto The "Delphi Stuff" tree node.


Kevin
0
 

Expert Comment

by:Begli
ID: 2790133
just listening
0
 

Author Comment

by:Venne
ID: 2790873
Hi, TheNeil:

Thanks. I know I must do it in pixel level. But I don't know the algorithm about pixel caculating.

for example, I have a personal photo, I want use
red color mix the face skin's color in photo without changing the face's lightness and darkness. It's look like  the man is making up.

How Can I do ?  

0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2791473
Well in your example I'd suggest increasing the red elements while decreasing the green and blue. Something along the lines of:

r := r + 2;
g := g - 1;
b := b - 1;

Then make sure that all of the values are still in the range 0 to 255. Normally I'd just suggest increasing the red value so you might need to ignore the modifications to the green and blue values.

Try this:

CONST
  MaxPixelCount   =  32768;

TYPE
  pRGBArray = ^TRGBArray;
  TRGBArray = ARRAY[0..MaxPixelCount-1] OF TRGBTriple;
....

VAR
  PixelArray : TRGBArray;
....

bmpTemp.PixelFormat := pf24bit;
FOR iY := 0 TO (bmpTemp.Height - 1)
DO
BEGIN
  PixelArray := bmpTemp.Scanline[iY];
  FOR iX := 0 TO (bmpTemp.Width - 1)
  DO
  BEGIN
    Pixel := PixelArray[iX];
    r := Pixel MOD 256;
    g := (Pixel MOD 65536) DIV 256;
    b := Pixel DIV 65536;

    r := r + 2;
    IF r > 255 THEN r := 255;
    Pixel := RGB(r, g, b);
    PixelArray[iX] := Pixel;
  END;
END;

This is using scanlines as well so it's really fast. I don't know if it will solve your red face problem but this is the basic principle for doing most pixel manipulation

The Neil
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2791489
Hi Venne,

here's code to adjust an image's colors on the fly. It's advantage is that it is fast, the disadvantage that it does not care about preserving luminance.

procedure Coloring(Source: TBitmap; Red, Green, Blue: Integer);

// adjusts colors in the given bitmap according to the values passed in (useful range is -255..+255)

var Table: array[0..255]of TRGB;
    X, Y: Integer;
    I: Byte;
    TargetPixel: PRGB;

begin
  for I := 0 to 255 do
  begin
    Table[I].b := IntToByte(I + Blue);
    Table[I].g := IntToByte(I + Green);
    Table[I].r := IntToByte(I + Red);
  end;

  for Y := 0 to Source.Height - 1 do
  begin
    TargetPixel := Source.ScanLine[Y];
    for X := 0 to Source.Width - 1 do
    begin
      TargetPixel.b := Table[TargetPixel.b].b;
      TargetPixel.g := Table[TargetPixel.g].g;
      TargetPixel.r := Table[TargetPixel.r].r;
      Inc(TargetPixel);
    end;
  end;
end;


function IntToByte(Value: Integer): Byte;

begin
  if Value < 0 then Result:= 0
               else
    if Value > 255 then Result := 255
                   else Result := Value;
end;


IntToByte can be replaced by a smarter construct:

  ByteValue := Max(0, Min(255, IntValue));

See if this code is enough for your images, otherwise we can work out a special solution using a different color scheme, like HSL.

Ciao, Mike
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2794605
I remember I saw a delphi app. to do some of those effects.. it was in delphi super page I think, in full projects
or in delphi.about.com can't remember right now..
but I'm not sure if it came with source
0
 

Accepted Solution

by:
SERENNE earned 500 total points
ID: 2806444
with this you can convert RGB to HSL, HSL to RGB

var
  HSLRange : integer = 240;

// convert a HSL value into a RGB in a TColor
// HSL values are 0.0 to 1.0 double
function HSLtoRGB (H, S, L: double): TColor;

// convert a HSL value into a RGB in a TColor
// SL values are 0 to the HSLRange variable
// H value is to HSLRange-1
function HSLRangeToRGB (H, S, L : integer): TColor;

// convert a RGB value (as TColor) into HSL
// HSL values are 0.0 to 1.0 double
procedure RGBtoHSL (RGB: TColor; var H, S, L : double);

// convert a RGB value (as TColor) into HSL
// SL values are 0 to the HSLRange variable
// H value is to HSLRange-1
procedure RGBtoHSLRange (RGB: TColor; var H, S, L : integer);

implementation

function HSLtoRGB (H, S, L: double): TColor;
var
  M1,
  M2: double;

  function HueToColourValue (Hue: double) : byte;
  var
    V : double;
  begin
    if Hue < 0 then
      Hue := Hue + 1
    else
      if Hue > 1 then
        Hue := Hue - 1;

    if 6 * Hue < 1 then
      V := M1 + (M2 - M1) * Hue * 6
    else
      if 2 * Hue < 1 then
        V := M2
      else
        if 3 * Hue < 2 then
          V := M1 + (M2 - M1) * (2/3 - Hue) * 6
        else
          V := M1;
    Result := round (255 * V)
  end;

var
  R,
  G,
  B: byte;
begin
  if S = 0 then
  begin
    R := round (255 * L);
    G := R;
    B := R
  end else begin
    if L <= 0.5 then
      M2 := L * (1 + S)
    else
      M2 := L + S - L * S;
    M1 := 2 * L - M2;
    R := HueToColourValue (H + 1/3);
    G := HueToColourValue (H);
    B := HueToColourValue (H - 1/3)
  end;

  Result := RGB (R, G, B)
end;

function HSLRangeToRGB (H, S, L : integer): TColor;
begin
  Result := HSLToRGB (H / (HSLRange-1), S / HSLRange, L / HSLRange)
end;

// Convert RGB value (0-255 range) into HSL value (0-1 values)

procedure RGBtoHSL (RGB: TColor; var H, S, L : double);

  function Max (a, b : double): double;
  begin
    if a > b then
      Result := a
    else
      Result := b
  end;

  function Min (a, b : double): double;
  begin
    if a < b then
      Result := a
    else
      Result := b
  end;

var
  R,
  G,
  B,
  D,
  Cmax,
  Cmin: double;

begin
  R := GetRValue (RGB) / 255;
  G := GetGValue (RGB) / 255;
  B := GetBValue (RGB) / 255;
  Cmax := Max (R, Max (G, B));
  Cmin := Min (R, Min (G, B));

// calculate luminosity
  L := (Cmax + Cmin) / 2;

  if Cmax = Cmin then  // it's grey
  begin
    H := 0; // it's actually undefined
    S := 0
  end else begin
    D := Cmax - Cmin;

// calculate Saturation
    if L < 0.5 then
      S := D / (Cmax + Cmin)
    else
      S := D / (2 - Cmax - Cmin);

// calculate Hue
    if R = Cmax then
      H := (G - B) / D
    else
      if G = Cmax then
        H  := 2 + (B - R) /D
      else
        H := 4 + (R - G) / D;

    H := H / 6;
    if H < 0 then
      H := H + 1
  end
end;

procedure RGBtoHSLRange (RGB: TColor; var H, S, L : integer);
var
  Hd,
  Sd,
  Ld: double;
begin
  RGBtoHSL (RGB, Hd, Sd, Ld);
  H := round (Hd * (HSLRange-1));
  S := round (Sd * HSLRange);
  L := round (Ld * HSLRange);
end;
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2806546
Hi SERENNE, welcome to Experts-Exchange. I haven't not said anything in the first question you answered but this time I think it is better to say a few words.

Please, here at E-E it is common practise to give only comments instead locking a question with an answer. This is in particular important when other experts have already contributed to the question. Don't be afraid that you will not receive points if they are well earned, because the quesioner gets links for every comment to accept it as answer and can so pick a one. Additionally you have only answer one small part of the entire question.

Please be so kind and withdraw your answer. If Venne thinks your contribution is an answer to his/her question then (s)he can still accept it.

Thank you for listening.

Ciao, Mike
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now