Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*-
   fb_print_char
  -----------------------------------------------------------------------------
   Descriptif: Cette fonction permet d'afficher un caractère en fonction
   	   	   	   de la couleur et de la position choisie par l'utilisateur.
   Entrée    : int color 			: couleur choisie
   	   	   	   int color_fond 		: couleur de fond
   	   	   	   unsigned char car 	: caractère choisi
   	   	   	   int x 				: position en x sur l'afficheur
   	   	   	   int y 				: position en y sur l'afficheur
   Sortie    : Aucune
-*---------------------------------------------------------------------------*/
void fb_print_char(int color, int color_fond, unsigned char car, int x, int y)
{
	unsigned char ligne;
	unsigned int j;
	unsigned int i;
	unsigned int tab[] = { 1, 2, 4, 8, 16, 32, 64, 128};

	// Permet de parcourir les 8 lignes
	for (i = 0; i < 8 ; i++)
	{
		// Permet de récuperer la valeur codé sur 8 bits
		// pour le caractère.
		ligne = fb_font_data[car-FIRST_CHAR][i];

		// Permet de parcourir les 8 colonnes
		for (j = 0 ; j < 8; j++)
		{
			// Permet de déterminer si on doit allumer le pixel cocnerné
			if (ligne & tab[7-j])
				fb_set_pixel(y+i,x+j,color);
			else
				fb_set_pixel(y+i,x+j,color_fond);
		}
	}
}
Ejemplo n.º 2
0
void fb_draw_line2(int x0, int y0, int x1, int y1, uchar color)
 {
        int i;
        int steep = 1;
        int sx, sy;  /* step positive or negative (1 or -1) */
        int dx, dy;  /* delta (difference in X and Y between points) */
        int e;

        /*
         * optimize for vertical and horizontal lines here
         */

        dx = (x1 > x0) ? (x1 - x0) : x0 - x1;
        sx = ((x1 - x0) > 0) ? 1 : -1;
        dy = (y1 > y0) ? (y1 - y0) : y0 - y1;
        sy = ((y1 - y0) > 0) ? 1 : -1;
        e = (dy << 1) - dx;
        for (i = 0; i < dx; i++) {
                if (steep) {
                        fb_set_pixel(x0,y0,color);
                } else {
                        fb_set_pixel(y0,x0,color);
                }
                while (e >= 0) {
                        y0 += sy;
                        e -= (dx << 1);
                }
                x0 += sx;
                e += (dy << 1);
        }
 }
Ejemplo n.º 3
0
int fb_font_draw_bitmap(FB_SCREEN *screenp, FT_Bitmap *bitmap, FT_Int x, FT_Int y)
{
	COLOR_32 color[2], backcolor;
	FB_POINT point;

	FT_Int  i, j, p, q;
	FT_Int  x_max = x + bitmap->width;
	FT_Int  y_max = y + bitmap->rows;
	unsigned char ch;

	color[0] = fb_formatRGB(255, 255, 255);
	color[1] = fb_formatRGB(120, 120, 120);
	backcolor = fb_formatRGB(0, 0, 0);
	
	for ( j = y, q = 0; j < y_max; j++, q++ )
	{
		for ( i = x, p = 0; i < x_max; i++, p++ ){
			ch = bitmap->buffer[q * bitmap->width + p];
			if(ch > 128){
				//int fb_set_pixel(FB_POINT *point, int x, int y, COLOR_32 color);
				fb_set_pixel(&point, i, j, color[0]);
				//int fb_draw_pixel(struct framebuffer *fbp, FB_POINT *point);
				fb_draw_pixel_screen(screenp, &point);
			}else if(ch > 10){
				fb_set_pixel(&point, i, j, color[1]);
				fb_draw_pixel_screen(screenp, &point);
			}else{
				fb_set_pixel(&point, i, j, backcolor);
				fb_draw_pixel_screen(screenp, &point);
			}
		}
	}
	
	return 0;
}
Ejemplo n.º 4
0
// ------------------------------------------------------------------
// fb_draw_circle draws a circle at the specified location based on
// bresenham's circle drawing algorithm
void fb_draw_circle(ulong x, ulong y, ulong radius, uchar color)
{
    ulong xpos, ypos, d;

    xpos = x;
    ypos = radius;

    d = 3 - (2 * ypos);

    while(ypos >= xpos)
    {
		fb_set_pixel(x + xpos, y + ypos, color); // point in octant 1 
		fb_set_pixel(x - xpos, y + ypos, color); // point in octant 4 
		fb_set_pixel(x - xpos, y - ypos, color); // point in octant 5 
		fb_set_pixel(x + xpos, y - ypos, color); // point in octant 8 
		fb_set_pixel(x + ypos, y + xpos, color); // point in octant 2 
		fb_set_pixel(x - ypos, y + xpos, color); // point in octant 3 
		fb_set_pixel(x - ypos, y - xpos, color); // point in octant 6 
		fb_set_pixel(x + ypos, y - xpos, color); // point in octant 7 

		if (d < 0)
		{
		     d = (d + (4 * xpos)) + 6;
		}
		else
		{
			d = (d + (4 * (xpos - ypos))) + 10;
			ypos = ypos - 1;
		}

        xpos++;
    }
}
Ejemplo n.º 5
0
/* Dessine un cercle en fonction des coordonn�es du centre, du rayon,
   et de la couleur 							*/
