コード例 #1
0
ファイル: rayonator.c プロジェクト: gabfou/RT
void	rayonator(t_env *e, int x, int y)
{
	e->c.x = 0;
	e->c.y = 0;
	e->c.z = 0;
	e->d = 0xf0000;
	testall(1, pixelpos(e->o, x, y, e), e, e->o.dir);
	e->c.x *= e->c2.x;
	e->c.y *= e->c2.y;
	e->c.z *= e->c2.z;
	put_pixel(e, x, y, 0x000000);
}
コード例 #2
0
ファイル: vga.c プロジェクト: Ichimonji10/phoenix
/*!
 * Uses Bresenham's line-drawing algorithm, which uses no multiplication or division. Based on
 * code by David Brackeen.
 *
 * \param x1 The x position of the first point (0 to 319).
 * \param y1 The y position of the first point (0 to 199).
 * \param x2 The x position of the second point (0 to 319).
 * \param y2 The y position of the second point (0 to 199).
 * \param color The color of the line.
 */
void line( int x1, int y1, int x2, int y2, byte color )
{
    int i, dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py;

    dx    = x2 - x1;      /* the horizontal distance of the line */
    dy    = y2 - y1;      /* the vertical distance of the line */
    dxabs = abs( dx );
    dyabs = abs( dy );
    sdx   = sgn( dx );
    sdy   = sgn( dy );
    x     = dyabs >> 1;
    y     = dxabs >> 1;
    px    = x1;
    py    = y1;

    put_pixel( px, py, color );

    if( dxabs >= dyabs ) { /* the line is more horizontal than vertical */
        for( i = 0; i < dxabs; i++ ) {
            y += dyabs;
            if( y >= dxabs ) {
                y -= dxabs;
                py += sdy;
            }
            px += sdx;
            put_pixel( px, py, color );
        }
    }
    else  { /* the line is more vertical than horizontal */
        for( i = 0; i < dyabs; i++ ) {
            x += dxabs;
            if( x >= dyabs ) {
                x -= dyabs;
                px += sdx;
            }
            py += sdy;
            put_pixel( px, py, color );
        }
    }
}
コード例 #3
0
int main(int argc, char** argv)
{
    GtkWidget *window;
	int x, y;

    gtk_init(&argc, &argv);

   /* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_opacity(window, 0.7);
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), "pressed");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_widget_show(window);
    gtk_main();
	*/
	GdkPixbuf* photo = gdk_pixbuf_new_from_file_at_size("bluesky.jpg", 300, 200, NULL);
	//GdkPixbuf* image = gdk_pixbuf_new_from_data(photo,;
	//photo = gdk_pixbuf_flip(photo, FALSE);
	//gdk_pixbuf_fill(photo, 0xff00ff64);
	//gdk_pixbuf_rotate_simple(photo, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
	//gdk_pixbuf_save(photo, "thumbnail.png", "png", NULL, NULL);
	guchar *pixels, *p;
	int rowstride, n_channels, bits, width, height ;
	GdkColorspace cs;

	n_channels = gdk_pixbuf_get_n_channels(photo);
	rowstride = gdk_pixbuf_get_rowstride(photo);
	pixels = gdk_pixbuf_get_pixels(photo);
	bits = gdk_pixbuf_get_bits_per_sample(photo);
	cs = gdk_pixbuf_get_colorspace(photo);
	width = gdk_pixbuf_get_width(photo);
	height = gdk_pixbuf_get_height(photo);
	printf("n_channels %d\n", n_channels);
	printf("rowstride %d\n", rowstride);
	printf("bits %d\n", bits);
	printf("cs %d\n", cs);
	printf("width %d\n", width);
	printf("height %d\n", height);

	//photo = gdk_pixbuf_new_from_data(pixels, cs, TRUE, bits, width, height, rowstride, NULL, NULL);
	//gdk_pixbuf_add_alpha(photo, FALSE, 0, 0, 0);

	for(x = 0; x < width; x++)
	{
		for(y = 0; y < height; y++)
		{
			put_pixel(photo, x, y, 100);
		}
	}
	gdk_pixbuf_save(photo, "thumbnail.jpg", "jpeg", NULL, NULL);

    return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: Sequoya42/scaling-meme
void	ft_test(t_env *e)
{
	int x = 0;
	int y = 0;
	int c = try_color(0, 20, 0);
	while (x++ < WIDTH)
	{
		y = 0;
		while (y++ < HEIGHT)
			put_pixel(e->f, x, y, c);
	}
	mlx_put_image_to_window(e->mlx, e->win, e->f->img, 0, 0);
}
コード例 #5
0
// helper function for drawing
void draw() {

    int x, y;
    int t = 20;

    // t x t pix black and blue checkerboard
    for (y = 0; y < vinfo.yres; y++) {
        int xoffset = y / t % 2;
        for (x = 0; x < vinfo.xres; x++) {

            // color based on the tile
            int c = (x / t + xoffset) % 2;

            // draw pixel
            put_pixel(x, y, c);

        }
    }
    // colored blocks
    for (y = 0; y < vinfo.yres; y += t) {
        int xoffset = y / t % 2;
        for (x = t * xoffset; x < vinfo.xres; x += t * 2) {
            int x2, y2;
            for (y2 = 0; y2 < t; y2++) {
                for (x2 = 0; x2 < t; x2++) {

                    // color based on y2 value
                    // using the custom colors (16+)
                    int c = 16 + (y2 % 16);

                    // draw pixel
                    put_pixel(x + x2, y + y2, c);

                }
            }
        }
    }

}
コード例 #6
0
ファイル: primitives.cpp プロジェクト: ololo1982/aseprite
void draw_brush(Image* image, Brush* brush, int x, int y, color_t fg, color_t bg)
{
  Image* brush_image = brush->image();
  const gfx::Rect& brushBounds = brush->bounds();

  x += brushBounds.x;
  y += brushBounds.y;

  if (fg == bg) {
    fill_rect(image, x, y, x+brushBounds.w-1, y+brushBounds.h-1, bg);
  }
  else {
    int u, v;
    for (v=0; v<brushBounds.h; v++) {
      for (u=0; u<brushBounds.w; u++) {
        if (get_pixel(brush_image, u, v))
          put_pixel(image, x+u, y+v, fg);
        else
          put_pixel(image, x+u, y+v, bg);
      }
    }
  }
}
コード例 #7
0
ファイル: drmtest.c プロジェクト: papciakk/drmtest
static void display_animation(void) {
	int color, i, j, dx, px = 500, py = 500, k, len, x=0;

	for(k = 0; k < ANIM_LENGTH; k++) {
		color = get_random_int();
		for(j=0; j<connectors_count; j++) {
			if(fb_h[j] > 0 && fb_w[j] > 0) {

				if(get_random_int() % 2) {
					dx = 1;
				} else {
					dx = -1;
				}

				len = get_random_int() % 100;

				if(x) { // horizontal
					for(i=0; i<len; i++) {
						px = (px+dx) % fb_w[j];
						if(px < 0) px += fb_w[j];
						put_pixel(px, py, color, j);
						udelay(500);
						x = 0;
					}
				} else { // vertical
					for(i=0; i<len; i++) {
						py = (py+dx) % fb_h[j];
						if(py < 0) py += fb_h[j];
						put_pixel(px, py, color, j);
						udelay(500);
						x = 1;
					}
				}
			}
		}	
	}
}
コード例 #8
0
// helper function for drawing - no more need to go mess with
// the main function when just want to change what to draw
void draw() {

	int x, y;

	for (y = 0; y < (vinfo.yres / 2); y++) {
		for (x=0; x < vinfo.xres; x++) {
			
			// color based on the 16th of the screen width
			int c = 16 * x / vinfo.xres;

			// call the helper function
			put_pixel(x, y, c);
		}
	}
}
コード例 #9
0
ファイル: satfind.c プロジェクト: ChakaZulu/my_tuxbox_apps
void draw_rectangle(screen_t screen,int x, int y,int x2, int y2, char col) {
  int x_count,y_count;
  
  if(col&FILLED) {
    for(y_count=y;y_count<=y2;y_count++)
      for(x_count=x;x_count<=x2;x_count++)
	put_pixel(screen,x_count,y_count,col);
  }
  else {
    draw_horiz_line(screen,x,y,x2,col);
    draw_horiz_line(screen,x,y2,x2,col);
    draw_vert_line(screen,x,y,y2,col);
    draw_vert_line(screen,x2,y,y2,col);
  }
}
コード例 #10
0
ファイル: zen_graph.c プロジェクト: TacOS-team/tacos-gui
/*
 * @see http://www.brackeen.com/vga/shapes.html
 */
void draw_line(int x1, int y1, int x2, int y2, char color, char *buffer) {
	int i, dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py;

	dx = x2 - x1; /* the horizontal distance of the line */
	dy = y2 - y1; /* the vertical distance of the line */
	dxabs = (dx >= 0 ? dx : -dx);
	dyabs = (dy >= 0 ? dy : -dy);
	sdx = (dx >= 0 ? 1 : -1);
	sdy = (dy >= 0 ? 1 : -1);
	x = dyabs >> 1;
	y = dxabs >> 1;
	px = x1;
	py = y1;

	if (dxabs >= dyabs) { /* the line is more horizontal than vertical */
		for (i = 0; i < dxabs; i++) {
			y += dyabs;
			if (y >= dxabs) {
				y -= dxabs;
				py += sdy;
			}
			px += sdx;
			put_pixel(color, px, py, buffer);
		}
	} else { /* the line is more vertical than horizontal */
		for (i = 0; i < dyabs; i++) {
			x += dxabs;
			if (x >= dyabs) {
				x -= dyabs;
				px += sdx;
			}
			py += sdy;
			put_pixel(color, px, py, buffer);
		}
	}
}
コード例 #11
0
ファイル: default.c プロジェクト: q-life/pebble
/*
 * set vertical stroke in matrix
 */
static void put_vertical_stroke(int x, int y, GContext* ctx, int segWidth,
		int mintueY) {
	APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "#V#vertical stroke:%d,%d", x, y);
	int segY, vSegCount, hPixelCount, vPixelCount;
	//vertical segment
	for (vSegCount = 0; vSegCount < V_STROKE_SEG_NUM; vSegCount++) {
		//segment left top y position
		segY = y + (SEG_HEIGHT + SEG_SPACING) * vSegCount;
		for (hPixelCount = 0; hPixelCount < segWidth; hPixelCount++) {
			for (vPixelCount = 0; vPixelCount < SEG_HEIGHT; vPixelCount++) {
				//current position
				put_pixel(ctx, x + hPixelCount, segY + vPixelCount, mintueY);
			}
		}
	}
}
コード例 #12
0
ファイル: ppm-lite.c プロジェクト: NickMcConnell/OangbandU
/* Paste part of one image into another, with all necessary clipping.
   Alpha controls the blending of the new image into the old image
    (and any alpha already in the new image is also taken into account.)
  If override_fg/bg is an RGB value (0xNNNNNN) then any dark/light values
    in the source image are assumed to be that, and only the source image's
    intensity and alpha are used.  (Note that 0 is a color: black.  To not
    specify override_color at all, pass in -1 (or ~0, which is the same
    thing.)
 */
