Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Inverse palette conversion algorithm...
Re: Inverse palette conversion algorithm... [message #2304 is a reply to message #2301] Fri, 07 April 2006 11:16 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14265
Registered: November 2005
Ultimate Member
What a nice trick, I did not knew this one! Thanks!

As for the purpose of the code: You have truecolor raster image and you have some existing palette. You want to convert truecolor to palette (indexed).

Now in theory, you should for each color of image find closest color - by equaction (r1 - r2)^2 + (g1 - g2)^2 + (b1 - b2)^2 (where ^2 is not xor but square).

Of course, performing this calculation for each pixel would be too slow, therefore standard approach reduces original pixel depth (to 64K colors here) and provides "inverse transformation cube" - a table that can be used to perform quick lookup of palette index for each possible color.

This algorithm builds such cube. "Brute force approach" is to go through all cells of cube and find closest color from palette for it. Above implementation is almost 20x faster in the average case...

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: DLL and U++ type
Next Topic: Alpha composition OVER operator WITHOUT premultiplied alpha
Goto Forum:
  


Current Time: Tue Jul 08 14:00:02 CEST 2025

Total time taken to generate the page: 0.16315 seconds