int fb_circle(int yPos, int xPos, int radius, int color) {
	int i, y;
	int a, b, c, d;
	if (radius >= LCD_MAX_X / 2)
		radius = LCD_MAX_X / 2;

	for (i = 0; i <= radius; i++) {
		y = circleYpos(i, radius); /* calcul pixel p�riph�rie */

		a = (yPos > LCD_MAX_Y) ? LCD_MAX_Y : yPos;
		b = (yPos < 0) ? 0 : yPos;
		c = (xPos + i > LCD_MAX_X) ? LCD_MAX_X : xPos + i;
		d = (xPos - i < 0) ? 0 : xPos - i;
		fb_set_pixel(a, c, color);
		fb_set_pixel(b, c, color);
		fb_set_pixel(a, d, color);
		fb_set_pixel(b, d, color);

		a = (yPos + y > LCD_MAX_Y) ? LCD_MAX_Y : yPos + y;
		b = (yPos - y < 0) ? 0 : yPos - y;
		c = (xPos + i > LCD_MAX_X) ? LCD_MAX_X : xPos + i;
		d = (xPos - i < 0) ? 0 : xPos - i;
		fb_set_pixel(a, c, color);
		fb_set_pixel(b, c, color);
		fb_set_pixel(a, d, color);
		fb_set_pixel(b, d, color);
	}
	return 0;
}
Ejemplo n.º 6
0
FB_Surface *
gfx_bitmap_load(GFX_Bitmap *bitmap) {
	int bpp = bitmap->bytes_per_pixel;
	FB_Surface *sfc;
	FB_Color c;

	sfc = fb_create_surface(bitmap->width, bitmap->height, FB_FORMAT_BEST);

	for (int y=0; y<sfc->height; y++) {
		for (int x=0; x<sfc->width; x++) {
			int idx = y * sfc->width * bpp + x * bpp;
			c.a = 0xff;

			switch (bpp) {
				case 4:
					c.a = bitmap->pixel_data[idx + 3];
				// fall through!

				case 3:
					c.b = bitmap->pixel_data[idx + 2];
					c.g = bitmap->pixel_data[idx + 1];
					c.r = bitmap->pixel_data[idx + 0];
				break;

				case 1:
					c.r = c.g = c.b = bitmap->pixel_data[idx];
				break;
			}

			fb_set_pixel(sfc, x, y, &c);
		}
	}

	return (sfc);
}
Ejemplo n.º 7
0
FB_Surface *
gfx_glyph_load(GFX_Bitmap *bitmap, FB_Color *c) {
	int bpp = bitmap->bytes_per_pixel;
	FB_Surface *sfc;

	sfc = fb_create_surface(bitmap->width, bitmap->height, FB_FORMAT_BEST);

	for (int y=0; y<sfc->height; y++) {
		for (int x=0; x<sfc->width; x++) {
			int idx = y * sfc->width * bpp + x * bpp;

			switch (bpp) {
				case 1:
					// grayscale image
					c->a = bitmap->pixel_data[idx + 0];
				break;

				case 4:
					// RGBA image
					c->a = bitmap->pixel_data[idx + 3];
				break;
			}

			fb_set_pixel(sfc, x, y, c);
		}
	}

	return (sfc);
}
Ejemplo n.º 8
0
// ------------------------------------------------------------------
// fb_print_char prints a character at the specified location.
//
void fb_print_char(uchar cchar, ulong x, ulong y, uchar color)
{
    ulong idx1, idx2;
    uchar font_line, fcolor;

	// printable characters only
	if ((cchar < FIRST_CHAR) || (cchar > LAST_CHAR))
		return;

    // loop through each row of the font.
    for(idx1 = 0; idx1 < FONT_HEIGHT; idx1++)
    {
        // read the byte which describes this row of the font.
        font_line = fb_font_data[(cchar - FIRST_CHAR) * FONT_STEP][idx1];

        // loop through each column of this row.
        for(idx2 = 0; idx2 < 8; idx2++)
        {
            // set the pixel based on the value of this bit of the font, 
            // using the requested or the backround color.
            fcolor = font_line & 1 << ((FONT_WIDTH - 1) - idx2) ? color : bcolor;

            fb_set_pixel(x + idx2, y + idx1, fcolor);
        }
    }
}
Ejemplo n.º 9
0
void fb_rect_fill(int y_min, int y_max, int x_min, int x_max, int couleur) {

  int x = 0, y = 0;

  for (y = y_min; y <= y_max; y++)
    for (x = x_min; x <= x_max; x++)
      fb_set_pixel(y, x, couleur);
}
Ejemplo n.º 10
0
/* remplit un cercle en fonction des coordonn�es du centre, du rayon,
   et de la couleur 							*/
