Color Desaturate(Color c) { #ifdef GREYSCALE return c; #else int a = (c.Red() + c.Green() + c.Blue()) / 3; return Color((c.Red() + a) / 2, (c.Green() + a) / 2, (c.Blue() + a) / 2); #endif }
void FormatHexColor(TCHAR *buffer, size_t size, const Color _color) { assert(size >= 7); #if defined(__ARM_ARCH_7A__) && GCC_VERSION < 40500 // NOTE: The local "c" copy of "color" works around an android compiler // bug (observed with gcc version 4.4.3) const Color color(_color.Red(), _color.Green(), _color.Blue()); #else const Color color(_color); #endif _sntprintf(buffer, size, _T("#%02X%02X%02X"), color.Red(), color.Green(), color.Blue()); }
// returns the addition of this color with another color Color Color::operator+ (const Color& vRhs) const { double trans=Transparent() > vRhs.Transparent() ? Transparent() : vRhs.Transparent(); return Color(Red()+vRhs.Red(),Green()+vRhs.Green(),Blue()+vRhs.Blue(), trans); }
static constexpr ActivePixelTraits::color_type Import(Color color) { #ifdef GREYSCALE return Luminosity8(color.GetLuminosity()); #else return BGRA8Color(color.Red(), color.Green(), color.Blue(), color.Alpha()); #endif }
/** * Returns a darker version of the specified color. */ static inline constexpr Color DarkColor(Color c) { #ifdef GREYSCALE return Color(DarkColor(c.GetLuminosity())); #else return Color(DarkColor(c.Red()), DarkColor(c.Green()), DarkColor(c.Blue())); #endif }
//------------------------------------------------------------------------------ void Canvas::DrawHLine(int x1, int x2, int y, Color color) { QPainterPath p; p.moveTo(x1, y); p.lineTo(x2, y); QPen a_pen = this->pen(); a_pen.setColor(QColor(color.Red(), color.Green(), color.Blue())); this->pushObject(p, a_pen, this->brush()); }
void MagicView::OnViewBackColor() { ModelView* view = GetModelViewByIndex(view_focus); if (view) { ActiveWindow* win = (ActiveWindow*) view->GetWindow(); Color c = win->GetBackColor(); COLORREF crgb = RGB(c.Red(), c.Green(), c.Blue()); CColorDialog chooser(crgb); if (chooser.DoModal() == IDOK) { crgb = chooser.GetColor(); win->SetBackColor( Color(GetRValue(crgb), GetGValue(crgb), GetBValue(crgb)) ); } } }
//------------------------------------------------------------------------------ void Canvas::DrawOutlineRectangle(int left, int top, int right, int bottom, Color color) { QPainterPath p; p.addRect(left, top, right - left, bottom - top); QPen a_pen = this->pen(); QBrush a_brush; // Qt::NoBrush. #ifndef NDEBUG std::cerr << __FILE__ << ", " << __LINE__ << ": " << a_brush.color().red() << ", " << a_brush.color().green() << ", " << a_brush.color().blue() << std::endl; #endif a_pen.setColor(QColor(color.Red(), color.Green(), color.Blue())); this->pushObject(p, a_pen, a_brush); }
void GraphicsManager::RenderText (int x, int y, const std::string& text, const Color& color, TTF_Font* font) { SDL_Color sdlColor = { color.Red(), color.Green(), color.Blue(), color.Alpha() }; SDL_Surface* surface = nullptr; SDL_Texture* texture = nullptr; ScopeGuard guard([&surface, &texture] () { if (texture != nullptr) { SDL_DestroyTexture(texture); texture = nullptr; } if (surface != nullptr) { SDL_FreeSurface(surface); surface = nullptr; } }); surface = TTF_RenderText_Blended(font, text.c_str(), sdlColor); if (surface == nullptr) throw error::Create("Failed to create surface!", ERROR_LOCATION); texture = SDL_CreateTextureFromSurface(device, surface); if (texture == nullptr) throw error::Create("Failed to create texture from surface!", ERROR_LOCATION); SDL_Rect destRect = { x, y, 0, 0 }; SDL_QueryTexture(texture, nullptr, nullptr, &destRect.w, &destRect.h); SDL_RenderCopy(device, texture, nullptr, &destRect); }
HRESULT AviFile::AddFrame(const Bitmap& bmp) { HRESULT hr = E_FAIL; if (!iserr && !play && bmp.IsHighColor() && bmp.Width() == rect.w && bmp.Height() == rect.h) { int w = bmp.Width(); int h = bmp.Height(); BYTE* buffer = new(__FILE__,__LINE__) BYTE[frame_size]; BYTE* dst = buffer; for (int y = 0; y < bmp.Height(); y++) { Color* src = bmp.HiPixels() + (h - 1 - y) * w; for (int x = 0; x < bmp.Width(); x++) { *dst++ = (BYTE) src->Blue(); *dst++ = (BYTE) src->Green(); *dst++ = (BYTE) src->Red(); src++; } } #pragma warning(suppress: 6001) hr = AVIStreamWrite(ps_comp, nframe, 1, buffer, frame_size, AVIIF_KEYFRAME, 0, 0); if (SUCCEEDED(hr)) { nframe++; } else { Print("AVIStreamWriteFile failed. %08x\n", hr); iserr = true; } delete [] buffer; } return hr; }
/** * Basic set / get. */ void testBasicSetGet() { TS_TRACE("Pen basic set get"); Pen p; for (int i = 0; i < 10000; i++) { Pen::Style penmap[3] = {Pen::SOLID, Pen::DASH, Pen::BLANK}; uint8_t refr, refg, refb; refr = rand(); refg = rand(); refb = rand(); Color refc(refr, refg, refb); unsigned refw = lrand48(); Pen::Style refs = penmap[rand() % sizeof(penmap)]; Pen p(refs, refw, refc); TS_ASSERT_EQUALS(p.GetWidth(), refw); Color rc = p.GetColor(); TS_ASSERT_EQUALS(rc.Red(), refr); TS_ASSERT_EQUALS(rc.Green(), refg); TS_ASSERT_EQUALS(rc.Blue(), refb); TS_ASSERT_EQUALS(p.GetStyle(), refs); } }
Color operator-(const Color& lhs, const Color& rhs) { Color result(lhs.Red() - rhs.Red(), lhs.Green() - rhs.Green(), lhs.Blue() - rhs.Blue(), lhs.Alpha() - rhs.Alpha()); return result; }
Color Desaturate(Color c) { int a = (c.Red() + c.Green() + c.Blue()) / 3; return Color((c.Red() + a) / 2, (c.Green() + a) / 2, (c.Blue() + a) / 2); }
/////////////////////////////////////////////////////////////////////////////// // RGB --> HSB /////////////////////////////////////////////////////////////////////////////// unsigned long RGBtoHSB (Color C) { return RGBtoHSB (C.Red(), C.Green(), C.Blue()); }
void Canvas::StretchMono(PixelScalar dest_x, PixelScalar dest_y, UPixelScalar dest_width, UPixelScalar dest_height, const Bitmap &src, PixelScalar src_x, PixelScalar src_y, UPixelScalar src_width, UPixelScalar src_height, Color fg_color, Color bg_color) { /* note that this implementation ignores the background color; it is not mandatory, and we can assume that the background is already set; it is only being passed to this function because the GDI implementation will be faster when erasing the background again */ GLTexture &texture = *src.GetNative(); GLEnable scope(GL_TEXTURE_2D); texture.Bind(); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); if (fg_color == COLOR_WHITE) { /* white text requested: use this trivial implementation */ GLLogicOp logic_op(GL_OR_INVERTED); texture.Draw(dest_x, dest_y, dest_width, dest_height, src_x, src_y, src_width, src_height); return; } /* apply the mask, pixels will be black then */ GLLogicOp logic_op(GL_AND); if (bg_color != COLOR_BLACK) texture.Draw(dest_x, dest_y, dest_width, dest_height, src_x, src_y, src_width, src_height); if (fg_color != COLOR_BLACK) { /* draw */ #ifndef HAVE_GLES if (fg_color != COLOR_WHITE) { /* XXX OpenGL/ES doesn't support GL_OPERAND0_RGB; we can't print colored mono images currently */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR); const GLfloat color[] = { GLfloat(fg_color.Red() / 256.), GLfloat(fg_color.Green() / 256.), GLfloat(fg_color.Blue() / 256.), GLfloat(1.0), }; OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); logic_op.set(GL_OR); } else #endif logic_op.set(GL_OR_INVERTED); texture.Draw(dest_x, dest_y, dest_width, dest_height, src_x, src_y, src_width, src_height); } }
bool operator==(const Color& lhs, const Color& rhs) { return lhs.Red() == rhs.Red() && lhs.Green() == rhs.Green() && lhs.Blue() == rhs.Blue() && lhs.Alpha() == rhs.Alpha(); }
Color operator*(const Color& lhs, const ElVisFloat& s) { Color result( lhs.Red() * s, lhs.Green() * s, lhs.Blue() * s, lhs.Alpha() * s); return result; }