Do only clear legends when modifying an extended palette.

Now we are compatible with MetaPalettes again.
Add test cases for palette extending.
Bugfix: do not use "while ($foo = next($bar))" as this skips the first element.
Merge pull request #18 from discordier/extend-palette-fix

Extend palette fix - including test cases.