int fb_circle_fill(int yPos,int xPos,int radius,int color){
   int i,j,y;
   if (radius >= LCD_MAX_X/2) radius = LCD_MAX_X/2;
   if (xPos+radius >= LCD_MAX_X) xPos = LCD_MAX_X-1-radius;
   if (yPos+radius >= LCD_MAX_Y) yPos = LCD_MAX_Y-1-radius;
   if (xPos-radius < 0 ) xPos = radius;
   if (yPos-radius < 0 ) yPos = radius;
   for (i=0;i<=radius;i++){
      y = circleYpos( i, radius);             /* calcul pixel p�riph�rie */
      for (j=0;j<=y;j++) {                     /* remplissage */
         fb_set_pixel(yPos+j,xPos+i,color);
         fb_set_pixel(yPos-j,xPos+i,color);
         fb_set_pixel(yPos+j,xPos-i,color);
         fb_set_pixel(yPos-j,xPos-i,color);
      }
   }
 return 0;
}
Ejemplo n.º 11
0
/*
 * Draw a line form point1 to point2.
 */
int fb_draw_line_screen(FB_SCREEN *screenp, FB_POINT *point1, FB_POINT *point2)
{
	/* generalized integer Bresenham's algorithm for all quadrants
	 * the line end points aire (x1, y1) and (x2 , y2), assumed not equal
	 * all variables are assumed integer*/

	/* initialize variables */
	FB_POINT point;
	int x, y, dx, dy;
	int s1, s2;
	int e;			/* err(math) */
	int i, tmp, interchange;

	x = point1->x;
	y = point1->y;
	dx = abs(point2->x - x);
	dy = abs(point2->y - y);
	s1 = fb_line_sign(point2->x - point1->x);
	s2 = fb_line_sign(point2->y - point1->y);
	
	/* interchange dx and dy depending on the slope of the line */
	if(dy > dx){
		tmp = dx;
		dx = dy;
		dy = tmp;
		interchange = 1;
	}else{
		interchange = 0;
	}

	/* initialize the error term to compensate for a non zero intercept */
	e = 2 * dy - dx;

	/* main loop */
	for(i = 0; i <= dx; i++){
		fb_set_pixel(&point, x, y, point1->color);
		fb_draw_pixel_screen(screenp, &point);
		while(e > 0){
			if(interchange == 1){
				x = x + s1;
			}else{
				y = y + s2;
			}
			e = e - 2 * dx;
		}

		if(interchange == 1){
			y = y + s2;
		}else{
			x = x + s1;
		}
		e = e + 2 * dy;
	}

	return 0;
}
Ejemplo n.º 12
0
// ------------------------------------------------------------------
// fb_print_charx2 prints a double-sized character at the specified location.
//
void fb_print_charx2(char cchar, ulong x, ulong y, uchar color)
{
    ulong idx1, idx2;
    ushort font_line;
    uchar fcolor;

	// printable characters only
	if (((unsigned char)cchar < FIRST_CHAR) ||
		((unsigned char)cchar > LAST_CHAR))
		return;

    // loop through each row of the font.
    for(idx1 = 0; idx1 < FONT_HEIGHT; idx1++)
    {
        // read the byte which describes this row of the font.
        font_line = (fb_font_data[(cchar - FIRST_CHAR) * FONT_STEP][idx1]) << 8;
		if (FONT_WIDTH > 8)	// get the second byte if present
		{
	        font_line = fb_font_data[(cchar - FIRST_CHAR) * FONT_STEP][idx1 + 1];
		}

        // loop through each column of this row.
        for(idx2 = 0; idx2 < FONT_WIDTH; idx2++)
        {
            // determine the color of this pixel block.
            fcolor = font_line & (1 << ((FONT_WIDTH - 1) - idx2)) ? color : bcolor;

            // set the pixel block (2x2) based on the value of this bit of
            // the font, using the requested or the backround color.
            fb_set_pixel(x + (idx2 << 1), y + (idx1 << 1), fcolor);
            fb_set_pixel(x + (idx2 << 1) + 1, y + (idx1 << 1), fcolor);
            fb_set_pixel(x + (idx2 << 1), y + (idx1 << 1) + 1, fcolor);
            fb_set_pixel(x + (idx2 << 1) + 1, y + (idx1 << 1) + 1, fcolor);
        }
    }
}
Ejemplo n.º 13
0
void fb_draw_circle2(ulong xpos, ulong ypos, ulong radius, uchar color)
{
	int x;
	int y = radius;
	int d = -radius;
	for(x = 1; x < (radius/1.414); x++)
	{  d += (2 * x) - 1;
		if (d >= 0) 
			{  y--;
			   d -= (2 * y); /* Must do this AFTER y-- */
			}
	//	   fb_set_pixel(x + xpos, y + ypos, color);
		fb_set_pixel(xpos + x, ypos + y, color); // point in octant 1 
		fb_set_pixel(xpos - x, ypos + y, color); // point in octant 4 
		fb_set_pixel(xpos - x, ypos - y, color); // point in octant 5 
		fb_set_pixel(xpos + x, ypos - y, color); // point in octant 8 
		fb_set_pixel(xpos + y, ypos + x, color); // point in octant 2 
		fb_set_pixel(xpos - y, ypos + x, color); // point in octant 3 
		fb_set_pixel(xpos - y, ypos - x, color); // point in octant 6 
		fb_set_pixel(xpos + y, ypos - x, color); // point in octant 7 
	}    
}
Ejemplo n.º 14
0
/*
 * Draw a line form point1 to point2, only for the first octant
 */
