void Debug::log(const char *str) { /* * Low-level JTAG debug messages. Blocks indefinitely if * OpenOCD is not attached! To get these messages, run * "monitor target_request debugmsgs enable" in GDB. */ const uint32_t command = 0x01; int len = 0; for (const char *p = str; *p && len < 0xFFFF; p++, len++); dcc(command | (len << 16)); while (len > 0) { uint32_t data = ( str[0] | ((len > 1) ? (str[1] << 8) : 0) | ((len > 2) ? (str[2] << 16) : 0) | ((len > 3) ? (str[3] << 24) : 0) ); dcc(data); len -= 4; str += 4; } }
// returns 16, 24, 32 bit depth CLIB_API int GetFirstPixel(HBITMAP hBitmap, COLORREF& firstPixel) { BITMAP bmp; if (::GetObject(hBitmap, sizeof(bmp), &bmp) && bmp.bmBits) { if (bmp.bmBitsPixel > 16) { unsigned offset=(((bmp.bmWidth*bmp.bmBitsPixel/8)+3)/4) * 4 * (bmp.bmHeight-1); firstPixel = *(COLORREF*)((BYTE*)bmp.bmBits + offset); // in memory it is laid out as BGR, so convert to RGB... firstPixel = RGB(GetBValue(firstPixel), GetGValue(firstPixel), GetRValue(firstPixel)); return bmp.bmBitsPixel; } else { ATLASSERT(bmp.bmBitsPixel==16); // we need a temporary memory bitmap to paint into. CClientDC dcc(0); CMemBm bmpFirstPixel(dcc, 0, 0, 0, 1, 1); CDCHandle hdcH = bmpFirstPixel; HBITMAP hbmpold=dcc.SelectBitmap(hBitmap); hdcH.BitBlt(0, 0, 1, 1, dcc, 0, 0, SRCCOPY); dcc.SelectBitmap(hbmpold); // get trans color firstPixel = bmpFirstPixel.GetFirstPixel(); return bmp.bmBitsPixel; } } return 0; }
CLIB_API GraphTypes::IBitmap* GetIBitmapFromIHTMLElement(IHTMLElementRender* htmlElementRender) { CDC dc; { CClientDC dcc(0); dc.CreateCompatibleDC(dcc); } CComQIPtr<IHTMLElement> htmlElement = htmlElementRender; long height, width; htmlElement->get_offsetHeight(&height); htmlElement->get_offsetWidth(&width); void* buf; BITMAPINFO bmp_info; bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmp_info.bmiHeader.biWidth = width; bmp_info.bmiHeader.biHeight = height; bmp_info.bmiHeader.biPlanes = 1; bmp_info.bmiHeader.biBitCount = 32; bmp_info.bmiHeader.biCompression = BI_RGB; bmp_info.bmiHeader.biSizeImage = 0; bmp_info.bmiHeader.biXPelsPerMeter = 0; bmp_info.bmiHeader.biYPelsPerMeter = 0; bmp_info.bmiHeader.biClrUsed = 0; bmp_info.bmiHeader.biClrImportant = 0; HBITMAP hbmp=0; hbmp = ::CreateDIBSection( dc.m_hDC, &bmp_info, DIB_RGB_COLORS, &buf, 0, 0 ); ATLASSERT(hbmp); GraphTypes::IBitmap* ibmp=0; if(hbmp && dc.m_hDC) { HBITMAP oldbmp=dc.SelectBitmap(hbmp); // NOTE: this fill should be irrelevent since image gets rendered next // It would fail on Vista anyway, since transcolor=0x00d3d3d3 now. dc.FillSolidRect(0, 0, width, height, RGB(0,0,211)); // default to trans color (GIF) for web (ASSUMPTION) //dc.FillSolidRect(0, 0, width, height, GetSysColor(COLOR_WINDOW)); HRESULT hr=htmlElementRender->DrawToDC(dc.m_hDC); ATLASSERT(SUCCEEDED(hr)); dc.SelectBitmap(oldbmp); ibmp=GraphTypes::CreateIBitmap(hbmp); } return ibmp; }
void hdDrawingView::onPaint(wxPaintEvent &event) { // Prepare Context for Buffered Draw wxPaintDC dcc(this); wxBufferedDC dc(&dcc, canvasSize); dc.Clear(); hdIFigure *toDraw = NULL; hdIteratorBase *iterator = drawing->figuresEnumerator(); while(iterator->HasNext()) { toDraw = (hdIFigure *)iterator->Next(); if(toDraw->isSelected(diagramIndex)) toDraw->drawSelected(dc, this); else toDraw->draw(dc, this); } delete iterator; hdIHandle *tmpHandle = NULL; hdIteratorBase *selectionIterator = drawing->selectionFigures();//selection->createIterator(); while(selectionIterator->HasNext()) { toDraw = (hdIFigure *)selectionIterator->Next(); hdIteratorBase *handlesIterator = toDraw->handlesEnumerator()->createIterator(); while(handlesIterator->HasNext()) { tmpHandle = (hdIHandle *)handlesIterator->Next(); tmpHandle->draw(dc, this); } delete handlesIterator; } delete selectionIterator; //Hack to avoid selection rectangle drawing bug if (drawSelRect) { wxPen *pen = wxThePenList->FindOrCreatePen(*wxRED, 1, wxDOT); dc.SetPen(*pen); wxBrush *brush = wxTheBrushList->FindOrCreateBrush(*wxRED, wxTRANSPARENT); dc.SetBackground(*brush); dc.SetBackgroundMode(wxTRANSPARENT); //Adjust points before drawing wxPoint selAjustedPoints[5]; CalcScrolledPosition(selPoints[0].x, selPoints[0].y, &selAjustedPoints[0].x, &selAjustedPoints[0].y); CalcScrolledPosition(selPoints[1].x, selPoints[1].y, &selAjustedPoints[1].x, &selAjustedPoints[1].y); CalcScrolledPosition(selPoints[2].x, selPoints[2].y, &selAjustedPoints[2].x, &selAjustedPoints[2].y); CalcScrolledPosition(selPoints[3].x, selPoints[3].y, &selAjustedPoints[3].x, &selAjustedPoints[3].y); CalcScrolledPosition(selPoints[4].x, selPoints[4].y, &selAjustedPoints[4].x, &selAjustedPoints[4].y); //Draw dc.DrawLines(5, selAjustedPoints, 0, 0); drawSelRect = false; } }
DigitChain bridge_digit_chains(DigitChain& dca, DigitChain& dcb, StrongLink& link) { //std::cout << "bridge_digit_chains" << std::endl; DigitChain dcc(dca.val); Spot aspot; Spot bspot; if(dca.has_spot(link.a)) { aspot = link.a; bspot = link.b; } else if(dcb.has_spot(link.b)){ aspot = link.b; bspot = link.a; } else { std::cout << "!! Should not be bridging (merging) digitchains" << std::endl; } int a_idx_spot = idx_of_digit_vertex(dca.verts, aspot); int b_idx_spot = idx_of_digit_vertex(dcb.verts, bspot); // whether to reverse B's colors bool reverse = (dca.verts[a_idx_spot].color == dcb.verts[b_idx_spot].color); //std::cout << "bridge_digit_chains: init complete" << std::endl; // add A's verts for(int i=0; i < dca.verts.size(); i++) { dcc.verts.push_back(DigitVertex(dca.verts[i].spot, dca.verts[i].color)); for(int j=0; j < dca.verts[i].peers.size(); j++) { dcc.verts[i].peers.push_back(dca.verts[i].peers[j]); dcc.verts[i].links.push_back(dca.verts[i].links[j]); } } //std::cout << "bridge_digit_chains: A's verts added" << std::endl; int offset = dca.verts.size(); // add B's verts for(int i=0; i < dcb.verts.size(); i++) { dcc.verts.push_back(DigitVertex(dcb.verts[i].spot, (reverse ? dc_other_color(dcb.verts[i].color) : dcb.verts[i].color))); for(int j=0; j < dcb.verts[i].peers.size(); j++) { dcc.verts[i + offset].peers.push_back(dcb.verts[i].peers[j] + offset); dcc.verts[i + offset].links.push_back(dcb.verts[i].links[j]); } } //std::cout << "bridge_digit_chains: B's verts added" << std::endl; // connect link int b_idx_off = b_idx_spot + offset; dcc.verts[a_idx_spot].connect(link, b_idx_off); //std::cout << "bridge_digit_chains: X" << std::endl; dcc.verts[b_idx_off].connect(link, a_idx_spot); //std::cout << "bridge_digit_chains: connected" << std::endl; return dcc; }
// Detect when should be drawn the canvas with the model information void gqbView::onPaint(wxPaintEvent &event) { wxPaintDC dcc(this); // Prepare Context for Buffered Draw wxBufferedDC dc(&dcc, canvasSize); drawAll(dc, true); // Call Function to draw all }
CLIB_API GraphTypes::IBitmap* GetIBitmapFromIPicture(IPicture* ipic) { GraphTypes::IBitmap* ibmp=0; if (!ipic) return ibmp; CDC dc; { CClientDC dcc(0); dc.CreateCompatibleDC(dcc); } OLE_YSIZE_HIMETRIC height; OLE_XSIZE_HIMETRIC width; ipic->get_Height(&height); ipic->get_Width(&width); CSize nsize(width, height); // convert OLE size into pixels dc.HIMETRICtoDP(&nsize); void* buf; BITMAPINFO bmp_info; bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmp_info.bmiHeader.biWidth = nsize.cx; bmp_info.bmiHeader.biHeight = nsize.cy; bmp_info.bmiHeader.biPlanes = 1; bmp_info.bmiHeader.biBitCount = 32; bmp_info.bmiHeader.biCompression = BI_RGB; bmp_info.bmiHeader.biSizeImage = 0; bmp_info.bmiHeader.biXPelsPerMeter = 0; bmp_info.bmiHeader.biYPelsPerMeter = 0; bmp_info.bmiHeader.biClrUsed = 0; bmp_info.bmiHeader.biClrImportant = 0; HBITMAP hbmp=0; hbmp = ::CreateDIBSection( dc.m_hDC, &bmp_info, DIB_RGB_COLORS, &buf, 0, 0 ); ATLASSERT(hbmp); if(hbmp && dc.m_hDC) { HBITMAP oldbmp=dc.SelectBitmap(hbmp); HRESULT hr = ipic->Render( dc.m_hDC, 0, nsize.cy, nsize.cx, -nsize.cy, 0, 0, width, height, 0); ATLASSERT(SUCCEEDED(hr)); dc.SelectBitmap(oldbmp); ibmp=GraphTypes::CreateIBitmap(hbmp); } return ibmp; }
void CChildView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here //Creates a CFourier object //The CFourier class has the FFT function and a couple of usefull variables CFourier fft; //sample rate of the signal (must be 2^n) long sample_rate=8192; //number of samples you want to send for processing in the fft (any) //for example 100 samples long captured_samples=500; //frequency of the signal (has to be smaller than sample_rate/2) //for example 46 int frequency=250; float data[5000]; //example of a sin signal(you can try to add some more signals to see the //fourier change for(int i=0; i<captured_samples; i++) { double temp=(double)(2*fft.pi*frequency*((float)i/sample_rate)); data[i]=((double)30*sin(temp)); } //aply the FFT to the signal fft.ComplexFFT(data,captured_samples,sample_rate,1); //do the drawing of the signal //the fft object has two usefull variables //one is the fft.fundamental_frequency which contains the value of //the fundamental frequency //the second one is the fft.vector which contains the values of the //Fourier signal we will use to do the drawing CRect rcClient; GetClientRect(rcClient); CClientDC dcc(this); CBitmap Bitmap; CBitmap* pbmOld = NULL; CDC dcMem; dcMem.CreateCompatibleDC(&dcc); Bitmap.CreateCompatibleBitmap(&dcc,rcClient.right,rcClient.bottom); pbmOld = dcMem.SelectObject(&Bitmap); dcMem.PatBlt(0, 0,rcClient.right, rcClient.bottom, WHITENESS); char buffer[25]; itoa(fft.fundamental_frequency,buffer,10); dcMem.TextOut(rcClient.right-280,20,"The fundamental frequency is:"); dcMem.TextOut(rcClient.right-50,20,buffer); int x,y, x_temp, y_temp; for(x=0 ; x<rcClient.right; x++) { //this temp variables are used to ajust the sign to the wiindow //if you want to see more of the signal ajust these fields x_temp=((x*(sample_rate/2))/rcClient.right); y_temp=(int)((rcClient.bottom*(pow(fft.vector[2*x_temp],2)+pow(fft.vector[2*x_temp+1],2)))/((double)pow(fft.vector[2*fft.fundamental_frequency],2)+pow(fft.vector[2*fft.fundamental_frequency+1],2))); dcMem.MoveTo(x,rcClient.bottom); y=rcClient.bottom-y_temp; dcMem.LineTo(x,y); } dcc.BitBlt(0,0,rcClient.right,rcClient.bottom, &dcMem, 0, 0, SRCCOPY); dcMem.SelectObject(pbmOld); dcMem.DeleteDC(); // Do not call CWnd::OnPaint() for painting messages }