Added color_is_valid() function to know if a color is inside the valid range of palette indices.

This commit is contained in:
David Capello 2010-06-01 22:03:44 -03:00
parent 70240c9639
commit c975930fc3
2 changed files with 17 additions and 0 deletions

View File

@ -139,6 +139,22 @@ int color_type(color_t color)
return GET_COLOR_TYPE(color);
}
// Returns false only if the color is a index and it is outside the
// valid range (outside the maximum number of colors in the current
// palette)
bool color_is_valid(color_t color)
{
switch (GET_COLOR_TYPE(color)) {
case COLOR_TYPE_INDEX: {
size_t i = GET_COLOR_DATA_INDEX(color);
return (i >= 0 && i < get_current_palette()->size());
}
}
return true;
}
bool color_equals(color_t c1, color_t c2)
{
return

View File

@ -39,6 +39,7 @@ char *color_to_string(color_t color, char *buf, int size);
color_t string_to_color(const char *str);
int color_type(color_t color);
bool color_is_valid(color_t color);
bool color_equals(color_t c1, color_t c2);
color_t color_mask();