Exemplo n.º 1
0
//===========================================================================
// 
//	Gets the average color of a texture for use as a sky cap color
//
//===========================================================================
static PalEntry SkyCapColor(FTextureID texno, bool bottom)
{
	PalEntry col;

	FTexture *tex = TexMan[texno];
	if (!tex) return 0;

	if (!tex->gl_info.bSkyColorDone)
	{
		tex->gl_info.bSkyColorDone = true;

		FGLTexture * gltex = FGLTexture::ValidateTexture(tex);
		if (tex)
		{
			int w;
			int h;
			unsigned char * buffer = gltex->CreateTexBuffer(FGLTexture::GLUSE_TEXTURE, CM_DEFAULT, 0, w, h);

			if (buffer)
			{
				tex->gl_info.CeilingSkyColor = averageColor((DWORD *) buffer, w * MIN(30, h), 0);
				if (h>30)
				{
					tex->gl_info.FloorSkyColor = averageColor(((DWORD *) buffer)+(h-30)*w, w * 30, 0);
				}
				else tex->gl_info.FloorSkyColor = tex->gl_info.CeilingSkyColor;
				delete buffer;
			}
		}
	}
	return bottom? tex->gl_info.FloorSkyColor : tex->gl_info.CeilingSkyColor;
}
Exemplo n.º 2
0
// Find top right coordinate of the box containing point (x,y)
Coordinate findTopRight(Pixels& img,
	const unsigned int& x,     const unsigned int& y,
	const unsigned int& max_x, const unsigned int& max_y)
{
	unsigned int result_x = x;
	unsigned int result_y = y;
	unsigned int missed   = 0;
	unsigned int r = relative_r(max_x, max_y);

	// Search right then up until hitting color < min_black
	for (unsigned int search_y = y+r, search_x = x; search_y >= 0 && search_y < max_y; --search_y)
	{
		for (search_x = result_x; search_x < max_x; ++search_x)
		{
			if (averageColor(img, search_x, search_y, r, max_x, max_y) > min_black)
			{
				result_x = search_x;
				result_y = search_y;
			}
			else break;
		}

		// If we haven't gone up any and are just moving left, break after only a few white
		// pixels instead of going all the way to the wall
		if (missed > max_missed)
			break;
		if (search_x == result_x && averageColor(img, search_x, search_y, r, max_x, max_y) < min_black)
			++missed;
	}

	return Coordinate(result_x, result_y);
}
Exemplo n.º 3
0
QColor QgsCompoundColorWidget::sampleColor( QPoint point ) const
{
  int sampleRadius = mSpinBoxRadius->value() - 1;
  QPixmap snappedPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), point.x() - sampleRadius, point.y() - sampleRadius,
                          1 + sampleRadius * 2, 1 + sampleRadius * 2 );
  QImage snappedImage = snappedPixmap.toImage();
  //scan all pixels and take average color
  return averageColor( snappedImage );
}
Exemplo n.º 4
0
//===========================================================================
// 
//	Gets the average color of a texture for use as a sky cap color
//
//===========================================================================
static PalEntry SkyCapColor(unsigned int texno, bool bottom)
{
	PalEntry col;

	if (!SkyColors)
	{
		MaxSkyTexture=TexMan.NumTextures();
		SkyColors=new PalEntry[MaxSkyTexture*2];	// once for top cap, once for bottom cap
		memset(SkyColors, 0, sizeof(PalEntry)*MaxSkyTexture);
	}

	if (texno<MaxSkyTexture)
	{
		if (SkyColors[texno].a==0)
		{
			FGLTexture * tex = FGLTexture::ValidateTexture(texno);
			if (tex)
			{
				int w;
				int h;
				unsigned char * buffer = tex->CreateTexBuffer(CM_DEFAULT, 0, NULL, w, h);

				if (buffer)
				{
					SkyColors[texno]=averageColor((unsigned long *) buffer, w * MIN(30, h), false);
					if (h>30)
					{
						SkyColors[texno+MaxSkyTexture]=	averageColor(((unsigned long *) buffer)+(h-30)*w, w * 30, false);
					}
					else SkyColors[texno+MaxSkyTexture]=SkyColors[texno];
					delete buffer;
					SkyColors[texno].a=1;	// mark as processed
				}
			}
		}
		return SkyColors[texno+MaxSkyTexture*bottom];
	}
	else
	{
		return 0;
	}
}
Exemplo n.º 5
0
/*  Apply the current color transform state, which applied a multiplier,
    followed by an addition and finally an average.  The transform values
    are set in the draw context state.  */
