Recent

Author Topic: Questions about Hue  (Read 2037 times)

user5

  • Sr. Member
  • ****
  • Posts: 357
Questions about Hue
« on: February 06, 2019, 05:53:38 pm »
I have several questions about the code below.
        1. What is the term "fpictureON"?
        2. What type of variable should "hue" be and what is its acceptable range?
    The code runs but it only produces a black image. Thanks.

   
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button4Click(Sender: TObject);
  2. var
  3.   t: TLazIntfImage;
  4.   mybitmap:TBitmap;
  5.   newcolor:TColor;
  6.   px,py : integer;
  7.   CurFPColor: TFPColor;
  8.   r,g,b,h,l,s : byte;
  9.   alpha : word;
  10.   hue:integer;
  11.   filename:string;
  12.   mypicture:TPicture;
  13. begin
  14.  
  15.  if opendialog1.execute = true then
  16.   begin
  17.    mypicture := TPicture.create;
  18.    mybitmap := TBitmap.create;
  19.    filename := opendialog1.FileName;
  20.    hue := 128;
  21.    try
  22.     image3.Picture.Bitmap.loadfromfile(filename);
  23.     mypicture.loadfromfile(filename);;
  24.     image3.width := mypicture.width;
  25.     image3.height := mypicture.height;
  26.     image4.width := image3.width;
  27.     image4.height := image3.height;
  28.     //t :=  fpictureON.Bitmap.CreateIntfImage;
  29.     t:=TLazIntfImage.Create(0,0);
  30.     t.loadfromfile(filename);
  31.  
  32.     t.width := image3.width;
  33.     t.height := image3.height;
  34.     for py:=0 to image3.Height-1 do begin
  35.     for px:=0 to image3.Width-1 do begin
  36.     CurFPColor := t.Colors[px,py];
  37.     newcolor := image3.canvas.pixels[px,py];
  38.     RGBtoHLS(hi(curFPColor.red),hi(curFPColor.green),hi(curFPColor.blue),h,l,s);
  39.     HLStoRGB(hue,l,s,r,g,b);
  40.     curFPColor.red := r shl 8;
  41.     curFPColor.green := g shl 8;
  42.     curFPColor.blue := b shl 8;
  43.     t.Colors[px,py] :=  curFPColor;
  44.    end;
  45.    end;
  46.  
  47.     t.savetofile('C:\Users\Arthur\Desktop\temp11\new1.bmp');
  48.     application.processmessages;
  49.     image4.Picture.bitmap.loadfromfile('C:\Users\Arthur\Desktop\temp11\new1.bmp');;
  50.    finally
  51.      t.free;
  52.    end;
  53.    mybitmap.free;
  54.    mypicture.free;
  55.   end;



Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Questions about Hue
« Reply #1 on: February 06, 2019, 06:43:26 pm »
1) Probably some public or protected field:
Code: Pascal  [Select][+][-]
  1. fpictureON: TPicture;
2) You have to look to code of HLSToRGB (I don't know what library it is). The range can be 0..100 or rather 0..255 since it is byte.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Questions about Hue
« Reply #2 on: February 06, 2019, 06:53:58 pm »
I don't know, I see that you extract the hue value into variable h, but you convert the wrong value from a different variable hue:
Code: Pascal  [Select][+][-]
  1.         RGBtoHLS(hi(curFPColor.red),hi(curFPColor.green),hi(curFPColor.blue),h,l,s);
  2.         HLStoRGB(hue,l,s,r,g,b);
  3.  

Edit:
IIRC, setting the dimensions might delete the image. Your code seems to do that.
« Last Edit: February 06, 2019, 08:04:22 pm by engkin »

 

TinyPortal © 2005-2018