summaryrefslogtreecommitdiff
path: root/src/image
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-11 19:46:23 -0600
committersanine <sanine.not@pm.me>2023-02-11 19:46:23 -0600
commit6722ef01e34f75bde72ba29e3279c0d1df030593 (patch)
tree1cb389a5af3c0aa4709def8a76c0628342c8aa7c /src/image
parent3b740d521a685fdc4f85d100447ff6d88c0b1d28 (diff)
add materials and images processingyacc-xml
Diffstat (limited to 'src/image')
-rw-r--r--src/image/CMakeLists.txt3
-rw-r--r--src/image/image.c99
-rw-r--r--src/image/image.h16
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