static BROGUE_DRAW_COLOR applyColorTransform(
    BROGUE_DRAW_CONTEXT_STATE *state, 
    BROGUE_DRAW_COLOR color, int is_foreground)
{
    if (is_foreground)
    {
	color = multiplyColor(color, state->foreground_multiplier);
	color = addColor(color, state->foreground_addition);
	color = averageColor(color, 
			     state->foreground_average_target, 
			     state->foreground_average_weight);
    }
    else
    {
	color = multiplyColor(color, state->background_multiplier);
	color = addColor(color, state->background_addition);
	color = averageColor(color, 
			     state->background_average_target, 
			     state->background_average_weight);
    }

    return color;
}
int main (void)
{
	int n;
	int i;
	int r, g, b;
	Color c[N], average;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d", &r, &g, &b);
		initColor(&(c[i]), r, g, b);
		printColor(&(c[i]));
	}
	average = averageColor(c, n);
	printColor(&average);
	return 0;
}
Exemplo n.º 7
0
//-----------------------------------------------------------------------------
//!
//-----------------------------------------------------------------------------
QRect tWindPlotGraph::DrawXAxisLabel(QPainter* pPainter, eGraphType graphType, qreal value, eXAxisLabel labelType, QRect& avoidRect)
{
    QFontMetrics fm = QFontMetrics(pPainter->font());

    QPoint textPoint = GraphToPixel(graphType, 0, value).toPoint();

    textPoint.ry() -= (m_GraphConfig.topMarginHeight );

    QString label;

    if(graphType == eGraphType_TWD)
    {
        if(value < 0.0F)
        {
            label = QString("%1").arg( static_cast<int>( m_GraphConfig.circularLimit[graphType] ) + ( static_cast<int>(value) % static_cast<int>( m_GraphConfig.circularLimit[graphType] ) ), 3, 10, QChar( '0' ) );
        }
        else
        {
            label = QString("%1").arg( static_cast<int>( value ) % static_cast<int>( m_GraphConfig.circularLimit[graphType] ), 3, 10, QChar( '0' ) );
        }

        if( "360" == label )
        {
            label = "000";
        }
    }
    else
    {
        label = QString("%1").arg(value, 0, 'f', 1);
    }

    QRect boundingRect = fm.boundingRect( " " + label + " " );

    // Determine the X position depending on the label type
    int labelXPos;

    switch(labelType)
    {
        case eXAxisLabel_Left :
            // Start label at the left hand axis
            labelXPos = textPoint.rx();
            break;

        case eXAxisLabel_Average :
            // Put centre of label where average value is
            labelXPos = textPoint.rx() - (boundingRect.width() / 2);

            // Check the label doesn't go past either axis
            if(labelXPos < m_GraphConfig.originX[graphType])
            {
                labelXPos = m_GraphConfig.originX[graphType];
            }

            if((labelXPos + boundingRect.width()) > (m_GraphConfig.originX[graphType] + m_GraphConfig.extentX[graphType]))
            {
                labelXPos = m_GraphConfig.originX[graphType] + m_GraphConfig.extentX[graphType] - boundingRect.width();
            }
            break;

        case eXAxisLabel_Right :
            // Put right of label at the right hand axis
            labelXPos = textPoint.rx() - boundingRect.width();
            break;

        default :
            Q_ASSERT(0);
            labelXPos = textPoint.rx() - (boundingRect.width() / 2);
            break;
    }

    QRect textRect = QRect(labelXPos, textPoint.ry(), boundingRect.width(), boundingRect.height() );

    if ( labelType == eXAxisLabel_Average )
    {
        QColor averageColor( Qt::red );
        pPainter->save();
        pPainter->setPen( averageColor );
        pPainter->drawText(textRect, Qt::AlignCenter, label );
        averageColor.setAlpha(128);
        pPainter->setPen( averageColor );
        pPainter->drawLine( textPoint.rx(), m_GraphConfig.originY, textPoint.rx(), (m_GraphConfig.originY + m_GraphConfig.extentY) );
        pPainter->restore();
    }
    else
    {
        // Check if this text will avoid the average text already displayed
        if(textRect.intersects(avoidRect) == false)
        {
            pPainter->drawText(textRect, Qt::AlignCenter, label );
        }
    }

    // Return the rect containing the text with a bit of a margin
    textRect.adjust(-10, 0, 10, 0);
    return textRect;
}
Exemplo n.º 8
0
// Find boxes on left of image
vector< vector<unsigned int> > findBoxes(Pixels& img,
	const unsigned int& max_x, const unsigned int& max_y,
	unsigned int& box_width, Image& image)
{
	double firstDist = 0;
	vector<Coordinate> boxesLeft;
	vector< vector<unsigned int> > boxes;
	unsigned int r = relative_r(max_x, max_y);
	unsigned int box_size = relative_box(max_x, max_y);

	// Search from left up a y = x line going down the image
	// Max y+x for also scanning the bottom of the image if shifted to the right
	for (unsigned int z = 0; z < max_y + max_x; ++z)
	{
		for (unsigned int x = 0, y = z; x <= z && x < max_x; ++x, --y)
		{
			// This is an imaginary point
			if (y > max_y - 1)
				continue;

			if (averageColor(img, x, y, r, max_x, max_y) > min_black)
			{
				Coordinate topLeft = findTopLeft(img, x, y, max_x, max_y);

				// Add this if it is not already a box and is large enough to be one
				if (find(boxesLeft.begin(), boxesLeft.end(), topLeft) == boxesLeft.end() &&
					averageColor(img, x, y, box_size, max_x, max_y) > min_black)
					boxesLeft.push_back(topLeft);
				else
					break;
				
				// We only care about the left-most black value
				break;
			}
		}
	}

	// Find top right points and delete abnormally sized boxes
	for (unsigned int i = 0; i < boxesLeft.size(); ++i)
	{
		unsigned int x1 = boxesLeft[i].x();
		unsigned int y1 = boxesLeft[i].y();

		Coordinate topRight = findTopRight(img, x1, y1, max_x, max_y);
		
		unsigned int x2 = topRight.x();
		unsigned int y2 = topRight.y();

		double dist = distance(x1, y1, x2, y2);

		// Size of first box is the standard
		if (i == 0)
		{
			firstDist = dist;

			/*cout << dist << endl;
			if (dist < 40)
			{
				image.fillColor("pink");
				image.draw(DrawableRectangle(x1, y1, x1+15, y1+15));
				image.draw(DrawableRectangle(x2, y2, x2+15, y2+15));
			}*/

			vector<unsigned int> v = { x1, y1, x2, y2 };
			boxes.push_back(v);
		}
		// Get rid of all that are way larger or smaller than the first
		else if (dist < (1+max_error)*firstDist && dist > (1-max_error)*firstDist)
		{
			vector<unsigned int> v = { x1, y1, x2, y2 };
			boxes.push_back(v);
		}
	}

	// Save the box width for use when reading data
	box_width = firstDist;

	return boxes;
}