Exemple #1
0
static guchar*
rhk_sm3_read_string(const guchar **buffer,
                    gsize len)
{
    gchar *s, *p;
    guint i, n;
    gunichar chr;

    if (len < 2)
        return NULL;

    n = get_WORD(buffer);
    len -= 2;
    if (len < 2*n)
        return NULL;

    if (!n)
        return g_strdup("");

    p = s = g_new(gchar, 6*n + 1);
    for (i = 0; i < n; i++) {
        chr = get_WORD(buffer);
        p += g_unichar_to_utf8(chr, p);
    }
    *p = '\0';
    g_strstrip(s);
    gwy_debug("String: <%s>", s);

    return s;
}
Exemple #2
0
static gint
burleigh_detect(const gchar *filename,
                gboolean only_name)
{
    FILE *fh;
    struct stat st;
    guchar buffer[4 + 2 + 2];
    const guchar *p;
    guint version_int, xres, yres;
    gdouble version;
    gint score = 0;

    if (only_name) {
        gchar *filename_lc;

        filename_lc = g_ascii_strdown(filename, -1);
        score = g_str_has_suffix(filename_lc, EXTENSION) ? 10 : 0;
        g_free(filename_lc);

        return score;
    }

    if (stat(filename, &st))
        return 0;

    if (!(fh = fopen(filename, "rb")))
        return 0;

    if (fread(buffer, sizeof(buffer), 1, fh) == 1)
        score = 100;
    fclose(fh);

    if (!score)
        return 0;

    p = buffer;
    version = get_FLOAT(&p);
    version_int = ROUND(10*version);
    gwy_debug("Version: %g", version);

    if (version_int == 21) {
        if (st.st_size < TOTAL_SIZE_V21 + 2)
            return 0;

        xres = get_WORD(&p);
        yres = get_WORD(&p);
        if (st.st_size == TOTAL_SIZE_V21 + 2*xres*yres)
            return 100;
        return 0;
    }

    return 0;
}
Exemple #3
0
void *append_WORD_no_NULL(void *p1, void *p2){
    WORD *tw, *w1 = (WORD *)p1, *w2 = (WORD *)p2;

    tw = get_WORD(); 
    tw->use = 1;
    tw->T1 = w1->T1;
    tw->T2 = w2->T2;
    tw->T_dur = tw->T2 - tw->T1; 
    tw->weight = w1->weight + w2->weight; 
    tw->conf = (w1->conf + w2->conf) / 2.0;
    tw->frag_corr = (w1->frag_corr && w2->frag_corr);

    if (w1->opt_del && w2->opt_del){
      tw->intern_value =
	TEXT_strdup((TEXT*)rsprintf("%s%s",
			      (! w1->opt_del) ? w1->value : w1->intern_value,
			      (! w2->opt_del) ? w2->value : w2->intern_value));
      tw->value = 
      	TEXT_strdup((TEXT*)rsprintf(WORD_OPT_DEL_PRE_STR "%s"
				    WORD_OPT_DEL_POST_STR, tw->intern_value));

      tw->opt_del = TRUE;
    } else {
      if (TEXT_strcmp(w1->value, (TEXT *)"@") == 0)
	tw->value = TEXT_strdup((! w2->opt_del) ? w2->value : w2->intern_value);
      else if (TEXT_strcmp(w2->value,(TEXT *)"@") == 0)
	tw->value = TEXT_strdup((! w1->opt_del) ? w1->value : w1->intern_value);
      else
	tw->value = TEXT_add((! w1->opt_del) ? w1->value : w1->intern_value,
			     (! w2->opt_del) ? w2->value : w2->intern_value);
    }

    return(tw);
}
Exemple #4
0
static const gint16*
burleigh_load_v21(IMGFile *imgfile,
                  const guchar *buffer,
                  gsize size)
{
    const guchar *p = buffer + 4; /* size of version */
    guint32 n;

    /* Header */
    imgfile->xres = get_WORD(&p);
    imgfile->yres = get_WORD(&p);
    n = imgfile->xres * imgfile->yres;
    if (size != 2*n + TOTAL_SIZE_V21) {
        g_warning("File size mismatch");
        return NULL;
    }
    /* Skip to footer */
    p += 2*n;
    imgfile->xrangemax = get_DWORD(&p);
    imgfile->yrangemax = get_DWORD(&p);
    imgfile->zrangemax = get_DWORD(&p);
    imgfile->xrange = get_DWORD(&p);
    imgfile->yrange = get_DWORD(&p);
    imgfile->zrange = get_DWORD(&p);
    imgfile->scan_speed = get_WORD(&p);
    imgfile->zoom_level = get_WORD(&p);
    imgfile->data_type = get_WORD(&p);
    imgfile->z_gain = get_WORD(&p);
    imgfile->bias_volts = get_FLOAT(&p);
    imgfile->tunneling_current = get_FLOAT(&p);

    return (const gint16*)(buffer + HEADER_SIZE_V21);
}
Exemple #5
0
WORD *new_WORD(TEXT *t, int id, double t1, double t2, double conf, TEXT *tag1, TEXT *tag2, int fcorr, int odel, double weight){
    WORD *tw = get_WORD();
    int len;
    
    tw->use = 1;
    if (t != (TEXT *)0){
      len = TEXT_strlen(t);
      if (len > 1 && *(t + len - 1) == '*')
	tw->value = TEXT_strndup(t,len-1);
      else
	tw->value = TEXT_strdup(t);
    }
    tw->tag1  = (tag1 == (TEXT *)0) ? tag1 : TEXT_strdup(tag1);
    tw->tag2  = (tag2 == (TEXT *)0) ? tag2 : TEXT_strdup(tag2);
    tw->value_id = id;
    tw->T1 = t1;
    tw->T2 = t2;
    tw->T_dur = t2 - t1;
    tw->weight = weight;
    tw->conf = conf;
    tw->frag_corr = fcorr;
    tw->opt_del = odel;
    return(tw);
}
Exemple #6
0
static RHKPage*
rhk_sm3_read_page(const guchar **buffer,
                  gsize *len)

