diff options
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/image/image.c | 99 | ||||
-rw-r--r-- | src/image/image.h | 16 |
3 files changed, 118 insertions, 0 deletions
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 <string.h> +#include <stdio.h> + +#include <kalmia.h> +#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<l.image_count; i++) { + kai_release_image(l.image[i]); + } + free(l.image); +} diff --git a/src/image/image.h b/src/image/image.h new file mode 100644 index 0000000..79ff299 --- /dev/null +++ b/src/image/image.h @@ -0,0 +1,16 @@ +#ifndef KALMIA_IMAGE_H +#define KALMIA_IMAGE_H + +#include <kalmia.h> +#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 |