int fb_draw_line_study(FB *fbp, FB_POINT *point1, FB_POINT *point2)
{
	/* Bresenham's line rasterization algorithm for the first octant
	 * the line end points are (x1, y1) and (x2, y2), assumed not equal
	 * Interger is the interger function*/
	FB_POINT point;
	int x, y, dx, dy;
	float m, e;
	int i;

	/* initialize variables */
	x = point1->x;
	y = point1->y;
	dx = point2->x - point1->x;
	dy = point2->y - point1->y;
	m = dy / (float)dx;

	/* initialize e to compensate for a nonzero intercept */
	e = m - 0.5;

#if TEST
	fprintf(stdout, "initialize variables: \n");
	fprintf(stdout, "(x, y) = (%d, %d)\n", x, y);
	fprintf(stdout, "(dx, dy) = (%d, %d)\n", dx, dy);
	fprintf(stdout, "m = %f, e = %f\n", m, e);
#endif
	/* begin the main loop */
	for(i = 0; i < dx; i++){
		fb_set_pixel(&point, x, y, point1->color);
		fb_draw_pixel(fbp, &point);
		while(e > 0){
			y = y + 1;
			e = e - 1;
		}
		x = x + 1;
		e = e + m;
	}

	return 0;
}
Ejemplo n.º 15
0
void fb_line(int x0, int y0, int x1, int y1, int color){
	int dx, dy, sx, sy, err, e2;

	/* On calcule les deltas en X et en Y entre les 2 points de la ligne */
	dx = abs(x1 - x0);
	dy = abs(y1 - y0);

	/* On calcule le sens de tracage et "l'erreur" (erreur = 0 -> segment à 45°) */
	if (x0 < x1){
		sx = 1;
	}else{
		sx = -1;
	}

	if (y0 < y1){
		sy = 1;
	}else{
		sy = -1;
	}

	err = dx - dy;

	/* Boucle de tracage de la ligne */
	do {
		fb_set_pixel(y0,x0,color);		// Dessiner un pixel

		e2 = 2 * err;
		// On corrige la trajectoire en X
		if (e2 > -dy) {
			err = err - dy;
			x0 = x0 + sx;
		}
		// On corrige la trajectoire en Y
		if (e2 < dx) {
			err = err + dx;
			y0 = y0 + sy;
		}
	} while ((x0 != x1) || (y0 != y1));
}
Ejemplo n.º 16
0
/*
 * Draw a frame for image,
 * @imgnum: status->img_list_mini[imgnum];
 */