{
    RHKPage *page;
    const guchar *p = *buffer;
    guint i, expected;

    if (!*len)
        return NULL;

    if (*len < HEADER_SIZE + 4) {
        g_warning("Page header truncated");
        return NULL;
    }
    if (memcmp(p + MAGIC_OFFSET, MAGIC, MAGIC_SIZE) != 0) {
        g_warning("Magic doesn't match");
        return NULL;
    }

    page = g_new0(RHKPage, 1);
    page->param_size = get_WORD(&p);
    gwy_debug("param_size = %u", page->param_size);
    if (*len < page->param_size + 4) {
        g_warning("Real page header truncated");
        goto FAIL;
    }
    /* TODO: Convert to UTF-8, store to meta */
    memcpy(page->version, p, MAGIC_TOTAL_SIZE);
    p += MAGIC_TOTAL_SIZE;
    page->string_count = get_WORD(&p);
    gwy_debug("string_count = %u", page->string_count);
    page->type = get_DWORD(&p);
    gwy_debug("type = %u", page->type);
    page->page_type = get_DWORD(&p);
    gwy_debug("page_type = %u", page->page_type);
    page->data_sub_source = get_DWORD(&p);
    page->line_type = get_DWORD(&p);
    page->x_coord = get_DWORD(&p);
    page->y_coord = get_DWORD(&p);
    page->x_size = get_DWORD(&p);
    page->y_size = get_DWORD(&p);
    gwy_debug("x_size = %u, y_size = %u", page->x_size, page->y_size);
    page->source_type = get_DWORD(&p);
    page->image_type = get_DWORD(&p);
    gwy_debug("image_type = %u", page->image_type);
    page->scan_dir = get_DWORD(&p);
    gwy_debug("scan_dir = %u", page->scan_dir);
    page->group_id = get_DWORD(&p);
    gwy_debug("group_id = %u", page->group_id);
    page->data_size = get_DWORD(&p);
    gwy_debug("data_size = %u", page->data_size);
    page->min_z_value = (gint)get_DWORD(&p);
    page->max_z_value = (gint)get_DWORD(&p);
    gwy_debug("min,max_z_value = %d %d", page->min_z_value, page->max_z_value);
    page->x_scale = get_FLOAT(&p);
    page->y_scale = get_FLOAT(&p);
    page->z_scale = get_FLOAT(&p);
    gwy_debug("x,y,z_scale = %g %g %g",
              page->x_scale, page->y_scale, page->z_scale);
    page->xy_scale = get_FLOAT(&p);
    page->x_offset = get_FLOAT(&p);
    page->y_offset = get_FLOAT(&p);
    page->z_offset = get_FLOAT(&p);
    gwy_debug("x,y,z_offset = %g %g %g",
              page->x_offset, page->y_offset, page->z_offset);
    page->period = get_FLOAT(&p);
    page->bias = get_FLOAT(&p);
    page->current = get_FLOAT(&p);
    page->angle = get_FLOAT(&p);
    gwy_debug("period = %g, bias = %g, current = %g, angle = %g",
              page->period, page->bias, page->current, page->angle);
    memcpy(page->page_id, p, 16);
    p += 16;

    p = *buffer + 2 + page->param_size;
    for (i = 0; i < page->string_count; i++) {
        gchar *s;

        gwy_debug("position %04x", p - *buffer);
        s = rhk_sm3_read_string(&p, *len - (p - *buffer));
        if (!s) {
            g_warning("String truncated");
            goto FAIL;
        }
        if (i < RHK_STRING_NSTRINGS)
            page->strings[i] = s;
        else
            g_free(s);
    }

    expected = page->x_size * page->y_size * sizeof(gint32);
    gwy_debug("expecting %u bytes of page data now", expected);
    if (*len < (p - *buffer) + expected) {
        g_warning("Page data truncated");
        goto FAIL;
    }

    if (page->type == RHK_TYPE_IMAGE)
        page->page_data = p;
    else
        page->spectral_data = p;
    p += expected;

    if (page->type == RHK_TYPE_IMAGE) {
        if (*len < (p - *buffer) + 4) {
            g_warning("Color data header truncated");
            goto FAIL;
        }
        /* Info size includes itself */
        page->color_info.size = get_DWORD(&p) - 2;
        if (*len < (p - *buffer) + page->color_info.size) {
            g_warning("Color data truncated");
            goto FAIL;
        }

        p += page->color_info.size;
    }

    *len -= p - *buffer;
    *buffer = p;
    return page;

FAIL:
    rhk_sm3_page_free(page);
    return NULL;
}