Пример #1
0
void Renderer::DrawPoint(Point point, int subWindow)
{
    int pixelStart = PosToIndex((point.Position()));
    
    Color color = point.GetColor();
    
    if(pixelStart >= 0 && pixelStart + 2 <= (sSubwindowSize.mX) * (sSubwindowSize.mY) * 3)
    {
        if(subWindow == sSubWindow1)
        {
            sPixelBuffer1[pixelStart] = color.GetRed();
            sPixelBuffer1[pixelStart + 1] = color.GetGreen();
            sPixelBuffer1[pixelStart + 2] = color.GetBlue();
        }
        else if(subWindow == sSubWindow2)
        {
            sPixelBuffer2[pixelStart] = color.GetRed();
            sPixelBuffer2[pixelStart + 1] = color.GetGreen();
            sPixelBuffer2[pixelStart + 2] = color.GetBlue();

        }
        else if(subWindow == sSubWindow3)
        {
            sPixelBuffer3[pixelStart] = color.GetRed();
            sPixelBuffer3[pixelStart + 1] = color.GetGreen();
            sPixelBuffer3[pixelStart + 2] = color.GetBlue();

        }
    }
    else
    {
        throw out_of_range("Point outside of pixel buffer range");
    }
}
Пример #2
0
ZString GetString(int indent, const Color& color)
{
    return
          "Color("
        + ZString(color.GetRed()  ) + ", "
        + ZString(color.GetGreen()) + ", "
        + ZString(color.GetBlue() ) + ")";
}
Пример #3
0
    Color Color::Modulate(const Color& c) const
    {
        uint8 R = static_cast<uint8>(GetRed()   * c.GetRed()   / 255);
        uint8 G = static_cast<uint8>(GetGreen() * c.GetGreen() / 255);
        uint8 B = static_cast<uint8>(GetBlue()  * c.GetBlue()  / 255);
        uint8 A = static_cast<uint8>(GetAlpha() * c.GetAlpha() / 255);

        return Color(R, G, B, A);
    }
Пример #4
0
void SDLSurface::Clear(const Color & color /*= Color::INVISIBLE*/)
{
	SDL_Rect rect;
	Uint32 sdl_color;
	rect.x = 0;
	rect.y = 0;
	rect.w = m_surface->w;
	rect.h = m_surface->h;
	sdl_color = SDL_MapRGB(m_surface->format,color.GetRed(),color.GetGreen(),color.GetBlue());// alpha isn´t used
	SDL_FillRect(m_surface,&rect,sdl_color);
}
Пример #5
0
    Color Color::operator +(const Color& c) const
    {
        int R = GetRed()   + c.GetRed();
        int G = GetGreen() + c.GetGreen();
        int B = GetBlue()  + c.GetBlue();
        int A = GetAlpha() + c.GetAlpha();

        Color Ret;
        Ret.SetInt(R, G, B, A);

        return Ret;
    }
