Exemple #1
0
pixel_t compose_over(pixel_t fg, pixel_t bg)
{
	double mul;
	double mul_cmp;

	double res_a;
	double res_r;
	double res_g;
	double res_b;

	if (ALPHA(bg) == 255) {
		res_a = 1;
		mul = ((double) ALPHA(fg)) / 255.0;
		mul_cmp = 1 - mul;
	} else {
		double fg_a = ((double) ALPHA(fg)) / 255.0;
		double bg_a = ((double) ALPHA(bg)) / 255.0;

		res_a = 1 - (1 - fg_a) * (1 - bg_a);
		mul = fg_a / res_a;
		mul_cmp = 1 - mul;
	}

	res_r = mul * ((double) RED(fg)) + mul_cmp * ((double) RED(bg));
	res_g = mul * ((double) GREEN(fg)) + mul_cmp * ((double) GREEN(bg));
	res_b = mul * ((double) BLUE(fg)) + mul_cmp * ((double) BLUE(bg));

	return PIXEL((unsigned) (res_a * 255),
	    (unsigned) res_r, (unsigned) res_g, (unsigned) res_b);
}
void PointSet::Draw ( float* view_mat, float rad )
{
	char* dat;
	Point* p;
	glEnable ( GL_NORMALIZE );	

	if ( m_Param[PNT_DRAWMODE] == 0 ) {
		glLoadMatrixf ( view_mat );
		dat = mBuf[0].data;	
		for (int n = 0; n < NumPoints(); n++) {
			p = (Point*) dat;
			glPushMatrix ();
			glTranslatef ( p->pos.x, p->pos.y, p->pos.z );		
			glScalef ( 0.2, 0.2, 0.2 );	
			if(p->type == 0)
			glColor4f ( 0.1,0.3,1.0,1.0 );//glColor4f ( RED(p->clr), GRN(p->clr), BLUE(p->clr), ALPH(p->clr) );
			else
            glColor4f ( RED(p->clr), GRN(p->clr), BLUE(p->clr), 0.0 );
			drawSphere ();
			glPopMatrix ();		
			dat += mBuf[0].stride;
		}	
	} else if ( m_Param[PNT_DRAWMODE] == 1 ) {
		glLoadMatrixf ( view_mat );
		dat = mBuf[0].data;
		glBegin ( GL_POINTS );
		for (int n=0; n < NumPoints(); n++) {
			p = (Point*) dat;
			glColor3f ( RED(p->clr), GRN(p->clr), BLUE(p->clr) );			
			glVertex3f ( p->pos.x, p->pos.y, p->pos.z );			
			dat += mBuf[0].stride;
		}
		glEnd ();
	}
}
Exemple #3
0
static int
rain_init(video_adapter_t *adp)
{
	video_info_t info;
	int i;
	
	if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
		scrmode = M_VGA_CG320;
	} else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) {
		scrmode = M_PC98_PEGC640x480;
	} else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) {
		scrmode = M_PC98_PEGC640x400;
	} else {
		log(LOG_NOTICE,
		    "%s: the console does not support M_VGA_CG320\n",
		    SAVER_NAME);
		return (ENODEV);
	}
	
	scrw = info.vi_width;
	scrh = info.vi_height;

	/* intialize the palette */
	for (i = 1; i < MAX; i++)
		rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)] + INCREMENT;
	
	return (0);
}
Exemple #4
0
int normalize(int width, int height, unsigned char* rgb)
{
	int
		x,y,
		red_min=255, red_max=0, 
		blue_min=255, blue_max=0, 
		green_min=255, green_max=0;
	double
		min, max, amplify; 

	/* determine min and max per color... */

	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			MINMAX( RED(rgb,x,y,width), red_min,   red_max  );
			MINMAX( GREEN(rgb,x,y,width), green_min, green_max);
			MINMAX( BLUE(rgb,x,y,width), blue_min,  blue_max );
		}
	}

	/* determine min and max per color... */

	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			MINMAX( RED(rgb,x,y,width), red_min,   red_max  );
			MINMAX( GREEN(rgb,x,y,width), green_min, green_max);
			MINMAX( BLUE(rgb,x,y,width), blue_min,  blue_max );
		}
	}

	/* Normalize brightness ... */

	max = MAX( MAX( red_max, green_max ), blue_max);
	min = MIN( MIN( red_min, green_min ), blue_min);
	amplify = 255.0/(max-min);


	printf("min=%f max=%f amplify=%f\n",min,max,amplify);
	if (max == 255)
		printf("max is already max'ed at 255. Exiting from normalize()\n");
		return 0;



	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			RED(rgb,x,y,width)= MIN(amplify*(double)(RED(rgb,x,y,width)-min),255);
			GREEN(rgb,x,y,width)= MIN(amplify*(double)(GREEN(rgb,x,y,width)-min),255);
			BLUE(rgb,x,y,width)= MIN(amplify*(double)(BLUE(rgb,x,y,width)-min),255);
		}
	}

	return 0;
}
ColorARGB GifTranscoder::computeAverage(ColorARGB c1, ColorARGB c2, ColorARGB c3, ColorARGB c4) {
    char avgAlpha = (char)(((int) ALPHA(c1) + (int) ALPHA(c2) +
                            (int) ALPHA(c3) + (int) ALPHA(c4)) / 4);
    char avgRed =   (char)(((int) RED(c1) + (int) RED(c2) +
                            (int) RED(c3) + (int) RED(c4)) / 4);
    char avgGreen = (char)(((int) GREEN(c1) + (int) GREEN(c2) +
                            (int) GREEN(c3) + (int) GREEN(c4)) / 4);
    char avgBlue =  (char)(((int) BLUE(c1) + (int) BLUE(c2) +
                            (int) BLUE(c3) + (int) BLUE(c4)) / 4);
    return MAKE_COLOR_ARGB(avgAlpha, avgRed, avgGreen, avgBlue);
}
Exemple #6
0
static void
rain_update(video_adapter_t *adp)
{
	int i, t;

	t = rain_pal[BLUE(MAX)];
	for (i = MAX; i > 1; i--)
		rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)];
	rain_pal[BLUE(1)] = t;
	vidd_load_palette(adp, rain_pal);
}
internal void
PT_CopyBlend(u32 *destPixels, PT_Rect *destRect, u32 destPixelsPerRow,
             u32 *srcPixels, PT_Rect *srcRect, u32 srcPixelsPerRow,
             u32 *newColor)
{
    // If src and dest rects are not the same size ==> bad things
    assert(destRect->w == srcRect->w && destRect->h == srcRect->h);

    // For each pixel in the destination rect, alpha blend to it the 
    // corresponding pixel in the source rect.
    // ref: https://en.wikipedia.org/wiki/Alpha_compositing

    u32 stopX = destRect->x + destRect->w;
    u32 stopY = destRect->y + destRect->h;

    for (u32 dstY = destRect->y, srcY = srcRect->y; 
         dstY < stopY; 
         dstY++, srcY++) {
        for (u32 dstX = destRect->x, srcX = srcRect->x; 
             dstX < stopX; 
             dstX++, srcX++) {

            u32 srcColor = srcPixels[(srcY * srcPixelsPerRow) + srcX];
            u32 *destPixel = &destPixels[(dstY * destPixelsPerRow) + dstX];
            u32 destColor = *destPixel;

            // Colorize our source pixel before we blend it
            srcColor = PT_ColorizePixel(srcColor, *newColor);

            if (ALPHA(srcColor) == 0) {
                // Source is transparent - so do nothing
                continue;
            } else if (ALPHA(srcColor) == 255) {
                // Just copy the color, no blending necessary
                *destPixel = srcColor;
            } else {
                // Do alpha blending
                float srcA = ALPHA(srcColor) / 255.0;
                float invSrcA = (1.0 - srcA);
                float destA = ALPHA(destColor) / 255.0;

                float outAlpha = srcA + (destA * invSrcA);
                u8 fRed = ((RED(srcColor) * srcA) + (RED(destColor) * destA * invSrcA)) / outAlpha;
                u8 fGreen = ((GREEN(srcColor) * srcA) + (GREEN(destColor) * destA * invSrcA)) / outAlpha;
                u8 fBlue = ((BLUE(srcColor) * srcA) + (BLUE(destColor) * destA * invSrcA)) / outAlpha;
                u8 fAlpha = outAlpha * 255;

                *destPixel = COLOR_FROM_RGBA(fRed, fGreen, fBlue, fAlpha);
            }
        }
    }
}
void
hippo_cairo_set_source_rgba32(cairo_t *cr,
                              guint32  color)
{
    /* trying to avoid alpha 255 becoming a double alpha that isn't quite opaque ?
     * not sure this is needed.
     */
    if ((color & 0xff) == 0xff) {
        cairo_set_source_rgb(cr, RED(color), GREEN(color), BLUE(color));
    } else {
        cairo_set_source_rgba(cr, RED(color), GREEN(color), BLUE(color), ALPHA(color));
    }
}
uint32_t getBilinearInterpolatedPixel(const void *pixels, int width, int height, int stride, float x, float y) {
	int x1 = (int) x;
	int x2 = x1+1;
	int y1 = (int) y;
	int y2 = y1+1;
	
	uint32_t pixel1 = getPixelRGBA(pixels, stride, x1%width, y1%height);
	uint32_t pixel2 = getPixelRGBA(pixels, stride, x2%width, y1%height);
	uint32_t pixel3 = getPixelRGBA(pixels, stride ,x1%width, y2%height);
	uint32_t pixel4 = getPixelRGBA(pixels, stride, x2%width, y2%height);
	
	int red1 = RED(pixel1);
	int green1 = GREEN(pixel1);
	int blue1 = BLUE(pixel1);
	
	int red2 = RED(pixel2);
	int green2 = GREEN(pixel2);
	int blue2 = BLUE(pixel2);
	
	int red3 = RED(pixel3);
	int green3 = GREEN(pixel3);
	int blue3 = BLUE(pixel3);
	
	int red4 = RED(pixel4);
	int green4 = GREEN(pixel4);
	int blue4 = BLUE(pixel4);
	
	float w1 = x2-x;
	float w2 = x-x1; 
	
	float red1_2 = w1*red1 + w2*red2;
	float red2_3 = w1*red3 + w2*red4;
	
	float green1_2 = w1*green1 + w2*green2;
	float green2_3 = w1*green3 + w2*green4;
	
	float blue1_2 = w1*blue1 + w2*blue2;
	float blue2_3 = w1*blue3 + w2*blue4;
	
	w1 = y2-y;
	w2 = y-y1;
	
	int red = (int) (w1*red1_2 + w2*red2_3 + 0.5);
	int green = (int) (w1*green1_2 + w2*green2_3 + 0.5);
	int blue = (int) (w1*blue1_2 + w2*blue2_3 + 0.5);

	return createRGBAPixel(red, green, blue, 0);
}
void TermCMD::help(cTerm & t,int argc,char *argv[])
{
	t<<(GREEN("TermCMD commands:\n"));

	cmd_table_t* t_ptr = NULL;
	char txt[16];

	int k = 0;
	do
	{
		t_ptr = &mCmdTable[k++];
		if(!t_ptr->cmd)
			break;

		if(t_ptr->f)
		{
			sprintf(txt,"%s %s", t_ptr->cmd, t_ptr->argDesc);
			t<<"  "<<t.format("%-10s - ",txt)<<t.format("%s\n",t_ptr->desc);
		}
		else
		{
			//this is a caption
			t<<t.format(BLUE("%s\n"), t_ptr->cmd);
		}

	}while(t_ptr->cmd);
}
Exemple #11
0
/*
void draw2DBox(int top, int left, int right, int bottom, DWORD colour[4])
{
	CONTROLVERTEX Vertices[4] =	{
		// x, y, z, rhw, colour, tu,tv
		{	left,	bottom,		0.0f,	1.0f,	colour[0],	0.0f,	1.0f },		// BL
		{	right,	bottom, 0.0f,	1.0f,	colour[2],	1.0f,	1.0f },		// BR
		{	left,	top,			0.0f,	1.0f,	colour[1],	0.0f,	0.0f },		// TL
		{	right,	top,		0.0f,	1.0f,	colour[3],	1.0f,	0.0f },		// TR
	};                                                          
	
	glBegin(GL_TRIANGLE_STRIP);
	for (int i = 0; i < 4; )
	{
			DWORD &c = Vertices[i].diffuse;
			float c1[4] ={
				((float)RED(c)) / 255.0,
			  ((float)GREEN(c)) / 255.0,
			  ((float)BLUE(c)) / 255.0,
			  ((float)ALPHA(c)) / 255.0
			};
			
			glColor4fv(c1);  
			glTexCoord2d(Vertices[i].tu0,Vertices[i].tv0);
			glVertex3f(Vertices[i].x, Vertices[i].y, Vertices[i].z); 
			i++;
	}	
	glEnd();
}
*/
void draw2DBox(float top, float left, float right, float bottom, DWORD colour[4])
{
	CONTROLVERTEX Vertices[4] =	{
		// x, y, z, rhw, colour, tu,tv
		{	left,	bottom,		0.0f,	1.0f,	colour[0],	0.0f,	1.0f },		// BL
		{	right,	bottom, 0.0f,	1.0f,	colour[2],	1.0f,	1.0f },		// BR
		{	left,	top,			0.0f,	1.0f,	colour[1],	0.0f,	0.0f },		// TL
		{	right,	top,		0.0f,	1.0f,	colour[3],	1.0f,	0.0f },		// TR
	};                                                          
	
	glBegin(GL_TRIANGLE_STRIP);
	for (int i = 0; i < 4; )
	{
			DWORD &c = Vertices[i].diffuse;
			float c1[4] ={
				((float)RED(c)) / 255.0f,
			  ((float)GREEN(c)) / 255.0f,
			  ((float)BLUE(c)) / 255.0f,
			  ((float)ALPHA(c)) / 255.0f
			};
			
			glColor4fv(c1);  
			glTexCoord2d(Vertices[i].tu0,Vertices[i].tv0);
			glVertex3f(Vertices[i].x, Vertices[i].y, Vertices[i].z); 
			i++;
	}	
	glEnd();
}
Exemple #12
0
char *region_of_interest (NEURON_LAYER *nl_input, int x_center, int y_center, int width, int height)
{
	int xi, yi, wi, hi, xo, yo, wo, ho;
	NEURON_OUTPUT value;
	
	char * output = malloc(width * height * 3 * sizeof(char));
	
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;
	
	wo = width;
	ho = height;
	
	for (yo = 0; yo < ho; yo++)
	{
		for (xo = 0; xo < wo; xo++)
		{			
			xi = (int) ((double) xo + .5) + x_center - wo/2;
			yi = (int) ((double) yo + .5) + y_center - ho/2;
			
			if (xi >= 0 && xi < wi && yi >= 0 && yi < hi)
				value = nl_input->neuron_vector[xi + wi * yi].output;
			else
				value.ival = 0;
			
			output[3 * (yo * wo + xo) + 0] = RED(value.ival);
			output[3 * (yo * wo + xo) + 1] = GREEN(value.ival);
			output[3 * (yo * wo + xo) + 2] = BLUE(value.ival);
		}
	}
	
	return output;
}
	bool RGBLinearQuantizationFilter::Apply(til::Image &image) const
	{
		if (image.GetBitDepth() != til::Image::BPP_32B_R8G8B8) return false;

		til::uint32 *image_pixels = reinterpret_cast<til::uint32*>(image.GetPixels());

		std::vector<til::byte> palette[3] = { 
			std::vector<til::byte>(max(((til::byte)(_palette_quants)),       1), 0x00),
			std::vector<til::byte>(max(((til::byte)(_palette_quants >>  8)), 1), 0x00),
			std::vector<til::byte>(max(((til::byte)(_palette_quants >> 16)), 1), 0x00)
		};

		til::byte index[] = { 
			static_cast<til::byte>(0x100 / palette[0].size()) + (palette[0].size() % 2 * static_cast<til::byte>(palette[0].size() > 1)), 
			static_cast<til::byte>(0x100 / palette[1].size()) + (palette[1].size() % 2 * static_cast<til::byte>(palette[1].size() > 1)), 
			static_cast<til::byte>(0x100 / palette[2].size()) + (palette[2].size() % 2 * static_cast<til::byte>(palette[2].size() > 1)) 
		};

		for(std::vector<til::byte>::size_type i = 0, max = palette[0].size(); i < max; ++i) palette[0][i] = static_cast<til::byte>(i * index[0]);
		for(std::vector<til::byte>::size_type i = 0, max = palette[1].size(); i < max; ++i) palette[1][i] = static_cast<til::byte>(i * index[1]);
		for(std::vector<til::byte>::size_type i = 0, max = palette[2].size(); i < max; ++i) palette[2][i] = static_cast<til::byte>(i * index[2]);

		for (til::uint64 i = 0, max = image.GetWidth() * image.GetHeight(); i < max; ++i)
		{
			image_pixels[i] = RGB(
					palette[0][index[0] == 0x00 ? 0 : RED(image_pixels[i])   / index[0]],
					palette[1][index[1] == 0x00 ? 0 : GREEN(image_pixels[i]) / index[1]],
					palette[2][index[2] == 0x00 ? 0 : BLUE(image_pixels[i])  / index[2]]
				);
		}

		return true;
	}
