diff --git a/include/bu/mime.h b/include/bu/mime.h index 661ddb160db..c31d056b4f8 100644 --- a/include/bu/mime.h +++ b/include/bu/mime.h @@ -56,7 +56,7 @@ __BEGIN_DECLS * was found. It is the responsibility of the caller to cast * the return int to the correct mime_CONTEXT_t type. */ -BU_EXPORT extern int bu_file_mime(const char *ext, bu_mime_context_t context); +BU_EXPORT extern int bu_file_mime(const char *ext, long context); /** @@ -67,7 +67,7 @@ BU_EXPORT extern int bu_file_mime(const char *ext, bu_mime_context_t context); * containing the extensions if a result was found. * It is the responsibility of the caller to free the returned string. */ -BU_EXPORT extern const char *bu_file_mime_ext(int t, bu_mime_context_t context); +BU_EXPORT extern const char *bu_file_mime_ext(int t, long context); /** @@ -78,7 +78,7 @@ BU_EXPORT extern const char *bu_file_mime_ext(int t, bu_mime_context_t context); * returns NULL if no match was found, or a string if a result was found. * It is the responsibility of the caller to free the returned string. */ -BU_EXPORT extern const char *bu_file_mime_str(int t, bu_mime_context_t context); +BU_EXPORT extern const char *bu_file_mime_str(int t, long context); /** diff --git a/include/gcv/api.h b/include/gcv/api.h index ab61352acab..19b56f06715 100644 --- a/include/gcv/api.h +++ b/include/gcv/api.h @@ -147,7 +147,7 @@ struct gcv_filter { * FIXME: input/output plugins conceivably could be something * other than geometry (e.g., png input or csv output). */ - const bu_mime_model_t mime_type; + const long mime_type; /* For plugins supporting multiple file types, call this to * process them. diff --git a/include/icv/io.h b/include/icv/io.h index 78dbc84219f..e9ccd2db50f 100644 --- a/include/icv/io.h +++ b/include/icv/io.h @@ -83,7 +83,7 @@ ICV_EXPORT extern int icv_destroy(icv_image_t *bif); * Returns 1 if an image size was identified, zero otherwise. * */ -ICV_EXPORT extern int icv_image_size(const char *label, size_t dpi, size_t data_size, bu_mime_image_t type, size_t *widthp, size_t *heightp); +ICV_EXPORT extern int icv_image_size(const char *label, size_t dpi, size_t data_size, long type, size_t *widthp, size_t *heightp); /** * Load a file into an ICV struct. For most formats, this will be @@ -108,7 +108,7 @@ ICV_EXPORT extern int icv_image_size(const char *label, size_t dpi, size_t data_ * program. * @return A newly allocated struct holding the loaded image info. */ -ICV_EXPORT extern icv_image_t *icv_read(const char *filename, bu_mime_image_t format, size_t width, size_t height); +ICV_EXPORT extern icv_image_t *icv_read(const char *filename, long format, size_t width, size_t height); /** * Saves Image to a file or streams to stdout in respective format @@ -120,7 +120,7 @@ ICV_EXPORT extern icv_image_t *icv_read(const char *filename, bu_mime_image_t fo * @param format Specific format of the file to be written. * @return on success 0, on failure -1 with log messages. */ -ICV_EXPORT extern int icv_write(icv_image_t *bif, const char*filename, bu_mime_image_t format); +ICV_EXPORT extern int icv_write(icv_image_t *bif, const char*filename, long format); /** * Write an image line to the data of ICV struct. Can handle unsigned diff --git a/src/conv/3dm/3dm-g.c b/src/conv/3dm/3dm-g.c index fcaec55b418..6302a8d98ff 100644 --- a/src/conv/3dm/3dm-g.c +++ b/src/conv/3dm/3dm-g.c @@ -35,13 +35,13 @@ static const struct gcv_filter * -find_filter(enum gcv_filter_type filter_type, bu_mime_model_t mime_type, const char *data) +find_filter(enum gcv_filter_type filter_type, long mime_type, const char *data) { const struct gcv_filter * const *entry; const struct bu_ptbl * const filters = gcv_list_filters(); for (BU_PTBL_FOR(entry, (const struct gcv_filter * const *), filters)) { - bu_mime_model_t emt = (*entry)->mime_type; + long emt = (*entry)->mime_type; if ((*entry)->filter_type != filter_type) continue; if ( (emt != BU_MIME_MODEL_AUTO) && (emt == mime_type)) return *entry; if ( (emt == BU_MIME_MODEL_AUTO) && ((*entry)->data_supported && data && (*(*entry)->data_supported)(data)) ) return *entry; diff --git a/src/conv/gcv/gcv.c b/src/conv/gcv/gcv.c index 7e43780a291..d13109e8ab7 100644 --- a/src/conv/gcv/gcv.c +++ b/src/conv/gcv/gcv.c @@ -186,7 +186,7 @@ static int parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt, const char *input) { int type_int = 0; - bu_mime_model_t type = BU_MIME_MODEL_UNKNOWN; + long type = BU_MIME_MODEL_UNKNOWN; struct bu_vls format_cpy = BU_VLS_INIT_ZERO; struct bu_vls path = BU_VLS_INIT_ZERO; @@ -206,8 +206,8 @@ parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt, /* If we have an explicit option, that overrides any other format specifiers */ if (opt) { - type_int = bu_file_mime(opt, BU_MIME_MODEL); - type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_model_t)type_int; + type_int = bu_file_mime(opt, BU_MIME_AUTO); + type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (long)type_int; if (type == BU_MIME_MODEL_UNKNOWN) { /* Have prefix, but doesn't result in a known format - that's an error */ if (slog) @@ -223,8 +223,8 @@ parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt, * find out if it maps to a valid type */ if (type == BU_MIME_MODEL_UNKNOWN && format) { /* Yes - see if the prefix specifies a model format */ - type_int = bu_file_mime(bu_vls_addr(format), BU_MIME_MODEL); - type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_model_t)type_int; + type_int = bu_file_mime(bu_vls_addr(format), BU_MIME_AUTO); + type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (long)type_int; if (type == BU_MIME_MODEL_UNKNOWN) { /* Have prefix, but doesn't result in a known format - that's an error */ if (slog) @@ -238,8 +238,8 @@ parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt, /* If we don't already have a type and we were passed a format string, give it a try */ if (type == BU_MIME_MODEL_UNKNOWN && format && bu_vls_strlen(&format_cpy) > 0) { bu_vls_sprintf(format, "%s", bu_vls_addr(&format_cpy)); - type_int = bu_file_mime(bu_vls_addr(&format_cpy), BU_MIME_MODEL); - type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_model_t)type_int; + type_int = bu_file_mime(bu_vls_addr(&format_cpy), BU_MIME_AUTO); + type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (long)type_int; if (type == BU_MIME_MODEL_UNKNOWN) { /* Have prefix, but doesn't result in a known format - that's an error */ if (slog) @@ -252,8 +252,8 @@ parse_model_string(struct bu_vls *format, struct bu_vls *slog, const char *opt, /* If we have no prefix or the prefix didn't map to a model type, try file extension */ if (type == BU_MIME_MODEL_UNKNOWN && extract_path(&path, input)) { if (bu_path_component(format, bu_vls_addr(&path), BU_PATH_EXT)) { - type_int = bu_file_mime(bu_vls_addr(format), BU_MIME_MODEL); - type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_model_t)type_int; + type_int = bu_file_mime(bu_vls_addr(format), BU_MIME_AUTO); + type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (long)type_int; if (type == BU_MIME_MODEL_UNKNOWN) { /* Have file extension, but doesn't result in a known format - that's an error */ if (slog) @@ -315,13 +315,13 @@ static int model_mime(struct bu_vls *msg, size_t argc, const char **argv, void *set_mime) { int type_int; - bu_mime_model_t type = BU_MIME_MODEL_UNKNOWN; - bu_mime_model_t *set_type = (bu_mime_model_t *)set_mime; + long type = BU_MIME_MODEL_UNKNOWN; + long *set_type = (long *)set_mime; BU_OPT_CHECK_ARGV0(msg, argc, argv, "mime format"); - type_int = bu_file_mime(argv[0], BU_MIME_MODEL); - type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_model_t)type_int; + type_int = bu_file_mime(argv[0], BU_MIME_AUTO); + type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (long)type_int; if (type == BU_MIME_MODEL_UNKNOWN) { if (msg) { bu_vls_sprintf(msg, "Error - unknown geometry file type: %s \n", argv[0]); @@ -361,8 +361,8 @@ help(struct bu_vls *UNUSED(msg), size_t argc, const char **argv, void *set_var) static int do_conversion( struct bu_vls *messages, - const char *in_path, bu_mime_model_t in_type, - const char *out_path, bu_mime_model_t out_type, + const char *in_path, long in_type, + const char *out_path, long out_type, size_t in_argc, const char **in_argv, size_t out_argc, const char **out_argv) { @@ -372,7 +372,7 @@ do_conversion( struct gcv_context context; for (BU_PTBL_FOR(entry, (const struct gcv_filter * const *), filters)) { - bu_mime_model_t emt = (*entry)->mime_type; + long emt = (*entry)->mime_type; if ((*entry)->filter_type == GCV_FILTER_READ) { if (!in_filter && (emt != BU_MIME_MODEL_AUTO) && (emt == in_type)) in_filter = *entry; @@ -385,16 +385,16 @@ do_conversion( if (!out_filter && (emt != BU_MIME_MODEL_AUTO) && (emt == out_type)) out_filter = *entry; if (!out_filter && (emt == BU_MIME_MODEL_AUTO) && - ((*entry)->data_supported && (*(*entry)->data_supported)(bu_file_mime_str(out_type, BU_MIME_MODEL)))) { + ((*entry)->data_supported && (*(*entry)->data_supported)(bu_file_mime_str(out_type, BU_MIME_AUTO)))) { out_filter = *entry; } } } if (!in_filter) - bu_vls_printf(messages, "No filter for %s\n", bu_file_mime_str(in_type, BU_MIME_MODEL)); + bu_vls_printf(messages, "No filter for %s\n", bu_file_mime_str(in_type, BU_MIME_AUTO)); if (!out_filter) - bu_vls_printf(messages, "No filter for %s\n", bu_file_mime_str(out_type, BU_MIME_MODEL)); + bu_vls_printf(messages, "No filter for %s\n", bu_file_mime_str(out_type, BU_MIME_AUTO)); if (!in_filter || !out_filter) return 0; @@ -435,8 +435,8 @@ main(int ac, const char **av) int fmt = 0; int ret = 0; - static bu_mime_model_t in_type = BU_MIME_MODEL_UNKNOWN; - static bu_mime_model_t out_type = BU_MIME_MODEL_UNKNOWN; + static long in_type = BU_MIME_MODEL_UNKNOWN; + static long out_type = BU_MIME_MODEL_UNKNOWN; static struct fmt_opts in_only_opts; static struct fmt_opts out_only_opts; @@ -630,13 +630,13 @@ main(int ac, const char **av) /* Find out what input file type we are dealing with */ if (in_type == BU_MIME_MODEL_UNKNOWN) { fmt = parse_model_string(&in_format, &slog, in_fmt, bu_vls_addr(&in_path_raw)); - in_type = (fmt < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_model_t)fmt; + in_type = (fmt < 0) ? BU_MIME_MODEL_UNKNOWN : (long)fmt; in_fmt = NULL; } /* Identify output file type */ if (out_type == BU_MIME_MODEL_UNKNOWN) { fmt = parse_model_string(&out_format, &slog, out_fmt, bu_vls_addr(&out_path_raw)); - out_type = (fmt < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_model_t)fmt; + out_type = (fmt < 0) ? BU_MIME_MODEL_UNKNOWN : (long)fmt; out_fmt = NULL; } @@ -663,8 +663,8 @@ main(int ac, const char **av) /* If we've gotten this far, we know enough to try to convert. Until we * hook in conversion calls to libgcv, print a summary of the option * parsing results for debugging. */ - in_fmt = bu_file_mime_str((int)in_type, BU_MIME_MODEL); - out_fmt = bu_file_mime_str((int)out_type, BU_MIME_MODEL); + in_fmt = bu_file_mime_str((int)in_type, BU_MIME_AUTO); + out_fmt = bu_file_mime_str((int)out_type, BU_MIME_AUTO); if (in_fmt) { bu_log("Input file format: %s\n", in_fmt); } else { diff --git a/src/libbu/mime.cmake b/src/libbu/mime.cmake index a35dde78e58..f636b3d08b2 100644 --- a/src/libbu/mime.cmake +++ b/src/libbu/mime.cmake @@ -123,34 +123,48 @@ foreach(line ${TYPES}) endforeach(line ${TYPES}) # HEADER with typedefs - +set(a 0) list(GET ACTIVE_TYPES 0 FIRST_TYPE) -set(mcstr "typedef enum {") +set(mcstr "${mcstr}\n#define BU_MIME_UNKNOWN ${a}\n") +math(EXPR a "${a}+1") foreach(context ${ACTIVE_TYPES}) string(TOUPPER "${context}" c) if("${context}" STREQUAL "${FIRST_TYPE}") - set(mcstr "${mcstr}\n BU_MIME_${c} = 0,") + set(mcstr "${mcstr}#define BU_MIME_${c} ${a}") + math(EXPR a "${a}+1") else("${context}" STREQUAL "${FIRST_TYPE}") - set(mcstr "${mcstr}\n BU_MIME_${c},") + set(mcstr "${mcstr}\n#define BU_MIME_${c} ${a}") + math(EXPR a "${a}+1") endif("${context}" STREQUAL "${FIRST_TYPE}") endforeach(context ${ACTIVE_TYPES}) -set(mcstr "${mcstr}\n BU_MIME_UNKNOWN") -set(mcstr "${mcstr}\n} bu_mime_context_t;\n\n") +set(mcstr "${mcstr}\n#define BU_MIME_AUTO ${a}") +math(EXPR a "${a}+1") +set(mcstr "${mcstr}\n") set(h_contents "${h_contents}\n${mcstr}") +set(b 1) +list(GET ACTIVE_TYPES 0 FIRST_ACTIVE_TYPE) foreach(c ${ACTIVE_TYPES}) - set(enum_str "typedef enum {") list(SORT ${c}_types) + list(GET ${FIRST_ACTIVE_TYPE}_types 0 FIRST_TYPE) string(TOUPPER "${c}" c_u) # Default first enum for all types is an auto type - set(enum_str "${enum_str}\n BU_MIME_${c_u}_AUTO,") - foreach(type ${${c}_types}) - set(enum_str "${enum_str}\n BU_MIME_${type},") - endforeach(type ${${c}_types}) - set(enum_str "${enum_str}\n BU_MIME_${c_u}_UNKNOWN") - set(enum_str "${enum_str}\n} bu_mime_${c}_t;\n\n") - set(h_contents "${h_contents}\n${enum_str}") + if("${c_u}" STREQUAL "${FIRST_TYPE}") + set(enum_str "${enum_str}\n#define BU_MIME_${c_u}_AUTO ${b}") + math(EXPR b "${b}+1") + else("${c_u}" STREQUAL "${FIRST_TYPE}") + set(enum_str "${enum_str}\n#define BU_MIME_${c_u}_AUTO ${b}") + math(EXPR b "${b}+1") + foreach(type ${${c}_types}) + set(enum_str "${enum_str}\n#define BU_MIME_${type} ${b}") + math(EXPR b "${b}+1") + endforeach(type ${${c}_types}) + set(enum_str "${enum_str}\n#define BU_MIME_${c_u}_UNKNOWN ${b}") + math(EXPR b "${b}+1") + endif("${c_u}" STREQUAL "${FIRST_TYPE}") endforeach(c ${ACTIVE_TYPES}) +set(enum_str "${enum_str}\n") +set(h_contents "${h_contents}\n${enum_str}") set(h_contents "${h_contents}\n__END_DECLS\n") set(h_contents "${h_contents}\n#endif /*BU_MIME_TYPES_H*/\n") @@ -168,7 +182,7 @@ foreach(c ${ACTIVE_TYPES}) endforeach(c ${ACTIVE_TYPES}) # Public C mapping function - extension to type -set(mcstr "\nint\nbu_file_mime(const char *ext, bu_mime_context_t context)\n{") +set(mcstr "\nint\nbu_file_mime(const char *ext, long context)\n{") set(mcstr "${mcstr}\n switch (context) {\n") foreach(context ${ACTIVE_TYPES}) string(TOUPPER "${context}" c) @@ -176,6 +190,14 @@ foreach(context ${ACTIVE_TYPES}) set(mcstr "${mcstr} return mime_${context}(ext);\n") set(mcstr "${mcstr} break;\n") endforeach(context ${ACTIVE_TYPES}) +set(mcstr "${mcstr} case BU_MIME_AUTO:\n") +foreach(context ${ACTIVE_TYPES}) + string(TOUPPER "${context}" c) + set(mcstr "${mcstr} if (mime_${context}(ext) != -1){\n") + set(mcstr "${mcstr} return mime_${context}(ext);\n") + set(mcstr "${mcstr} }\n") +endforeach(context ${ACTIVE_TYPES}) +set(mcstr "${mcstr} break;\n") set(mcstr "${mcstr} default:\n") set(mcstr "${mcstr} return -1;\n") set(mcstr "${mcstr} break;\n") @@ -200,7 +222,7 @@ foreach(c ${ACTIVE_TYPES}) endforeach(c ${ACTIVE_TYPES}) # Public C mapping function - type to string -set(mcstr "\nconst char *\nbu_file_mime_str(int t, bu_mime_context_t context)\n{") +set(mcstr "\nconst char *\nbu_file_mime_str(int t, long context)\n{") set(mcstr "${mcstr}\n switch (context) {\n") foreach(context ${ACTIVE_TYPES}) string(TOUPPER "${context}" c) @@ -208,6 +230,14 @@ foreach(context ${ACTIVE_TYPES}) set(mcstr "${mcstr} return mime_str_${context}(t);\n") set(mcstr "${mcstr} break;\n") endforeach(context ${ACTIVE_TYPES}) +set(mcstr "${mcstr} case BU_MIME_AUTO:\n") +foreach(context ${ACTIVE_TYPES}) + string(TOUPPER "${context}" c) + set(mcstr "${mcstr} if (mime_str_${context}(t) != NULL && !BU_STR_EQUIV(\"BU_MIME_${c}_UNKNOWN\", mime_str_${context}(t))){\n") + set(mcstr "${mcstr} return mime_str_${context}(t);\n") + set(mcstr "${mcstr} }\n") +endforeach(context ${ACTIVE_TYPES}) +set(mcstr "${mcstr} break;\n") set(mcstr "${mcstr} default:\n") set(mcstr "${mcstr} return NULL;\n") set(mcstr "${mcstr} break;\n") @@ -246,7 +276,7 @@ foreach(c ${ACTIVE_TYPES}) endforeach(c ${ACTIVE_TYPES}) # Public C mapping function - type to string -set(mcstr "\nconst char *\nbu_file_mime_ext(int t, bu_mime_context_t context)\n{") +set(mcstr "\nconst char *\nbu_file_mime_ext(int t, long context)\n{") set(mcstr "${mcstr}\n switch (context) {\n") foreach(context ${ACTIVE_TYPES}) string(TOUPPER "${context}" c) @@ -254,6 +284,14 @@ foreach(context ${ACTIVE_TYPES}) set(mcstr "${mcstr} return mime_ext_${context}(t);\n") set(mcstr "${mcstr} break;\n") endforeach(context ${ACTIVE_TYPES}) +set(mcstr "${mcstr} case BU_MIME_AUTO:\n") +foreach(context ${ACTIVE_TYPES}) + string(TOUPPER "${context}" c) + set(mcstr "${mcstr} if (mime_ext_${context}(t) != NULL){\n") + set(mcstr "${mcstr} return mime_ext_${context}(t);\n") + set(mcstr "${mcstr} }\n") +endforeach(context ${ACTIVE_TYPES}) +set(mcstr "${mcstr} break;\n") set(mcstr "${mcstr} default:\n") set(mcstr "${mcstr} return NULL;\n") set(mcstr "${mcstr} break;\n") @@ -262,6 +300,35 @@ set(mcstr "${mcstr} return NULL;\n") set(mcstr "${mcstr}}\n") set(c_contents "${c_contents}\n${mcstr}") +# Public C mapping function - type to category +set(mcstr "\nlong \nbu_mime_context(long mime_id)\n{") +foreach(context ${ACTIVE_TYPES}) + string(TOUPPER "${context}" c) + set(mcstr "${mcstr}\n static long BU_MIME_${c}S[] = {\n") + foreach(type ${${context}_types}) + set(mcstr "${mcstr} BU_MIME_${type},\n") + endforeach(type ${${context}_types}) + set(mcstr "${mcstr} 0\n") + set(mcstr "${mcstr} };\n") +endforeach(context ${ACTIVE_TYPES}) +set(mcstr "${mcstr}\n static long *BU_MIME_CONTEXTS[] = {\n") +foreach(context ${ACTIVE_TYPES}) + string(TOUPPER "${context}" c) + set(mcstr "${mcstr} BU_MIME_${c}S,\n") +endforeach(context ${ACTIVE_TYPES}) +set(mcstr "${mcstr} NULL\n") +set(mcstr "${mcstr} };\n") +set(mcstr "${mcstr} for(long i=0; i<(${a}-2); i++){\n") +set(mcstr "${mcstr} while (BU_MIME_CONTEXTS[i] != 0){\n") +set(mcstr "${mcstr} if (*BU_MIME_CONTEXTS[i] == mime_id){\n") +set(mcstr "${mcstr} return i+1;\n") +set(mcstr "${mcstr} }\n") +set(mcstr "${mcstr} }\n") +set(mcstr "${mcstr} }\n") +set(mcstr "${mcstr} return 0;\n") +set(mcstr "${mcstr}}\n") +set(c_contents "${c_contents}\n${mcstr}") + file(WRITE ${mime_types_h_file_tmp} "${h_contents}") file(WRITE ${mime_c_file_tmp} "${c_contents}") diff --git a/src/libbu/tests/CMakeLists.txt b/src/libbu/tests/CMakeLists.txt index 17d713004ba..68f86f630a4 100644 --- a/src/libbu/tests/CMakeLists.txt +++ b/src/libbu/tests/CMakeLists.txt @@ -119,9 +119,9 @@ BRLCAD_ADD_TEST(NAME bu_path_component_c_sl_usr_sl_dir_sl_file_dir_core COMMAN BRLCAD_ADD_TEST(NAME bu_file COMMAND bu_test file) # tests bu/file.h API # NOTE: these test numbers correspond with the bu_mime_t enum values in include/bu/mime.h -BRLCAD_ADD_TEST(NAME bu_file_mime_dxf COMMAND bu_test file_mime dxf 5 1) # tests dxf extension in model context -BRLCAD_ADD_TEST(NAME bu_file_mime_stp COMMAND bu_test file_mime stp 5 7) # tests stp extension in model context -BRLCAD_ADD_TEST(NAME bu_file_mime_png COMMAND bu_test file_mime png 3 13) # tests png extension in image context +BRLCAD_ADD_TEST(NAME bu_file_mime_dxf COMMAND bu_test file_mime dxf 5 695) # tests dxf extension in model context +BRLCAD_ADD_TEST(NAME bu_file_mime_stp COMMAND bu_test file_mime stp 5 701) # tests stp extension in model context +BRLCAD_ADD_TEST(NAME bu_file_mime_png COMMAND bu_test file_mime png 3 645) # tests png extension in image context #BRLCAD_ADD_TEST(NAME bu_file_glob COMMAND bu_test file_glob) # runs a series of built-in unit tests diff --git a/src/libbu/tests/file_mime.c b/src/libbu/tests/file_mime.c index 59af46b3557..b1a6b4461d6 100644 --- a/src/libbu/tests/file_mime.c +++ b/src/libbu/tests/file_mime.c @@ -26,7 +26,7 @@ #include "bu.h" int -test_ext(const char *str, bu_mime_context_t context, int expected) +test_ext(const char *str, long context, int expected) { int status = 0; int type = bu_file_mime(str, context); @@ -59,7 +59,7 @@ main(int ac, char *av[]) if (context >= BU_MIME_UNKNOWN) return -1; - return test_ext(av[1], (bu_mime_context_t)context, expected); + return test_ext(av[1], (long)context, expected); } diff --git a/src/libgcv/plugins/vol/CMakeLists.txt b/src/libgcv/plugins/vol/CMakeLists.txt index 2a18432c645..1522f22553d 100644 --- a/src/libgcv/plugins/vol/CMakeLists.txt +++ b/src/libgcv/plugins/vol/CMakeLists.txt @@ -3,7 +3,7 @@ set(VOL_SRCS ) gcv_plugin_library(gcv-vol SHARED ${VOL_SRCS}) -target_link_libraries(gcv-vol libwdb librt libbu) +target_link_libraries(gcv-vol libwdb librt libbu libicv) set_property(TARGET gcv-vol APPEND PROPERTY COMPILE_DEFINITIONS BRLCADBUILD HAVE_CONFIG_H) VALIDATE_STYLE(gcv-vol "${VOL_SRCS}") PLUGIN_SETUP(gcv-vol gcv) diff --git a/src/libgcv/plugins/vol/png_read.c b/src/libgcv/plugins/vol/png_read.c index 32b18fdf950..c821cd71c9d 100644 --- a/src/libgcv/plugins/vol/png_read.c +++ b/src/libgcv/plugins/vol/png_read.c @@ -24,12 +24,21 @@ */ #include "common.h" - +#include "icv.h" +#include "bu.h" #include "gcv/api.h" #include "bu/mime.h" #include "wdb.h" +typedef unsigned char uchar; // Get a short form of unsigned char +typedef struct vol_db // Struct which stores the VOL's BW data in "vol_data" and the amount of data in "data" +{ + uchar *vol_data; + int data; +} vol_db; + struct png_read_opts{ + icv_image_t **pngs; int coloured; }; @@ -60,19 +69,101 @@ static void free_opts(void *options_data) } -static int png_read(struct gcv_context *context, const struct gcv_opts *UNUSED(gcv_options), const void *options_data, const char *source_path) +HIDDEN void make_vol(struct gcv_context *context, int num_of_files, icv_image_t **images, vol_db data) +{ + /* Some variables which have to be initialized after the for loops */ // BRLCAD database object + //int num_of_files = 1; + vect_t h = {1.0, 1.0, 5.0}; // Cell size variable of VOL + mat_t l = {1.0, 0.0, 0.0, 0.0, 0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; // matrix of VOL + + /* Make the VOL inside the database */ + mk_binunif(context->dbip->dbi_wdbp, "dbobj", data.vol_data, WDB_BINUNIF_UCHAR, data.data); // Make binary object in the database containing VOL data + mk_vol(context->dbip->dbi_wdbp, "vol", RT_VOL_SRC_OBJ, "dbobj", // Make the VOL + images[0]->width, // in the database using + images[0]->height, // the data from + num_of_files, 1, 255, h, // the binary object + (matp_t)l); +} + + +HIDDEN uchar *cat(unsigned char *dest, const unsigned char *src, int l1, int l2) { - const point_t center = {0.0, 0.0, 0.0}; - const fastf_t radius = 1.0; + unsigned char *str = (uchar *)bu_malloc(l1 + l2, "vol_data"); + for (int i = 0; i < l1; i++) + { + str[i] = dest[i]; + } + + for (int i = 0; i < l2; i++) + { + str[l1 + i] = src[i]; + } + return str; +} - const struct png_read_opts *opts = (struct png_read_opts *)options_data; - bu_log("importing from PNG file '%s'\n", source_path); - bu_log("image is coloured: %s\n", opts->coloured ? "True" : "False"); +static int png_read(struct gcv_context *context, const struct gcv_opts *UNUSED(gcv_options), const void *options_data, const char *source_paths) +{ + size_t num_png = 1; + struct bu_vls fmt_prefix = BU_VLS_INIT_ZERO; + size_t argc = 0; + const char **argv = (const char **)bu_malloc(sizeof(argv), "arguments"); + + struct png_read_opts *opts = (struct png_read_opts *)options_data; + const char **files = (const char **)bu_malloc(sizeof(files) * (argc + 1), "the filenames"); + files[0] = source_paths; + for (size_t j=0; j < argc; j++){ + bu_path_component(&fmt_prefix, argv[j], BU_PATH_EXT); + if (bu_file_mime(bu_vls_cstr(&fmt_prefix), BU_MIME_IMAGE) != -1){ + files[num_png] = argv[j]; + bu_log("%ld %ld %ld\n", num_png, j, argc); + num_png++; + } + } + + vol_db *ret = (vol_db *)bu_malloc(sizeof(ret), "data for making the vol"); // The struct variable which will store the required information for making the VOL afterwards. + int imgs_data[num_png]; // array of the amount of data per ICV images object. + opts->pngs = (icv_image_t **)bu_malloc(sizeof(opts->pngs) * num_png, "png files"); + uchar *data[num_png]; + for (size_t i = 0; i < num_png; i++){ + opts->pngs[i] = icv_read(files[i], BU_MIME_IMAGE_PNG, 0, 0); + } + for (size_t i = 0; i < num_png; i++) + { + icv_rgb2gray(opts->pngs[i], (ICV_COLOR)0, 0, 0, 0); + } + + /* Save the BW data to an array of uchar variables */ + for (size_t i = 0; i < num_png; i++) + { + data[i] = icv_data2uchar(opts->pngs[i]); + } + //data[0] = icv_data2uchar(opts->pngs); + + /* Get the amount of BW data */ + for (size_t i = 0; i < num_png; i++) + { + imgs_data[i] = opts->pngs[i]->width * opts->pngs[i]->height; + } + + ret->data = imgs_data[0]; // Amount of VOL data + ret->vol_data = data[0]; + //ret->vol_data = icv_data2uchar(opts->pngs); // Concatenated BW data of the provided PNG files + + /* Concatenate the BW data of all the files */ + for (size_t i = 1; i < num_png; i++) + { + ret->vol_data = cat(ret->vol_data, data[i], ret->data, imgs_data[i]); + ret->data += imgs_data[i]; + } + make_vol(context, num_png, opts->pngs, *ret); + bu_log("importing from PNG file '%s'\n", source_paths); mk_id(context->dbip->dbi_wdbp, "GCV plugin test"); - - mk_sph(context->dbip->dbi_wdbp, "test", center, radius); + //bu_log("%ld\n", gcv_options->unknown_argc); + //for(size_t i = 0; i< gcv_options->unknown_argc; i++){ + // bu_log("%s\n", gcv_options->unknown_argv[i]); + //} return 1; } @@ -89,7 +180,7 @@ HIDDEN int png_can_read(const char * data) const struct gcv_filter gcv_conv_png_read = { - "PNG Reader", GCV_FILTER_READ, BU_MIME_MODEL_UNKNOWN, png_can_read, + "PNG Reader", GCV_FILTER_READ, BU_MIME_IMAGE_PNG, png_can_read, create_opts, free_opts, png_read }; diff --git a/src/libged/overlay/overlay.c b/src/libged/overlay/overlay.c index e278a7105e1..4c2a563a3e2 100644 --- a/src/libged/overlay/overlay.c +++ b/src/libged/overlay/overlay.c @@ -37,13 +37,13 @@ static int image_mime(struct bu_vls *msg, size_t argc, const char **argv, void *set_mime) { int type_int; - bu_mime_image_t type = BU_MIME_IMAGE_UNKNOWN; - bu_mime_image_t *set_type = (bu_mime_image_t *)set_mime; + long type = BU_MIME_IMAGE_UNKNOWN; + long *set_type = (long *)set_mime; BU_OPT_CHECK_ARGV0(msg, argc, argv, "mime format"); type_int = bu_file_mime(argv[0], BU_MIME_IMAGE); - type = (type_int < 0) ? BU_MIME_IMAGE_UNKNOWN : (bu_mime_image_t)type_int; + type = (type_int < 0) ? BU_MIME_IMAGE_UNKNOWN : (long)type_int; if (type == BU_MIME_IMAGE_UNKNOWN) { if (msg) { bu_vls_sprintf(msg, "Error - unknown geometry file type: %s \n", argv[0]); @@ -59,7 +59,7 @@ image_mime(struct bu_vls *msg, size_t argc, const char **argv, void *set_mime) int ged_overlay_core(struct ged *gedp, int argc, const char *argv[]) { - bu_mime_image_t type = BU_MIME_IMAGE_UNKNOWN; + long type = BU_MIME_IMAGE_UNKNOWN; double size = 0.0; int clear = 0; int height = 0; /* may need to specify for some formats (such as PIX) */ @@ -218,7 +218,7 @@ ged_overlay_core(struct ged *gedp, int argc, const char *argv[]) struct bu_vls c = BU_VLS_INIT_ZERO; if (bu_path_component(&c, file_name, BU_PATH_EXT)) { int itype = bu_file_mime(bu_vls_cstr(&c), BU_MIME_IMAGE); - type = (bu_mime_image_t)itype; + type = (long)itype; } else { bu_vls_printf(gedp->ged_result_str, "no input file image type specified - need either a specified input image type or a path that provides MIME information.\n"); bu_vls_free(&c); diff --git a/src/libged/screengrab/screengrab.c b/src/libged/screengrab/screengrab.c index ad5222e754b..e0b52c03de6 100644 --- a/src/libged/screengrab/screengrab.c +++ b/src/libged/screengrab/screengrab.c @@ -37,13 +37,13 @@ static int image_mime(struct bu_vls *msg, size_t argc, const char **argv, void *set_mime) { int type_int; - bu_mime_image_t type = BU_MIME_IMAGE_UNKNOWN; - bu_mime_image_t *set_type = (bu_mime_image_t *)set_mime; + long type = BU_MIME_IMAGE_UNKNOWN; + long *set_type = (long *)set_mime; BU_OPT_CHECK_ARGV0(msg, argc, argv, "mime format"); type_int = bu_file_mime(argv[0], BU_MIME_IMAGE); - type = (type_int < 0) ? BU_MIME_IMAGE_UNKNOWN : (bu_mime_image_t)type_int; + type = (type_int < 0) ? BU_MIME_IMAGE_UNKNOWN : (long)type_int; if (type == BU_MIME_IMAGE_UNKNOWN) { if (msg) { bu_vls_sprintf(msg, "Error - unknown geometry file type: %s \n", argv[0]); @@ -70,7 +70,7 @@ ged_screen_grab_core(struct ged *gedp, int argc, const char *argv[]) struct icv_image *bif = NULL; /**< icv image container for saving images */ struct dm *dmp = NULL; struct fb *fbp = NULL; - bu_mime_image_t type = BU_MIME_IMAGE_AUTO; + long type = BU_MIME_IMAGE_AUTO; static char usage[] = "Usage: screengrab [-h] [-F] [--format fmt] [file.img]\n"; struct bu_opt_desc d[4]; diff --git a/src/libicv/fileformat.c b/src/libicv/fileformat.c index 80732bda85e..222bf9cb022 100644 --- a/src/libicv/fileformat.c +++ b/src/libicv/fileformat.c @@ -51,7 +51,7 @@ * return the string as as return type (making the int type be an int* * argument instead that gets set). */ -bu_mime_image_t +long icv_guess_file_format(const char *filename, char *trimmedname) { /* look for the FMT: header */ @@ -83,7 +83,7 @@ icv_guess_file_format(const char *filename, char *trimmedname) /* begin public functions */ icv_image_t * -icv_read(const char *filename, bu_mime_image_t format, size_t width, size_t height) +icv_read(const char *filename, long format, size_t width, size_t height) { if (format == BU_MIME_IMAGE_AUTO) { /* do some voodoo with the file magic or something... */ @@ -109,7 +109,7 @@ icv_read(const char *filename, bu_mime_image_t format, size_t width, size_t heig int -icv_write(icv_image_t *bif, const char *filename, bu_mime_image_t format) +icv_write(icv_image_t *bif, const char *filename, long format) { /* FIXME: should not be introducing fixed size buffers */ char buf[BUFSIZ] = {0}; diff --git a/src/libicv/size.c b/src/libicv/size.c index b991c87e930..b2fe6db4f07 100644 --- a/src/libicv/size.c +++ b/src/libicv/size.c @@ -170,7 +170,7 @@ struct paper_size paper_sizes[] = { size_t dpi_array[] = {72, 96, 150, 300, 2540, 4000, 0}; int -icv_image_size(const char *name, size_t udpi, size_t file_size, bu_mime_image_t img_type, size_t *widthp, size_t *heightp) +icv_image_size(const char *name, size_t udpi, size_t file_size, long img_type, size_t *widthp, size_t *heightp) { struct xy_size *sp; struct paper_size *ps; diff --git a/src/libicv/tests/crop.c b/src/libicv/tests/crop.c index df7a9ab0576..5fc1c8bada4 100644 --- a/src/libicv/tests/crop.c +++ b/src/libicv/tests/crop.c @@ -55,7 +55,7 @@ int main(int argc, char* argv[]) int inx=0, iny=0; int outx=0, outy=0; icv_image_t *bif; - bu_mime_image_t format = BU_MIME_IMAGE_AUTO; + long format = BU_MIME_IMAGE_AUTO; int urx, ury, ulx, uly, llx, lly, lrx, lry; int ret; diff --git a/src/libicv/tests/fade.c b/src/libicv/tests/fade.c index 8ed7de18799..4a25226f8a9 100644 --- a/src/libicv/tests/fade.c +++ b/src/libicv/tests/fade.c @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) int c; int inx=0, iny=0; icv_image_t *bif; - bu_mime_image_t format = BU_MIME_IMAGE_AUTO; + long format = BU_MIME_IMAGE_AUTO; double multiplier=0.2; bu_setprogname(argv[0]); diff --git a/src/libicv/tests/filter.c b/src/libicv/tests/filter.c index 2f6dc04cc76..9d28070d573 100644 --- a/src/libicv/tests/filter.c +++ b/src/libicv/tests/filter.c @@ -92,7 +92,7 @@ int main(int argc, char* argv[]) int c; int inx=0, iny=0; icv_image_t *bif; - bu_mime_image_t format = BU_MIME_IMAGE_AUTO; + long format = BU_MIME_IMAGE_AUTO; ICV_FILTER filter = ICV_FILTER_LOW_PASS; bu_setprogname(argv[0]); diff --git a/src/libicv/tests/operations.c b/src/libicv/tests/operations.c index 651948e0e7d..5f4df237ce6 100644 --- a/src/libicv/tests/operations.c +++ b/src/libicv/tests/operations.c @@ -58,7 +58,7 @@ int main(int argc, char* argv[]) int inx=0, iny=0; char *operation = NULL; icv_image_t *bif1, *bif2, *out_bif; - bu_mime_image_t format = BU_MIME_IMAGE_AUTO; + long format = BU_MIME_IMAGE_AUTO; bu_setprogname(argv[0]); diff --git a/src/libicv/tests/read_write.c b/src/libicv/tests/read_write.c index 2e0b4fb76f6..72c2066f63e 100644 --- a/src/libicv/tests/read_write.c +++ b/src/libicv/tests/read_write.c @@ -53,7 +53,7 @@ int main(int argc, char* argv[]) char *in_file = NULL; int inx=0, iny=0; icv_image_t *bif; - bu_mime_image_t format = BU_MIME_IMAGE_AUTO; + long format = BU_MIME_IMAGE_AUTO; int c; bu_setprogname(argv[0]); diff --git a/src/libicv/tests/rect.c b/src/libicv/tests/rect.c index 01d723db4ac..bf6ec88fa1f 100644 --- a/src/libicv/tests/rect.c +++ b/src/libicv/tests/rect.c @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) int xorig=0, yorig=0; int outx=0, outy=0; icv_image_t *bif; - bu_mime_image_t format=BU_MIME_IMAGE_AUTO; + long format=BU_MIME_IMAGE_AUTO; bu_setprogname(argv[0]); diff --git a/src/libicv/tests/saturate.c b/src/libicv/tests/saturate.c index 73475871eb5..4d50929d90f 100644 --- a/src/libicv/tests/saturate.c +++ b/src/libicv/tests/saturate.c @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) int inx=0, iny=0; icv_image_t *bif; double fraction = 0; - bu_mime_image_t format = BU_MIME_IMAGE_AUTO; + long format = BU_MIME_IMAGE_AUTO; bu_setprogname(argv[0]); diff --git a/src/libicv/tests/size_down.c b/src/libicv/tests/size_down.c index 7105d3ea663..332032cfe6f 100644 --- a/src/libicv/tests/size_down.c +++ b/src/libicv/tests/size_down.c @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) int inx=0, iny=0; int factor=2; icv_image_t *bif; - bu_mime_image_t format = BU_MIME_IMAGE_AUTO; + long format = BU_MIME_IMAGE_AUTO; ICV_RESIZE_METHOD method = ICV_RESIZE_SHRINK; size_t index; diff --git a/src/libicv/tests/size_up.c b/src/libicv/tests/size_up.c index 4ddc6f718b9..05739c798f0 100644 --- a/src/libicv/tests/size_up.c +++ b/src/libicv/tests/size_up.c @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) int inx=0, iny=0; int outx=0, outy=0; icv_image_t *bif; - bu_mime_image_t format = BU_MIME_IMAGE_AUTO; + long format = BU_MIME_IMAGE_AUTO; ICV_RESIZE_METHOD method = ICV_RESIZE_NINTERP; bu_setprogname(argv[0]); diff --git a/src/util/icv.cpp b/src/util/icv.cpp index 105b5a4c82f..1e358bdbdae 100644 --- a/src/util/icv.cpp +++ b/src/util/icv.cpp @@ -70,13 +70,13 @@ int image_mime(struct bu_vls *msg, size_t argc, const char **argv, void *set_mime) { int type_int; - bu_mime_image_t type = BU_MIME_IMAGE_UNKNOWN; - bu_mime_image_t *set_type = (bu_mime_image_t *)set_mime; + long type = BU_MIME_IMAGE_UNKNOWN; + long *set_type = (long *)set_mime; BU_OPT_CHECK_ARGV0(msg, argc, argv, "mime format"); type_int = bu_file_mime(argv[0], BU_MIME_IMAGE); - type = (type_int < 0) ? BU_MIME_IMAGE_UNKNOWN : (bu_mime_image_t)type_int; + type = (type_int < 0) ? BU_MIME_IMAGE_UNKNOWN : (long)type_int; if (type == BU_MIME_IMAGE_UNKNOWN) { if (msg) bu_vls_sprintf(msg, "Error - unknown geometry file type: %s \n", argv[0]); return -1; @@ -95,8 +95,8 @@ main(int ac, const char **av) size_t height = 0; const char *in_fmt = NULL; const char *out_fmt = NULL; - static bu_mime_image_t in_type = BU_MIME_IMAGE_UNKNOWN; - static bu_mime_image_t out_type = BU_MIME_IMAGE_UNKNOWN; + static long in_type = BU_MIME_IMAGE_UNKNOWN; + static long out_type = BU_MIME_IMAGE_UNKNOWN; static char *in_path_str = NULL; static char *out_path_str = NULL; int need_help = 0; @@ -214,7 +214,7 @@ main(int ac, const char **av) ret = 1; } else { if (bu_path_component(&c, bu_vls_addr(&in_path), BU_PATH_EXT)) { - in_type = (bu_mime_image_t)bu_file_mime(bu_vls_addr(&c), BU_MIME_IMAGE); + in_type = (long)bu_file_mime(bu_vls_addr(&c), BU_MIME_IMAGE); } else { bu_vls_printf(&slog, "No input file image type specified - need either a specified input image type or a path that provides MIME information.\n"); ret = 1; @@ -229,7 +229,7 @@ main(int ac, const char **av) ret = 1; } else { if (bu_path_component(&c, bu_vls_addr(&out_path), BU_PATH_EXT)) { - out_type = (bu_mime_image_t)bu_file_mime(bu_vls_addr(&c), BU_MIME_IMAGE); + out_type = (long)bu_file_mime(bu_vls_addr(&c), BU_MIME_IMAGE); } else { bu_vls_printf(&slog, "No output file image type specified - need either a specified output image type or a path that provides MIME information.\n"); ret = 1;