// Test function SetAsGrey() void TargetPixel::TestSetAsGrey() { // http://en.wikipedia.org/wiki/Grayscales // Random color const int red = 50; const int green = 128; const int blue = 203; const double calcs = 0.2126 * red + 0.7152 * green + 0.0722 * blue; const int grey = (int)floor(calcs + 0.5); qDebug() << endl << "TestSetAsGrey(): random RGB color"; qDebug() << "RGB:" << red << green << blue; qDebug() << "Grey:" << grey; RGB color(red, green, blue); SetAsGrey(color); RGB greyResult1 = GetRGB(); qDebug() << "Result:" << greyResult1.GetRed() << greyResult1.GetGreen() << greyResult1.GetBlue(); // Grey color const int greyChannel = 50; qDebug() << endl << "TestSetAsGrey(): grey RGB color"; qDebug() << "Grey RGB:" << greyChannel; RGB greyColor(greyChannel, greyChannel, greyChannel); SetAsGrey(greyColor); RGB greyResult2 = GetRGB(); qDebug() << "Result:" << greyResult2.GetRed() << greyResult2.GetGreen() << greyResult2.GetBlue(); }
void CairoImage::putPixel(int x, int y, const Color& color) { if (!mCairoSurface) { throw GCN_EXCEPTION("Trying to write a pixel on a non loaded image."); } int stride=cairo_image_surface_get_stride(mCairoSurface); unsigned char *imagePixels=cairo_image_surface_get_data(mCairoSurface); if (!imagePixels) { throw GCN_EXCEPTION("Surface data are not available (surface is not of type Image or has been finished)"); } // deal differently with each surface format switch(cairo_image_surface_get_format(mCairoSurface)) { case CAIRO_FORMAT_ARGB32: *((unsigned long*)(&imagePixels[x*4 + y*stride]))=PrecomputeAlpha(color); break; case CAIRO_FORMAT_RGB24: *((unsigned long*)(&imagePixels[x*4 + y*stride]))=GetRGB(color); break; case CAIRO_FORMAT_A8: imagePixels[x + y*stride]=(unsigned char)color.a; break; default : //do nothing break; } }
void wxColourExt::GetHSV(float* h, float* s, float* v) const { if(!WasLastMode(HSV)) { float r, g, b; GetRGB(&r, &g, &b); float var_Min = r < g ? r : g; var_Min = var_Min < b ? var_Min : b; float var_Max = r > g ? r : g; var_Max = var_Max > b ? var_Max : b; float del_Max = var_Max - var_Min; V1 = var_Max; if(del_Max==0) { H1 = 0; S1 = 0; } else { S1 = del_Max/var_Max; float del_R = (((var_Max - r)/6.0) + (del_Max/2.0))/del_Max; float del_G = (((var_Max - g)/6.0) + (del_Max/2.0))/del_Max; float del_B = (((var_Max - b)/6.0) + (del_Max/2.0))/del_Max; if (r == var_Max) H1 = del_B - del_G; else if (g == var_Max) H1 = (1.0/3.0) + del_R - del_B; else if (b == var_Max) H1 = (2.0/3.0) + del_G - del_R; if ( H1 < 0 ) H1 += 1.0; if ( H1 > 1 ) H1 -= 1.0; } } *h = H1; *s = S1; *v = V1; }
void HueToCol(int h, int hueVals, int& r, int& g, int& b) { double H = (double)h/(double)hueVals; double R, G, B; GetRGB(H, 0.9, 0.55, R, G, B); r = cvRound(R*255); g = cvRound(G*255); b = cvRound(B*255); }
static int BitBlt_PATINVERT_16bpp(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight) { int x, y; uint8 *dstp; uint8 *patp; uint8 colR, colG, colB; uint16 col; uint16 *dstp16; if(hdcDest->brush->style == BS_SOLID) { GetRGB(colR, colG, colB, hdcDest->brush->color); RGB_888_565(colR, colG, colB); col = RGB16(colR, colG, colB); for (y = 0; y < nHeight; y++) { dstp16 = (uint16*)gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); if (dstp16 != 0) { for (x = 0; x < nWidth; x++) { *dstp16 ^= col; dstp16++; } } } } else { for (y = 0; y < nHeight; y++) { dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); if (dstp != 0) { for (x = 0; x < nWidth; x++) { patp = gdi_get_brush_pointer(hdcDest, x, y); *dstp = *patp ^ *dstp; patp++; dstp++; *dstp = *patp ^ *dstp; patp++; dstp++; } } } } return 0; }
byte *tga_t::GrabData(byte *buff, int size) { if (bits == 32) return GetRGBA (buff, size); else if (bits == 24) return GetRGB (buff, size); else if (bits == 8) return GetGray (buff, size); return 0; }
FX_BOOL CPDF_ColorSpace::GetCMYK(FX_FLOAT* pBuf, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k) const { if (v_GetCMYK(pBuf, c, m, y, k)) { return TRUE; } FX_FLOAT R, G, B; if (!GetRGB(pBuf, R, G, B)) { return FALSE; } sRGB_to_AdobeCMYK(R, G, B, c, m, y, k); return TRUE; }
void CPDF_LabCS::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, FX_BOOL bTransMask) const { for (int i = 0; i < pixels; i ++) { FX_FLOAT lab[3]; FX_FLOAT R, G, B; lab[0] = (pSrcBuf[0] * 100 / 255.0f); lab[1] = (FX_FLOAT)(pSrcBuf[1] - 128); lab[2] = (FX_FLOAT)(pSrcBuf[2] - 128); GetRGB(lab, R, G, B); pDestBuf[0] = (int32_t)(B * 255); pDestBuf[1] = (int32_t)(G * 255); pDestBuf[2] = (int32_t)(R * 255); pDestBuf += 3; pSrcBuf += 3; } }
void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf, const uint8_t* src_buf, int pixels, int image_width, int image_height, FX_BOOL bTransMask) const { CFX_FixedBufGrow<FX_FLOAT, 16> srcbuf(m_nComponents); FX_FLOAT* src = srcbuf; FX_FLOAT R, G, B; for (int i = 0; i < pixels; i ++) { for (int j = 0; j < m_nComponents; j ++) if (m_Family == PDFCS_INDEXED) { src[j] = (FX_FLOAT)(*src_buf ++); } else { src[j] = (FX_FLOAT)(*src_buf ++) / 255; } GetRGB(src, R, G, B); *dest_buf ++ = (int32_t)(B * 255); *dest_buf ++ = (int32_t)(G * 255); *dest_buf ++ = (int32_t)(R * 255); } }
int FillRect_32bpp(HDC hdc, HRECT rect, HBRUSH hbr) { int x, y; uint8 *dstp; char r, g, b; int nXDest, nYDest; int nWidth, nHeight; RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); if (ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL) == 0) return 0; GetRGB(r, g, b, hbr->color); for (y = 0; y < nHeight; y++) { dstp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y); if (dstp != 0) { for (x = 0; x < nWidth; x++) { *dstp = b; dstp++; *dstp = g; dstp++; *dstp = r; #ifdef USE_ALPHA dstp++; *dstp = 0xFF; dstp++; #else dstp += 2; #endif } } } InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight); return 0; }
void CPDF_CalRGB::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, FX_BOOL bTransMask) const { if (bTransMask) { FX_FLOAT Cal[3]; FX_FLOAT R, G, B; for(int i = 0; i < pixels; i ++) { Cal[0] = ((FX_FLOAT)pSrcBuf[2]) / 255; Cal[1] = ((FX_FLOAT)pSrcBuf[1]) / 255; Cal[2] = ((FX_FLOAT)pSrcBuf[0]) / 255; GetRGB(Cal, R, G, B); pDestBuf[0] = FXSYS_round(B * 255); pDestBuf[1] = FXSYS_round(G * 255); pDestBuf[2] = FXSYS_round(R * 255); pSrcBuf += 3; pDestBuf += 3; } } ReverseRGB(pDestBuf, pSrcBuf, pixels); }
/* * createToolBar - create the tool bar */ static void createToolBar( RECT *rect ) { int toolbar_height; TOOLDISPLAYINFO dinfo; fixedToolBar = true; dinfo.button_size.x = EditVars.ToolBarButtonWidth; dinfo.button_size.y = EditVars.ToolBarButtonHeight; dinfo.border_size.x = BORDER_X( EditVars.ToolBarButtonWidth ); dinfo.border_size.y = BORDER_Y( EditVars.ToolBarButtonHeight ); dinfo.style = TOOLBAR_FIXED_STYLE; dinfo.is_fixed = true; toolbar_height = TOOLBAR_HEIGHT( EditVars.ToolBarButtonHeight ); dinfo.area = *rect; dinfo.area.bottom = ((dinfo.area.top + toolbar_height + 1) & ~1) - 1; dinfo.area.top -= 1; dinfo.area.bottom -= 1; dinfo.area.left -= 1; dinfo.area.right += 1; dinfo.hook = myToolBarProc; dinfo.helphook = toolBarHelp; dinfo.background = LoadBitmap( InstanceHandle, "BUTTONPATTERN" ); dinfo.use_tips = 1; buttonPattern = dinfo.background; toolBar = ToolBarInit( root_window_id ); #if defined( __NT__ ) ToolBarChangeSysColors( GetSysColor( COLOR_BTNFACE ), #else ToolBarChangeSysColors( GetRGB( EditVars.ToolBarColor ), #endif GetSysColor( COLOR_BTNHIGHLIGHT ), GetSysColor( COLOR_BTNSHADOW ) ); ToolBarDisplay( toolBar, &dinfo ); if( toolBar != NULL ) { // CopyRect( &fixedRect, &dinfo.area ); // WARNING: These are some pretty stupid arbitrary constants here rect->top = dinfo.area.bottom; ShowWindow( ToolBarWindow( toolBar ), SW_SHOWNORMAL ); // UpdateWindow( ToolBarWindow( toolBar ) ); } } /* createToolBar */
static int BitBlt_DSPDxax_16bpp(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc) { int x, y; char *srcp; char *dstp; char r, g, b; HBITMAP hSrcBmp; /* D = (S & P) | (~S & D) */ /* DSPDxax, used to draw glyphs */ GetRGB(r, g, b, hdcDest->textColor); hSrcBmp = (HBITMAP) hdcSrc->selectedObject; srcp = hSrcBmp->data; if (hdcSrc->bytesPerPixel != 1) { printf("BitBlt_DSPDxax expects 1 bpp, unimplemented for %d\n", hdcSrc->bytesPerPixel); return 0; } for (y = 0; y < nHeight; y++) { srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y); dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y); if (dstp != 0) { for (x = 0; x < nWidth; x++) { *dstp = (*srcp & g) | (~(*srcp) & *dstp); dstp++; *dstp = (*srcp & g) | (~(*srcp) & *dstp); dstp++; srcp++; } } } return 0; }
int FillRect_16bpp(HDC hdc, HRECT rect, HBRUSH hbr) { int x, y; char *dstp; char r, g, b; int nXDest, nYDest; int nWidth, nHeight; uint16 *dstp16; uint16 color16; RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); if (ClipCoords(hdc, &nXDest, &nYDest, &nWidth, &nHeight, NULL, NULL) == 0) return 0; GetRGB(r, g, b, hbr->color); RGB_888_565(r, g, b); color16 = RGB16(r, g, b); for (y = 0; y < nHeight; y++) { dstp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y); if (dstp != 0) { for (x = 0; x < nWidth; x++) { dstp16 = (uint16*) dstp; *dstp16 = color16; dstp += 2; } } } InvalidateRegion(hdc, nXDest, nYDest, nWidth, nHeight); return 0; }
void wxColourExt::GetHSL(float* h, float* s, float* l) const { if(!WasLastMode(HSL)) { float r, g, b; GetRGB(&r, &g, &b); float var_Min = r < g ? r : g; var_Min = var_Min < b ? var_Min : b; float var_Max = r > g ? r : g; var_Max = var_Max > b ? var_Max : b; float del_Max = var_Max - var_Min; L0 = (var_Max + var_Min) / 2.0; if(del_Max==0) { H0 = 0.0; S0 = 0.0; } else { if (L0 < 0.5) S0 = del_Max/(var_Max + var_Min); else S0 = del_Max/(2.0 - var_Max - var_Min); float del_R = (((var_Max - r)/6.0) + (del_Max/2.0))/del_Max; float del_G = (((var_Max - g)/6.0) + (del_Max/2.0))/del_Max; float del_B = (((var_Max - b)/6.0) + (del_Max/2.0))/del_Max; if (r == var_Max) H0 = del_B - del_G; else if (g == var_Max) H0 = (1.0/3.0) + del_R - del_B; else if (b == var_Max) H0 = (2.0/3.0) + del_G - del_R; if ( H0 < 0 ) H0 += 1.0; if ( H0 > 1 ) H0 -= 1.0; } } *h = H0; *s = S0; *l = L0; }
status_t Converter::CreateNode(BMessage *nodeS,BMessage *connectionS,TiXmlElement *parent,int32 level, int32 thisLine) { TiXmlNode *node; BMessage *pDocNode = new BMessage(P_C_CLASS_TYPE); BMessage *data = new BMessage(); BMessage *pattern = new BMessage(); int32 line = 0; for( node = parent->FirstChild("node"); node;) { CreateConnection(connectionS, parent,node->ToElement()); CreateNode(nodeS,connectionS, node->ToElement(),level+1, line); line++; node = node->NextSibling(); } if (parent->Attribute("TEXT")) data->AddString("Name",parent->Attribute("TEXT")); else data->AddString("Name","Unnamed"); if (parent->Attribute("ID")) { const char *idString = parent->Attribute("ID"); int32 id = GetID(idString); pDocNode->AddPointer("this",(void *)id); } if (parent->Attribute("CREATED")) pDocNode->AddInt32("Node::created",atoi(parent->Attribute("CREATED"))); if (parent->Attribute("MODIFIED")) pDocNode->AddInt32("Node::modified",atoi(parent->Attribute("MODIFIED"))); if (parent->Attribute("BACKGROUND_COLOR")) pattern->AddInt32("FillColor",GetRGB(parent->Attribute("BACKGROUND_COLOR"))); if (parent->Attribute("COLOR")) pattern->AddInt32("BorderColor",GetRGB(parent->Attribute("COLOR"))); //find all Attributes for (node = parent->FirstChild("arrowlink"); node;) { CreateConnection(connectionS,parent,node->ToElement()); node = node->NextSibling(); } pDocNode->AddMessage("Node::Data",data); pDocNode->AddMessage("Node::Pattern",pattern); BRect *nodeRect = new BRect(100,100,200,150); if (pDocNode->FindRect("Node::frame",nodeRect) != B_OK) { int32 left, top, right, bottom; if (level == 0) { left = X_START; top = Y_START; } else { if (parent->Attribute("POSITION")) { if (strcmp(parent->Attribute("POSITION"),"left") != 0) left = (level*(NODE_WIDTH+10))+X_START; else left = X_START-(level*(NODE_WIDTH+10)); } top = (thisLine*(NODE_HEIGHT+10))+ 10; } right = left + NODE_WIDTH; bottom = top + NODE_HEIGHT; nodeRect->Set(left,top, right, bottom); pDocNode->AddRect("Node::frame",*nodeRect); } nodeS->AddMessage("node",pDocNode); }
float wxColourExt::RgbRed() const { GetRGB(&R, &G, &B); return R; }
float wxColourExt::RgbBlue() const { GetRGB(&R, &G, &B); return B; }
float wxColourExt::RgbGreen() const { GetRGB(&R, &G, &B); return G; }
// Set current pixel as grey // @input: // @output: void TargetPixel::SetAsGrey() { RGB currColor = GetRGB(); ToGrey(currColor); }
void Renderer::clearAll(unsigned int r, unsigned int g, unsigned int b) { FillRect(0, 0, d_width, d_height, GetRGB(r,g,b)); }
/******************************************************* * Get pixel *******************************************************/ rgb_color BitmapDrawer::GetRGB(BPoint p){ return GetRGB(p.x, p.y); }
void DrawableLine::draw() { unsigned int color = GetRGB(d_r, d_g, d_b); DrawLine((int)d_start.x(), (int)d_start.y(), (int)d_end.x(), (int)d_end.y(), color); }