Exemple #14
0
void draw3DLine(float sx, float sy, float sz, float ex, float ey, float ez, DWORD colour)
{
	glLoadIdentity();
	/*D3DXMATRIX mat;
	D3DXMatrixIdentity(&mat);
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &mat );	// Move object
*/
			DWORD &c = colour;
			float c1[4] ={
				((float)RED(c)) / 255.0f,
			  ((float)GREEN(c)) / 255.0f,
			  ((float)BLUE(c)) / 255.0f,
			  ((float)ALPHA(c)) / 255.0f
			};
			
			glColor4fv(c1);  
	
		glBegin(GL_LINES);
//		glColor4f(RED(colour), GREEN(colour), BLUE(colour), ALPHA(colour));  
		glVertex3f(sx, sy, sz);
		glVertex3f(ex, ey, ez);
	glEnd();	
	/*
	#define D3DFVF_LVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
	struct LVERTEX { float x, y, z; DWORD diffuse; };
	LVERTEX line[2] = {
		{ sx,	sy,	sz,	colour	}, 
		{ ex,	ey, ez,	colour	}
	};			
	SetVertexShader( D3DFVF_LVERTEX );
	g_pd3dDevice->DrawPrimitiveUP(D3DPT_LINELIST, 2, line, sizeof(LVERTEX));
*/
}
Exemple #15
0
void GEQuad::drawVisual(vector_t unit_size)
{
  float hx, hy, hz;
  hx = (this->dimensions.x * unit_size.x) / 2;
  hy = (this->dimensions.y * unit_size.y) / 2;
  hz = (this->dimensions.z * unit_size.z) / 2;
  glBegin(GL_QUADS);
  glColor3ub(RED(bg_color), GREEN(bg_color), BLUE(bg_color));
  glVertex3f( hx, hy,-hz);
  glVertex3f(-hx, hy,-hz);
  glVertex3f(-hx, hy, hz);
  glVertex3f( hx, hy, hz);
  glVertex3f( hx,-hy, hz);
  glVertex3f(-hx,-hy, hz);
  glVertex3f(-hx,-hy,-hz);
  glVertex3f( hx,-hy,-hz);
  glVertex3f( hx, hy, hz);
  glVertex3f(-hx, hy, hz);
  glVertex3f(-hx,-hy, hz);
  glVertex3f( hx,-hy, hz);
  glVertex3f( hx,-hy,-hz);
  glVertex3f(-hx,-hy,-hz);
  glVertex3f(-hx, hy,-hz);
  glVertex3f( hx, hy,-hz);
  glEnd();
}
Exemple #16
0
/*
 * Enforces all pixels to grayscale.
 */
