//--------------------------------------------------------------------------- void __fastcall TGLForm2D::Triangulos1Click(TObject *Sender) { if(ColorDialog1->Execute()){ TColor c = ColorDialog1->Color; colorLinea1 = (GLfloat)GetRValue(ColorToRGB(c))/255; colorLinea2 = (GLfloat)GetGValue(ColorToRGB(c))/255; colorLinea3 = (GLfloat)GetBValue(ColorToRGB(c))/255; GLScene(); }
//--------------------------------------------------------------------------- void __fastcall TGLForm2D::CentroGravedad1Click(TObject *Sender) { if(ColorDialog1->Execute()){ TColor c = ColorDialog1->Color; colorGravedad1 = (GLfloat)GetRValue(ColorToRGB(c))/255; colorGravedad2 = (GLfloat)GetGValue(ColorToRGB(c))/255; colorGravedad3 = (GLfloat)GetBValue(ColorToRGB(c))/255; GLScene(); }
/*-----------------------------------------------------------------*/ void __fastcall CrFeld::DrawCursor() { if (visible) return; int i = fb.kbd.i; if (frm->righttoleft && (feld==EINZUG || feld==GEWEBE || feld==BLATTEINZUG || feld==KETTFARBEN)) i = fb.pos.width/fb.gw - fb.kbd.i - 1; int j = fb.kbd.j; if (frm->toptobottom && (feld==EINZUG || feld==AUFKNUEPFUNG)) j = fb.pos.height/fb.gh - fb.kbd.j - 1; int x0 = fb.pos.x0 + i*fb.gw; int y0 = fb.pos.y0 + fb.pos.height - (j+1)*fb.gh; int x1 = x0 + fb.gw; int y1 = y0 + fb.gh; // Extrawurst für Blatteinzug, weil der kein // Vielfaches der Gridheight hoch ist... if (feld==BLATTEINZUG) { y0 = fb.pos.y0; y1 = y0 + fb.pos.height; } frm->Canvas->Pen->Color = inputposcol; // Falls Gewebe und Farbeffekt und aktuelles Feld // hat weisse Farbe, dann muss Cursor rot // gemalt werden! if (feld==GEWEBE && frm->GewebeFarbeffekt->Checked) { int ii = frm->scroll_x1+fb.kbd.i; int jj = frm->scroll_y2+fb.kbd.j; if (ii>=frm->kette.a && ii<=frm->kette.b && jj>=frm->schuesse.a && jj<=frm->schuesse.b) { if (frm->gewebe.feld.Get(ii, jj)>0) { DWORD color = ColorToRGB(GETPALCOL(frm->kettfarben.feld.Get (ii))); WORD value = WORD((GetRValue(color)+GetGValue(color)+GetBValue(color))/3); if (value>=128) frm->Canvas->Pen->Color = inputposcol2; } else { DWORD color = ColorToRGB(GETPALCOL(frm->schussfarben.feld.Get (jj))); WORD value = WORD((GetRValue(color)+GetGValue(color)+GetBValue(color))/3); if (value>=128) frm->Canvas->Pen->Color = inputposcol2; } } } frm->Canvas->MoveTo (x0, y0); frm->Canvas->LineTo (x1, y0); frm->Canvas->LineTo (x1, y1); frm->Canvas->LineTo (x0, y1); frm->Canvas->LineTo (x0, y0); visible = true; }
//--------------------------------------------------------------------------- // set the text color to the value (or auto-color if the value is the // same as normal text) // void __fastcall TTaeTextAttributes::SetColor(TColor Value) { TCharFormat Format; InitFormat(Format); Format.dwMask = CFM_COLOR; if (Value == clWindowText) Format.dwEffects = CFE_AUTOCOLOR; else Format.crTextColor = ColorToRGB(Value); SetAttributes(Format); }
// expand image edges void CImageInfo::ExpandEdges( INDEX ctPasses/*=8192*/) { // do nothing if image is too small or doesn't have an alpha channel if( ii_Width<3 || ii_Height<3 || ii_BitsPerPixel!=32) return; // allocate some memory for spare picture and wipe it clean SLONG slSize = ii_Width*ii_Height*ii_BitsPerPixel/8; ULONG *pulSrc = (ULONG*)ii_Picture; ULONG *pulDst = (ULONG*)AllocMemory(slSize); memcpy( pulDst, pulSrc, slSize); // loop while there are some more pixels to be processed or for specified number of passes for( INDEX iPass=0; iPass<ctPasses; iPass++) { BOOL bAllPixelsVisible = TRUE; // loop thru rows for( PIX pixV=1; pixV<ii_Height-1; pixV++) { // loop thru pixels in row for( PIX pixU=1; pixU<ii_Width-1; pixU++) { // determine pixel location const PIX pixOffset = pixV*ii_Width + pixU; // do nothing if it is already visible COLOR col = ByteSwap(pulSrc[pixOffset]); if( ((col&CT_AMASK)>>CT_ASHIFT)>3) continue; bAllPixelsVisible = FALSE; // average all surrounding pixels that are visible ULONG ulRa=0, ulGa=0, ulBa=0; INDEX ctVisible=0; for( INDEX j=-1; j<=1; j++) { for( INDEX i=-1; i<=1; i++) { const PIX pixSurrOffset = pixOffset + j*ii_Width + i; col = ByteSwap(pulSrc[pixSurrOffset]); if( ((col&CT_AMASK)>>CT_ASHIFT)<4) continue; // skip non-visible pixels UBYTE ubR, ubG, ubB; ColorToRGB( col, ubR,ubG,ubB); ulRa+=ubR; ulGa+=ubG; ulBa += ubB; ctVisible++; } } // if there were some visible pixels around if( ctVisible>0) { // calc average ulRa/=ctVisible; ulGa/=ctVisible; ulBa/=ctVisible; col = RGBAToColor( ulRa,ulGa,ulBa,255); // put it to center pixel pulDst[pixOffset] = ByteSwap(col); } } } // copy resulting picture over source memcpy( pulSrc, pulDst, slSize); // done if all pixels are visible if( bAllPixelsVisible) break; } // free temp memory FreeMemory(pulDst); }
RGBA TfrmLayer::tcolor2rgb(TColor tc, int a) { int color = ColorToRGB(tc); RGBA rgb; rgb.b = color/(256*256); rgb.g = color%(256*256)/256; rgb.r = color%256; rgb.a = a; return rgb; }
//--------------------------------------------------------------------------- vtkRenderer * __fastcall TvtkBorlandRenderWindow::GetRenderer(void) { if (!FRenderer) { FRenderer = vtkRenderer::New(); GetRenderWindow()->AddRenderer(FRenderer); FRenderer->ResetCamera(); DWORD L = ColorToRGB(Color); double rgb[3] = { GetRValue(L)/255.0, GetGValue(L)/255.0, GetBValue(L)/255.0 }; FRenderer->SetBackground(rgb); } return FRenderer; }
void DrawBitmap(renderlist_t *RenderList, game_item_e BitmapId, float X, float Y, color_t Color, float Width, float Height, u8 BitmapFlags) { ADD_RENDERLIST_OP(RenderList, RenderOp_bitmap); renderdata_bitmap_t Bitmap; Bitmap.Id = BitmapId; Bitmap.X = X; Bitmap.Y = Y; Bitmap.Width = Width; Bitmap.Height = Height; Bitmap.Color = ColorToRGB(Color); Bitmap.Flags = (bitmap_flags_e)BitmapFlags; ADD_RENDERLIST(RenderList, &Bitmap); }
void CColoredButton::ColorToComponents(void) { if( m_colColor == m_colLastColor) return; UBYTE ubR, ubG, ubB; UBYTE ubH, ubS, ubV; ColorToRGB( m_colColor, ubR, ubG, ubB); ColorToHSV( m_colColor, ubH, ubS, ubV); UBYTE ubA = (UBYTE) (m_colColor&255); m_ubComponents[0][0] = ubH; m_ubComponents[0][1] = ubS; m_ubComponents[0][2] = ubV; m_ubComponents[0][3] = ubA; m_ubComponents[1][0] = ubR; m_ubComponents[1][1] = ubG; m_ubComponents[1][2] = ubB; m_colLastColor = m_colColor; }
void CColoredButton::OnMouseMove(UINT nFlags, CPoint point) { if( (m_iColorIndex != -1) && (nFlags & MK_LBUTTON) && _bMouseMoveEnabled) { SetOverButtonInfo( point); EnableToolTips( TRUE); theApp.m_cttToolTips.ManualUpdate(); CPoint ptCurrent; GetCursorPos( &ptCurrent); ColorToComponents(); SLONG slResult = m_ubComponents[ m_iColorIndex][m_iComponentIndex]; slResult += ptCurrent.x-m_ptCenter.x; slResult = Min(Max(slResult,0L), 255L); m_ubComponents[ m_iColorIndex][m_iComponentIndex] = UBYTE( slResult); COLOR colResult; if( m_iColorIndex == 0) { colResult = HSVToColor( m_ubComponents[0][0], m_ubComponents[0][1], m_ubComponents[0][2]); ColorToRGB(colResult, m_ubComponents[1][0], m_ubComponents[1][1], m_ubComponents[1][2]); } else { colResult = RGBToColor( m_ubComponents[1][0], m_ubComponents[1][1], m_ubComponents[1][2]); ColorToHSV(colResult, m_ubComponents[0][0], m_ubComponents[0][1], m_ubComponents[0][2]); } // add alpha colResult |= m_ubComponents[0][3]; m_colColor = colResult; m_colLastColor = colResult; m_bMixedColor = FALSE; Invalidate( FALSE); SendMessage( WM_PAINT); // invalidate parent dialog if( m_pwndParentDialog != NULL) m_pwndParentDialog->UpdateData( TRUE); if(ptCurrent != m_ptCenter) { SetCursorPos( m_ptCenter.x, m_ptCenter.y); } } CButton::OnMouseMove(nFlags, point); }
CColoredButton::CColoredButton() { m_colColor = 0xFFFFFFFF; m_colLastColor = 0xFFFFFFFF; m_ptPickerType = PT_MFC; m_pwndParentDialog = NULL; m_bMixedColor = FALSE; UBYTE ubR, ubG, ubB; UBYTE ubH, ubS, ubV; ColorToRGB( m_colColor, ubR, ubG, ubB); ColorToHSV( m_colColor, ubH, ubS, ubV); UBYTE ubA = (UBYTE) (m_colColor&255); m_ubComponents[0][0] = ubH; m_ubComponents[0][1] = ubS; m_ubComponents[0][2] = ubV; m_ubComponents[0][3] = ubA; m_ubComponents[1][0] = ubR; m_ubComponents[1][1] = ubG; m_ubComponents[1][2] = ubB; }
CTString GetPropertyValue(CEntity *pen, CEntityProperty *pepProperty, INDEX &iFormat) { CTString strResult=""; iFormat=PDF_STRING; // see type of changing property switch( pepProperty->ep_eptType) { case CEntityProperty::EPT_FLAGS: { strResult.PrintF("0x%08x", ENTITYPROPERTY( pen, pepProperty->ep_slOffset, ULONG)); break; } case CEntityProperty::EPT_ENUM: { // obtain enum property description object CEntityPropertyEnumType *epEnum = pepProperty->ep_pepetEnumType; INDEX iEnum = ENTITYPROPERTY( pen, pepProperty->ep_slOffset, INDEX); // search for selected enum BOOL bEnumFound=FALSE; for(INDEX iEnumItem=0; iEnumItem<epEnum->epet_ctValues; iEnumItem++) { if(iEnum==epEnum->epet_aepevValues[ iEnumItem].epev_iValue) { strResult=epEnum->epet_aepevValues[ iEnumItem].epev_strName; bEnumFound=TRUE; } } if( !bEnumFound) { strResult="Invalid enum value!!!"; } break; } case CEntityProperty::EPT_ANIMATION: { iFormat=PDF_INDEX; INDEX iAnim = ENTITYPROPERTY( pen, pepProperty->ep_slOffset, INDEX); CAnimData *pAD = pen->GetAnimData( pepProperty->ep_slOffset); if( pAD != NULL) { CAnimInfo aiInfo; pAD->GetAnimInfo(iAnim, aiInfo); strResult=aiInfo.ai_AnimName; } break; } case CEntityProperty::EPT_ENTITYPTR: case CEntityProperty::EPT_PARENT: { CEntity *penPtr = ENTITYPROPERTY( pen, pepProperty->ep_slOffset, CEntityPointer); if( penPtr!=NULL) { strResult="->"+penPtr->GetName(); } else { strResult="No target"; } break; } case CEntityProperty::EPT_FLOAT: case CEntityProperty::EPT_RANGE: case CEntityProperty::EPT_ANGLE: { iFormat=PDF_FLOAT; strResult.PrintF("%g", ENTITYPROPERTY( pen, pepProperty->ep_slOffset, FLOAT)); break; } case CEntityProperty::EPT_ILLUMINATIONTYPE: { INDEX iIllumination = ENTITYPROPERTY( pen, pepProperty->ep_slOffset, INDEX); strResult=pen->en_pwoWorld->wo_aitIlluminationTypes[iIllumination].it_strName; break; } case CEntityProperty::EPT_STRING: case CEntityProperty::EPT_STRINGTRANS: { strResult=ENTITYPROPERTY( pen, pepProperty->ep_slOffset, CTString); break; } case CEntityProperty::EPT_FLOATAABBOX3D: { FLOATaabbox3D box=ENTITYPROPERTY( pen, pepProperty->ep_slOffset, FLOATaabbox3D); strResult.PrintF("(%g,%g,%g)-(%g,%g,%g)", box.Min()(1),box.Min()(2),box.Min()(3), box.Max()(1),box.Max()(2),box.Max()(3)); break; } case CEntityProperty::EPT_ANGLE3D: { ANGLE3D ang=ENTITYPROPERTY( pen, pepProperty->ep_slOffset, ANGLE3D); strResult.PrintF("%g,%g,%g",ang(1),ang(2),ang(3)); break; } case CEntityProperty::EPT_INDEX: { iFormat=PDF_INDEX; strResult.PrintF("%d", ENTITYPROPERTY( pen, pepProperty->ep_slOffset, INDEX)); break; } case CEntityProperty::EPT_BOOL: { if(ENTITYPROPERTY( pen, pepProperty->ep_slOffset, BOOL)) { strResult="Yes"; } else { strResult="No"; } break; } case CEntityProperty::EPT_COLOR: { iFormat=PDF_COLOR; COLOR col=ENTITYPROPERTY( pen, pepProperty->ep_slOffset, COLOR); UBYTE ubR, ubG, ubB; UBYTE ubH, ubS, ubV; ColorToHSV( col, ubH, ubS, ubV); ColorToRGB( col, ubR, ubG, ubB); UBYTE ubA = (UBYTE) (col&255); strResult.PrintF( "RGB=(%d,%d,%d) HSV=(%d,%d,%d) Alpha=%d", ubR, ubG, ubB, ubH, ubS, ubV, ubA); break; } case CEntityProperty::EPT_FILENAME: { strResult = ENTITYPROPERTY( pen, pepProperty->ep_slOffset, CTFileName); break; } case CEntityProperty::EPT_FILENAMENODEP: { strResult = ENTITYPROPERTY( pen, pepProperty->ep_slOffset, CTFileNameNoDep); break; } default: { } } return strResult; }
void PerformRender(renderlist_t *RenderList, gamestate_t *GameState) { drawbuffer_t *DrawBuffer = &GameState->DrawBuffer; uint BufferSize = DrawBuffer->Width * DrawBuffer->Height; u8 *Pixels = (u8 *)(DrawBuffer->Buffer); u8 *Address = (u8 *)RenderList->Data; bool FirstRender = false; for (renderop_e RenderOp = (renderop_e)*Address; RenderOp != RenderOp_stop; RenderOp = (renderop_e)*Address) { // Skip past render op Address += sizeof(renderop_e); #define RENDERDATA(SubType) (renderdata_##SubType##_t *)Address; Address += sizeof(renderdata_##SubType##_t) switch (RenderOp) { case RenderOp_clear: { uint Color = *(uint *)Address; Address += sizeof(uint); uint *Dst = (uint *)Pixels; for (uint i=0; i < BufferSize; ++i) { *Dst++ = Color; } FirstRender = true; // Why? Because everything's gone now break; } case RenderOp_bitmap: { renderdata_bitmap_t *Bitmap = RENDERDATA(bitmap); artfile_entry_t *Entry = GET_ENTRY((&ArtsMemory), Bitmap->Id); u8 *EntryData = GET_ENTRY_DATA((&ArtsMemory), Bitmap->Id); int StartX = Bitmap->X * DrawBuffer->Width; int StartY = Bitmap->Y * DrawBuffer->Height; bool UseColorKey = Bitmap->Flags & BitmapFlag_ColorKey; bool UseAlpha = Bitmap->Flags & BitmapFlag_Alpha; if (Bitmap->Flags & BitmapFlag_AlignLeft) { StartX = 0; } else if (Bitmap->Flags & BitmapFlag_AlignRight) { StartX = DrawBuffer->Width - Entry->Dim.Width * Bitmap->Width; } if (Bitmap->Flags & BitmapFlag_AlignTop) { StartY = 0; } else if (Bitmap->Flags & BitmapFlag_AlignBottom) { StartY = DrawBuffer->Height - Entry->Dim.Height * Bitmap->Height; } /* if (((StartX + Entry->Dim.Width < 0) && (StartY + Entry->Dim.Height < 0)) || (StartX > DrawBuffer->Width) && (StartY > DrawBuffer->Height)) { // Not visible break; } */ Bitmap->Width = (Bitmap->Width < 0 ? 0 : Bitmap->Width); Bitmap->Height = (Bitmap->Height < 0 ? 0 : Bitmap->Height); uint RealDimWidth = Entry->Dim.Width; uint RealDimHeight = Entry->Dim.Height; u8 *Src = EntryData; if (StartY < 0) { Src += abs(StartY) * Entry->Dim.Width; RealDimHeight -= abs(StartY); StartY = 0; } if (StartX < 0) { Src += abs(StartX); RealDimWidth -= abs(StartX); StartX = 0; } if (StartX + RealDimWidth > DrawBuffer->Width) { RealDimWidth -= (StartX + RealDimWidth) - DrawBuffer->Width; } if (StartY + RealDimHeight > DrawBuffer->Height) { RealDimHeight -= (StartY + RealDimHeight) - DrawBuffer->Height; } uint *Dst = (uint *)(Pixels + 4 * (StartY * DrawBuffer->Width + StartX)); // uint *LastDst = (uint *)(Pixels + 4 * DrawBuffer->Width * DrawBuffer->Height - 1); float StepX = 1 / Bitmap->Width; float StepY = 1 / Bitmap->Height; uint DrawBufferSize = 4 * DrawBuffer->Width * DrawBuffer->Height - 1; for (float Y = 0; Y < Entry->Dim.Height; Y += StepY) { if (((uint)(Y+0.5f)) >= RealDimHeight || !BoundsCheck(Pixels, DrawBufferSize, Dst) /*Dst > LastDst*/) { break; } uint iY = (uint)Y; uint Scanline = 0; for (float X = 0; X < Entry->Dim.Width; X += StepX) { //if (Dst > LastDst) { if (Scanline >= DrawBuffer->Width || !BoundsCheck(Pixels, DrawBufferSize, Dst)) { break; } uint iX = (uint)X; u8 C = *(Src + iY * Entry->Dim.Width + iX); uint FinalColor = 0; if (C) { FinalColor = Bitmap->Color; } if (X < RealDimWidth && (!UseColorKey || FinalColor)) { if (!FirstRender && UseAlpha) { uint DstRaw = *Dst; color_t DstColor = UintToColor(DstRaw); color_t SrcColor = UintToColor(FinalColor); float OneMinusSrcA = 1.0f - SrcColor.A; DstColor.R = SrcColor.R + (DstColor.R * OneMinusSrcA); DstColor.G = SrcColor.G + (DstColor.G * OneMinusSrcA); DstColor.B = SrcColor.B + (DstColor.B * OneMinusSrcA); FinalColor = ColorToRGB(DstColor); } *Dst = FinalColor; } ++Dst; ++Scanline; } Dst += DrawBuffer->Width - Scanline; } FirstRender = false; break; } default: assert(!"Unknown render op"); } #undef RENDERDATA } }
//--------------------------------------------------------------------------- void __fastcall ProcesoThresholdingColorNegro::obtenerPixel() { valorPixel = ColorToRGB(imPicture->Canvas->Pixels[xpos][ypos]); }