ocpCursor::ocpCursor( const char **xpm_data, long type, int hotSpotX, int hotSpotY ) : wxCursor( wxCURSOR_ARROW ) { wxImage cImage( xpm_data ); // wxMSW Bug??? // On Windows XP, conversion from wxImage to wxBitmap fails at the ::CreateDIBitmap() call // unless a "compatible" dc is provided. Why?? // As a workaround, just make a simple wxDC for temporary use wxBitmap tbmp( cImage.GetWidth(), cImage.GetHeight(), -1 ); wxMemoryDC dwxdc; dwxdc.SelectObject( tbmp ); // HCURSOR hcursor = wxBitmapToHCURSOR ( wxBitmap ( cImage, ( wxDC & ) dwxdc ), // hotSpotX, hotSpotY ); HCURSOR hcursor = NULL; if( !hcursor ) { wxLogWarning( _T( "Failed to create ocpCursor." ) ); return; } // Replace the HANDLE created in the base class constructor // Probably leaks.... GetGDIImageData()->m_handle = hcursor; }
BOOL CBSObject::DrawPNG(HDC hDC, const RECT &rectDst, LPCTSTR strImagePath, HINSTANCE hInst) { BOOL bRet = FALSE; if (strImagePath == NULL) { return bRet; } Gdiplus::Graphics graphics(hDC); CFileStatus status; if (CFile::GetStatus(strImagePath, status)) { Gdiplus::Image cImage(strImagePath); Gdiplus::RectF cRectF(static_cast<Gdiplus::REAL>(rectDst.left), static_cast<Gdiplus::REAL>(rectDst.top), static_cast<Gdiplus::REAL>(rectDst.right - rectDst.left), static_cast<Gdiplus::REAL>(rectDst.bottom - rectDst.top)); graphics.DrawImage(&cImage, cRectF); bRet = TRUE; } return bRet; }
ocpCursor::ocpCursor ( const char **xpm_data, long type, int hotSpotX, int hotSpotY ) : wxCursor ( wxCURSOR_ARROW ) { wxImage cImage ( xpm_data ); wxBitmap tbmp ( cImage.GetWidth(),cImage.GetHeight(),-1 ); }
virtual void SaveAsImage(const std::string& str_path) { fipImage cImage(FIT_BITMAP, m_unPixelsPerMeter * m_cHalfArenaSize.GetX()*2, m_unPixelsPerMeter * m_cHalfArenaSize.GetY()*2, 24); Real fFactor = 1.0f / static_cast<Real>(m_unPixelsPerMeter); CVector2 cFloorPos; CColor cARGoSPixel; RGBQUAD tFIPPixel; for(UInt32 y = 0; y < cImage.getHeight(); ++y) { for(UInt32 x = 0; x < cImage.getWidth(); ++x) { cFloorPos.Set(x * fFactor, y * fFactor); cFloorPos -= m_cHalfArenaSize; cARGoSPixel = m_cLoopFunctions.GetFloorColor(cFloorPos); tFIPPixel.rgbRed = cARGoSPixel.GetRed(); tFIPPixel.rgbGreen = cARGoSPixel.GetGreen(); tFIPPixel.rgbBlue = cARGoSPixel.GetBlue(); cImage.setPixelColor(x, y, &tFIPPixel); } } if(!cImage.save(str_path.c_str())) { THROW_ARGOSEXCEPTION("Cannot save image \"" << str_path << "\" for floor entity."); } }
int main(int, char *[]) { const std::string file = "/home/mathieu/dev/cochleo/share/cochlee.wav"; const audiofile audio(file); filterbank fb(audio.sample_frequency(),100,6000,1000); const auto xaxis = audio.time(); const auto yaxis = fb.center_frequency(); auto cochleo = fb.compute(audio.channel(0)); normalization(cochleo); // Create the color palette auto palette = vtkSmartPointer<vtkLookupTable>::New(); palette->SetTableRange(0.0,1.0); palette->SetHueRange(0.67,0.); palette->SetSaturationRange(0.7,0.3); palette->Build(); // Create a c-style rgb image const std::size_t width = xaxis.size(); const std::size_t height = yaxis.size(); std::vector<unsigned char> cImage(3*width*height); for(std::size_t i=0; i<width; ++i) for(std::size_t j=0; j<height; ++j) { unsigned char* color = palette->MapValue(cochleo[i][j]); cImage[3*(i+width*j)] = color[0]; cImage[3*(i+width*j)+1] = color[1]; cImage[3*(i+width*j)+2] = color[2]; } // Convert the c-style image to a vtkImageData auto imageImport = vtkSmartPointer<vtkImageImport>::New(); imageImport->SetDataSpacing(0.07, 1, 1); imageImport->SetDataOrigin(0, 0, 0); imageImport->SetWholeExtent(0, width-1, 0, height-1, 0, 0); imageImport->SetDataExtentToWholeExtent(); imageImport->SetDataScalarTypeToUnsignedChar(); imageImport->SetNumberOfScalarComponents(3); imageImport->SetImportVoidPointer(cImage.data()); imageImport->Update(); // Create an actor auto actor = vtkSmartPointer<vtkImageActor>::New(); actor->SetInput(imageImport->GetOutput()); // Create a scalar bar auto scalarBar = vtkSmartPointer<vtkScalarBarActor>::New(); scalarBar->SetLookupTable(palette); scalarBar->SetTitle("gain"); scalarBar->SetNumberOfLabels(5); // Configure text of the scalar bar auto textBar = vtkSmartPointer<vtkTextProperty>::New(); textBar->SetFontSize(10); scalarBar->SetTitleTextProperty(textBar); scalarBar->SetLabelTextProperty(textBar); // Setup renderer auto renderer = vtkSmartPointer<vtkRenderer>::New(); renderer->AddActor(actor); renderer->AddActor(scalarBar); renderer->ResetCamera(); // Setup render window auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); // Setup render window interactor auto renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); auto style = vtkSmartPointer<vtkInteractorStyleImage>::New(); renderWindowInteractor->SetInteractorStyle(style); // Render and start interaction renderWindowInteractor->SetRenderWindow(renderWindow); renderWindowInteractor->Initialize(); renderWindowInteractor->Start(); return EXIT_SUCCESS; }
ocpCursor::ocpCursor ( const char **xpm_data, long type, int hotSpotX, int hotSpotY ) : wxCursor ( wxCURSOR_CROSS ) { wxImage cImage ( xpm_data ); int width = cImage.GetWidth(); int height = cImage.GetHeight(); // m_refData = new wxCursorRefData(); // Get some X parameters int xscreen = DefaultScreen ( ( Display* ) wxGlobalDisplay() ); Window xroot = RootWindow ( ( Display* ) wxGlobalDisplay(), xscreen ); Visual* xvisual = DefaultVisual ( ( Display* ) wxGlobalDisplay(), xscreen ); M_CURSORDATA->m_display = wxGlobalDisplay(); wxASSERT_MSG ( M_CURSORDATA->m_display, wxT ( "No display" ) ); // Make a pixmap Pixmap cpixmap = XCreatePixmap ( ( Display* ) wxGlobalDisplay(), xroot, width, height, 1 ); // Make an Ximage XImage *data_image = XCreateImage ( ( Display* ) wxGlobalDisplay(), xvisual, 1, ZPixmap, 0, 0, width, height, 32, 0 ); data_image->data = ( char* ) malloc ( data_image->bytes_per_line * data_image->height ); int index = 0; int pixel = 0; unsigned char* data = cImage.GetData(); // Create mask Pixmap cmask; unsigned char mr, mg, mb; if ( cImage.HasMask() ) { XImage *mask_image = XCreateImage ( ( Display* ) wxGlobalDisplay(), xvisual, 1, ZPixmap, 0, 0, width, height, 32, 0 ); mask_image->data = ( char* ) malloc ( mask_image->bytes_per_line * mask_image->height ); cImage.GetOrFindMaskColour ( &mr, &mg, &mb ); int rit = ( mr << 16 ) + ( mg << 8 ) + mb; for ( int y = 0; y < height; y++ ) { for ( int x = 0; x < width; x++ ) { int ri = ( int ) data[index++]; ri += data[index++] << 8; ri += data[index++] << 16; /* int ri = *(int *)(&data[index]); ri &= 0x00ffffff; index++; index++; index++; */ pixel = 1; if ( ri == rit ) // if data is mask value, mask pixel gets 0 pixel = 0; XPutPixel ( mask_image, x, y, pixel ); } } cmask = XCreatePixmap ( ( Display* ) wxGlobalDisplay(), xroot, width, height, 1 ); GC gc = XCreateGC ( ( Display* ) wxGlobalDisplay(), cmask, 0, NULL ); XPutImage ( ( Display* ) wxGlobalDisplay(), cmask, gc, mask_image, 0, 0, 0, 0, width, height ); XDestroyImage ( mask_image ); XFreeGC ( ( Display* ) wxGlobalDisplay(), gc ); } // Render the wxImage cImage onto the Ximage // Simple black/white cursors only, please index = 0; for ( int y = 0; y < height; y++ ) { for ( int x = 0; x < width; x++ ) { int ri = ( int ) data[index++]; ri += data[index++] << 8; ri += data[index++] << 16; /* int ri = *(int *)(&data[index]); ri &= 0x00ffffff; index++; index++; index++; */ pixel = 0; if ( ri ) pixel = 1; XPutPixel ( data_image, x, y, pixel ); } } // Put the Ximage into the pixmap GC gc = XCreateGC ( ( Display* ) wxGlobalDisplay(), cpixmap, 0, NULL ); XPutImage ( ( Display* ) wxGlobalDisplay(), cpixmap, gc, data_image, 0, 0, 0, 0, width, height ); // Free the Ximage stuff XDestroyImage ( data_image ); XFreeGC ( ( Display* ) wxGlobalDisplay(), gc ); // Make a X cursor from the pixmap XColor fg, bg; fg.red = fg.blue = fg.green = 0xffff; bg.red = bg.blue = bg.green = 0; M_CURSORDATA->m_cursor = ( WXCursor ) XCreatePixmapCursor ( ( Display* ) wxGlobalDisplay(), cpixmap, cmask, &fg, &bg, hotSpotX, hotSpotY ); }
BOOL CBSObject::DrawPNG(HDC hDC, const RECT &rectDst, const RECT* prectImagePortion, UINT Res, HINSTANCE hInst) { BOOL bRet = FALSE; Gdiplus::Graphics graphics(hDC); HRSRC hResource = ::FindResource(hInst, MAKEINTRESOURCE(Res), TEXT("PNG")); if (hResource > 0) { DWORD imageSize = ::SizeofResource(hInst, hResource); if (imageSize > 0) { HGLOBAL hHandle = ::LoadResource(hInst,hResource); if (NULL != hHandle) { void* pResourceData = ::LockResource(hHandle); if (pResourceData != NULL) { HGLOBAL hBuffer; hBuffer = ::GlobalAlloc(GMEM_MOVEABLE, imageSize); if (hBuffer) { void* pBuffer = ::GlobalLock(hBuffer); if (pBuffer) { memcpy_s(pBuffer, imageSize, pResourceData, imageSize); //For stm0117 IStream* pStream = NULL; if (::CreateStreamOnHGlobal(hBuffer, FALSE, &pStream) == S_OK) { Gdiplus::Image cImage(pStream); Gdiplus::RectF cRectF(static_cast<Gdiplus::REAL>(rectDst.left), static_cast<Gdiplus::REAL>(rectDst.top), static_cast<Gdiplus::REAL>(rectDst.right - rectDst.left), static_cast<Gdiplus::REAL>(rectDst.bottom - rectDst.top)); Gdiplus::ImageAttributes clImgAtt; clImgAtt.SetWrapMode(Gdiplus::WrapModeTileFlipXY); if (NULL == prectImagePortion) { graphics.DrawImage(&cImage, cRectF, static_cast<Gdiplus::REAL>(0), static_cast<Gdiplus::REAL>(0), static_cast<Gdiplus::REAL>(cImage.GetWidth()), static_cast<Gdiplus::REAL>(cImage.GetHeight()), Gdiplus::UnitPixel, &clImgAtt); // } else { graphics.DrawImage(&cImage, cRectF, static_cast<Gdiplus::REAL>(prectImagePortion->left), static_cast<Gdiplus::REAL>(prectImagePortion->top), static_cast<Gdiplus::REAL>(prectImagePortion->right - prectImagePortion->left), static_cast<Gdiplus::REAL>(prectImagePortion->bottom - prectImagePortion->top), Gdiplus::Unit::UnitPixel, NULL, NULL, NULL); } pStream->Release(); bRet = TRUE; } ::GlobalUnlock(hBuffer); } ::GlobalFree(hBuffer); hBuffer = NULL; } } } } } return bRet; }