Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-07

Color thief

13 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

aradeonas

Hi,

Today I saw?Color thief[1]?and I was impressed.I like to have something like this in my application so I reviewed the code but I dont know how to implement this in FreePascal or couldn't find anything like this in Pascal that do as good as this.

Any one know about a library like this in Pascal or Delphi or probably write similar to this?

Regards, Ara

Links:

1. https://github.com/lokesh/color-thief

http://www.fastmail.com - Choose from over 50 domains or use your own -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150708/b31b4d1f/attachment.html>

Reply by email

Michael Van Canneyt
to aradeonas
aradeonas wrote 6 lines
Hi, ? Today I saw?Color thief?and I was impressed.I like to have something like this in my application so I reviewed the code but I dont know how to implement this in FreePascal or couldn't find anything like this in Pascal that do as good as this. ? Any one know about a library like this in Pascal or Delphi or probably write similar to this?
TFPCustomImage can do this for you.
Load the image, set UsePalette:=True, and then the palette is available in the Palette property.

Michael.

Reply by email

aradeonas

Thank you.

I get exception when try to load from file and I could not debug in FPC source,debugger don't go there:

Show quoted text 8 lines
var? i: Integer;? Img: TFPCustomImage;? reader: TFPCustomImageReader; begin? Img := TFPCustomImage.Create(0, 0);? Reader := TFPReaderJPEG.Create;? img.LoadFromFile('E:\photo1.jpg',Reader); img.UsePalette := True;? for i := 0 to img.Palette.Count do? begin with TPanel.Create(Self) do? ? begin? ? ? Parent := Self;? ? ? Align := alTop;? ? ? Color:=FPColorToTColor(img.Palette.Color[i]);? ? end; end; end;

Also is there a class to do file loading with readers automatically like TImage? Tlazintfimage seems not does this . yes its not hard to implement it but as just now I find out there is many things in Lazarus and FreePascal that I'm not aware of them!

Regards, Ara

http://www.fastmail.com - Access your email from home and the web -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150708/c7235c50/attachment.html>

Reply by email

Michael Van Canneyt
to aradeonas
aradeonas wrote 23 lines
Thank you. ? I get exception when try to load from file and I could not debug in FPC source,debugger don't go there: ? var ? i: Integer; ? Img: TFPCustomImage; ? reader: TFPCustomImageReader; begin ? Img := TFPCustomImage.Create(0, 0); ? Reader := TFPReaderJPEG.Create; ? img.LoadFromFile('E:\photo1.jpg',Reader); ? img.UsePalette := True; ? for i := 0 to img.Palette.Count do ? begin ? ? with TPanel.Create(Self) do ? ? begin ? ? ? Parent := Self; ? ? ? Align := alTop; ? ? ? Color:=FPColorToTColor(img.Palette.Color[i]); ? ? end; ? end; end; ?

What is the exception you get ?

The loading should go automatically, provided you have included the necessary reader files (fpreadjpeg.pas) in your uses clause.

Michael.

Reply by email

aradeonas
to aradeonas

For now I used lovely BGRABitmap like this,thanks to its author circular.

Show quoted text 9 lines
uses?BGRABitmap, BGRABitmapTypes, BGRAColorQuantization; var? bmp:TBGRABitmap;? quant: TBGRAColorQuantizer;? i: Integer; begin bmp:=TBGRABitmap.Create('E:\photo1.jpg');? quant := TBGRAColorQuantizer.Create(bmp, acIgnore, 5);? for i := 0 to quant.ReducedPalette.Count- 1 do? begin? ? with TPanel.Create(Self) do? ? begin? ? ? Parent := Self;? ? ? Align := alTop; Color:=BGRAToColor(quant.ReducedPalette.Color[i]);? ? end; ? end;

Regards, Ara

http://www.fastmail.com - Faster than the air-speed velocity of an unladen european swallow -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150708/ec4f2c03/attachment-0001.html>

Reply by email

Michael Van Canneyt
to aradeonas
aradeonas wrote

Your program contained an error, I should have seen used TFPCustomImage. This is an abstract class. You should have used a descendent like TFPMemoryImage instead. (
the compiler warns you:
testpalette.lpr(10,37) Warning: Constructing a class "TFPCustomImage" with abstract method "SetInternalPixel" )

So:

program testpalette;
uses fpimage,fpreadjpeg;
var
   i: Integer;
   Img: TFPCustomImage;
begin
   Img := TFPMemoryImage.Create(0, 0);
   try
     img.LoadFromFile('photo1.jpg');
     img.UsePalette := True;
     for i := 0 to img.Palette.Count-1 do
       With img.Palette.Color[i] do
         Writeln(red,',',green,',',blue);
   finally
     Img.free;
   end;
end.

Works as expected.

Michael.

Reply by email

Graeme Geldenhuys
to aradeonas
aradeonas wrote
I test the code but app will wait for more than a minute and so on on "img.UsePalette := True;" and I couldn't get values.

It took a while here... just under a minute, but then it started writing out all the RGB values. So it works, but it just ain't fast because the palette is huge (as expected).

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: It took a while here... just under a minute, but then it started writing out all the RGB…
Graeme Geldenhuys wrote 7 lines
On 2015-07-08 22:30, aradeonas wrote: > I test the code but app will wait for more than a minute and so on on > "img.UsePalette := True;" and I couldn't get values. It took a while here... just under a minute, but then it started writing out all the RGB values. So it works, but it just ain't fast because the palette is huge (as expected).

Well, I have faster palette creation on my list.
But it will always take a while, since the palette will be huge in each case. A palette with too many colors is nonsense anyway.

Michael.

Reply by email