diff --git a/src/gmio_amf/amf_document.h b/src/gmio_amf/amf_document.h
index a2158b4..d08116e 100644
--- a/src/gmio_amf/amf_document.h
+++ b/src/gmio_amf/amf_document.h
@@ -47,16 +47,16 @@
struct gmio_amf_metadata
{
- const char* type; /* UTF8-encoded */
- const char* data; /* UTF8-encoded */
+ const char* type; /*!< UTF8-encoded */
+ const char* data; /*!< UTF8-encoded */
};
struct gmio_amf_color
{
- double r; /* in [0,1] */
- double g; /* in [0,1] */
- double b; /* in [0,1] */
- double a; /* in [0,1] optional */
+ double r; /*!< Red channel in [0,1] */
+ double g; /*!< Green channel in [0,1] */
+ double b; /*!< Blue channel in [0,1] */
+ double a; /*!< Optional alpha(transparency) channel in [0,1] */
const char* r_formula;
const char* g_formula;
const char* b_formula;
@@ -71,13 +71,19 @@ struct gmio_amf_material
uint32_t metadata_count;
};
+/*! Proportion of the composition of another material
+ *
+ * The proportion can be specified as a formula(with \c value_formula) or as a
+ * constant mixing(with \c value).
+ */
struct gmio_amf_composite
{
uint32_t materialid; /* XML:nonNegativeInteger, required */
- double value; /* governs the percent of material */
+ double value; /*!< governs the percent of material */
const char* value_formula;
};
+/*! Vertex within an AMF mesh */
struct gmio_amf_vertex
{
struct gmio_vec3d coords;
@@ -88,6 +94,7 @@ struct gmio_amf_vertex
uint32_t metadata_count;
};
+/*! Edge within an AMF mesh, for curved triangles */
struct gmio_amf_edge
{
uint32_t v1; /* XML:nonNegativeInteger */
@@ -126,11 +133,12 @@ enum gmio_amf_volume_type
GMIO_AMF_VOLUME_TYPE_SUPPORT
};
+/*! Volume within an AMF mesh */
struct gmio_amf_volume
{
uint32_t materialid; /* XML:nonNegativeInteger */
enum gmio_amf_volume_type type;
- uint32_t triangle_count; /* Should be >= 4 */
+ uint32_t triangle_count; /*!< Should be >= 4 */
uint32_t metadata_count;
bool has_color;
struct gmio_amf_color color; /* XML:Color */
@@ -155,10 +163,11 @@ struct gmio_amf_object
struct gmio_amf_constellation
{
uint32_t id; /* XML:integer */
- uint32_t instance_count; /* Should be >= 2 */
+ uint32_t instance_count; /*!< Should be >= 2 */
uint32_t metadata_count;
};
+/*! Instance within an AMF constellation */
struct gmio_amf_instance
{
uint32_t objectid; /* XML:nonNegativeInteger */
@@ -179,9 +188,10 @@ struct gmio_amf_texture
uint32_t depth; /* XML:nonNegativeInteger */
bool tiled;
enum gmio_amf_texture_type type;
- struct gmio_memblock binary_data; /* Will be converted to base64 */
+ struct gmio_memblock binary_data; /*!< Will be converted to base64 */
};
+/*! Units supported by AMF */
enum gmio_amf_unit
{
GMIO_AMF_UNIT_UNKNOWN,
@@ -192,6 +202,7 @@ enum gmio_amf_unit
GMIO_AMF_UNIT_MICRON
};
+/*! The direct elements of an AMF document(ie. inside ...) */
enum gmio_amf_document_element
{
GMIO_AMF_DOCUMENT_ELEMENT_OBJECT,
@@ -201,6 +212,7 @@ enum gmio_amf_document_element
GMIO_AMF_DOCUMENT_ELEMENT_METADATA
};
+/*! The direct elements of an AMF mesh(ie. inside ...) */
enum gmio_amf_mesh_element
{
GMIO_AMF_MESH_ELEMENT_VERTEX,
@@ -223,7 +235,7 @@ struct gmio_amf_document
const void* cookie;
enum gmio_amf_unit unit;
- uint32_t object_count; /* Must be >= 1 */
+ uint32_t object_count; /*!< Must be >= 1 */
uint32_t material_count;
uint32_t texture_count;
uint32_t constellation_count;
diff --git a/src/gmio_amf/amf_io.c b/src/gmio_amf/amf_io.c
index d3e7531..d3f746b 100644
--- a/src/gmio_amf/amf_io.c
+++ b/src/gmio_amf/amf_io.c
@@ -37,6 +37,7 @@
#include "../gmio_core/internal/helper_stream.h"
#include "../gmio_core/internal/helper_task_iface.h"
#include "../gmio_core/internal/ostringstream.h"
+#include "../gmio_core/internal/zip_utils.h"
#include "../gmio_core/internal/zlib_utils.h"
#include
@@ -58,8 +59,12 @@ struct gmio_amf_wcontext
struct gmio_memblock z_memblock;
struct z_stream_s z_stream;
int z_flush;
+ uintmax_t z_compressed_size;
+ uintmax_t z_uncompressed_size;
+ uint32_t z_crc32;
};
+/* Helper to set error code of the writing context */
GMIO_INLINE bool gmio_amf_wcontext_set_error(
struct gmio_amf_wcontext* context, int error)
{
@@ -67,6 +72,7 @@ GMIO_INLINE bool gmio_amf_wcontext_set_error(
return gmio_no_error(error);
}
+/* Helper to increment the current task progress of the writing context */
GMIO_INLINE void gmio_amf_wcontext_incr_task_progress(
struct gmio_amf_wcontext* context)
{
@@ -163,13 +169,11 @@ static void gmio_amf_write_amf_begin(
}
/* Writes document metadata to stream */
-static bool gmio_amf_write_root_metadata(
- struct gmio_amf_wcontext* context)
+static bool gmio_amf_write_root_metadata(struct gmio_amf_wcontext* context)
{
const struct gmio_amf_document* doc = context->document;
struct gmio_amf_metadata metadata = {0};
- uint32_t imeta;
- for (imeta = 0; imeta < doc->metadata_count; ++imeta) {
+ for (uint32_t imeta = 0; imeta < doc->metadata_count; ++imeta) {
doc->func_get_document_element(
doc->cookie,
GMIO_AMF_DOCUMENT_ELEMENT_METADATA, imeta, &metadata);
@@ -180,31 +184,27 @@ static bool gmio_amf_write_root_metadata(
}
/* Writes document materials to stream */
-static bool gmio_amf_write_root_materials(
- struct gmio_amf_wcontext* context)
+static bool gmio_amf_write_root_materials(struct gmio_amf_wcontext* context)
{
const struct gmio_amf_document* doc = context->document;
struct gmio_ostringstream* sstream = context->sstream;
struct gmio_amf_material material = {0};
- uint32_t imat;
- for (imat = 0; imat < doc->material_count; ++imat) {
+ for (uint32_t imat = 0; imat < doc->material_count; ++imat) {
doc->func_get_document_element(
doc->cookie,
GMIO_AMF_DOCUMENT_ELEMENT_MATERIAL, imat, &material);
gmio_ostringstream_write_chararray(sstream, "');
+ gmio_ostringstream_write_chararray(sstream, ">\n");
/* Write material elements */
if (material.metadata_count > 0) {
- uint32_t imeta;
- struct gmio_amf_metadata metadata = {0};
- /* Check function pointer is defined */
if (doc->func_get_document_element_metadata == NULL) {
return gmio_amf_wcontext_set_error(
context,
GMIO_AMF_ERROR_NULL_FUNC_GET_DOCUMENT_ELEMENT_METADATA);
}
- for (imeta = 0; imeta < material.metadata_count; ++imeta) {
+ struct gmio_amf_metadata metadata = {0};
+ for (uint32_t imeta = 0; imeta < material.metadata_count; ++imeta) {
doc->func_get_document_element_metadata(
doc->cookie,
GMIO_AMF_DOCUMENT_ELEMENT_MATERIAL,
@@ -218,15 +218,13 @@ static bool gmio_amf_write_root_materials(
gmio_amf_write_color(context, &material.color);
/* Write material elements */
if (material.composite_count > 0) {
- struct gmio_amf_composite composite = {0};
- uint32_t icomp;
- /* Check function pointer is defined */
if (doc->func_get_material_composite == NULL) {
return gmio_amf_wcontext_set_error(
context,
GMIO_AMF_ERROR_NULL_FUNC_GET_MATERIAL_COMPOSITE);
}
- for (icomp = 0; icomp < material.composite_count; ++icomp) {
+ struct gmio_amf_composite composite = {0};
+ for (uint32_t icomp = 0; icomp < material.composite_count; ++icomp) {
doc->func_get_material_composite(
doc->cookie, imat, icomp, &composite);
gmio_ostringstream_write_chararray(sstream, "f64_format;
- struct gmio_amf_vertex vertex = {0};
- uint32_t ivert;
/* Write mesh element */
- gmio_ostringstream_write_chararray(sstream, "\n");
- for (ivert = 0; ivert < mesh->vertex_count; ++ivert) {
+ struct gmio_amf_vertex vertex = {0};
+ gmio_ostringstream_write_chararray(sstream, "\n\n");
+ for (uint32_t ivert = 0; ivert < mesh->vertex_count; ++ivert) {
mesh_elt_index.value = ivert;
doc->func_get_object_mesh_element(
doc->cookie,
@@ -320,15 +317,13 @@ static bool gmio_amf_write_mesh(
}
/* Write elements */
if (vertex.metadata_count > 0) {
- struct gmio_amf_metadata metadata = {0};
- uint32_t imeta;
- /* Check function pointer */
if (doc->func_get_object_mesh_vertex_metadata == NULL) {
return gmio_amf_wcontext_set_error(
context,
GMIO_AMF_ERROR_NULL_FUNC_GET_OBJECT_MESH_VERTEX_METADATA);
}
- for (imeta = 0; imeta < vertex.metadata_count; ++imeta) {
+ struct gmio_amf_metadata metadata = {0};
+ for (uint32_t imeta = 0; imeta < vertex.metadata_count; ++imeta) {
doc->func_get_object_mesh_vertex_metadata(
doc->cookie, &mesh_elt_index, imeta, &metadata);
gmio_amf_write_metadata(sstream, &metadata);
@@ -342,8 +337,7 @@ static bool gmio_amf_write_mesh(
/* Write mesh vertices elements */
if (mesh->edge_count > 0) {
struct gmio_amf_edge edge = {0};
- uint32_t iedge;
- for (iedge = 0; iedge < mesh->edge_count; ++iedge) {
+ for (uint32_t iedge = 0; iedge < mesh->edge_count; ++iedge) {
mesh_elt_index.value = iedge;
doc->func_get_object_mesh_element(
doc->cookie,
@@ -374,9 +368,7 @@ static bool gmio_amf_write_mesh(
/* Write mesh elements */
if (mesh->volume_count > 0) {
struct gmio_amf_volume volume = {0};
- uint32_t ivol;
- for (ivol = 0; ivol < mesh->volume_count; ++ivol) {
- const char* str_volume_type = "";
+ for (uint32_t ivol = 0; ivol < mesh->volume_count; ++ivol) {
mesh_elt_index.value = ivol;
doc->func_get_object_mesh_element(
doc->cookie,
@@ -385,6 +377,7 @@ static bool gmio_amf_write_mesh(
gmio_ostringstream_write_chararray(sstream, "');
+ gmio_ostringstream_write_chararray(sstream, ">\n");
/* Write volume elements */
if (volume.metadata_count > 0) {
- struct gmio_amf_metadata metadata = {0};
- uint32_t imeta;
- /* Check function pointer */
if (doc->func_get_object_mesh_volume_metadata == NULL) {
return gmio_amf_wcontext_set_error(
context,
GMIO_AMF_ERROR_NULL_FUNC_GET_OBJECT_MESH_VOLUME_METADATA);
}
- for (imeta = 0; imeta < volume.metadata_count; ++imeta) {
+ struct gmio_amf_metadata metadata = {0};
+ for (uint32_t imeta = 0; imeta < volume.metadata_count; ++imeta) {
doc->func_get_object_mesh_volume_metadata(
doc->cookie, &mesh_elt_index, imeta, &metadata);
gmio_amf_write_metadata(sstream, &metadata);
@@ -415,8 +406,7 @@ static bool gmio_amf_write_mesh(
/* Write elements */
if (volume.triangle_count > 0) {
struct gmio_amf_triangle triangle = {0};
- uint32_t itri;
- for (itri = 0; itri < volume.triangle_count; ++itri) {
+ for (uint32_t itri = 0; itri < volume.triangle_count; ++itri) {
doc->func_get_object_mesh_volume_triangle(
doc->cookie, &mesh_elt_index, itri, &triangle);
gmio_ostringstream_write_chararray(sstream, "");
@@ -453,26 +443,23 @@ static bool gmio_amf_write_root_objects(struct gmio_amf_wcontext* context)
const struct gmio_amf_document* doc = context->document;
struct gmio_ostringstream* sstream = context->sstream;
struct gmio_amf_object object = {0};
- uint32_t iobj;
- for (iobj = 0; iobj < doc->object_count; ++iobj) {
+ for (uint32_t iobj = 0; iobj < doc->object_count; ++iobj) {
doc->func_get_document_element(
doc->cookie,
GMIO_AMF_DOCUMENT_ELEMENT_OBJECT, iobj, &object);
/* Open object element */
gmio_ostringstream_write_chararray(sstream, "