void compute_gray(struct jpeg_data *jpeg)
{
        if (jpeg == NULL || jpeg->raw_data == NULL)
                return;


        uint32_t nb_pixels, pixel;
        uint32_t *image = jpeg->raw_data;
        uint32_t R, G, B, gray;

        /* Compute the buffer size */
        if (jpeg->is_plain_image)
                nb_pixels = jpeg->width * jpeg->height;

        else
                nb_pixels = jpeg->mcu.size * jpeg->mcu.nb;


        /* Convert each pixel */
        for (uint32_t i = 0; i < nb_pixels; i++) {

                pixel = image[i];

                R = RED(pixel);
                G = GREEN(pixel);
                B = BLUE(pixel);

                gray = (R + G + B) / 3;


                image[i] = gray << 16 | gray << 8 | gray;
        }
}
Exemple #17
0
/*
 * InitPixelShade:
 *      Fills the PixelShade array with precomputed shades of every possible pixel (32 shades)
 */
void InitPixelShade(void)
{
    int i, j;
    int r, g, b;
    int dr, dg, db;
    const double alpha[32] = { 0.0, 0.03, 0.06, 0.09,
                               0.13, 0.17, 0.21, 0.24,
                               0.27, 0.31, 0.34, 0.37,
                               0.41, 0.44, 0.47, 0.49,
                               0.51, 0.53, 0.56, 0.59,
                               0.63, 0.66, 0.69, 0.73,
                               0.76, 0.79, 0.83, 0.87,
                               0.91, 0.94, 0.97, 1.0
                             };
                             
    for (i = 0; i < 32; i++) {
        for (j = 0; j < 65536; j++) {
            r = RED(j);
            g = GREEN(j);
            b = BLUE(j);
            dr = (int)(r * alpha[i]);
            dg = (int)(g * alpha[i]);
            db = (int)(b * alpha[i]);
            PixelShade[i][j] = RGB16(dr, dg, db);
        }
    }
}
void omb_draw_rect(int x, int y, int width, int height, int color)
{
	int i, j;
	long int location = 0;
	unsigned char alpha = ALPHA(color);
	unsigned char red = RED(color);
	unsigned char green = GREEN(color);
	unsigned char blue = BLUE(color);
	
	for (i = y; i < y + height; i++) {
		for (j = x; j < x + width; j++) {
			
			if (i < 0 || j < 0 || i > omb_var_screen_info.yres || j > omb_var_screen_info.xres)
				continue;

			location = ((j + omb_var_screen_info.xoffset) * (omb_var_screen_info.bits_per_pixel / 8)) +
				((i + omb_var_screen_info.yoffset) * omb_fix_screen_info.line_length);

			*(omb_fb_map + location) = blue;
			*(omb_fb_map + location + 1) = green;
			*(omb_fb_map + location + 2) = red;
			*(omb_fb_map + location + 3) = alpha;
		}
	}
}
Exemple #19
0
void GEMapCell::drawVisual(vector_t unit_size)
{
  float hx, hy, hz;
  hx = (this->parent->cell_size.x * unit_size.x) / 2 - unit_size.x/20;
  hy = (this->parent->cell_size.y * unit_size.y) / 2 - unit_size.y/20;
  hz = (this->height * unit_size.z) + 0.01;
  if (visual)
    visual->draw(unit_size);
  glBegin(GL_QUADS);
  glColor3ub(RED(bg_color), GREEN(bg_color), BLUE(bg_color));
  glVertex3f( hx, hy, 0);
  glVertex3f(-hx, hy, 0);
  glVertex3f(-hx, hy, hz);
  glVertex3f( hx, hy, hz);
  glVertex3f( hx,-hy, hz);
  glVertex3f(-hx,-hy, hz);
  glVertex3f(-hx,-hy, 0);
  glVertex3f( hx,-hy, 0);
  glVertex3f( hx, hy, hz);
  glVertex3f(-hx, hy, hz);
  glVertex3f(-hx,-hy, hz);
  glVertex3f( hx,-hy, hz);
  glVertex3f( hx,-hy, 0);
  glVertex3f(-hx,-hy, 0);
  glVertex3f(-hx, hy, 0);
  glVertex3f( hx, hy, 0);
  glEnd();
}
Exemple #20
0
void ColorQuantizer::shrink(cube_t *cube)
{
    byte    r, g, b;
    word    i,color;

    cube->rmin = 255;
    cube->rmax = 0;
    cube->gmin = 255;
    cube->gmax = 0;
    cube->bmin = 255;
    cube->bmax = 0;
    for (i = cube->lower; i <= cube->upper; i++)
    {
        color = histPtr[i];
        r = RED(color);
        if (r > cube->rmax) cube->rmax = r;
        if (r < cube->rmin) cube->rmin = r;
        g = GREEN(color);
        if (g > cube->gmax) cube->gmax = g;
        if (g < cube->gmin) cube->gmin = g;
        b = BLUE(color);
        if (b > cube->bmax) cube->bmax = b;
        if (b < cube->bmin) cube->bmin = b;
    }
}
Exemple #21
0
INT BndStrg_SetInfFlags(PRTMP_ADAPTER pAd, PBND_STRG_CLI_TABLE table, BOOLEAN bInfReady)
{
	INT ret_val = BND_STRG_SUCCESS;
	BNDSTRG_MSG msg;

	if (WMODE_CAP_5G(pAd->CommonCfg.PhyMode) &&
		(table->b5GInfReady ^ bInfReady))
	{
		table->b5GInfReady = bInfReady;

		msg.Action = INF_STATUS_RSP_5G;
		msg.b5GInfReady = table->b5GInfReady;
		RtmpOSWrielessEventSend(
			pAd->net_dev,
			RT_WLAN_EVENT_CUSTOM,
			OID_BNDSTRG_MSG,
			NULL,
			(UCHAR *)&msg,
			sizeof(msg));
		BND_STRG_DBGPRINT(RT_DEBUG_OFF,
					(BLUE("%s(): BSS (%02x:%02x:%02x:%02x:%02x:%02x)")
					 BLUE(" set 5G Inf %s.\n")
					 , __FUNCTION__, PRINT_MAC(pAd->ApCfg.MBSSID[0].wdev.bssid),
					 bInfReady ? "ready" : "not ready"));
	}
	else if (table->b2GInfReady ^ bInfReady)
	{
		table->b2GInfReady = bInfReady;
		msg.Action = INF_STATUS_RSP_2G;
		msg.b2GInfReady = table->b2GInfReady;
		RtmpOSWrielessEventSend(
			pAd->net_dev,
			RT_WLAN_EVENT_CUSTOM,
			OID_BNDSTRG_MSG,
			NULL,
			(UCHAR *)&msg,
			sizeof(msg));
		BND_STRG_DBGPRINT(RT_DEBUG_OFF,
					(BLUE("%s(): BSS (%02x:%02x:%02x:%02x:%02x:%02x)")
					 BLUE(" set 2G Inf %s.\n")
					 , __FUNCTION__, PRINT_MAC(pAd->ApCfg.MBSSID[0].wdev.bssid),
					 bInfReady ? "ready" : "not ready"));
	}
	
	return ret_val;
}
Exemple #22
0
    void print_to_file(const char * userfile, int lineno, T obj, ADDON addon =
                           ADDON()) {

        tagset.insert("notag");
        (*OS) << DIV("notag") << br << BLUE( obj) << NBSP << CALLINFO << NBSP
              << BROWN(addon.getString()) << NBSP << EDIV;
        (*OS).flush();
    }
