From 6722ef01e34f75bde72ba29e3279c0d1df030593 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 11 Feb 2023 19:46:23 -0600 Subject: add materials and images processing --- src/image/CMakeLists.txt | 3 ++ src/image/image.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ src/image/image.h | 16 ++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/image/CMakeLists.txt create mode 100644 src/image/image.c create mode 100644 src/image/image.h (limited to 'src/image') diff --git a/src/image/CMakeLists.txt b/src/image/CMakeLists.txt new file mode 100644 index 0000000..991b39d --- /dev/null +++ b/src/image/CMakeLists.txt @@ -0,0 +1,3 @@ +project(kalmia) + +target_sources(kalmia PUBLIC image.c) diff --git a/src/image/image.c b/src/image/image.c new file mode 100644 index 0000000..464b86d --- /dev/null +++ b/src/image/image.c @@ -0,0 +1,99 @@ +#include +#include + +#include +#include "image.h" +#include "xml/xml.h" +#include "util/util.h" + + +int kai_read_init_from(struct ka_init_from_t *dest, struct kai_tag_t *src) +{ + KAI_CHECK_TAG_TYPE("init_from"); + + struct kai_tag_t *ref = kai_tag_get_first_child_with_type(src, "ref"); + if (ref != NULL) { + dest->ref = strdup(ref->content); + } + else { + dest->ref = strdup(src->content); + } + return 0; +} + +void kai_release_init_from(struct ka_init_from_t i) +{ + free(i.ref); +} + + +int kai_read_image(struct ka_image_t *dest, struct kai_tag_t *src) +{ + KAI_CHECK_TAG_TYPE("image"); + + dest->id = kai_tag_attr_to_dup(src, "id"); + dest->sid = kai_tag_attr_to_dup(src, "sid"); + dest->name = kai_tag_attr_to_dup(src, "name"); + + struct kai_tag_t *init_from = kai_tag_get_first_child_with_type(src, "init_from"); + if (init_from == NULL) { + free(dest->id); + free(dest->sid); + free(dest->name); + return -1; + } + + int result = kai_read_init_from(&(dest->init_from), init_from); + if (result != 0) { + free(dest->id); + free(dest->sid); + free(dest->name); + return -1; + } + + return 0; +} + +void kai_release_image(struct ka_image_t i) +{ + free(i.id); + free(i.sid); + free(i.name); + kai_release_init_from(i.init_from); +} + + +int kai_read_library_images(struct ka_library_images_t *dest, struct kai_tag_t *src) +{ + KAI_CHECK_TAG_TYPE("library_images"); + + dest->id = kai_tag_attr_to_dup(src, "id"); + dest->name = kai_tag_attr_to_dup(src, "name"); + + int result; + KAI_FILL_ARRAY_FROM_TAGS( + result, + dest->image, dest->image_count, struct ka_image_t, + src, "image", + kai_read_image, kai_release_image + ); + + if (result != 0) { + kai_release_library_images(*dest); + return -1; + } + + return 0; +} + +void kai_release_library_images(struct ka_library_images_t l) +{ + free(l.id); + free(l.name); + + int i; + for (i=0; i +#include "xml/xml.h" + +int kai_read_init_from(struct ka_init_from_t *dest, struct kai_tag_t *src); +void kai_release_init_from(struct ka_init_from_t i); + +int kai_read_image(struct ka_image_t *dest, struct kai_tag_t *src); +void kai_release_image(struct ka_image_t i); + +int kai_read_library_images(struct ka_library_images_t *dest, struct kai_tag_t *src); +void kai_release_library_images(struct ka_library_images_t l); + +#endif -- cgit v1.2.1