All pastes #404925 Raw Edit

alphaopacity.c

public c v1 · immutable
#404925 ·published 2007-03-21 10:55 UTC
rendered paste body
/*************************************************************************** *             __________               __   ___. *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  / *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  < *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \ *                     \/            \/     \/    \/            \/ * * Copyright (C) 2007 Stefan Saftescu * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ /*	lcd_drawpixel_alpha (returns true on success):		- draw a semi-transparent pixel		rb: the plugin api pointer		x, y: coordinates of the pixel		color: the colour of the pixel			(24bpp; you can write it just like in HTML: white is 0xFFFFFF, black 0x000000, pure green 0x00FF00 etc.)		alpha: the transparency of the rectangle; ranges from 255 (opaque) to 0 (transparent)*/bool lcd_drawpixel_alpha(struct plugin_api* rb, short int x, short int y, int color, unsigned char alpha);  /*	lcd_fillrect_alpha (returns true on success):		- draw a semi-transparent rectangle (useful over an image / irregular coloured pixels)		rb: the plugin api pointer		x1, y1: coordinates of the top left corner of the rectangle		x2, y2: coordinates of the bottom right corner of the rectangle		color: the colour of the rectangle			(24bpp; you can write it just like in HTML: white is 0xFFFFFF, black 0x000000, pure green 0x00FF00 etc.)		alpha: the transparency of the rectangle; ranges from 255 (opaque) to 0 (transparent)		*/bool lcd_fillrect_alpha(struct plugin_api* rb, short int x1, short int y1, short int x2, short int y2, int color, unsigned char alpha);/*	lcd_fillrect_alpha_uniform (returns true on success):		- draw a semi-transparent rectangle, based on the color of pixel at x1, y1 in the framebuffer		(useful over a uniform coloured background)		rb: the plugin api pointer		x1, y1: coordinates of the top left corner of the rectangle		x2, y2: coordinates of the bottom right corner of the rectangle		color: the colour of the rectangle			(24bpp; you can write it just like in HTML: white is 0xFFFFFF, black 0x000000, pure green 0x00FF00 etc.)		alpha: the transparency of the rectangle; ranges from 255 (opaque) to 0 (transparent)		*/bool lcd_fillrect_alpha_uniform(struct plugin_api* rb, short int x1, short int y1, short int x2, short int y2, int color, unsigned char alpha);/*	lcd_fillrect_halpha (returns true on success):		- draw a semi-transparent rectangle, based on the colors of pixels at x1 in the framebuffer		(useful over a horizontal gradient)		rb: the plugin api pointer		x1, y1: coordinates of the top left corner of the rectangle		x2, y2: coordinates of the bottom right corner of the rectangle		color: the colour of the rectangle			(24bpp; you can write it just like in HTML: white is 0xFFFFFF, black 0x000000, pure green 0x00FF00 etc.)		alpha: the transparency of the rectangle; ranges from 255 (opaque) to 0 (transparent)		*/bool lcd_fillrect_halpha(struct plugin_api* rb, short int x1, short int y1, short int x2, short int y2, int color, unsigned char alpha);/*	lcd_fillrect_valpha (returns true on success):		- draw a semi-transparent rectangle, based on the colors of pixels at y1 in the framebuffer		(useful over a vertical gradient)		rb: the plugin api pointer		x1, y1: coordinates of the top left corner of the rectangle		x2, y2: coordinates of the bottom right corner of the rectangle		color: the colour of the rectangle			(24bpp; you can write it just like in HTML: white is 0xFFFFFF, black 0x000000, pure green 0x00FF00 etc.)		alpha: the transparency of the rectangle; ranges from 255 (opaque) to 0 (transparent)		*/bool lcd_fillrect_valpha(struct plugin_api* rb, short int x1, short int y1, short int x2, short int y2, int color, unsigned char alpha);/* actual code starts here */bool lcd_drawpixel_alpha(struct plugin_api* rb, short int x, short int y, int color, unsigned char alpha){	short int r1, g1, b1, r2, g2, b2;	unsigned tmp = rb->lcd_get_foreground();		r2 = (color >> 16) & 255;	g2 = (color >>  8) & 255;	b2 = (color      ) & 255;		r1 = RGB_UNPACK_RED  (rb->lcd_framebuffer[y*LCD_WIDTH+x]); 	g1 = RGB_UNPACK_GREEN(rb->lcd_framebuffer[y*LCD_WIDTH+x]); 	b1 = RGB_UNPACK_BLUE (rb->lcd_framebuffer[y*LCD_WIDTH+x]);	r1 = ((255-alpha)*r1 + alpha*r2) / 255;	g1 = ((255-alpha)*g1 + alpha*g2) / 255;	b1 = ((255-alpha)*b1 + alpha*b2) / 255;	rb->lcd_set_foreground(LCD_RGBPACK(r1, g1, b1));	rb->lcd_drawpixel(x,y);	rb->lcd_set_foreground(tmp);	return true;}bool lcd_fillrect_alpha(struct plugin_api* rb, short int x1, short int y1, short int x2, short int y2, int color, unsigned char alpha){	short int r1, g1, b1, r2, g2, b2;	short int i, j;	unsigned tmp = rb->lcd_get_foreground();		r2 = (color >> 16) & 255;	g2 = (color >>  8) & 255;	b2 = (color      ) & 255;		for(i=x1;i<x2;++i)	{		for(j=y1;j<y2;++j)		{			r1 = RGB_UNPACK_RED  (rb->lcd_framebuffer[j*LCD_WIDTH+i]); 			g1 = RGB_UNPACK_GREEN(rb->lcd_framebuffer[j*LCD_WIDTH+i]); 			b1 = RGB_UNPACK_BLUE (rb->lcd_framebuffer[j*LCD_WIDTH+i]);			r1 = ((255-alpha)*r1 + alpha*r2) / 255;			g1 = ((255-alpha)*g1 + alpha*g2) / 255;			b1 = ((255-alpha)*b1 + alpha*b2) / 255;			rb->lcd_set_foreground(LCD_RGBPACK(r1, g1, b1));			rb->lcd_drawpixel(i, j);		}	}	rb->lcd_set_foreground(tmp);	return true;}bool lcd_fillrect_alpha_uniform(struct plugin_api* rb, short int x1, short int y1, short int x2, short int y2, int color, unsigned char alpha){	short int r1, g1, b1, r2, g2, b2;	unsigned tmp = rb->lcd_get_foreground();		r2 = (color >> 16) & 255;	g2 = (color >>  8) & 255;	b2 = (color      ) & 255;		r1 = RGB_UNPACK_RED  (rb->lcd_framebuffer[y1*LCD_WIDTH+x1]); 	g1 = RGB_UNPACK_GREEN(rb->lcd_framebuffer[y1*LCD_WIDTH+x1]); 	b1 = RGB_UNPACK_BLUE (rb->lcd_framebuffer[y1*LCD_WIDTH+x1]);	r1 = ((255-alpha)*r1 + alpha*r2) / 255;	g1 = ((255-alpha)*g1 + alpha*g2) / 255;	b1 = ((255-alpha)*b1 + alpha*b2) / 255;	rb->lcd_set_foreground(LCD_RGBPACK(r1, g1, b1));	rb->lcd_fillrect(x1,y1,x2-x1,y2-y1);	rb->lcd_set_foreground(tmp);	return true;}bool lcd_fillrect_halpha(struct plugin_api* rb, short int x1, short int y1, short int x2, short int y2, int color, unsigned char alpha){	short int r1, g1, b1, r2, g2, b2;	short int i;	unsigned tmp = rb->lcd_get_foreground();		r2 = (color >> 16) & 255;	g2 = (color >>  8) & 255;	b2 = (color      ) & 255;		for(i=y1;i<=y2;++i)	{				r1 = RGB_UNPACK_RED  (rb->lcd_framebuffer[i*LCD_WIDTH+x1]); 		g1 = RGB_UNPACK_GREEN(rb->lcd_framebuffer[i*LCD_WIDTH+x1]); 		b1 = RGB_UNPACK_BLUE (rb->lcd_framebuffer[i*LCD_WIDTH+x1]);		r1 = ((255-alpha)*r1 + alpha*r2) / 255;		g1 = ((255-alpha)*g1 + alpha*g2) / 255;		b1 = ((255-alpha)*b1 + alpha*b2) / 255;		rb->lcd_set_foreground(LCD_RGBPACK(r1, g1, b1));		rb->lcd_hline(x1, x2, i);	}	rb->lcd_set_foreground(tmp);	return true;}bool lcd_fillrect_valpha(struct plugin_api* rb, short int x1, short int y1, short int x2, short int y2, int color, unsigned char alpha){	short int r1, g1, b1, r2, g2, b2;	short int i;	unsigned tmp = rb->lcd_get_foreground();		r2 = (color >> 16) & 255;	g2 = (color >>  8) & 255;	b2 = (color      ) & 255;		for(i=x1;i<=x2;++i)	{				r1 = RGB_UNPACK_RED  (rb->lcd_framebuffer[y1*LCD_WIDTH+i]); 		g1 = RGB_UNPACK_GREEN(rb->lcd_framebuffer[y1*LCD_WIDTH+i]); 		b1 = RGB_UNPACK_BLUE (rb->lcd_framebuffer[y1*LCD_WIDTH+i]);		r1 = ((255-alpha)*r1 + alpha*r2) / 255;		g1 = ((255-alpha)*g1 + alpha*g2) / 255;		b1 = ((255-alpha)*b1 + alpha*b2) / 255;		rb->lcd_set_foreground(LCD_RGBPACK(r1, g1, b1));		rb->lcd_vline(i, y1, y2);	}	rb->lcd_set_foreground(tmp);	return true;}