Esempio n. 1
0
picture
load_xpm (url file_name) {
    static hashmap<string,picture> cache;
    string name= as_string (file_name);
    if (cache->contains (name)) return cache[name];

#ifdef QTTEXMACS

    picture pict= qt_load_xpm (file_name);

#else

    tree t= xpm_load (file_name);

    // get main info
    int ok, i=0, j, k, w, h, c, b, x, y;
    string s= as_string (t[0]);
    skip_spaces (s, i);
    ok= read_int (s, i, w);
    skip_spaces (s, i);
    ok= read_int (s, i, h) && ok;
    skip_spaces (s, i);
    ok= read_int (s, i, c) && ok;
    skip_spaces (s, i);
    ok= read_int (s, i, b) && ok;
    if ((!ok) || (N(t)<(c+1)) || (c<=0)) {
        failed_error << "file_name= " << file_name << "\n";
        FAILED ("invalid xpm");
    }

    // setup colors
    string first_name;
    hashmap<string,color> pmcs(0);
    for (k=0; k<c; k++) {
        string s   = as_string (t[k+1]);
        string name= "";
        string def = "none";
        if (N(s)<b) i=N(s);
        else {
            name= s(0,b);
            i=b;
        }
        if (k==0) first_name= name;

        skip_spaces (s, i);
        if ((i<N(s)) && (s[i]=='s')) {
            i++;
            skip_spaces (s, i);
            while ((i<N(s)) && (s[i]!=' ') && (s[i]!='\t')) i++;
            skip_spaces (s, i);
        }
        if ((i<N(s)) && (s[i]=='c')) {
            i++;
            skip_spaces (s, i);
            j=i;
            while ((i<N(s)) && (s[i]!=' ') && (s[i]!='\t')) i++;
            def= locase_all (s (j, i));
        }
        pmcs(name)= xpm_color (def);
    }

    // setup pixmap
    picture pict= raster_picture (w, h);
    draw_on (pict, 0x00646464, compose_source);
    for (y=0; y<h; y++) {
        if (N(t) < (y+c+1)) s= "";
        else s= as_string (t[y+c+1]);
        for (x=0; x<w; x++) {
            string name;
            if (N(s)<(b*(x+1))) name= first_name;
            else name= s (b*x, b*(x+1));
            color pmc= pmcs[name];
            if (!pmcs->contains (name)) pmc= pmcs[first_name];
            pict->set_pixel (x, h-1-y, pmc);
        }
    }
    pict= as_native_picture (pict);

#endif

    cache (name)= pict;
    return pict;
}
Esempio n. 2
0
void
draw_on (picture& dest, picture src, int x, int y, composition_mode mode) {
  raster<true_color> dest_ras= as_raster<true_color> (dest);
  raster<true_color> src_ras = as_raster<true_color> (src);
  draw_on (dest_ras, src_ras, x, y, mode);
}
Esempio n. 3
0
picture
error_picture (int w, int h) {
    picture pic= raster_picture (w, h);
    draw_on (pic, 0x20ff0000, compose_source);
    return pic;
}
Esempio n. 4
0
void
draw_on (picture& pic, color c, composition_mode mode) {
  raster<true_color> ras= as_raster<true_color> (pic);
  draw_on (ras, true_color (c), mode);
}