void
paste_ppm (struct ppm *into, int to_x, int to_y,
           struct ppm *from, int from_x, int from_y, int w, int h,
           unsigned char fg, unsigned char bg)
{
  int i, j;

  for (j = 0; j < h; j++)
    for (i = 0; i < w; i++)
      {
        unsigned char pixel;

        get_pixel (from, from_x + i, from_y + j, &pixel);
        put_pixel (into,   to_x + i,   to_y + j,  (pixel != 0) ? fg : bg);
      }
}
コード例 #13
0
ファイル: draw_circle.c プロジェクト: amasson42/projects
void	draw_circle(t_img *img, t_pix o, float r)
{
	t_pix i;

	i.x = o.x - r;
	while (i.x <= o.x + r)
	{
		i.y = o.y - r;
		while (i.y <= o.y + r)
		{
			if ((i.x - o.x) * (i.x - o.x) + (i.y - o.y) * (i.y - o.y) <= r * r)
				put_pixel(img, i);
			i.y++;
		}
		i.x++;
	}
}
コード例 #14
0
ファイル: draw_scene.c プロジェクト: amasson42/projects
void	draw_scene_to_img(t_scene *scene, t_img *img)
{
	t_pix	p;

	p.x = 0;
	while (p.x < img->width)
	{
		p.y = 0;
		while (p.y < img->height)
		{
			set_color(ray_trac(scene, p, img));
			put_pixel(img, p);
			p.y++;
		}
		p.x++;
	}
}
コード例 #15
0
ファイル: draw_map.c プロジェクト: amasson42/projects
void	draw_tex(t_img *img, short tile, t_pix o, float s)
{
	t_pix i;

	i.x = o.x * s;
	while (i.x < o.x * s + s)
	{
		i.y = o.y * s;
		while (i.y < o.y * s + s)
		{
			color_of_texture(tile, (i.x - o.x * s) / s, (i.y - o.y * s) / s);
			put_pixel(img, i);
			i.y++;
		}
		i.x++;
	}
}
コード例 #16
0
ファイル: graphics.c プロジェクト: roma-jam/stm32_template
void line(CANVAS* canvas, const POINT *a, const POINT *b, unsigned int color)
{
    POINT cur;
    bool vline;
    short x0, x1, y0, y1, dx, dy, err, ystep, x, y;
    x0 = a->x;
    y0 = a->y;
    x1 = b->x;
    y1 = b->y;
    vline = gabs(y1 - y0) > gabs(x1 - x0);
    if (vline)
    {
        gswap(&x0, &y0);
        gswap(&x1, &y1);
    }
    if (x0 > x1)
    {
        gswap(&x0, &x1);
        gswap(&y0, &y1);
    }
    dx = x1 - x0;
    dy = gabs(y1 - y0);
    err = dx >> 1;
    ystep = (y0 < y1) ? 1 : -1;
    for (x = x0, y = y0; x <= x1; ++x)
    {
       if (vline)
       {
           cur.x = y;
           cur.y = x;
       }
       else
       {
           cur.x = x;
           cur.y = y;
       }
       put_pixel(canvas, &cur, color);
       err -= dy;
       if (err < 0)
       {
           y += ystep;
           err += dx;
       }
    }
}
コード例 #17
0
ファイル: rubberbox.c プロジェクト: debrouxl/tiemu
static void
draw_vline(int x, int y, int h)
{
#ifndef FAST_DRAW
  guchar r, g, b;
	int j;

	for (j = y; j < y + h; j++)
    {
      get_pixel (pixbuf, x, j, &r, &g, &b);
      r = ~r; g = ~g; b = ~b;
      put_pixel (pixbuf, x, j, r, g, b);
		}
#else
  int width, height, rowstride, n_channels;
  guchar *pixels, *p;
	int j;

  n_channels = gdk_pixbuf_get_n_channels (pixbuf);

  g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
  g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
  g_assert (!gdk_pixbuf_get_has_alpha (pixbuf));
  g_assert (n_channels == 3);

  width = gdk_pixbuf_get_width (pixbuf);
  height = gdk_pixbuf_get_height (pixbuf);

  g_assert (x >= 0 && x < width);
  g_assert (y >= 0 && y < height);

  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
  pixels = gdk_pixbuf_get_pixels (pixbuf);

  for (j = y; j < y + h; j++)
    {
	p = pixels + j * rowstride + x * n_channels;
	p[0] = ~p[0]; 
	p[1] = ~p[1]; 
	p[2] = ~p[2];
    }
#endif
}
コード例 #18
0
ファイル: default.c プロジェクト: q-life/pebble
/*
 * set horizontal stroke in matrix
 */