void 
hsv_v_filter(FILTER_DESC *filter_desc)
{
	// http://en.wikipedia.org/wiki/HSL_and_HSV
	// http://cs.haifa.ac.il/hagit/courses/ist/Lectures/Demos/ColorApplet2/t_convert.html
	
	PARAM_LIST *p_list = NULL;
	NEURON_LAYER_LIST *n_list = NULL;
	NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
	int nl_number, p_number;
	int xo, yo, wi, hi, wo, ho;
	int r, g, b;

	// Checks the Neuron Layers Number
	for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
            	;

	// Checks the Parameters Number
	for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
            	;

	if (p_number != 1)
	{
		Erro ("Error: Wrong number of parameters. The blue_mask_filter must have no parameters.", "", "");
		return;
	}

	// Gets the Input Neuron Layer
	nl_input = filter_desc->neuron_layer_list->neuron_layer;

	// Gets the Filter Output 
	nl_output = filter_desc->output;
	
	// Input-Output width
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;

	wo = nl_output->dimentions.x;
	ho = nl_output->dimentions.y;
	
	if (wi != wo || hi != ho)
	{
		Erro ("Error: Input and output layers on blue_channel_mask filter must have the same 2D size.", "", "");
		return;
	}
	
	for (yo = 0; yo < ho; yo++)
	{
		for (xo = 0; xo < wo; xo++)
		{
			r = RED(nl_input->neuron_vector[xo + yo * wo].output.ival);
			g = GREEN(nl_input->neuron_vector[xo + yo * wo].output.ival);
			b = BLUE(nl_input->neuron_vector[xo + yo * wo].output.ival);
			
			nl_output->neuron_vector[xo + yo * wo].output.ival = max_value(r, g, b);
		}
	}
}
Exemple #24
0
static rgb_color sample_rgb(uint16_t x, uint16_t y) {
  RGBQUAD quad;
  rgb_color ret;
  FreeImage_GetPixelColor(dib,x,y,&quad);
  ret.r = RED(&quad);
  ret.g = GREEN(&quad);
  ret.b = BLUE(&quad);
  return ret;
}
void 
Cr_filter(FILTER_DESC *filter_desc)
{
	// http://www.equasys.de/colorconversion.html
	
	PARAM_LIST *p_list = NULL;
	NEURON_LAYER_LIST *n_list = NULL;
	NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
	int nl_number, p_number;
	int xo, yo, wi, hi, wo, ho;
	double r, g, b;

	// Checks the Neuron Layers Number
	for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
            	;

	// Checks the Parameters Number
	for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
            	;

	if (p_number != 1)
	{
		Erro ("Error: Wrong number of parameters. The blue_mask_filter must have no parameters.", "", "");
		return;
	}

	// Gets the Input Neuron Layer
	nl_input = filter_desc->neuron_layer_list->neuron_layer;

	// Gets the Filter Output 
	nl_output = filter_desc->output;
	
	// Input-Output width
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;

	wo = nl_output->dimentions.x;
	ho = nl_output->dimentions.y;
	
	if (wi != wo || hi != ho)
	{
		Erro ("Error: Input and output layers on blue_channel_mask filter must have the same 2D size.", "", "");
		return;
	}
	
	for (yo = 0; yo < ho; yo++)
	{
		for (xo = 0; xo < wo; xo++)
		{
			r = (double) RED(nl_input->neuron_vector[xo + yo * wo].output.ival);
			g = (double) GREEN(nl_input->neuron_vector[xo + yo * wo].output.ival);
			b = (double) BLUE(nl_input->neuron_vector[xo + yo * wo].output.ival);
			nl_output->neuron_vector[xo + yo * wo].output.ival = (int) (0.500 * r - 0.419 * g - 0.081 * b + 128.0);
		}
	}
}
uint32 rgb565_to_rgb32(uint16 rgb565)
{
    uint8 r, g, b;
    uint32 rgb;
    r = (uint8)RED(rgb565);
    g = (uint8)GREEN(rgb565);
    b = (uint8)BLUE(rgb565);
    rgb = (((r << 8) + g) << 8) + b;
    return rgb;
}
Exemple #27
0
//scale using area averaging
void scale_area_avg(struct image* src, struct image* dest){
	int m, n, i, j;
	
	for (i = 0; i < dest->height; i++){
		for (j = 0; j < dest->width; j++){
			int rval = 0, gval = 0, bval = 0;
			for (m = i * SCALE_FACTOR; m < (i + 1) * SCALE_FACTOR; m++){
				for (n = j * SCALE_FACTOR; n < (j + 1) * SCALE_FACTOR; n++){
					rval += RED(src, m, n);
					gval += GREEN(src, m, n);
					bval += BLUE(src, m, n);
				}
			}
			RED(dest, i, j) = rval / SCALE_FACTOR / SCALE_FACTOR;
			GREEN(dest, i, j) = gval / SCALE_FACTOR / SCALE_FACTOR;
			BLUE(dest, i, j) = bval / SCALE_FACTOR / SCALE_FACTOR;
		}
	}
}
void omb_draw_rounded_rect(int x, int y, int width, int height, int color, int radius)
{
	int i, j;
	long int location = 0;
	unsigned char alpha = ALPHA(color);
	unsigned char red = RED(color);
	unsigned char green = GREEN(color);
	unsigned char blue = BLUE(color);
	
	for (i = y; i < y + height; i++) {
		for (j = x; j < x + width; j++) {
			if (i < 0 || j < 0 || i > omb_var_screen_info.yres || j > omb_var_screen_info.xres)
				continue;
			
			int relative_x = j - x;
			int relative_y = i - y;
			
			// top left corner
			if (relative_y < radius && relative_x < radius) {
				if (!omb_is_point_inside_circle(relative_x, relative_y, radius)) {
					continue;
				}
			}
			
			// top right corner
			else if (relative_y < radius && width - relative_x < radius) {
				if (!omb_is_point_inside_circle(width - relative_x, relative_y, radius)) {
					continue;
				}
			}
			
			// bottom left corner
			else if (height - relative_y < radius && relative_x < radius) {
				if (!omb_is_point_inside_circle(relative_x, height - relative_y, radius)) {
					continue;
				}
			}

			// bottom right corner
			else if (height - relative_y < radius && width - relative_x < radius) {
				if (!omb_is_point_inside_circle(width - relative_x, height - relative_y, radius)) {
					continue;
				}
			}

			location = ((j + omb_var_screen_info.xoffset) * (omb_var_screen_info.bits_per_pixel / 8)) +
				((i + omb_var_screen_info.yoffset) * omb_fix_screen_info.line_length);

			*(omb_fb_map + location) = blue;
			*(omb_fb_map + location + 1) = green;
			*(omb_fb_map + location + 2) = red;
			*(omb_fb_map + location + 3) = alpha;
		}
	}
}
internal void
PT_FillBlend(u32 *pixels, u32 pixelsPerRow, PT_Rect *destRect, u32 color)
{
    // For each pixel in the destination rect, alpha blend the 
    // bgColor to the existing color.
    // ref: https://en.wikipedia.org/wiki/Alpha_compositing

    u32 stopX = destRect->x + destRect->w;
    u32 stopY = destRect->y + destRect->h;

    // If the color we're trying to blend is transparent, then bail
    if (ALPHA(color) == 0) return;

    float srcA = ALPHA(color) / 255.0;
    float invSrcA = 1.0 - srcA;

    // Otherwise, blend each pixel in the dest rect
    for (u32 dstY = destRect->y; dstY < stopY; dstY++) {
        for (u32 dstX = destRect->x; dstX < stopX; dstX++) {
            u32 *pixel = &pixels[(dstY * pixelsPerRow) + dstX];

            if (ALPHA(color) == 255) {
                // Just copy the color, no blending necessary
                *pixel = color;
            } else {
                // Do alpha blending
                u32 pixelColor = *pixel;

                float destA = ALPHA(pixelColor) / 255.0;

                float outAlpha = srcA + (destA * invSrcA);
                u8 fRed = ((RED(color) * srcA) + (RED(pixelColor) * destA * invSrcA)) / outAlpha;
                u8 fGreen = ((GREEN(color) * srcA) + (GREEN(pixelColor) * destA * invSrcA)) / outAlpha;
                u8 fBlue = ((BLUE(color) * srcA) + (BLUE(pixelColor) * destA * invSrcA)) / outAlpha;
                u8 fAlpha = outAlpha * 255;

                *pixel = COLOR_FROM_RGBA(fRed, fGreen, fBlue, fAlpha);
            }
        }
    }
}
Exemple #30
0
int ColorQuantizer::compare(const void *a1, const void *a2)
{
    word color1, color2;
    byte c_1, c_2;

    color1 = (word)*(word *)a1;
    color2 = (word)*(word *)a2;
    switch (longdim)
    {
        case 0:
            c_1 = RED(color1), c_2 = RED(color2);
            break;
        case 1:
            c_1 = GREEN(color1), c_2 = GREEN(color2);
            break;
        case 2:
            c_1 = BLUE(color1), c_2 = BLUE(color2);
            break;
    }
    return ((int)(c_1 - c_2));
}