Link to home
Start Free TrialLog in
Avatar of Venne
Venne

asked on

Some questions about graphics!

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.
Avatar of Venne
Venne

ASKER

it's very urgent! pls!
if I solve this problem ,i can give you 500 points more.
Avatar of kretzschmar
hi venne,

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


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

meikl
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 =:)
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 =:)
to expensive to miss, listening...
Listening...
listening....
Take a look at the component at http://www.jps.net/gfody/

Goto The "Delphi Stuff" tree node.


Kevin
just listening
Avatar of Venne

ASKER

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 ?  

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
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
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
ASKER CERTIFIED SOLUTION
Avatar of SERENNE
SERENNE

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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