Introduction:
I have a program that receives an image as input and does stuff.
The more colors the image has the longer it takes for the program to finish and the less visible the difference between two colors, the less important it is to have both of them.
Since I know very little about working with computer colors I have been using Photoshop to reduce the amount of colors an image has.
The goal:
To convert the program to be usable by normal people.
It will need to have some code capable of reducing the amount of colors on the images given by the users.
I've learned some color reducing theories for image compression but I don't really know how to apply them in practice with the data I have.
The need:
An algorithm that receives a list (or matrix) of sRGB colors and reduces the amount of colors on that list keeping the most information of the original image possible with the colors available.
Preferably one where a number n can be specified which is the number of colors the output will have.
Extra details
Speed is a bit more valuable than color perfection as if possible it would be nice to show the user the converted image in real time (or near real time) so they could see how the settings they chose are going to affect the result.
The user should be able to use lots of colors if desired but the main use case expected is a number between 10 and 200 colors.
I'm looking for descriptions and/or suggestions of algorithms I can learn and implement not random implemented code to copy/steal.