Example #1
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source, int optional_alpha)
{
	ImpressionistDoc* pDoc = GetDocument();

	GLubyte color[4];

	memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
	color[3] = static_cast<GLubyte>(255.0f * m_pDoc->getAlpha());

	// dirty patch
	// just bear it, this is life

	// for debug
	/*
	int tset = optional_alpha;
	char msg[222];
	sprintf(msg, "%d\n\n", tset);
	OutputDebugString(msg);
	*/

	if (optional_alpha > 0) {
		// OutputDebugString("called, gengge\n");
		color[3] = (GLubyte)optional_alpha;
	}

	for (int i = 0; i < 3; i++) {
		if (m_pDoc->m_pUI->m_ReverseColorButton->value()) color[i] = (GLubyte) (255 - color[i] * m_pDoc->m_pUI->blendColor[i]);
		else color[i] = (GLubyte) (color[i] * m_pDoc->m_pUI->blendColor[i]);
	}
 
	glColor4ubv( color );
}
Example #2
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
	ImpressionistDoc* pDoc = GetDocument();

	GLubyte color[4];
	
	memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
	color[3] = (GLubyte)pDoc->getAlpha(); //Set the alpha channel to whatever the slider says

	glColor4ubv( color );

}
Example #3
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
	ImpressionistDoc* pDoc = GetDocument();


	GLubyte color[3];

	memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
 
	glColor3ubv( color );

}
Example #4
0
void ImpBrush::SetColor (const Point source, int alpha)
{
	ImpressionistDoc* pDoc = GetDocument();


	GLubyte color[4];

	memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
	color[3] = alpha * 255/100;
 
	glColor4ubv( color );

}
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor(const Point source, float alphaValue) // alphaValue from 0 - 1
{
	ImpressionistDoc* pDoc = GetDocument();
	GLubyte color[4];

	memcpy(color, pDoc->GetOriginalPixel(source), 3);
	color[3] = (GLubyte)(alphaValue * 255.0f);

	for (int i = 0; i < 3; i++)
		color[i] = (GLubyte)(color[i] * m_pDoc->m_pUI->getBlendColour(i));

	glColor4ubv(color);
}
Example #6
0
void GreyscaleBrush::SetColor (const Point source)
{
	ImpressionistDoc* pDoc = GetDocument();


	GLubyte color[3];

	memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );

	// Convert the color to a greyscale
	float brightness = 2.0;
	float gray = (color[0]/255.0*0.299 + color[1]/255.0*0.587 + color[2]/255.0*0.114)/3.0 * brightness;
	gray = (gray > 1.0) ? 1.0 : gray;
	glColor3f( gray, gray, gray );
}
Example #7
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
    ImpressionistDoc* pDoc = GetDocument();
    float alpha = pDoc->getAlpha();
    float* colorBlend = pDoc->getColorBlend();


    GLubyte color[4];

    memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
    color[0] = static_cast<GLubyte> (color[0] * colorBlend[0]);
    color[1] = static_cast<GLubyte> (color[1] * colorBlend[1]);
    color[2] = static_cast<GLubyte> (color[2] * colorBlend[2]);
    color[3] = static_cast<GLubyte>(alpha * 255.f);
    glColor4ubv( color );

}
Example #8
0
void FilterBrush::Blur(const Point source, double opacity){
	
	ImpressionistDoc* pDoc = GetDocument();

	GLubyte color[3][3][3];
	GLubyte filteredColor[4];
	for (int i = -1; i < 2; i++)
		for (int j = -1; j < 2;j++)
			memcpy(color[i+1][j+1], pDoc->GetOriginalPixel(Point(source.x+i,source.y+j)), 3);

	for (int k = 0; k < 3; k++){
		filteredColor[k] =  (1 * (color[0][0][k] + color[0][2][k] + color[2][0][k] + color[2][2][k]) \
			+ 2 * (color[0][1][k] + color[1][0][k] + color[1][2][k] + color[2][1][k]) + 4 * color[1][1][k])/16;
	}	
	filteredColor[3] = opacity * 255;
	glColor4ubv(filteredColor);
}
Example #9
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample
// the color from
//----------------------------------------------------
void ImpBrush::SetColorOpac(const Point source, double opacity)
{
    ImpressionistDoc* pDoc = GetDocument();
    float r = pDoc->m_pUI->m_colorChooser->r();
    float g = pDoc->m_pUI->m_colorChooser->g();
    float b = pDoc->m_pUI->m_colorChooser->b();

    GLubyte color[4];

    memcpy(color, pDoc->GetOriginalPixel(source), 3);
    color[0] *= r;
    color[1] *= g;
    color[2] *= b;
    color[3] = opacity * 255;
    //glColor3ubv(color);
    glColor4ubv(color);

}
Example #10
0
void FilterBrush::Sharpen(const Point source, double opacity){
	
	ImpressionistDoc* pDoc = GetDocument();

	GLubyte color[3][3][3];
	GLubyte filteredColor[4] = { 0, 0, 0, 0 };
	for (int i = -1; i < 2; i++)
		for (int j = -1; j < 2; j++)
			memcpy(color[i + 1][j + 1], pDoc->GetOriginalPixel(Point(source.x + i, source.y + j)), 3);
	
	//for (int k = 0; k < 3; k++){
	//	filteredColor[k] =(-1 * (color[0][1][k] + color[1][0][k] + color[1][2][k] + color[2][1][k]) + 4 * color[1][1][k]);
	//}
	
	int kernel[3][3] = { -1, -1, -1, -1, 8, -1, -1, -1, -1 };

	int kCenterX = 1;
	int kCenterY = 1;
	int ii, jj, mm, nn;

	for (int k = 0; k < 3; k++){
		for (int m = 0; m < 3; m++)     // kernel rows
		{
			mm = 2 - m;      // row index of flipped kernel

			for (int n = 0; n < 3; n++) // kernel columns
			{
				nn = 2 - n;  // column index of flipped kernel
				// index of input signal, used for checking boundary
				ii = m;
				jj = n;				
				filteredColor[k] = filteredColor[k] + (color[ii][jj][k] * kernel[mm][nn]);
			}
		}
	}
	filteredColor[3] = opacity * 255;
	glColor4ubv(filteredColor);




}
Example #11
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const ImpBrush::Point source)
{
    ImpressionistDoc* pDoc = GetDocument();
    GLfloat alpha = pDoc->getAlpha();

    GLubyte color[3];
    memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );

    //
    // Setup the alpha settings
    //
    GLfloat color_r = ((GLfloat)color[0]/255);
    GLfloat color_g = ((GLfloat)color[1]/255);
    GLfloat color_b = ((GLfloat)color[2]/255);

    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glColor4f(color_r, color_g, color_b, alpha);
}
Example #12
0
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample 
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
	ImpressionistDoc* pDoc = GetDocument();
	int r, g, b;
	ucolor32 col = pDoc->getBlendColor();


	GLubyte color[4];

	memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );

	// Blend the color
	UNPACK_COLOR(r, g, b, col);
	color[0] = (unsigned)((r * color[0]) / 255);
	color[1] = (unsigned)((g * color[1]) / 255);
	color[2] = (unsigned)((b * color[2]) / 255);

	//Alpha
	color[3] = (int)(pDoc->getAlpha() * 255);
 
	glColor4ubv( color );

}
void ScatteredLineBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("LineBrush::BrushMove  document is NULL\n");
		return;
	}

	int size = pDoc->getSize();
	int angle = pDoc->getAngle();
	double opacity = pDoc->getOpac();
	int strokeDirChoice = dlg->m_StrokeDirChoice->value();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	srand(time(0));
	glMatrixMode(GL_MODELVIEW);
	
	switch (strokeDirChoice){
	// Slider/Right mouse 
	case 0:
		// don't have to change size and angle value
		for (int i = 0; i < 4; i++){
			float length = fRand(1, size / 2)*2.5;
			float dist = fRand(-size*0.3, size*0.3)*2.5;
			float displacement = fRand(-size*0.75, size*0.75);
			float x1 = target.x + displacement;
			float y1 = target.y + dist;

			glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
					SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
					glVertex2d(x1 - length*0.75, y1);
					glVertex2d(x1 + length*0.75, y1);
				glEnd();
			glPopMatrix();
		}
		break;

	// Gradient
	case 1:
		// change angle value according to 
		// the gradient at this point
		for (int i = 0; i < 4; i++){
			float length = fRand(1, size / 2)*2.5;
			float dist = fRand(-size*0.3, size*0.3)*2.5;
			float displacement = fRand(-size*0.75, size*0.75);
			float x1 = target.x + displacement;
			float y1 = target.y + dist;
			double Gx;
			double Gy;
			GLubyte color[3][3][3];
			double intensity[3][3];
			for (int i = -1; i < 2; i++){
				for (int j = -1; j < 2; j++){
					memcpy(color[i + 1][j + 1], pDoc->GetOriginalPixel(Point(source.x + displacement + i, source.y + dist + j)), 3);
					intensity[i + 1][j + 1] = 0.299*color[i + 1][j + 1][0] + 0.587*color[i + 1][j + 1][1] + 0.144*color[i + 1][j + 1][2];
				}
			}
			Gx = intensity[0][0] * (-1) + intensity[0][1] * (-2) + intensity[0][2] * (-1)\
				+ intensity[2][0] * (1) + intensity[2][1] * (2) + intensity[2][2] * (1);
			Gy = intensity[0][0] * (-1) + intensity[1][0] * (-2) + intensity[2][0] * (-1)\
				+ intensity[0][2] * (1) + intensity[1][2] * (2) + intensity[2][2] * (1);
			angle = -(int)(atan2(Gy, Gx)*57.32) % 360;

			glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
					SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
					glVertex2d(x1 - length*0.75, y1);
					glVertex2d(x1 + length*0.75, y1);
				glEnd();
			glPopMatrix();
		}
		break;

	// Brush direction
	case 2:
		current.x = target.x;
		current.y = target.y;
		if (prev.x!=-1&&current.x!=-1&&(current.x != prev.x || current.y != prev.y)){
			int dx = current.x - prev.x;
			int dy = current.y - prev.y;
			angle = (int)(atan2(dy, dx)*57.32) % 360;

			
			
			for (int i = 0; i < 4; i++){
				float length = size;
				float dist = fRand(-size*0.3, size*0.3)*2.5;
				float displacement = fRand(-size*0.75, size*0.75);
				float x1 = target.x + displacement;
				float y1 = target.y + dist;

				glPushMatrix();
				glTranslatef(x1, y1, 0.0);
				glRotatef(angle, 0.0, 0.0, 1.0);
				glTranslatef(-x1, -y1, 0.0);
				glBegin(GL_LINE_STRIP);
				SetColorOpac(Point(source.x + displacement, source.y + dist), opacity);
				glVertex2d(x1 - length*0.75, y1);
				glVertex2d(x1 + length*0.75, y1);
				glEnd();
				glPopMatrix();
			}
		}
		prev.x = current.x;
		prev.y = current.y;
		break;

	default:
		break;

	}
	
}
Example #14
0
GLint ScatteredLinesBrush::SobelGradient(const ImpBrush::Point source)
{
	/*
		a0		a1		a2
		a7				a3
		a6		a5		a4			
	*/
	ImpressionistDoc *pDocument = GetDocument(); 
	GLubyte dColor[3]; 
	GLdouble fAtan = 0.0; 
	GLint dAngle = 0.0; 
	ImpBrush::Point srcPoint = source;
	GLdouble a0, a1, a2, a3, a4, a5, a6, a7; 

	// Calculate a0 above .. 
	srcPoint.x = source.x-1; 
	srcPoint.y = source.y+1; 
	memcpy(dColor, pDocument->GetOriginalPixel(srcPoint),3);
	a0 = GraphicsUtils::GetLuminosity(dColor);

	// Calculate a1 above .. 
	srcPoint.x = source.x;
	srcPoint.y = source.y+1;
	memcpy(dColor, pDocument->GetOriginalPixel(srcPoint), 3);
	a1 = GraphicsUtils::GetLuminosity(dColor);

	// Calculate a2 above .. 
	srcPoint.x = source.x + 1;
	srcPoint.y = source.y + 1;
	memcpy(dColor, pDocument->GetOriginalPixel(srcPoint), 3);
	a2 = GraphicsUtils::GetLuminosity(dColor);

	// Calculate a3 above .. 
	srcPoint.x = source.x + 1;
	srcPoint.y = source.y;
	memcpy(dColor, pDocument->GetOriginalPixel(srcPoint), 3);
	a3 = GraphicsUtils::GetLuminosity(dColor);

	// Calculate a4 above .. 
	srcPoint.x = source.x + 1;
	srcPoint.y = source.y - 1;
	memcpy(dColor, pDocument->GetOriginalPixel(srcPoint), 3);
	a4 = GraphicsUtils::GetLuminosity(dColor);

	// Calculate a5 above .. 
	srcPoint.x = source.x + 1;
	srcPoint.y = source.y - 1;
	memcpy(dColor, pDocument->GetOriginalPixel(srcPoint), 3);
	a5 = GraphicsUtils::GetLuminosity(dColor);

	// Calculate a6 above .. 
	srcPoint.x = source.x - 1;
	srcPoint.y = source.y - 1;
	memcpy(dColor, pDocument->GetOriginalPixel(srcPoint), 3);
	a6 = GraphicsUtils::GetLuminosity(dColor);

	// Calculate a7 above .. 
	srcPoint.x = source.x - 1;
	srcPoint.y = source.y;
	memcpy(dColor, pDocument->GetOriginalPixel(srcPoint), 3);
	a7 = GraphicsUtils::GetLuminosity(dColor);

	/* 
		Sobel Filter is -  the following two matrices convolved
		with the image. fdY & fdX

		[-1		0		 1]
		[-2		0(x,y)	 2]
		[-1		0		 1]

		[1		2		1]
		[0		0(x,y)	 0]
		[-1		-2		 -1]

		We'll average the gradient at the center pixel
	*/

	// Multiply with a the matrix above 
	GLdouble fDx = (a2 + 2 * a3 + a4) - (a0 + 2 * a7 + a6); 
	GLdouble fDy = (a0 + 2 * a1 + a2) - (a6 + 2 * a5 + a4);
	fAtan = atan2(fDy, fDx); 
	
	// Switch to Radians
	dAngle = fAtan * (180 / PI); 
	
	// Account for negative angles .. 
	dAngle = (dAngle < 0) ? (360 + dAngle) : dAngle; 

	// We want the line to be drawn 90 degress 
	// perpendicular to the gradient change. 
	dAngle = (GLint)(dAngle + 90);
	dAngle %= 360; 

	return dAngle; 

}
void MotionBlurBrush::SetColor(const Point source) {

	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;


	GLdouble MotionBlur[81] =
	{
		1, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 1, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 1, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 1, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 1, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 1, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 1, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 1, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 1,
	};

	GLfloat red = 0.0;
	GLfloat green = 0.0;
	GLfloat blue = 0.0;
	int index = 0;
	GLubyte tempColor[3];
	GLubyte color[3];

	GLfloat color1[3];
	GLfloat tempColor1[3];


	for (int k = -4; k <= 4; k += 1) {
		for (int l = -4; l <= 4; l += 1) {
			memcpy(tempColor, pDoc->GetOriginalPixel(source.x + k, source.y + l), 3);
			// We strictly need to convert to float!!!
			// I spent a lot of time finding the solution
			for (int n = 0; n < 3; n++)
			{
				tempColor1[n] = (float)tempColor[n];
			}

			red += tempColor1[0] * MotionBlur[index];
			green += tempColor1[1] * MotionBlur[index];
			blue += tempColor1[2] * MotionBlur[index];
			++index;
		}
	}

	double factor = 1.0 / 9.0;
	double bias = 0.0;

	red = min(max(int(factor * red + bias), 0), 255);
	green = min(max(int(factor * green + bias), 0), 255);
	blue = min(max(int(factor * blue + bias), 0), 255);

	color1[0] = red;
	color1[1] = green;
	color1[2] = blue;

	// Change to GLubyte before setting color to brush
	color[0] = (GLubyte)color1[0];
	color[1] = (GLubyte)color1[1];
	color[2] = (GLubyte)color1[2];

	glColor3ubv(color);
}
void EmbossBrush::SetColor(const Point source) {

	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	//// 3x3 kernel
	//GLdouble WeightedMeanKernel[9] =
	//{ 1 / 9, 1 / 9, 1 / 9,
	//1 / 9, 1 / 9, 1 / 9,
	//1 / 9, 1 / 9, 1 / 9,
	//};

	//GLdouble GaussianKernel[9] =
	//{	0.0625, 0.125, 0.0625,
	//	0.125, 0.25, 0.125,
	//	0.0625, 0.125, 0.0625,
	//};

	GLfloat red = 0.0;
	GLfloat green = 0.0;
	GLfloat blue = 0.0;
	int index = 0;
	GLubyte tempColor[3];
	GLubyte color[3];
	
	GLfloat color1[3];
	GLfloat tempColor1[3];

	GLfloat EmbossKernel[25] =
	{	-1, -1, -1, -1, 0,
		-1, -1, -1, 0, 1,
		-1, -1, 0, 1, 1,
		-1, 0, 1, 1, 1,
		 0, 1, 1, 1, 1
	};

	for (int k = -2; k <= 2; k += 1) {
		for (int l = -2; l <= 2; l += 1) {
			memcpy(tempColor, pDoc->GetOriginalPixel(source.x + k, source.y + l), 3);
			// We strictly need to convert to float!!!
			// I spent a lot of time finding the solution
			for (int n = 0; n < 3; n++)
			{
				tempColor1[n] = (float)tempColor[n];
			}

			red += tempColor1[0] * EmbossKernel[index];
			green += tempColor1[1] * EmbossKernel[index];
			blue += tempColor1[2] * EmbossKernel[index];
			++index;
		}
	}

	double factor = 1.0;
	double bias = 128.0;

	red = min(max(int(factor * red + bias), 0), 255);
	green = min(max(int(factor * green + bias), 0), 255);
	blue = min(max(int(factor * blue + bias), 0), 255);

	color1[0] = red;
	color1[1] = green;
	color1[2] = blue;

	// Change to GLubyte before setting color to brush
	color[0] = (GLubyte)color1[0];
	color[1] = (GLubyte)color1[1];
	color[2] = (GLubyte)color1[2];

	glColor3ubv(color);
}
Example #17
0
GLint LineBrush::SobelGradient( const ImpBrush::Point source)
{
    // do nothing so far
    ImpressionistDoc* pDoc = GetDocument();
    GLubyte color[3];
    ImpBrush::Point tempPoint = source;
    GLdouble atan = 0.0;
    GLint angle = 0.0;

    // a0
    tempPoint.x = source.x - 1;
    tempPoint.y = source.y + 1;
    memcpy ( color, pDoc->GetOriginalPixel( tempPoint ), 3 );
    GLdouble a0 = Transformations::YPrime(color);

    // a1
    tempPoint.x = source.x;
    tempPoint.y = source.y + 1;
    memcpy ( color, pDoc->GetOriginalPixel( tempPoint ), 3 );
    GLdouble a1 = Transformations::YPrime(color);

    // a2
    tempPoint.x = source.x + 1;
    tempPoint.y = source.y + 1;
    memcpy ( color, pDoc->GetOriginalPixel( tempPoint ), 3 );
    GLdouble a2 = Transformations::YPrime(color);

    // a7
    tempPoint.x = source.x - 1;
    tempPoint.y = source.y;
    memcpy ( color, pDoc->GetOriginalPixel( tempPoint ), 3 );
    GLdouble a7 = Transformations::YPrime(color);

    // a3
    tempPoint.x = source.x + 1;
    tempPoint.y = source.y;
    memcpy ( color, pDoc->GetOriginalPixel( tempPoint ), 3 );
    GLdouble a3 = Transformations::YPrime(color);

    // a6
    tempPoint.x = source.x - 1;
    tempPoint.y = source.y - 1;
    memcpy ( color, pDoc->GetOriginalPixel( tempPoint ), 3 );
    GLdouble a6 = Transformations::YPrime(color);

    // a5
    tempPoint.x = source.x;
    tempPoint.y = source.y - 1;
    memcpy ( color, pDoc->GetOriginalPixel( tempPoint ), 3 );
    GLdouble a5 = Transformations::YPrime(color);

    // a4
    tempPoint.x = source.x + 1;
    tempPoint.y = source.y - 1;
    memcpy ( color, pDoc->GetOriginalPixel( tempPoint ), 3 );
    GLdouble a4 = Transformations::YPrime(color);

    GLdouble s_x = (a2 + 2*a3 + a4) - (a0 + 2*a7 + a6);
    GLdouble s_y = (a0 + 2*a1 + a2) - (a6 + 2*a5 + a4);

    atan = atan2(s_y,s_x);
    angle = atan * (180 / PI);

    //
    // Adjust to 360 degree scale
    //
    if(angle < 0)
    {
        angle = 360 + angle;
    }

    // add 90 deg to make perpendicular
    angle = (GLint)(angle + 90); // % 360;
    angle %= 360;

    return angle;
}