static void put_horizontal_stroke(int x, int y, GContext* ctx, int segWidth,
		int mintueY, char isVMiddle) {
	APP_LOG(APP_LOG_LEVEL_DEBUG_VERBOSE, "#H#horizontal stroke:%d,%d", x, y);
	int segX, hSegCount, hPixelCount, vPixelCount, vPixelNum;
	vPixelNum = isVMiddle ? SEG_HEIGHT + 1 : SEG_HEIGHT;
	//horizontal segment
	for (hSegCount = 0; hSegCount < H_STROKE_SEG_NUM; hSegCount++) {
		//segment left top x position
		segX = x + (segWidth + SEG_SPACING) * hSegCount;
		for (hPixelCount = 0; hPixelCount < segWidth; hPixelCount++) {
			for (vPixelCount = 0; vPixelCount < vPixelNum; vPixelCount++) {
				//current position
				if (isVMiddle && y + vPixelCount == H_MIDDLE_STROKE_SPLIT_Y) {
					vPixelCount++;
				}
				put_pixel(ctx, segX + hPixelCount, y + vPixelCount, mintueY);
			}
		}
	}
}
コード例 #19
0
//internal function
void draw(BOOL* output) {
//draws the output to the framebuffer and handles the double 
//buffering
    int x, y;
    
    cur_page = (cur_page + 1) % 2;

    clear_screen(0);


    for (x=0;x<vinfo.xres;x++){
    for (y=0;y<vinfo.yres;y++){

      put_pixel(x,y,output[vinfo.xres*y+x]);}}


    vinfo.yoffset = cur_page * vinfo.yres;
    ioctl(fbfd, FBIOPAN_DISPLAY, &vinfo);
    ioctl(fbfd, FBIO_WAITFORVSYNC, 0);
}
コード例 #20
0
ファイル: draw_map.c プロジェクト: amasson42/projects
void	draw_floor(t_img *img, t_map *map, t_raycaster *r, t_pix p)
{
	t_point	floor_wall;
	t_point	current_floor;
	double	weight;

	init_floor_wall(&floor_wall, r);
	if (p.y < 0)
		p.y = img->height;
	while (p.y < img->height)
	{
		weight = (img->height / (2.0 * p.y - img->height)) / r->w_dis;
		current_floor.x = weight * floor_wall.x + (1.0 - weight) * r->pos.x;
		current_floor.y = weight * floor_wall.y + (1.0 - weight) * r->pos.y;
		color_of_texture(tile_at_index(map, current_floor.x, current_floor.y),
		current_floor.x, current_floor.y);
		put_pixel(img, p);
		p.y++;
	}
}
コード例 #21
0
ファイル: vga.c プロジェクト: Ichimonji10/phoenix
/*!
 * Display a bmp image array. Use the tool bmp2hex and add the image to image.c.
 *
 * \param x The x position of the upper left corner (0 to 319).
 * \param y The y position of the upper left corner (0 to 199).
 * \param name A string representing the name of the image.
 */
