Skip to content

Commit

Permalink
Make GCV check from all the mime types.
Browse files Browse the repository at this point in the history
  • Loading branch information
sumagnadas committed Mar 22, 2021
1 parent b69ea94 commit 7ac3f4e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/conv/gcv/gcv.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ 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_int = bu_file_mime(opt, BU_MIME_AUTO);
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
if (type == BU_MIME_MODEL_UNKNOWN) {
/* Have prefix, but doesn't result in a known format - that's an error */
Expand All @@ -223,7 +223,7 @@ 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_int = bu_file_mime(bu_vls_addr(format), BU_MIME_AUTO);
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
if (type == BU_MIME_MODEL_UNKNOWN) {
/* Have prefix, but doesn't result in a known format - that's an error */
Expand All @@ -238,7 +238,7 @@ 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_int = bu_file_mime(bu_vls_addr(&format_cpy), BU_MIME_AUTO);
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
if (type == BU_MIME_MODEL_UNKNOWN) {
/* Have prefix, but doesn't result in a known format - that's an error */
Expand All @@ -252,7 +252,7 @@ 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_int = bu_file_mime(bu_vls_addr(format), BU_MIME_AUTO);
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
if (type == BU_MIME_MODEL_UNKNOWN) {
/* Have file extension, but doesn't result in a known format - that's an error */
Expand Down Expand Up @@ -320,7 +320,7 @@ model_mime(struct bu_vls *msg, size_t argc, const char **argv, void *set_mime)

BU_OPT_CHECK_ARGV0(msg, argc, argv, "mime format");

type_int = bu_file_mime(argv[0], BU_MIME_MODEL);
type_int = bu_file_mime(argv[0], BU_MIME_AUTO);
type = (type_int < 0) ? BU_MIME_MODEL_UNKNOWN : (bu_mime_context_t)type_int;
if (type == BU_MIME_MODEL_UNKNOWN) {
if (msg) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 26 additions & 1 deletion src/libbu/mime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ foreach(context ${ACTIVE_TYPES})
endif("${context}" STREQUAL "${FIRST_TYPE}")
set(last_type "BU_MIME_${c}")
endforeach(context ${ACTIVE_TYPES})
set(mcstr "${mcstr}\n BU_MIME_UNKNOWN")
set(mcstr "${mcstr}\n BU_MIME_UNKNOWN,")
set(mcstr "${mcstr}\n BU_MIME_AUTO")
set(mcstr "${mcstr}\n} bu_mime_context;\n\n")
set(h_contents "${h_contents}\n${mcstr}")

Expand Down Expand Up @@ -184,6 +185,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")
Expand Down Expand Up @@ -216,6 +225,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")
Expand Down Expand Up @@ -262,6 +279,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")
Expand Down
2 changes: 1 addition & 1 deletion src/libgcv/plugins/vol/png_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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
};

Expand Down

0 comments on commit 7ac3f4e

Please sign in to comment.