Color names, sort out cmake wackiness

This commit is contained in:
2021-05-09 22:26:40 -04:00
parent e05724ea53
commit ddf2bc5b42
5 changed files with 48 additions and 16 deletions

View File

@@ -27,9 +27,7 @@ set_target_properties(mazemaker_static PROPERTIES
)
install (TARGETS mazemaker_shared mazemaker_static DESTINATION ${LIB_INSTALL_DIR})
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/../include/mazemaker.h DESTINATION ${INCLUDE_INSTALL_DIR})
target_link_libraries(mazemaker_shared PUBLIC ${PNG_LIBRARIES} m)
target_include_directories(mazemaker_shared PUBLIC ${PNG_INCLUDE_DIRS} ../include)
target_include_directories(mazemaker_static PUBLIC ${PNG_INCLUDE_DIRS} ../include)
target_compile_options(mazemaker_shared PUBLIC ${PNG_CFLAGS_OTHER})
target_compile_options(mazemaker_static PUBLIC ${PNG_CFLAGS_OTHER})
target_link_options(mazemaker_shared PUBLIC -L${PNG_LIBDIR})
target_link_libraries(mazemaker_shared PUBLIC ${PNG_LIBRARIES};m)
target_link_directories(mazemaker_shared PUBLIC ${PNG_LIBRARY_DIRS})
target_include_directories(mazemaker_shared PUBLIC ${PNG_INCLUDE_DIRS};../include)
target_include_directories(mazemaker_static PUBLIC ${PNG_INCLUDE_DIRS};../include)

View File

@@ -18,15 +18,40 @@ void mazemaker_options_free(mazeoptions_t* options) {
free(options);
}
static int interpretColorName(char const* color_desc, rgb_color_t dst) {
if (0 == strcasecmp(color_desc, "black")) { dst[0] = dst[1] = dst[2] = 0; }
else if (0 == strcasecmp(color_desc, "white")) { dst[0] = dst[1] = dst[2] = 0xff; }
else if (0 == strcasecmp(color_desc, "red")) { dst[0] = 0xff; dst[1] = dst[2] = 0; }
else if (0 == strcasecmp(color_desc, "blue")) { dst[0] = dst[1] = 0; dst[2] = 0xff; }
else if (0 == strcasecmp(color_desc, "green")) { dst[0] = dst[2] = 0; dst[1] = 0xff; }
else if (0 == strcasecmp(color_desc, "yellow")) { dst[2] = 0; dst[0] = dst[1] = 0xff; }
else if ((0 == strcasecmp(color_desc, "magenta")) ||
(0 == strcasecmp(color_desc, "purple"))) { dst[1] = 0; dst[0] = dst[2] = 0xff; }
else if (0 == strcasecmp(color_desc, "cyan")) { dst[0] = 0; dst[1] = dst[2] = 0xff; }
else if (0 == strcasecmp(color_desc, "orange")) { dst[0] = 0xff; dst[1] = 0x7f; dst[2] = 0; }
else if (0 == strcasecmp(color_desc, "brown")) { dst[0] = 0x7f; dst[1] = 0x3f; dst[2] = 0; }
else if ((0 == strcasecmp(color_desc, "gray")) ||
(0 == strcasecmp(color_desc, "grey"))) { dst[0] = dst[1] = dst[2] = 0x7f; }
else if (0 == strcasecmp(color_desc, "darkblue")) { dst[0] = dst[1] = 0; dst[2] = 0x7f; }
else if (0 == strcasecmp(color_desc, "darkgreen")) { dst[0] = dst[2] = 0; dst[1] = 0x7f; }
else if (0 == strcasecmp(color_desc, "darkred")) { dst[0] = 0x7f; dst[1] = dst[2] = 0; }
else if (0 == strcasecmp(color_desc, "pink")) { dst[0] = 0xff; dst[1] = 0xa0; dst[2] = 0xbf; }
else if ((0 == strcasecmp(color_desc, "darkmagenta")) ||
(0 == strcasecmp(color_desc, "darkpurple"))) { dst[1] = 0; dst[0] = dst[2] = 0x7f; }
else if (0 == strcasecmp(color_desc, "darkcyan")) { dst[0] = 0; dst[1] = dst[2] = 0x7f; }
else return -1;
return 0;
}
static int stringToColor(char const* color_desc, rgb_color_t dst) {
if (color_desc[0] != '#') return -1; // bad format
if (color_desc[0] != '#') return interpretColorName(color_desc, dst);
size_t l;
for (l = 1; color_desc[l] != '\0'; l++) if (!isxdigit(color_desc[l])) return -1; // bad format
if ((l != 4) && (l != 7)) return -1; // bad format
char x2[3] = { 0, 0, 0};
char x2[3] = { 0, 0, 0 };
if (l == 4) {
x2[0] = x2[1] = color_desc[1];
sscanf(x2, "%hhx", &dst[0]);