void put_image( int x, int y, const char *name )
{
    int x_offset, y_offset;
    struct image my_image = get_image( name );

    if( my_image.data == NULL ) {
        vga_print_at( 0, 0, "Error: Invalid image name ", 0x04 );
        vga_print_at( 0, 26, name, 0x04 );
    }
    else {
        for( y_offset = 0; y_offset < my_image.height; y_offset++ ) {
            for( x_offset = 0; x_offset < my_image.width; x_offset++ ) {
                put_pixel( x + x_offset,
                           y + y_offset,
                           my_image.data[(y_offset * my_image.width) + x_offset] );
            }
        }
        if( my_image.palette != NULL ) set_palette( my_image.palette );
    }
}
コード例 #22
0
ファイル: julia.c プロジェクト: Thog/fractol
void				compute_julia_pixel(t_env *e, int x, int y)
{
	t_fractal	*data;
	int			i;
	int			it_max;

	data = (t_fractal*)e->data;
	it_max = data->iteration_max;
	i = -1;
	while ((++i) < it_max)
	{
		data->prev_cx = data->cx;
		data->prev_cy = data->cy;
		data->cx = data->prev_cx * data->prev_cx - data->prev_cy
			* data->prev_cy + data->c_re;
		data->cy = 2 * data->prev_cx * data->prev_cy + data->c_im;
		if ((data->cx * data->cx + data->cy * data->cy) > 4)
			break ;
	}
	put_pixel(e->render, x, y, ft_hsl_to_hex(i % 360, 1, 0.5 * (i < it_max)));
}
コード例 #23
0
ファイル: fractal_launcher.c プロジェクト: Galathorn/Project
void		print_julia(t_box *box, int id, t_cmplx *a)
{
	static t_cmplx		tmp;
	int					i;
	t_ptr				f;

	f = ptr(id, box);
	Z_X = box->width / (4 / box->add_z);
	Z_Y = box->height / (4 / box->add_z);
	if ((Y = -1) && box->b_mouse == 1)
	{
		tmp.r = a->r / Z_X - box->pos_x;
		tmp.i = a->i / Z_Y - box->pos_y;
	}
	while (++Y < box->height && (X = -1))
		while (++X < box->width)
		{
			i = (*f)(box, (X / Z_X - box->pos_x), (Y / Z_Y - box->pos_y), &tmp);
			put_pixel(box, X, Y, box->color_tab[i]);
		}
}
コード例 #24
0
ファイル: graphic.cpp プロジェクト: bciss/projets_42
void preparator(t_env & e)
{
	int    x;
	int    y;

	y = -1;
	while (++y < e.h)
	{
		x = -1;
		while (++x < e.l)
			put_pixel(e, x, y, 0x555555);
	}
	y = 299;
	while (++y < 501)
	{
		x = 99;
		while (++x < 301)
			put_pixel(e, x, y, 0x333333);
	}
	y = 299;
	while (++y < 501)
    {
        x = 319;
        while (++x < 521)
            put_pixel(e, x, y, 0x333333);
    }
	y = 299;
	while (++y < 501)
    {
        x = 539;
        while (++x < 741)
            put_pixel(e, x, y, 0x333333);
    }
	y = 299;
	while (++y < 501)
    {
        x = 759;
        while (++x < 961)
            put_pixel(e, x, y, 0x333333);
    }
	y = 49;
    while (++y < 250)
    {
        x = 759;
		while (++x < 1161)
            put_pixel(e, x, y, 0x333333);
    }
}
コード例 #25
0
/** Rescale the given surface to the given width and height. **/
SDL_Surface *cata_tiles::scale_surface(SDL_Surface *surface, Uint16 w, Uint16 h)
{
    SDL_Surface *rval = SDL_CreateRGBSurface(surface->flags, w, h, surface->format->BitsPerPixel,
        surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);
 
    double stretch_factor_x = (static_cast<double>(w)  / static_cast<double>(surface->w));
    double stretch_factor_y = (static_cast<double>(h) / static_cast<double>(surface->h));
 
    for(Sint32 y = 0; y < surface->h; y++) {
        for(Sint32 x = 0; x < surface->w; x++) {
            for(Sint32 o_y = 0; o_y < stretch_factor_y; ++o_y) {
                for(Sint32 o_x = 0; o_x < stretch_factor_x; ++o_x) {
                    put_pixel(rval, static_cast<Sint32>(stretch_factor_x * x) + o_x,
                        static_cast<Sint32>(stretch_factor_y * y) + o_y, get_pixel(surface, x, y));
                }
            }
        }
    }
 
    return rval;
}
コード例 #26
0
SDL_Surface *
array_to_surface (Uint8 * array, Uint32 flags, int width, int height,
		  int bitsPerPixel, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
		  Uint32 Amask)
{
  if (!array)
    {
      return NULL;
    }

  SDL_Surface *surface =
    SDL_CreateRGBSurface (flags, width, height, bitsPerPixel, Rmask, Gmask,
			  Bmask, Amask);
  if (!surface)
    {
      return NULL;
    }
  if (SDL_MUSTLOCK (surface))
    {
      SDL_LockSurface (surface);
    }

  Uint8 *pixel = array;
  for (int y = 0; y < height; ++y)
    {
      for (int x = 0; x < width; ++x)
	{
	  put_pixel (surface, x, y,
		     SDL_MapRGB (surface->format, pixel[0], pixel[1],
				 pixel[2]));
	  pixel += 3;
	}
    }

  if (SDL_MUSTLOCK (surface))
    {
      SDL_UnlockSurface (surface);
    }
  return surface;
}
コード例 #27
0
ファイル: vga.c プロジェクト: Ichimonji10/phoenix
/*!
 * The color chosen as the transparent color will not be printed to the screen. The background
 * will then show through.
 *
 * \param x The x position of the upper left corner (0 to 319).
 * \param y The y position of the upper left corner (0 to 199).
 * \param trans_color The transparent color.
 * \param name A string representing the name of the image.
 */