Пример #6
0
void RendererOpenGL::DrawCube(const Vector3& leftUpForwardVertex, const Vector3& rightBottomBackVertex, const Color& color) const
{
	// Set the color
	glColor3f(color.GetRed(), color.GetGreen(), color.GetBlue());
	
	glBegin(GL_QUADS);
		// Top face
		glVertex3f(leftUpForwardVertex.GetX(), leftUpForwardVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), leftUpForwardVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), leftUpForwardVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(leftUpForwardVertex.GetX(), leftUpForwardVertex.GetY(), rightBottomBackVertex.GetZ());

		// Bottom face
		glVertex3f(leftUpForwardVertex.GetX(), rightBottomBackVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(leftUpForwardVertex.GetX(), rightBottomBackVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), rightBottomBackVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), rightBottomBackVertex.GetY(), leftUpForwardVertex.GetZ());

		// Front face
		glVertex3f(leftUpForwardVertex.GetX(), leftUpForwardVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(leftUpForwardVertex.GetX(), rightBottomBackVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), rightBottomBackVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), leftUpForwardVertex.GetY(), leftUpForwardVertex.GetZ());

		// Back face
		glVertex3f(rightBottomBackVertex.GetX(), leftUpForwardVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), rightBottomBackVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(leftUpForwardVertex.GetX(), rightBottomBackVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(leftUpForwardVertex.GetX(), leftUpForwardVertex.GetY(), rightBottomBackVertex.GetZ());

		// Left face
		glVertex3f(leftUpForwardVertex.GetX(), leftUpForwardVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(leftUpForwardVertex.GetX(), rightBottomBackVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(leftUpForwardVertex.GetX(), rightBottomBackVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(leftUpForwardVertex.GetX(), leftUpForwardVertex.GetY(), leftUpForwardVertex.GetZ());

		// Right face
		glVertex3f(rightBottomBackVertex.GetX(), leftUpForwardVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), rightBottomBackVertex.GetY(), leftUpForwardVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), rightBottomBackVertex.GetY(), rightBottomBackVertex.GetZ());
		glVertex3f(rightBottomBackVertex.GetX(), leftUpForwardVertex.GetY(), rightBottomBackVertex.GetZ());
	glEnd();
}
Пример #7
0
void Segmentation::DrawContourFreeman(const Coordinate& firstPoint, const std::vector<int> &freemanCode, 
    const Color color, Image &targetImage) {
  int cx = firstPoint.GetX();
  int cy = firstPoint.GetY();
  
  std::vector<int>::const_iterator iter, end;
  end = freemanCode.end();
  
  // follow the contour code and fill the pixels with the specified color
  for (iter = freemanCode.begin(); iter != end; ++iter) {
    int dx, dy;
    get_fm(*iter, dx, dy);
    cx += dx; cy += dy;
    
    targetImage.SetPixel(cx, cy, 0, color.GetRed());
    targetImage.SetPixel(cx, cy, 1, color.GetGreen());
    targetImage.SetPixel(cx, cy, 2, color.GetBlue());
  }
}
Пример #8
0
Pixel PixelFormat::MakePixel(const Color& color) const
{
    return
        MakePixel(
            int(color.GetRed()   * RedSize()  ),
            int(color.GetGreen() * GreenSize()),
            int(color.GetBlue()  * BlueSize() )
        );

    // !!! this causes all of the artwork to change slightly
    //     since the rounding mode is different

    /*
    return
        MakePixel(
            MakeInt(color.GetRed()   * RedSize()  ),
            MakeInt(color.GetGreen() * GreenSize()),
            MakeInt(color.GetBlue()  * BlueSize() )
        );
    */
}
Пример #9
0
IrisColor* IrisBitmap::GetPixel(int x, int y){
	Color color;
	this->bitmap->GetPixel(x, y, &color);
	return new IrisColor(color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha());
}
Пример #10
0
void Color::Set(const Color &c) {
	this->r = c.GetRed();
	this->g = c.GetGreen();
	this->b = c.GetBlue();
}
Пример #11
0
/*
** Read the meter-specific options from the ini-file.
**
*/
void TintedImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const WCHAR* imagePath)
{
	// Store the current values so we know if the image needs to be tinted or transformed
	Rect oldCrop = m_Crop;
	CROPMODE oldCropMode = m_CropMode;
	bool oldGreyScale = m_GreyScale;
	ColorMatrix oldColorMatrix = *m_ColorMatrix;
	RotateFlipType oldFlip = m_Flip;
	REAL oldRotate = m_Rotate;
	std::wstring oldPath = m_Path;

	m_Path = parser.ReadString(section, m_OptionArray[OptionIndexImagePath], imagePath);
	PathUtil::AppendBacklashIfMissing(m_Path);

	m_HasPathChanged = (oldPath != m_Path);

	if (!m_DisableTransform)
	{
		m_Crop.X = m_Crop.Y = m_Crop.Width = m_Crop.Height = -1;
		m_CropMode = CROPMODE_TL;

		const std::wstring& crop = parser.ReadString(section, m_OptionArray[OptionIndexImageCrop], L"");
		if (!crop.empty())
		{
			if (wcschr(crop.c_str(), L','))
			{
				WCHAR* parseSz = _wcsdup(crop.c_str());
				WCHAR* token;

				token = wcstok(parseSz, L",");
				if (token)
				{
					m_Crop.X = parser.ParseInt(token, 0);

					token = wcstok(nullptr, L",");
					if (token)
					{
						m_Crop.Y = parser.ParseInt(token, 0);

						token = wcstok(nullptr, L",");
						if (token)
						{
							m_Crop.Width = parser.ParseInt(token, 0);

							token = wcstok(nullptr, L",");
							if (token)
							{
								m_Crop.Height = parser.ParseInt(token, 0);

								token = wcstok(nullptr, L",");
								if (token)
								{
									m_CropMode = (CROPMODE)parser.ParseInt(token, 0);
								}
							}
						}
					}
				}
				free(parseSz);
			}

			if (m_CropMode < CROPMODE_TL || m_CropMode > CROPMODE_C)
			{
				m_CropMode = CROPMODE_TL;
				LogErrorF(m_Skin, L"%s=%s (origin) is not valid in [%s]",  m_OptionArray[OptionIndexImageCrop], crop, section);
			}
		}
	}

	m_NeedsCrop = (oldCrop.X != m_Crop.X || oldCrop.Y != m_Crop.Y || oldCrop.Width != m_Crop.Width || oldCrop.Height != m_Crop.Height || oldCropMode != m_CropMode);

	m_GreyScale = parser.ReadBool(section, m_OptionArray[OptionIndexGreyscale], false);

	Color tint = parser.ReadColor(section, m_OptionArray[OptionIndexImageTint], Color::White);
	int alpha = parser.ReadInt(section, m_OptionArray[OptionIndexImageAlpha], tint.GetAlpha());  // for backwards compatibility
	alpha = min(255, alpha);
	alpha = max(0, alpha);

	*m_ColorMatrix = c_IdentityMatrix;

	// Read in the Color Matrix
	// It has to be read in like this because it crashes when reading over 17 floats
	// at one time. The parser does it fine, but after putting the returned values
	// into the Color Matrix the next time the parser is used it crashes.
	std::vector<Gdiplus::REAL> matrix1 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix1]);
	if (matrix1.size() == 5)
	{
		for (int i = 0; i < 4; ++i)  // The fifth column must be 0.
		{
			m_ColorMatrix->m[0][i] = matrix1[i];
		}
	}
	else
	{
		m_ColorMatrix->m[0][0] = (REAL)tint.GetRed() / 255.0f;
	}

	std::vector<Gdiplus::REAL> matrix2 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix2]);
	if (matrix2.size() == 5)
	{
		for (int i = 0; i < 4; ++i)  // The fifth column must be 0.
		{
			m_ColorMatrix->m[1][i] = matrix2[i];
		}
	}
	else
	{
		m_ColorMatrix->m[1][1] = (REAL)tint.GetGreen() / 255.0f;
	}

	std::vector<Gdiplus::REAL> matrix3 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix3]);
	if (matrix3.size() == 5)
	{
		for (int i = 0; i < 4; ++i)  // The fifth column must be 0.
		{
			m_ColorMatrix->m[2][i] = matrix3[i];
		}
	}
	else
	{
		m_ColorMatrix->m[2][2] = (REAL)tint.GetBlue() / 255.0f;
	}

	std::vector<Gdiplus::REAL> matrix4 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix4]);
	if (matrix4.size() == 5)
	{
		for (int i = 0; i < 4; ++i)  // The fifth column must be 0.
		{
			m_ColorMatrix->m[3][i] = matrix4[i];
		}
	}
	else
	{
		m_ColorMatrix->m[3][3] = (REAL)alpha / 255.0f;
	}

	std::vector<Gdiplus::REAL> matrix5 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix5]);
	if (matrix5.size() == 5)
	{
		for (int i = 0; i < 4; ++i)  // The fifth column must be 1.
		{
			m_ColorMatrix->m[4][i] = matrix5[i];
		}
	}

	m_NeedsTinting = (oldGreyScale != m_GreyScale || !CompareColorMatrix(&oldColorMatrix, m_ColorMatrix));

	m_UseExifOrientation = parser.ReadBool(section, m_OptionArray[OptionIndexUseExifOrientation], false);

	const WCHAR* flip = parser.ReadString(section, m_OptionArray[OptionIndexImageFlip], L"NONE").c_str();
	if (_wcsicmp(flip, L"NONE") == 0)
	{
		m_Flip = RotateNoneFlipNone;
	}
	else if (_wcsicmp(flip, L"HORIZONTAL") == 0)
	{
		m_Flip = RotateNoneFlipX;
	}
	else if (_wcsicmp(flip, L"VERTICAL") == 0)
	{
		m_Flip = RotateNoneFlipY;
	}
	else if (_wcsicmp(flip, L"BOTH") == 0)
	{
		m_Flip = RotateNoneFlipXY;
	}
	else
	{
		LogErrorF(m_Skin, L"%s=%s (origin) is not valid in [%s]",  m_OptionArray[OptionIndexImageFlip], flip, section);
	}

	if (!m_DisableTransform)
	{
		m_Rotate = (REAL)parser.ReadFloat(section, m_OptionArray[OptionIndexImageRotate], 0.0);
	}

	m_NeedsTransform = (oldFlip != m_Flip || oldRotate != m_Rotate);
}
Пример #12
0
inline void ToGDIColor(const Color& source, Gdiplus::Color& target) {
    target = Gdiplus::Color(source.GetAlpha(), source.GetRed(), source.GetGreen(), source.GetBlue());
}