int maindeal_img_frame_draw(struct mainstatus *status, FB_IMAGE *imagep, 
			    COLOR_32 startcolor, COLOR_32 stopcolor, int thick)
{
	int i;
	int tmp;		/* RGB temporary value */
	COLOR_32 color;
	FB_POINT point1;
	FB_RECT rect;

	for(i = 0; i < thick; i++){
		tmp = startcolor + (stopcolor - startcolor) / thick * i;
		color = fb_formatRGB(tmp, tmp, tmp);	

		fb_set_pixel(&point1, imagep->x - i - 1, imagep->y - i - 1 , color);
		fb_rect_set(&rect, &point1, imagep->width + 2 * i, 
			    imagep->height + 2 * i);

		//int fb_rect_draw_nonfill(FB *fbp, FB_RECT *rectp);
		fb_rect_draw_nofill_screen(&status->screen, &rect);
	}

	return 0;
}
Ejemplo n.º 17
0
Archivo: ds_jpeg.c Proyecto: dugoh/tcb
/**
 * load jpeg file to fb_pixmap
 * @param filename name of bmp file on the disk to load
 * @param fb_pixmap pointer to the memory for pixmap
 * @param w width of loaded image
 * @param h height of loaded image
 * @return 0 if success, 1 if failure.
 */