void put_trans_image( int x, int y, byte trans_color, const char *name )
{
    int x_offset, y_offset;
    byte current_pixel;
    struct image my_image = get_image( name );

    if( my_image.data == NULL ) {
        vga_print_at( 0, 0, "Error: Invalid image name ", 0x04 );
        vga_print_at( 0, 26, name, 0x04 );
    }
    else {
        for( y_offset = 0; y_offset < my_image.height; y_offset++ ) {
            for( x_offset = 0; x_offset < my_image.width; x_offset++ ) {
                current_pixel = my_image.data[(y_offset * my_image.width) + x_offset];
                if( current_pixel != trans_color ) {
                    put_pixel( x + x_offset, y + y_offset, current_pixel );
                }
            }
        }
        if( my_image.palette != NULL ) set_palette( my_image.palette );
    }
}
コード例 #28
0
ファイル: main.c プロジェクト: ElFeesho/OldCProjects
void renderGlyph(SDL_Surface *screen, char glyph)
{
	SDL_FillRect(screen, NULL, 0x00000000);
	int error;
   int glyph_index = FT_Get_Char_Index( face, glyph);
   error = FT_Load_Glyph( face, glyph_index, 0 ); // Load 'A' glyph with default parameters (0)
   if(error)
   {
      exit(0);
   }

   error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_NORMAL ); // Can haz bitmap?

   if(error)
   {
      exit(0); // no can haz bitmap :|
   }

	int i, j;
	for(i = 0; i<face->glyph->bitmap.rows;i++)
		for(j = 0;j<face->glyph->bitmap.width;j++)
			put_pixel(screen,face->glyph->bitmap.buffer[i*face->glyph->bitmap.pitch+j],j,i);
}
コード例 #29
0
void _gif_sw_codec(
                kal_int32 GIF_ox,
                kal_int32 GIF_oy,
                kal_int32 resized_width,
                kal_int32 resized_height,
                kal_uint16 transparent_index,
                gif_sw_image_struct *cache,
                kal_int32 frame_counter,
                kal_bool transparent_enable,
                kal_bool isResized,
                GIF_COLOR_FORMAT_ENUM gif_color_format,
                GIF_COLOR_FORMAT_ENUM palette_format)
{
   /*----------------------------------------------------------------*/
   /* Local Variables                                                */
   /*----------------------------------------------------------------*/
   kal_int32 src_clipx1, src_clipy1, src_clipx2, src_clipy2;
   int image_rows;
   int image_cols;
   kal_bool is_interlace;
   GIF_STATUS_ENUM status;
   /*----------------------------------------------------------------*/
   /* Code Body                                                      */
   /*----------------------------------------------------------------*/
   //kal_uint32 start, end;
   //start = drv_get_current_time();
   //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec(): Enter. GIF(ox,oy)=(%d,%d), resized_width=%d, resized_height=%d\n", GIF_ox, GIF_oy, resized_width, resized_height);

   src_clipx1 = _get_data(FSAL_ACCESS_U16, pfsal_handle); /* X */
   src_clipy1 = _get_data(FSAL_ACCESS_U16, pfsal_handle); /* Y */

   image_cols = _get_data(FSAL_ACCESS_U16, pfsal_handle); /* W */
   image_rows = _get_data(FSAL_ACCESS_U16, pfsal_handle); /* H */

   src_clipx2 = src_clipx1 + image_cols - 1;
   src_clipy2 = src_clipy1 + image_rows - 1;

   // If need not to draw, still need to decode to get correct next frame position
   status = gif_sw_resizer_init(
           cache->image_width,
           cache->image_height,
           src_clipx1,
           src_clipy1,
           src_clipx2,
           src_clipy2,
           GIF_ox,
           GIF_oy,
           GIF_ox + resized_width - 1,
           GIF_oy + resized_height - 1,
           gif_color_format);

   if (status != GIF_STATUS_OK)   
   {
      /* decode limitation, output width too large */
      SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: output width too large \n");
      //GIF_SW_RAISE(1);
      GIF_SW_RAISE(status);
   }

   cache->last_frame_x1 = (kal_int16) GIF_SW_RESIZER.want_dx1 - GIF_ox;
   cache->last_frame_y1 = (kal_int16) GIF_SW_RESIZER.want_dy1 - GIF_oy;
   cache->last_frame_x2 = (kal_int16) GIF_SW_RESIZER.want_dx2 - GIF_ox;
   cache->last_frame_y2 = (kal_int16) GIF_SW_RESIZER.want_dy2 - GIF_oy;

   {
      kal_int32 n;

      n = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;

      /* W05.39 Fix n value will be changed and the interlace attribute may be incorrect */
      if (n & 0x40)
      {
         is_interlace = KAL_TRUE;
      }
      else
      {
         is_interlace = KAL_FALSE;
      }
      if (n & 0x80)
      {
         gif_sw_color_from_rgb_func palette_color_from_rgb;
         kal_int32 i;

         n = 1 << ((n & 0x7) + 1);

         g_gif_sw_current_palette = g_gif_sw_local_palette;

         if (gif_color_format == GIF_SW_COLOR_FORMAT_8)
         {
#if defined(GIF_SUPPORT_SET_PALETTE_FORMAT)
            palette_color_from_rgb = gif_sw_color_from_rgb_array[palette_format];
#else
            palette_color_from_rgb = GIF_SW_PALETTE_COLOR_FROM_RGB;
#endif
         }
         else
         {
            palette_color_from_rgb = g_gif_sw_act_color_from_rgb;
         }

         /* Read the local color palette */
         if (n)
         {
            g_gif_sw_palette_size = n;
         }

         for (i = 0; i < n; i++)
         {
            kal_uint8 R, G, B;

            R = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;
            G = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;
            B = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;

            g_gif_sw_current_palette[i] = palette_color_from_rgb(0xFF, R, G, B);
            if ((g_gif_sw_dest_source_key_enable && g_gif_sw_current_palette[i] == g_gif_sw_dest_source_key)
                || (g_gif_sw_decoder_is_bypass_color && g_gif_sw_current_palette[i] == g_gif_sw_decoder_bypass_color))
            {
               g_gif_sw_current_palette[i] ^= 1;
            }
         }

         /* current layer is index color layer */
         if (gif_color_format == GIF_SW_COLOR_FORMAT_8)
         {
            for (i = 0; i < (kal_int32) n; i++)
            {
               if(g_gif_sw_layer_set_palette)
               {
                  (*g_gif_sw_layer_set_palette)((kal_uint8) i, g_gif_sw_current_palette[i]);
               }
               g_gif_sw_current_palette[i] = i;
            }
         }
      }
      else    /* use global palette */
      {
         g_gif_sw_current_palette = cache->palette;
      }
   }

   {
#define MaxStackSize  4096
#define NullCode  (~0)

      int offset, y;
      register int x = 0;
      register unsigned char *c;
      register unsigned int datum;
      kal_uint32 consump_byte_cnt = 0;
      kal_uint32 read_byte_cnt = 0;
      kal_uint32 data_block_start_addr = 0;

      short *prefix;
      int count;
      unsigned char *packet, *pixel_stack, *suffix, *top_stack;
      unsigned int available, bits, clear, code, code_mask, code_size,
                   data_size, first, end_of_information, in_code, old_code, pass;
      void (*put_pixel)(kal_int32* want_sx,gif_sw_color c,kal_bool want_draw);
      kal_int32 wantx = 0;
      kal_int32 wantx0 = 0;
      wantx0 = GIF_SW_RESIZER.want_start_sx;//(kal_int16)((((GIF_SW_RESIZER.want_start_dx - GIF_ox) * GIF_SW_RESIZER.src_width_range << 1) + GIF_SW_RESIZER.dest_width_range) / (GIF_SW_RESIZER.dest_width_range << 1));

      put_pixel = put_pixel_with_transparent_enable;
      if (!transparent_enable)
      {
         put_pixel = put_pixel_with_transparent_disable;
      }


      /* allocate decoder tables */
      {
         kal_uint8 *mem = (kal_uint8*) g_gif_sw_tree_buffer;

         prefix = (short*)mem;
         mem += MaxStackSize * sizeof(*prefix);
         suffix = (unsigned char*)mem;
         mem += MaxStackSize;
         pixel_stack = (unsigned char*)mem;  /* use MaxStackSize+1  bytes; */
      }

      /* Initialize GIF data stream decoder. */

      data_size = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;
      if (data_size > 8)
      {
         SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: CorruptImage \n");
         //GIF_SW_RAISE(1);   /* CorruptImage */
         GIF_SW_RAISE(GIF_STATUS_DEC_ERROR_INVALID_FILE);   /* CorruptImage */
      }

      clear = 1 << data_size;
      end_of_information = clear + 1;
      available = clear + 2;
      old_code = NullCode;
      code_size = data_size + 1;
      code_mask = (1 << code_size) - 1;
      for (code = 0; code < clear; code++)
      {
         prefix[code] = 0;
         suffix[code] = (unsigned char)code;
      }

      /* decode gif pixel stream */
      datum = 0;
      bits = 0;
      c = 0;
      count = 0;
      first = 0;
      offset = 0;
      pass = 0;
      top_stack = pixel_stack;
      data_block_start_addr =  _gif_fsal_tell(pfsal_handle);

      for (y = src_clipy1; y <= src_clipy2; y++)
      {
         if(g_gif_sw_image_progress_callback)
         {
            if(!(*g_gif_sw_image_progress_callback)())
            {
                SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: GIF_SW_RET_DECODE_TIME_OUT. x=%d, y=%d \n", x, y);
                //GIF_SW_RAISE(GIF_SW_RET_DECODE_TIME_OUT);
                GIF_SW_RAISE(GIF_STATUS_DECODE_TIME_OUT);
            }
         }

         /* move to 0,offset */
         wantx = wantx0; 
         for (x = src_clipx1; x <= src_clipx2;)
         {
             kal_int32 decoded_pixel_count = 0;
             kal_int32 next_dst_data_distance = 0;

             /* ImageMagick Open Source Code Segment Start  */
             if (top_stack == pixel_stack)
             {
                if (bits < code_size)
                {
                   /* Load bytes until there is enough bits for a code. */
                   if (count == 0)
                   {
                       /* Read a new data block. */
                       count = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;
                       read_byte_cnt += count;
                       if (count == 0)
                       {
                          break;
                       }
                       packet = (unsigned char*)g_gif_sw_stack;    /* this will only use 256 bytes */
                       GETS(c, packet, count);
                   }
                   datum += ((unsigned int)(*c)) << bits;
                   bits += 8;
                   c++;
                   count--;
                   continue;
                }

                /* Get the next code. */
                code = datum & code_mask;
                datum >>= code_size;
                bits -= code_size;

                /* Interpret the code */
                if ((code > available) || (code == end_of_information))
                {
                   SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: Interpret the code \n");
                   FLUSH(count);
                   while (!IS_EOF()) // skip he remaining data blocks of the frame.
                   {
                      count = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;
                      if(count == 0)
                      {
                         break;
                      }
                      FLUSH(count);
                   }
                   return;
                }

                if (code == clear)
                {
                   /* Reset decoder. */
                   code_size = data_size + 1;
                   code_mask = (1 << code_size) - 1;
                   available = clear + 2;
                   old_code = NullCode;
                   continue;
                }

                if (old_code == NullCode)
                {
                   *top_stack++ = suffix[code];
                   old_code = code;
                   first = code;
                   continue;
                }
                in_code = code;
                if (code >= available)
                {
                   *top_stack++ = (unsigned char)first;
                   code = old_code;
                }

                while (code >= clear)
                {
                   if ((top_stack - pixel_stack) >= MaxStackSize)
                   {
                      break;
                   }
                   *top_stack++ = suffix[code];
                   code = (unsigned int)prefix[code];
                }
                first = (unsigned int)suffix[code];
                /* Add a new string to the string table, */

                if ((top_stack - pixel_stack) >= MaxStackSize)
                {
                   SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: (top_stack - pixel_stack) >= MaxStackSize)\n");
                   break;
                }

                if (available >= MaxStackSize)
                {
                   SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: available >= MaxStackSize\n");
                   break;
                }

                *top_stack++ = (unsigned char)first;
                prefix[available] = (short)old_code;
                suffix[available] = (unsigned char)first;
                available++;
                if (((available & code_mask) == 0) && (available < MaxStackSize))
                {
                   code_size++;
                   code_mask += available;
                }
                old_code = in_code;
             }

             top_stack--;
             /* ImageMagick Open Source Code Segment   End  */

             /* Pop a pixel off the pixel stack. */
             if (isResized)
             {
                decoded_pixel_count = top_stack - pixel_stack; //how many decoded pixels
                if ((src_clipy1 + offset) == GIF_SW_RESIZER.want_sy)
                {
                   if (wantx >= x)
                   {
                      next_dst_data_distance = wantx - x;// how long the distance including x
                   }
                   else
                   {
                      next_dst_data_distance = src_clipx2 - x;
                   }

                   if (decoded_pixel_count < next_dst_data_distance)
                   {
                      //it means all the decoded data this time shall be discarded.
                      x += decoded_pixel_count;
                      top_stack -= (decoded_pixel_count);
                   }
                   else
                   {
                      //some pixels in the decoded pixels shall be output to the dst image.
                      x += next_dst_data_distance;//GIF_SW_RESIZER.want_sx;
                      top_stack -= (next_dst_data_distance);
                   }
                }
                else
                {
                   //The source lineY shall be discarded for the resized image.
                   //wantx shall be GIF_SW_RESIZER.want_sx_table for all x (no need to update wantx)
                   if ((x + decoded_pixel_count) > src_clipx2)
                   {
                      next_dst_data_distance = src_clipx2 - x;
                   }
                   else
                   {
                      next_dst_data_distance = decoded_pixel_count;
                   }
                   x += next_dst_data_distance;//GIF_SW_RESIZER.want_sx;
                   top_stack -= (next_dst_data_distance);
                }
             }

             if ((x == wantx) && ((src_clipy1 + offset) == GIF_SW_RESIZER.want_sy))
             {
                kal_uint32 index = (kal_uint32) *top_stack;
                put_pixel(&wantx, ((gif_sw_color) g_gif_sw_current_palette[index]), ((kal_bool) (transparent_index != index)));
             }
             x++;
         }   /* x loop */
         gif_sw_resizer_update_wanty(&wantx, is_interlace);

         if (!is_interlace)
         {
            offset++;
         }
         else
         {
            switch (pass)
            {
               case 0:
               default:
               {
                   offset += 8;
                   if (offset >= image_rows)
                   {
                      pass++;
                      offset = 4;
                   }
                   break;
               }
               case 1:
               {
                  offset += 8;
                  if (offset >= image_rows)
                  {
                     pass++;
                     offset = 2;
                  }
                  break;
               }
               case 2:
               {
                  offset += 4;
                  if (offset >= image_rows)
                  {
                     pass++;
                     offset = 1;
                  }
                  break;
               }
               case 3:
               {
                  offset += 2;
                  break;
               }
            }
            gif_sw_resizer_update_interlaced_want_sy(isResized, &wantx, src_clipy1 + offset);
         }
         if (x <= src_clipx2)
         {
            //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec() Fail: x:%d <= src_clipx2:%d \n", x, src_clipx2);
            break;
         }
      }   /* y loop */
      if (y <= src_clipy2)
      {
          //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec() Fail:y:%d <= src_clipy2:%d \n", y, src_clipy2);
          //GIF_SW_RAISE(1);
          GIF_SW_RAISE(GIF_STATUS_DEC_ERROR_PARSE);
      }

      //if (1)
      {
         kal_uint8 val;
         kal_int32 remaining_cnt;
         kal_uint32 len, curpos;

         curpos = _gif_fsal_tell(pfsal_handle);
         remaining_cnt = (data_block_start_addr + read_byte_cnt) - curpos;
         if (remaining_cnt > 0)
         {
            //kal_uint32 dbg_idx = 0;
            //for (dbg_idx = 0; dbg_idx < (remaining_cnt); dbg_idx++)
            //{
            //  val = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;
            //  printf("Flush The Remaining %dth Byte = %d.\n", dbg_idx, val);
            //}
            FLUSH(remaining_cnt);
            //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec(): Flush1 %d bytes.\n", remaining_cnt);
         }
      }

      //if (1)
      {
         kal_uint32 len, curpos;
         kal_uint8 val;
         len = 0;
         //Flush the remaining data.

         while (1) // skip data blocks
         {
            count = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;
            curpos = _gif_fsal_tell(pfsal_handle);
         
            len += count;
            if (count == 0) //Block Terminator
            {
               //printf("Count = 0, Flush %d data.\n", len);
               break;
            }
         
            FLUSH(count);
            //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec(): Flush2 %d bytes.\n", count);
            //if (count > 0)
            //{
            //   kal_uint32 dbg_idx = 0;
            //   for (dbg_idx = 0; dbg_idx < len; dbg_idx++)
            //   {
            //      val = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF;
            //      printf("Flush %dth byte = %d.\n", curpos+dbg_idx, val);
            //   }
            //}
         }
      }
   }   /* codec block */

   //end = drv_get_current_time();
   //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec() End. %d ticks \n", drv_get_duration_tick(start, end));
   //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec(): Leave. FileCurPos = %d\n", _gif_fsal_tell(pfsal_handle));
}
コード例 #30
0
ファイル: zen_graph.c プロジェクト: TacOS-team/tacos-gui
void draw_plate(char* buffer, char color, int x, int y) {
	put_pixel(color,x - 7,y-1,buffer);
	put_pixel(color,x - 6,y,buffer);
	put_pixel(color, x - 5,y,buffer);
	put_pixel(color, x - 4,y,buffer);
	put_pixel(color, x - color,y,buffer);
	put_pixel(color, x - 2,y,buffer);
	put_pixel(color, x - 1,y,buffer);
	put_pixel(color, x,y,buffer);
	put_pixel(color, x + 1,y,buffer);
	put_pixel(color, x + 2,y,buffer);
	put_pixel(color, x + color,y,buffer);
	put_pixel(color, x + 4,y,buffer);
	put_pixel(color, x + 5,y,buffer);
	put_pixel(color,x + 6,y,buffer);
	put_pixel(color,x + 7,y-1,buffer);
}