コード例 #1
0
ファイル: framebuffer.c プロジェクト: arczi84/NetSurf-68k
nsfb_t *
framebuffer_initialise(const char *fename, int width, int height, int bpp)
{
    enum nsfb_type_e fbtype;
    enum nsfb_format_e fbfmt;

    /* bpp is a proxy for the framebuffer format */
    if (framebuffer_format_from_bpp(bpp, &fbfmt) == false) {
        return NULL;
    }

    fbtype = nsfb_type_from_name(fename);
    if (fbtype == NSFB_SURFACE_NONE) {
        LOG("The %s surface is not available from libnsfb\n", fename);
        return NULL;
    }

    nsfb = nsfb_new(fbtype);
    if (nsfb == NULL) {
        LOG("Unable to create %s fb surface\n", fename);
        return NULL;
    }

    if (nsfb_set_geometry(nsfb, width, height, fbfmt) == -1) {
        LOG("Unable to set surface geometry\n");
        nsfb_free(nsfb);
        return NULL;
    }

    nsfb_cursor_init(nsfb);

    if (nsfb_init(nsfb) == -1) {
        LOG("Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return NULL;
    }

    return nsfb;

}
コード例 #2
0
ファイル: framebuffer.c プロジェクト: galexcode/NetSurf68k
void
framebuffer_finalise(void)
{
    nsfb_free(nsfb);    
}
コード例 #3
0
ファイル: framebuffer.c プロジェクト: galexcode/NetSurf68k
nsfb_t *
framebuffer_initialise(const char *fename, int width, int height, int bpp)
{
    enum nsfb_type_e fbtype;
    enum nsfb_format_e fbfmt;

    /* bpp is a proxy for the framebuffer format */
    switch (bpp) {
    case 32:
	    fbfmt = NSFB_FMT_XRGB8888;
	    break;

    case 24:
	    fbfmt = NSFB_FMT_RGB888;
	    break;

    case 16:
	    fbfmt = NSFB_FMT_RGB565;
	    break;

    case 8:
	    fbfmt = NSFB_FMT_I8;
	    break;

    case 4:
	    fbfmt = NSFB_FMT_I4;
	    break;

    case 1:
	    fbfmt = NSFB_FMT_I1;
	    break;

    default:
        LOG(("Bad bits per pixel (%d)\n", bpp));
        return NULL;	    
    }

    fbtype = nsfb_type_from_name(fename);
    if (fbtype == NSFB_SURFACE_NONE) {
        LOG(("The %s surface is not available from libnsfb\n", fename));
        return NULL;
    }

    nsfb = nsfb_new(fbtype);
    if (nsfb == NULL) {
        LOG(("Unable to create %s fb surface\n", fename));
        return NULL;
    }
    
    if (nsfb_set_geometry(nsfb, width, height, fbfmt) == -1) {
        LOG(("Unable to set surface geometry\n"));
        nsfb_free(nsfb);
        return NULL;
    }

    nsfb_cursor_init(nsfb);
    
    if (nsfb_init(nsfb) == -1) {
        LOG(("Unable to initialise nsfb surface\n"));
        nsfb_free(nsfb);
        return NULL;
    }

    return nsfb;

}
コード例 #4
0
ファイル: text-speed.c プロジェクト: ashmew2/kolibriosSVN
int main(int argc, char **argv)
{
    const char *fename;
    enum nsfb_type_e fetype;
    nsfb_t *nsfb;

    nsfb_bbox_t box;
    nsfb_bbox_t box3;
    uint8_t *fbptr;
    int fbstride;
    int i;
    unsigned int x, y;

    if (argc < 2) {
        fename="sdl";
    } else {
        fename = argv[1];
    }

    fetype = nsfb_type_from_name(fename);
    if (fetype == NSFB_SURFACE_NONE) {
        printf("Unable to convert \"%s\" to nsfb surface type\n",
               fename);
        return EXIT_FAILURE;
    }

    nsfb = nsfb_new(fetype);
    if (nsfb == NULL) {
        printf("Unable to allocate \"%s\" nsfb surface\n", fename);
        return EXIT_FAILURE;
    }

    if (nsfb_init(nsfb) == -1) {
        printf("Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return EXIT_FAILURE;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_buffer(nsfb, &fbptr, &fbstride);
    nsfb_claim(nsfb, &box);

    /* Clear to white */
    nsfb_plot_clg(nsfb, 0xffffffff);
    nsfb_update(nsfb, &box);

    /* test glyph plotting */
    for (i = 0; i < 1000; i++) {
        for (y = 0; y < box.y1 - Mglyph1.h; y += Mglyph1.h) {
            for (x = 0; x < box.x1 - Mglyph1.w; x += Mglyph1.w) {
                box3.x0 = x;
                box3.y0 = y;
                box3.x1 = box3.x0 + Mglyph1.w;
                box3.y1 = box3.y0 + Mglyph1.h;

                nsfb_plot_glyph1(nsfb, &box3,  Mglyph1.data,
                                 Mglyph1.w, 0xff000000);
            }
        }
        nsfb_update(nsfb, &box);
    }

    nsfb_update(nsfb, &box);
    nsfb_free(nsfb);

    return 0;
}
コード例 #5
0
ファイル: polystar.c プロジェクト: ChokshiUtsav/kolibriosSVN
int main(int argc, char **argv)
{
    const char *fename;
    enum nsfb_type_e fetype;
    nsfb_t *nsfb;

    int waitloop = 3;

    nsfb_event_t event;
    nsfb_bbox_t box;
    uint8_t *fbptr;
    int fbstride;

    int sides;
    int radius;
    nsfb_point_t *points;
    int loop;
    nsfb_plot_pen_t pen;

    double rotate;

    if (argc < 2) {
        fename="sdl";
    } else {
        fename = argv[1];
    }

    fetype = nsfb_type_from_name(fename);
    if (fetype == NSFB_SURFACE_NONE) {
        fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
        return 1;
    }

    nsfb = nsfb_new(fetype);
    if (nsfb == NULL) {
        fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
        return 2;
    }

    if (nsfb_init(nsfb) == -1) {
        fprintf(stderr, "Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return 4;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_buffer(nsfb, &fbptr, &fbstride);


    pen.stroke_colour = 0xff000000;
    pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;


    for (rotate =0; rotate < (2 * M_PI); rotate += (M_PI / 8)) {
	    /* claim the whole screen for update */
	    nsfb_claim(nsfb, &box);

	    nsfb_plot_clg(nsfb, 0xffffffff);

	    radius = (box.y1 / 2);

	    for (sides = 18; sides >=9; sides-=2) {
		    points = malloc(sizeof(nsfb_point_t) * sides);

		    for (loop = 0; loop < sides;loop+=2) {
			    points[loop].x = (box.x1 / 2) + 
				    (radius * cos((loop * 2 * M_PI / sides) + rotate));
			    points[loop].y = (box.y1 / 2) + 
				    (radius * sin((loop * 2 * M_PI / sides) + rotate));

			    points[loop+1].x = (box.x1 / 2) + 
				     ((radius / 3) * cos(((loop+1) * 2 * M_PI / sides) + rotate));
			    points[loop+1].y = (box.y1 / 2) + 
				     ((radius / 3) * sin(((loop+1) * 2 * M_PI / sides) + rotate));
		    }

		    nsfb_plot_polygon(nsfb, (const int *)points, sides, 
				      0xff000000 | (0xffffff / (sides * 2)));

		    nsfb_plot_polylines(nsfb, sides, points, &pen);

		    free(points);
		    radius -= 40;
	    }

	    nsfb_update(nsfb, &box);
	    sleepMilli(100);
    }
    
    /* wait for quit event or timeout */
    while (waitloop > 0) {
	if (nsfb_event(nsfb, &event, 1000)  == false) {
	    break;
	}
	if (event.type == NSFB_EVENT_CONTROL) {
	    if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
		/* timeout */
		waitloop--;
	    } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
		break;
	    }
	}
    }

    nsfb_free(nsfb);

    return 0;
}
コード例 #6
0
ファイル: plottest.c プロジェクト: ChokshiUtsav/kolibriosSVN
int main(int argc, char **argv)
{
    const char *fename;
    enum nsfb_type_e fetype;
    nsfb_t *nsfb;
    nsfb_event_t event;
    int waitloop = 3;

    nsfb_bbox_t box;
    nsfb_bbox_t box2;
    nsfb_bbox_t box3;
    uint8_t *fbptr;
    int fbstride;
    int p[] = { 300,300,  350,350, 400,300, 450,250, 400,200};
    int loop;
    nsfb_plot_pen_t pen;
    const char *dumpfile = NULL;

    if (argc < 2) {
        fename="sdl";
    } else {
        fename = argv[1];
	if (argc >= 3) {
	    dumpfile = argv[2];
	}
    }

    fetype = nsfb_type_from_name(fename);
    if (fetype == NSFB_SURFACE_NONE) {
        fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
        return 1;
    }

    nsfb = nsfb_new(fetype);
    if (nsfb == NULL) {
        fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
        return 2;
    }

    if (nsfb_init(nsfb) == -1) {
        fprintf(stderr, "Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return 4;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_buffer(nsfb, &fbptr, &fbstride);

    /* claim the whole screen for update */
    nsfb_claim(nsfb, &box);

    /* first test, repeatedly clear the graphics area, should result in the
     * same operation as a single clear to the final colour 
     */
    for (loop = 0; loop < 256;loop++) {
        nsfb_plot_clg(nsfb, 0xffffff00 | loop);
    }

    /* draw black radial lines from the origin */
    pen.stroke_colour = 0xff000000;
    for (loop = 0; loop < box.x1; loop += 20) {
        box2 = box;
        box2.x1 = loop;
        nsfb_plot_line(nsfb, &box2, &pen);
    }
    
    /* draw blue radial lines from the bottom right */
    pen.stroke_colour = 0xffff0000;
    for (loop = 0; loop < box.x1; loop += 20) {
        box2 = box;
        box2.x0 = loop;
        nsfb_plot_line(nsfb, &box2, &pen);
    }
    
    /* draw green radial lines from the bottom left */
    pen.stroke_colour = 0xff00ff00;
    for (loop = 0; loop < box.x1; loop += 20) {
        box2.x0 = box.x0;
        box2.x1 = loop;
        box2.y0 = box.y1;
        box2.y1 = box.y0;
        nsfb_plot_line(nsfb, &box2, &pen);
    }

    /* draw red radial lines from the top right */
    pen.stroke_colour = 0xff0000ff;
    for (loop = 0; loop < box.x1; loop += 20) {
        box2.x0 = box.x1;
        box2.x1 = loop;
        box2.y0 = box.y0;
        box2.y1 = box.y1;
        nsfb_plot_line(nsfb, &box2, &pen);
    }

    /* draw an unclipped rectangle */
    box2.x0 = box2.y0 = 100;
    box2.x1 = box2.y1 = 300;

    nsfb_plot_rectangle_fill(nsfb, &box2, 0xff0000ff);

    nsfb_plot_rectangle(nsfb, &box2, 1, 0xff00ff00, false, false);

    nsfb_plot_polygon(nsfb, p, 5, 0xffff0000);

    nsfb_plot_set_clip(nsfb, &box2);

    box3.x0 = box3.y0 = 200;
    box3.x1 = box3.y1 = 400;

    nsfb_plot_rectangle_fill(nsfb, &box3, 0xff00ffff);

    nsfb_plot_rectangle(nsfb, &box3, 1, 0xffffff00, false, false);

    for (loop = 100; loop < 400;loop++) {
        nsfb_plot_point(nsfb, loop, 150, 0xffaa1111);
        nsfb_plot_point(nsfb, loop, 160, 0x99aa1111);
    }

    nsfb_plot_set_clip(nsfb, NULL);

    box3.x0 = box3.y0 = 400;
    box3.x1 = box3.y1 = 600;

    nsfb_plot_ellipse_fill(nsfb, &box3, 0xffff0000);

    nsfb_plot_ellipse(nsfb, &box3, 0xff0000ff);

    box3.x0 = 500;
    box3.x1 = 700;
    box3.y0 = 400;
    box3.y1 = 500;

    nsfb_plot_ellipse_fill(nsfb, &box3, 0xffff0000);

    nsfb_plot_ellipse(nsfb, &box3, 0xff0000ff);

    box3.x0 = 600;
    box3.x1 = 700;
    box3.y0 = 300;
    box3.y1 = 500;

    nsfb_plot_ellipse_fill(nsfb, &box3, 0xff0000ff);

    nsfb_plot_ellipse(nsfb, &box3, 0xffff0000);

    box2.x0 = 400;
    box2.y0 = 400;
    box2.x1 = 500;
    box2.y1 = 500;

    box3.x0 = 600;
    box3.y0 = 200;
    box3.x1 = 700;
    box3.y1 = 300;

    nsfb_plot_copy(nsfb, &box2, nsfb, &box3);

    /* test glyph plotting */
    for (loop = 100; loop < 200; loop+= Mglyph1.w) {
        box3.x0 = loop;
        box3.y0 = 20;
        box3.x1 = box3.x0 + Mglyph8.w;
        box3.y1 = box3.y0 + Mglyph8.h;

        nsfb_plot_glyph1(nsfb, &box3,  Mglyph1.data, Mglyph1.w, 0xff000000);
    }

    /* test glyph plotting */
    for (loop = 100; loop < 200; loop+= Mglyph8.w) {
        box3.x0 = loop;
        box3.y0 = 50;
        box3.x1 = box3.x0 + Mglyph8.w;
        box3.y1 = box3.y0 + Mglyph8.h;

        nsfb_plot_glyph8(nsfb, &box3,  Mglyph8.data, Mglyph8.w, 0xff000000);
    }

    nsfb_update(nsfb, &box);

    /* random rectangles in clipped area*/
    box2.x0 = 400;
    box2.y0 = 50;
    box2.x1 = 600;
    box2.y1 = 100;

    nsfb_plot_set_clip(nsfb, &box2);

    srand(1234);

    for (loop=0; loop < 10000; loop++) {
        nsfb_claim(nsfb, &box2);
        box3.x0 = rand() / (RAND_MAX / box.x1);
        box3.y0 = rand() / (RAND_MAX / box.y1);
        box3.x1 = rand() / (RAND_MAX / 400);
        box3.y1 = rand() / (RAND_MAX / 400);
        nsfb_plot_rectangle_fill(nsfb, &box3, 0xff000000 | rand());
        nsfb_update(nsfb, &box2);
    }

    /* wait for quit event or timeout */
    while (waitloop > 0) {
	if (nsfb_event(nsfb, &event, 1000)  == false) {
	    break;
	}
	if (event.type == NSFB_EVENT_CONTROL) {
	    if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
		/* timeout */
		waitloop--;
	    } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
		break;
	    }
	}
    }

    dump(nsfb, dumpfile);

    nsfb_free(nsfb);

    return 0;
}
コード例 #7
0
ファイル: bezier.c プロジェクト: ChokshiUtsav/kolibriosSVN
int main(int argc, char **argv)
{
extern nsfb_surface_rtns_t sdl_rtns;
	
	_nsfb_register_surface(NSFB_SURFACE_SDL, &sdl_rtns, "sdl");
	
	__menuet__debug_out("Starting bezier\n");
	freopen("stderr","w",stderr);
	
	freopen("stdout","w",stdout);

    const char *fename;
    enum nsfb_type_e fetype;
    nsfb_t *nsfb;
    nsfb_event_t event;
    int waitloop = 3;

    nsfb_bbox_t box;
    nsfb_bbox_t box2;
    uint8_t *fbptr;
    int fbstride;
    nsfb_point_t ctrla;
    nsfb_point_t ctrlb;
    int loop;
    nsfb_plot_pen_t pen;

    if (argc < 2) {
        fename="sdl";
    } else {
        fename = argv[1];
    }

    fetype = nsfb_type_from_name(fename);
    if (fetype == NSFB_SURFACE_NONE) {
    __menuet__debug_out("Can't convert\n");
        fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename);
        return 1;
    }

    nsfb = nsfb_new(fetype);
    if (nsfb == NULL) {
		__menuet__debug_out("Can't allocate\n");
        fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename);
        return 2;
    }

    if (nsfb_init(nsfb) == -1) {
		__menuet__debug_out("Init failed\n");
        fprintf(stderr, "Unable to initialise nsfb surface\n");
        nsfb_free(nsfb);
        return 4;
    }

    /* get the geometry of the whole screen */
    box.x0 = box.y0 = 0;
    nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL);

    nsfb_get_buffer(nsfb, &fbptr, &fbstride);

    /* claim the whole screen for update */
    nsfb_claim(nsfb, &box);

    nsfb_plot_clg(nsfb, 0xffffffff);

    box2.x0=100;
    box2.y0=100;

    box2.x1=400;
    box2.y1=400;

    pen.stroke_colour = 0xff000000;
    pen.fill_colour = 0xffff0000;
    pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
    pen.fill_type = NFSB_PLOT_OPTYPE_NONE;

    for (loop=-300;loop < 600;loop+=100) {
        ctrla.x = 100;
        ctrla.y = loop;

        ctrlb.x = 400;
        ctrlb.y = 500 - loop;

        nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrlb, &pen);
    }


    box2.x0=400;
    box2.y0=100;

    box2.x1=600;
    box2.y1=400;

    nsfb_plot_line(nsfb, &box2, &pen);

    box2.x0=800;
    box2.y0=100;

    box2.x1=600;
    box2.y1=400;

    nsfb_plot_line(nsfb, &box2, &pen);

    box2.x0=400;
    box2.y0=100;

    box2.x1=800;
    box2.y1=100;

    ctrla.x = 600;
    ctrla.y = 400;

    pen.stroke_colour = 0xffff0000;

    nsfb_plot_cubic_bezier(nsfb, &box2, &ctrla, &ctrla, &pen);

    box2.x0=400;
    box2.y0=100;

    box2.x1=800;
    box2.y1=100;

    ctrla.x = 600;
    ctrla.y = 400;

    pen.stroke_colour = 0xff0000ff;

    nsfb_plot_quadratic_bezier(nsfb, &box2, &ctrla, &pen);

    nsfb_update(nsfb, &box);
    
    /* wait for quit event or timeout */
    while (waitloop > 0) {
	if (nsfb_event(nsfb, &event, 1000)  == false) {
	    break;
	}
	if (event.type == NSFB_EVENT_CONTROL) {
	    if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) {
		/* timeout */
		waitloop--;
	    } else if (event.value.controlcode == NSFB_CONTROL_QUIT) {
		break;
	    }
	}
    }

    nsfb_free(nsfb);

    return 0;
}