Ejemplo n.º 1
0
static GObject*
gwy_si_unit_deserialize(const guchar *buffer,
                        gsize size,
                        gsize *position)
{
    gchar *unitstr = NULL;
    GwySerializeSpec spec[] = {
        { 's', "unitstr", &unitstr, NULL, },
    };
    GwySIUnit *si_unit;

    g_return_val_if_fail(buffer, NULL);

    if (!gwy_serialize_unpack_object_struct(buffer, size, position,
                                            GWY_SI_UNIT_TYPE_NAME,
                                            G_N_ELEMENTS(spec), spec)) {
        return NULL;
    }

    if (unitstr && !*unitstr) {
        g_free(unitstr);
        unitstr = NULL;
    }
    si_unit = gwy_si_unit_new(unitstr);
    g_free(unitstr);

    return (GObject*)si_unit;
}
Ejemplo n.º 2
0
static GObject*
gwy_string_list_deserialize(const guchar *buffer,
                        gsize size,
                        gsize *position)
{
    gchar **pstr = NULL;
    guint32 len = 0;
    GwySerializeSpec spec[] = {
        { 'S', "strings", &pstr, &len, },
    };
    GwyStringList *strlist;
    GPtrArray *strings;
    guint i;

    g_return_val_if_fail(buffer, NULL);

    if (!gwy_serialize_unpack_object_struct(buffer, size, position,
                                            GWY_STRING_LIST_TYPE_NAME,
                                            G_N_ELEMENTS(spec), spec)) {
        return NULL;
    }

    strlist = gwy_string_list_new();
    strings = (GPtrArray*)strlist->strings;
    g_ptr_array_set_size(strings, len);
    for (i = 0; i < len; i++)
        g_ptr_array_index(strings, i) = pstr[i];
    g_free(pstr);

    return (GObject*)strlist;
}
Ejemplo n.º 3
0
static GObject*
gwy_3d_setup_deserialize(const guchar *buffer,
                         gsize size,
                         gsize *position)
{
    Gwy3DSetup *setup;

    gwy_debug("");
    g_return_val_if_fail(buffer, NULL);

    setup = gwy_3d_setup_new();
    {
        GwySerializeSpec spec[] = {
            { 'i', "projection", &setup->projection, NULL, },
            { 'i', "visualization", &setup->visualization, NULL, },
            { 'b', "axes-visible", &setup->axes_visible, NULL, },
            { 'b', "labels-visible", &setup->labels_visible, NULL, },
            { 'd', "rotation-x", &setup->rotation_x, NULL, },
            { 'd', "rotation-y", &setup->rotation_y, NULL, },
            { 'd', "scale", &setup->scale, NULL, },
            { 'd', "z-scale", &setup->z_scale, NULL, },
            { 'd', "light-phi", &setup->light_phi, NULL, },
            { 'd', "light-theta", &setup->light_theta, NULL, },
        };

        if (!gwy_serialize_unpack_object_struct(buffer, size, position,
                                                GWY_3D_SETUP_TYPE_NAME,
                                                G_N_ELEMENTS(spec), spec)) {
            return NULL;
        }
    }

    return (GObject*)setup;
}
Ejemplo n.º 4
0
static GObject*
gwy_surface_deserialize(const guchar *buffer,
                        gsize size,
                        gsize *position)
{
    guint32 datasize = 0;
    GwySIUnit *si_unit_xy = NULL, *si_unit_z = NULL;
    GwySurface *surface;
    GwyXYZ *data = NULL;
    GwySerializeSpec spec[] = {
        { 'o', "si_unit_xy", &si_unit_xy, NULL, },
        { 'o', "si_unit_z", &si_unit_z, NULL, },
        { 'D', "data", &data, &datasize, },
    };

    g_return_val_if_fail(buffer, NULL);

    if (!gwy_serialize_unpack_object_struct(buffer, size, position,
                                            GWY_SURFACE_TYPE_NAME,
                                            G_N_ELEMENTS(spec), spec)) {
        g_free(data);
        GWY_OBJECT_UNREF(si_unit_xy);
        GWY_OBJECT_UNREF(si_unit_z);
        return NULL;
    }
    if (datasize % 3 != 0) {
        g_critical("Serialized %s data size %u not a multiple of 3",
                   GWY_SURFACE_TYPE_NAME, datasize);
        g_free(data);
        GWY_OBJECT_UNREF(si_unit_xy);
        GWY_OBJECT_UNREF(si_unit_z);
        return NULL;
    }

    surface = gwy_surface_new();

    g_free(surface->data);
    surface->data = data;
    surface->n = datasize/3;

    if (si_unit_z) {
        GWY_OBJECT_UNREF(surface->priv->si_unit_z);
        surface->priv->si_unit_z = si_unit_z;
    }
    if (si_unit_xy) {
        GWY_OBJECT_UNREF(surface->priv->si_unit_xy);
        surface->priv->si_unit_xy = si_unit_xy;
    }

    return (GObject*)surface;
}
Ejemplo n.º 5
0
static GObject*
gwy_graph_curve_model_deserialize(const guchar *buffer,
                                  gsize size,
                                  gsize *position)
{
    GwyGraphCurveModel *gcmodel;

    gwy_debug("");
    g_return_val_if_fail(buffer, NULL);

    gcmodel = (GwyGraphCurveModel*)gwy_graph_curve_model_new();
    {
        gint nxdata, nydata;
        gchar *description = NULL;
        GwySerializeSpec spec[] = {
            { 'D', "xdata", &gcmodel->xdata, &nxdata },
            { 'D', "ydata", &gcmodel->ydata, &nydata },
            { 's', "description", &description, NULL },
            { 'd', "color.red", &gcmodel->color.r, NULL },
            { 'd', "color.green", &gcmodel->color.g, NULL },
            { 'd', "color.blue", &gcmodel->color.b, NULL },
            { 'i', "type", &gcmodel->type, NULL },
            { 'i', "point_type", &gcmodel->point_type, NULL },
            { 'i', "point_size", &gcmodel->point_size, NULL },
            { 'i', "line_style", &gcmodel->line_style, NULL },
            { 'i', "line_size", &gcmodel->line_size, NULL },
        };
        if (!gwy_serialize_unpack_object_struct(buffer, size, position,
                                                GWY_GRAPH_CURVE_MODEL_TYPE_NAME,
                                                G_N_ELEMENTS(spec), spec)) {
            g_free(description);
            g_object_unref(gcmodel);
            return NULL;
        }
        if (nxdata != nydata) {
            g_critical("Serialized xdata and ydata array sizes differ");
            g_free(description);
            g_object_unref(gcmodel);
            return NULL;
        }
        if (description) {
            g_string_assign(gcmodel->description, description);
            g_free(description);
        }
        gcmodel->n = nxdata;
    }

    return (GObject*)gcmodel;
}
Ejemplo n.º 6
0
static GObject*
gwy_spectra_deserialize(const guchar *buffer,
                        gsize size,
                        gsize *position)
{
    guint32 ncoords = 0, ncurves = 0, nselected = 0;
    gdouble *coords = NULL;
    guint32 *selected = NULL;
    GwySIUnit *si_unit_xy = NULL;
    GwyDataLine **curves = NULL;
    GwySpectra *spectra;
    gchar* title = NULL, *spec_xlabel = NULL, *spec_ylabel = NULL;
    guint isize, i;

    gwy_debug("");
    g_return_val_if_fail(buffer, NULL);

    {
        GwySerializeSpec spec[] = {
            { 's', "title",       &title,       NULL,       },
            { 'o', "si_unit_xy",  &si_unit_xy,  NULL,       },
            { 'D', "coords",      &coords,      &ncoords,   },
            { 'I', "selected",    &selected,    &nselected, },
            { 'O', "data",        &curves,      &ncurves,   },
            { 's', "spec_xlabel", &spec_xlabel, NULL,       },
            { 's', "spec_ylabel", &spec_ylabel, NULL,       },
        };

        if (!gwy_serialize_unpack_object_struct(buffer, size, position,
                                                GWY_SPECTRA_TYPE_NAME,
                                                G_N_ELEMENTS(spec), spec)) {
            for (i = 0; i < ncurves; i++)
                gwy_object_unref(curves[i]);
            g_free(curves);
            g_free(coords);
            g_free(selected);
            g_free(title);
            g_free(spec_xlabel);
            g_free(spec_ylabel);
            gwy_object_unref(si_unit_xy);

            return NULL;
        }
    }

    isize = 8*sizeof(guint32);
    if (2*ncurves != ncoords
        || (nselected && (ncurves + isize-1)/isize != nselected)) {
        g_critical("Serialized coordinate, data and selection array size "
                   "mismatch");
        for (i = 0; i < ncurves; i++)
            gwy_object_unref(curves[i]);
        g_free(curves);
        g_free(coords);
        g_free(selected);
        g_free(title);
        g_free(spec_xlabel);
        g_free(spec_ylabel);
        gwy_object_unref(si_unit_xy);

        return NULL;
    }

    spectra = gwy_spectra_new();

    g_free(spectra->title);
    spectra->title = title;
    g_free(spectra->spec_xlabel);
    spectra->spec_xlabel = spec_xlabel;
    g_free(spectra->spec_ylabel);
    spectra->spec_ylabel = spec_ylabel;

    /* Preallocate ncurves items */
    g_array_set_size(spectra->spectra, ncurves);
    g_array_set_size(spectra->spectra, 0);
    for (i = 0; i < ncurves; i++) {
        GwySpectrum spec;

        spec.x = coords[2*i + 0];
        spec.y = coords[2*i + 1];
        spec.ydata = curves[i];
        if (nselected)
            spec.selected = !!(selected[i/isize] & (1 << (i % isize)));
        else
            spec.selected = FALSE;
        g_array_append_val(spectra->spectra, spec);
    }
    g_free(curves);
    g_free(coords);
    g_free(selected);

    if (si_unit_xy) {
        gwy_object_unref(spectra->si_unit_xy);
        spectra->si_unit_xy = si_unit_xy;
    }

    return (GObject*)spectra;
}