int jpeg2fb_pixmap(char * filename, fb_pixel ** fb_pixmap, Uint16 * w, Uint16 * h)
{
	int i, j;
	
	/* This struct contains the JPEG decompression parameters and pointers to
	* working space (which is allocated as needed by the JPEG library).
	*/

	struct jpeg_decompress_struct cinfo;

	/* We use our private extension JPEG error handler.
	* Note that this struct must live as long as the main JPEG parameter
	* struct, to avoid dangling-pointer problems.
	*/
	struct my_error_mgr jerr;

	/* source file */
	FILE * infile;

	/* Output row buffer */
	JSAMPARRAY buffer;

	/* physical row width in output buffer */
	int row_stride;
	
	/* In this example we want to open the input file before doing anything else,
	* so that the setjmp() error recovery below can assume the file is open.
	* VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
	* requires it in order to read binary files.
	*/
	if ((infile = fopen(filename, "rb")) == NULL) {
		fprintf(stderr, "can't open %s\n", filename);
		return 1;
	}
	
	/* Step 1: allocate and initialize JPEG decompression object */
	
	/* We set up the normal JPEG error routines, then override error_exit. */
	cinfo.err = jpeg_std_error(&jerr.pub);
	jerr.pub.error_exit = my_error_exit;

	/* Establish the setjmp return context for my_error_exit to use. */

	if (setjmp(jerr.setjmp_buffer))
	{
		/* If we get here, the JPEG code has signaled an error.
		* We need to clean up the JPEG object, close the input file, and return.
		*/
		jpeg_destroy_decompress(&cinfo);
		fclose(infile);
		return 1;
	}

	/* Now we can initialize the JPEG decompression object. */
	jpeg_create_decompress(&cinfo);
	
	/* Step 2: specify data source (eg, a file) */
	jpeg_stdio_src(&cinfo, infile);
	
	/* Step 3: read file parameters with jpeg_read_header() */
	(void) jpeg_read_header(&cinfo, TRUE);
	/* We can ignore the return value from jpeg_read_header since
	*   (a) suspension is not possible with the stdio data source, and
	*   (b) we passed TRUE to reject a tables-only JPEG file as an error.
	* See libjpeg.doc for more info.
	*/
	
	/* Step 4: set parameters for decompression */
	
	/* In this example, we don't need to change any of the defaults set by
	* jpeg_read_header(), so we do nothing here.
	*/

cinfo.out_color_space = JCS_RGB;

/*
	switch (cinfo.jpeg_color_space)
    {
    case JCS_YCbCr:
      //printf("YUV colorspace detected.\n");
      cinfo.out_color_space = JCS_YCbCr;
      break;
    case JCS_GRAYSCALE:
      //printf("Grayscale colorspace detected.\n");
      cinfo.out_color_space = JCS_GRAYSCALE;
      break;
    default:
      printf("Unsupported colorspace detected.\n"); 
      break;
    }	
*/	
	
	
	
	/* Step 5: Start decompressor */
	
	(void) jpeg_start_decompress(&cinfo);
	/* We can ignore the return value since suspension is not possible
	* with the stdio data source.
	*/
	
	/* We may need to do some setup of our own at this point before reading
	* the data. After jpeg_start_decompress() we have the correct scaled
	* output image dimensions available, as well as the output colormap
	* if we asked for color quantization.
	* In this example, we need to make an output work buffer of the right size.
	*/

	/* JSAMPLEs per row in output buffer */
	row_stride = cinfo.output_width * cinfo.output_components;

	/* Make a one-row-high sample array that will go away when done with image */
	buffer = (*cinfo.mem->alloc_sarray)
			((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
	
	/* Step 6: while (scan lines remain to be read) */
	
	/* Here we use the library's state variable cinfo.output_scanline as the
	* loop counter, so that we don't have to keep track ourselves.
	*/
	*w = cinfo.output_width;
	*h = cinfo.output_height;
	
	*fb_pixmap = (fb_pixel*)malloc((*w) * (*h) * pixelsize);
	if ((*fb_pixmap)==NULL)
	{
		/* error while allocating memory */
		fclose(infile);
		(void)jpeg_finish_decompress(&cinfo);
		jpeg_destroy_decompress(&cinfo);
		return 1;
	}
	
	j = 0;
	
	/* We are reading each row of image, one by one */
	while (cinfo.output_scanline < cinfo.output_height) {

		/* jpeg_read_scanlines expects an array of pointers to scanlines.
		* Here the array is only one element long, but you could ask for
		* more than one scanline at a time if that's more convenient.
		*/
		(void) jpeg_read_scanlines(&cinfo, buffer, 1);

		/* Assume put_scanline_someplace wants a pointer and sample count. */
		
		for (i = 0; i < cinfo.output_width; i++) {
			/* Some of pointer magic, that allow me to create pixel in right framebuffer format */
			fb_set_pixel((*fb_pixmap)+((i+j*(*w))*pixelsize), *((*buffer)+i*3+0), *((*buffer)+i*3+1), *((*buffer)+i*3+2));
		}
		
		j++;
	}
	
	/* Step 7: Finish decompression */
	
	/* We can ignore the return value since suspension is not possible
	* with the stdio data source.
	*/
	(void) jpeg_finish_decompress(&cinfo);
	
	/* Step 8: Release JPEG decompression object */
	
	/* This is an important step since it will release a good deal of memory. */
	jpeg_destroy_decompress(&cinfo);
	
	/* After finish_decompress, we can close the input file.
	* Here we postpone it until after no more JPEG errors are possible,
	* so as to simplify the setjmp error logic above.  (Actually, I don't
	* think that jpeg_destroy can do an error exit, but why assume anything...)
	*/
	fclose(infile);
	
	/* At this point you may want to check to see whether any corrupt-data
	* warnings occurred (test whether jerr.pub.num_warnings is nonzero).
	*/
	
	/* And we're done! */
	return 0;
}