void TransferToWx(const Map& map, wxImage& wx) { wx.Create(map.width * 8, map.height * 8); if (map.tileset->bpp == 4) { for (unsigned int i = 0; i < map.data.size(); i++) { int x = i % map.width; int y = i / map.width; int tile_id = map.data[i] & 0x3FF; int pal_id = (map.data[i] >> 12) & 0xF; const Tile& tile = map.tileset->tilesExport[tile_id]; const PaletteBank& palette = map.tileset->paletteBanks[pal_id]; for (unsigned int j = 0; j < TILE_SIZE; j++) { unsigned char pix = tile.pixels[j]; if (!pix) continue; const auto& c = palette.At(pix); wx.SetRGB(x * 8 + j % 8, y * 8 + j / 8, c.r << 3, c.g << 3, c.b << 3); } } } else { for (unsigned int i = 0; i < map.data.size(); i++)
void wxHtmlImageCell::SetImage(const wxImage& img) { #if !defined(__WXMSW__) || wxUSE_WXDIB if ( img.IsOk() ) { delete m_bitmap; int ww, hh; ww = img.GetWidth(); hh = img.GetHeight(); if ( m_bmpW == wxDefaultCoord) m_bmpW = ww; if ( m_bmpH == wxDefaultCoord) m_bmpH = hh; // Only scale the bitmap at the rendering stage, // so we don't lose quality twice /* if ((m_bmpW != ww) || (m_bmpH != hh)) { wxImage img2 = img.Scale(m_bmpW, m_bmpH); m_bitmap = new wxBitmap(img2); } else */ m_bitmap = new wxBitmap(img); } #endif }
void BM2CMP_FRAME::ExportFile( FILE* aOutfile, OUTPUT_FMT_ID aFormat ) { // Create a potrace bitmap int h = m_NB_Image.GetHeight(); int w = m_NB_Image.GetWidth(); potrace_bitmap_t* potrace_bitmap = bm_new( w, h ); if( !potrace_bitmap ) { wxString msg; msg.Printf( wxT( "Error allocating memory for potrace bitmap" ) ); wxMessageBox( msg ); return; } /* fill the bitmap with data */ for( int y = 0; y < h; y++ ) { for( int x = 0; x < w; x++ ) { unsigned char pix = m_NB_Image.GetGreen( x, y ); BM_PUT( potrace_bitmap, x, y, pix ? 1 : 0 ); } } bitmap2component( potrace_bitmap, aOutfile, aFormat, m_imageDPI.x, m_imageDPI.y ); }
bool BM2CMP_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl ) { // Prj().MaybeLoadProjectSettings(); m_BitmapFileName = aFileSet[0]; if( !m_Pict_Image.LoadFile( m_BitmapFileName ) ) { // LoadFile has its own UI, no need for further failure notification here return false; } m_Pict_Bitmap = wxBitmap( m_Pict_Image ); int h = m_Pict_Bitmap.GetHeight(); int w = m_Pict_Bitmap.GetWidth(); // Determine image resolution in DPI (does not existing in all formats). // the resolution can be given in bit per inches or bit per cm in file m_imageDPI.x = m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX ); m_imageDPI.y = m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY ); if( m_imageDPI.x > 1 && m_imageDPI.y > 1 ) { if( m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM ) { // When the initial resolution is given in bits per cm, // experience shows adding 1.27 to the resolution converted in dpi // before convert to int value reduce the conversion error // but it is not perfect m_imageDPI.x = m_imageDPI.x * 2.54 + 1.27; m_imageDPI.y = m_imageDPI.y * 2.54 + 1.27; } } else // fallback to the default value m_imageDPI.x = m_imageDPI.y = DEFAULT_DPI; // Display image info: // We are using ChangeValue here to avoid generating a wxEVT_TEXT event. m_DPIValueX->ChangeValue( wxString::Format( wxT( "%d" ), m_imageDPI.x ) ); m_DPIValueY->ChangeValue( wxString::Format( wxT( "%d" ), m_imageDPI.y ) ); updateImageInfo(); m_InitialPicturePanel->SetVirtualSize( w, h ); m_GreyscalePicturePanel->SetVirtualSize( w, h ); m_BNPicturePanel->SetVirtualSize( w, h ); m_Greyscale_Image.Destroy(); m_Greyscale_Image = m_Pict_Image.ConvertToGreyscale( ); if( m_rbOptions->GetSelection() > 0 ) NegateGreyscaleImage( ); m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image ); m_NB_Image = m_Greyscale_Image; Binarize( (double) m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() ); return true; }
void Surface::SetPixels( const wxImage& image ) { m_Format = Format( image ); size_t numPixels = (size_t)m_Format.m_Pitch*m_Format.m_CanvasHeight; if ( m_Format.GetDepth() == 24 ) { m_Pixels = (void*)new char[ numPixels ]; memcpy( m_Pixels, image.GetData(), numPixels ); } else if ( m_Format.GetDepth() == 32 ) { // wx uses a screwed up image format with a separate alpha plane. We need to convert into RGBA m_Pixels = (void*)new char[ numPixels ]; unsigned int sPitch = image.GetWidth()*3; unsigned char* pData = image.GetData(); unsigned char* pAlpha= image.GetAlpha(); unsigned int aMask = m_Format.m_AMask; unsigned int aShift= m_Format.m_AShift; int w = (int)m_Format.GetWidth(); int h = (int)m_Format.GetHeight(); for ( int y = 0; y < h; y++ ) { unsigned int *pSrc = (unsigned int*)(pData + y*sPitch); unsigned int *pDst = (unsigned int*)((unsigned char*)m_Pixels + y*m_Format.GetPitch()); for ( int x = 0; x < w; x++ ) { *pDst++ = ((*pSrc) & ~aMask) | ((*pAlpha) << aShift); pAlpha++; pSrc = (unsigned int *)(((unsigned char*)pSrc) + 3); // performance issues with odd addresses??? } } } else if ( m_Format.GetDepth() == 8 ) { // 8 bit gray scale - downscale to gray using luma } else if ( m_Format.GetDepth() == 1 ) { // 1 bit bitmap } else { // cannot compute m_Pixels = NULL; } }
void BM2CMP_FRAME::ExportFile( FILE* aOutfile, OUTPUT_FMT_ID aFormat ) { // Create a potrace bitmap int h = m_NB_Image.GetHeight(); int w = m_NB_Image.GetWidth(); potrace_bitmap_t* potrace_bitmap = bm_new( w, h ); if( !potrace_bitmap ) { wxString msg; msg.Printf( wxT( "Error allocating memory for potrace bitmap" ) ); wxMessageBox( msg ); return; } /* fill the bitmap with data */ for( int y = 0; y < h; y++ ) { for( int x = 0; x < w; x++ ) { unsigned char pix = m_NB_Image.GetGreen( x, y ); BM_PUT( potrace_bitmap, x, y, pix ? 1 : 0 ); } } // choices of m_radio_PCBLayer are expected to be in same order as // BMP2CMP_MOD_LAYER. See bitmap2component.h BMP2CMP_MOD_LAYER modLayer = MOD_LYR_FSILKS; if( aFormat == PCBNEW_KICAD_MOD ) modLayer = (BMP2CMP_MOD_LAYER) m_radio_PCBLayer->GetSelection(); bitmap2component( potrace_bitmap, aOutfile, aFormat, m_imageDPI.x, m_imageDPI.y, modLayer ); }
bool wxBitmap::CreateFromImage(const wxImage& image, int depth) { UnRef(); wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") ) wxCHECK_MSG( depth == -1 || depth == 1, FALSE, wxT("invalid bitmap depth") ) if (image.GetWidth() <= 0 || image.GetHeight() <= 0) return false; m_refData = new wxBitmapRefData(); if (depth == 1) { return CreateFromImageAsBitmap(image); } else { #ifdef __WXGTK20__ if (image.HasAlpha()) return CreateFromImageAsPixbuf(image); #endif return CreateFromImageAsPixmap(image); } }
void AdjustAndSetBitmap(int size, wxImage &image, wxBitmap&bitmap) { if (image.GetHeight() == size) { bitmap = wxBitmap(image); } else { wxImage scaled = image.Scale(size, size, wxIMAGE_QUALITY_HIGH); bitmap = wxBitmap(scaled); } }
void TransferToWx(const Palette& palette, wxImage& wx) { wx.Create(16, 16); for (unsigned int i = 0; i < palette.Size(); i++) { const Color16& c = palette.At(i); wx.SetRGB(i % 16, i / 16, c.r << 3, c.g << 3, c.b << 3); } }
bool wxCreateGreyedImage(const wxImage& in, wxImage& out) { #if wxUSE_IMAGE out = in.ConvertToGreyscale(); if ( out.IsOk() ) return true; #endif // wxUSE_IMAGE return false; }
ImagePanelDyn::ImagePanelDyn(wxWindow* parent, wxImage &imageScaled, wxImage &imageNoScaled, wxPoint point, wxSize size, int style) : wxPanel(parent, wxID_ANY, point, size, style) { image0 = imageScaled.Copy(); image1 = imageNoScaled.Copy(); w = point.x; h = point.y; win = parent; }
void AffineTransformTestCase::setUp() { #if wxUSE_DC_TRANSFORM_MATRIX m_imgOrig.LoadFile("horse.jpg"); CPPUNIT_ASSERT( m_imgOrig.IsOk() ); m_bmpOrig = wxBitmap(m_imgOrig); #endif // wxUSE_DC_TRANSFORM_MATRIX }
wxImage zen::stackImages(const wxImage& img1, const wxImage& img2, ImageStackLayout dir, ImageStackAlignment align, int gap) { assert(gap >= 0); gap = std::max(0, gap); const int img1Width = img1.GetWidth (); const int img1Height = img1.GetHeight(); const int img2Width = img2.GetWidth (); const int img2Height = img2.GetHeight(); int width = std::max(img1Width, img2Width); int height = std::max(img1Height, img2Height); switch (dir) { case ImageStackLayout::HORIZONTAL: width = img1Width + gap + img2Width; break; case ImageStackLayout::VERTICAL: height = img1Height + gap + img2Height; break; } wxImage output(width, height); output.SetAlpha(); ::memset(output.GetAlpha(), wxIMAGE_ALPHA_TRANSPARENT, width * height); auto calcPos = [&](int imageExtent, int totalExtent) { switch (align) { case ImageStackAlignment::CENTER: return (totalExtent - imageExtent) / 2; case ImageStackAlignment::LEFT: return 0; case ImageStackAlignment::RIGHT: return totalExtent - imageExtent; } assert(false); return 0; }; switch (dir) { case ImageStackLayout::HORIZONTAL: writeToImage(img1, output, wxPoint(0, calcPos(img1Height, height))); writeToImage(img2, output, wxPoint(img1Width + gap, calcPos(img2Height, height))); break; case ImageStackLayout::VERTICAL: writeToImage(img1, output, wxPoint(calcPos(img1Width, width), 0)); writeToImage(img2, output, wxPoint(calcPos(img2Width, width), img1Height + gap)); break; } return output; }
bool CFrameWnd::StretchDraw(wxDC &x_dc, wxImage &x_img, wxRect &x_rect) {_STT(); if ( !x_img.Ok() ) return FALSE; // The slow but portable way... wxImage cWxImage = x_img.Copy(); cWxImage.Rescale( x_rect.GetWidth(), x_rect.GetHeight() ); x_dc.DrawBitmap( cWxImage, x_rect.x, x_rect.y ); return TRUE; }
// static ImageArray ImageRoll::SplitH(const wxImage &src, wxColour magicColor) { ImageArray result; int width = src.GetWidth(); int height = src.GetHeight(); unsigned char *data = src.GetData(); unsigned char *ptr = data; unsigned char magicRed = magicColor.Red(); unsigned char magicGreen = magicColor.Green(); unsigned char magicBlue = magicColor.Blue(); bool cur, prev; int i, j, start; // Sanity check... if (width<=0 || height<=0 || data==NULL) return result; prev = false; start = 0; for(i=0; i<width+1; i++) { if (i < width) { unsigned char *ptr2 = ptr; cur = true; for(j=0; j<height && cur; j++) { if (!(ptr2[0] == magicRed && ptr2[1] == magicGreen && ptr2[2] == magicBlue)) cur = false; ptr2 += 3 * width; } } else cur = !prev; if ((cur && !prev)) { wxRect subRect(start, 0, i-start, height); wxImage subImage; if (subRect.width > 0) subImage = src.GetSubImage(subRect); else subImage = wxImage(subRect.width, subRect.height); result.Add(subImage); } else if (!cur && prev) { start = i; } prev = cur; ptr += 3; } return result; }
static void addMipMap(GLuint* texture, const wxImage &l_Image, int &level) { if (l_Image.IsOk() == true) { glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, (GLsizei)l_Image.GetWidth(), (GLsizei)l_Image.GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)l_Image.GetData()); int err = glGetError(); if (err == GL_NO_ERROR) { level++; } } }
wxString Ocr::recognize(const wxImage & image) const { char * text = _api->TesseractRect(image.GetData(), 3, 3 * image.GetWidth(), 0, 0, image.GetWidth(), image.GetHeight()); wxString outputText(text, wxConvUTF8); delete[] text; return outputText; }
void TransferToWx(const Image16Bpp& image, wxImage& wx) { wx.Create(image.width, image.height); for (unsigned int i = 0; i < image.height; i++) { for (unsigned int j = 0; j < image.width; j++) { const Color16& c = image.At(j, i); wx.SetRGB(j, i, c.r << 3, c.g << 3, c.b << 3); } } }
void InitializeTexture(int w, int h) { glGenTextures(1, &g_texture); glBindTexture(GL_TEXTURE_2D, g_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); g_image.Create(w, h, false /* don't clear */); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, g_image.GetWidth(), g_image.GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, g_image.GetData()); }
void GreyOutImage(wxImage &img) { unsigned char *data = img.GetData(); unsigned char r,g,b; unsigned char mr,mg,mb; int i, tst; int len = img.GetHeight()*img.GetWidth()*3; if (img.HasMask()) { mr = img.GetMaskRed(); mg = img.GetMaskGreen(); mb = img.GetMaskBlue(); } tst=0; for (i=0;i<len;i+=3) { r=data[i]; g=data[i+1]; b=data[i+2]; if (!img.HasMask() || r!=mr || g!=mg || b!=mb) { if (!tst) { tst=1; } r = (unsigned char)((230.0-r)*0.7+r); g = (unsigned char)((230.0-g)*0.7+g); b = (unsigned char)((230.0-b)*0.7+b); data[i]=r; data[i+1]=g; data[i+2]=b; } } }
void BM2CMP_FRAME::NegateGreyscaleImage( ) { unsigned char pix; int h = m_Greyscale_Image.GetHeight(); int w = m_Greyscale_Image.GetWidth(); for( int y = 0; y < h; y++ ) for( int x = 0; x < w; x++ ) { pix = m_Greyscale_Image.GetGreen( x, y ); pix = ~pix; m_Greyscale_Image.SetRGB( x, y, pix, pix, pix ); } }
static bool DoRegionUnion(wxRegion& region, const wxImage& image, unsigned char loR, unsigned char loG, unsigned char loB, int tolerance) { unsigned char hiR, hiG, hiB; hiR = (unsigned char)wxMin(0xFF, loR + tolerance); hiG = (unsigned char)wxMin(0xFF, loG + tolerance); hiB = (unsigned char)wxMin(0xFF, loB + tolerance); // Loop through the image row by row, pixel by pixel, building up // rectangles to add to the region. int width = image.GetWidth(); int height = image.GetHeight(); for (int y=0; y < height; y++) { wxRect rect; rect.y = y; rect.height = 1; for (int x=0; x < width; x++) { // search for a continuous range of non-transparent pixels int x0 = x; while ( x < width) { unsigned char R = image.GetRed(x,y); unsigned char G = image.GetGreen(x,y); unsigned char B = image.GetBlue(x,y); if (( R >= loR && R <= hiR) && ( G >= loG && G <= hiG) && ( B >= loB && B <= hiB)) // It's transparent break; x++; } // Add the run of non-transparent pixels (if any) to the region if (x > x0) { rect.x = x0; rect.width = x - x0; region.Union(rect); } } } return true; }
void TransferToWx(const std::vector<PaletteBank>& banks, wxImage& wx) { wx.Create(16, 16); for (unsigned int bank_id = 0; bank_id < banks.size(); bank_id++) { const PaletteBank& bank = banks[bank_id]; int bx = (bank_id % 4) * 4; int by = (bank_id / 4) * 4; for (unsigned int i = 0; i < bank.Size(); i++) { const Color16& c = bank.At(i); wx.SetRGB(i % 4 + bx, i / 4 + by, c.r << 3, c.g << 3, c.b << 3); } } }
void InfoPanel::LoadBannerImage() { const wxImage banner_image = WxUtils::ToWxImage(m_game_list_item.GetBannerImage()); const wxSize banner_min_size = m_banner->GetMinSize(); if (banner_image.IsOk()) { m_banner->SetBitmap(WxUtils::ScaleImageToBitmap(banner_image, this, banner_min_size)); m_banner->Bind(wxEVT_RIGHT_DOWN, &InfoPanel::OnRightClickBanner, this); } else { m_banner->SetBitmap(WxUtils::LoadScaledResourceBitmap("nobanner", this, banner_min_size)); } }
ImageFrameDyn::ImageFrameDyn(wxWindow* parent, wxImage &imageScaled, wxImage &imageNoScaled, wxPoint point, wxSize size, int style) : wxFrame(parent, wxID_ANY, "", point, size, style) { cout << "ImageFrameDyn::ImageFrameDyn[0]" << endl; Model *model = new Model(); image0 = imageScaled.Copy(); imageZ = imageNoScaled.Copy(); model->isImageOK("ImageFrameDyn:image0", image0, true); model->isImageOK("ImageFrameDyn:imageZ", imageZ, true); // w = point.x; // h = point.y; win = parent; this->Show(); }
bool usImage::CopyFromImage(const wxImage& img) { Init(img.GetSize()); const unsigned char *pSrc = img.GetData(); unsigned short *pDest = ImageData; for (int i = 0; i < NPixels; i++) { *pDest++ = ((unsigned short) *pSrc) << 8; pSrc += 3; } return false; }
void PLOTTER::PlotImage(const wxImage & aImage, const wxPoint& aPos, double aScaleFactor ) { wxSize size( aImage.GetWidth() * aScaleFactor, aImage.GetHeight() * aScaleFactor ); wxPoint start = aPos; start.x -= size.x / 2; start.y -= size.y / 2; wxPoint end = start; end.x += size.x; end.y += size.y; Rect( start, end, NO_FILL ); }
wxImage FreeImage_Rescale(wxImage src, wxInt32 dst_width, wxInt32 dst_height, FREE_IMAGE_FILTER filter) { wxImage dst; if ((src.Ok()) && (dst_width > 0) && (dst_height > 0)) { dst.Create(dst_width, dst_height); // select the filter CGenericFilter *pFilter = NULL; switch(filter) { case FILTER_BOX: pFilter = new CBoxFilter(); break; case FILTER_BICUBIC: pFilter = new CBicubicFilter(); break; case FILTER_BILINEAR: pFilter = new CBilinearFilter(); break; case FILTER_BSPLINE: pFilter = new CBSplineFilter(); break; case FILTER_CATMULLROM: pFilter = new CCatmullRomFilter(); break; case FILTER_LANCZOS3: pFilter = new CLanczos3Filter(); break; } CResizeEngine Engine(pFilter); // perform upsampling or downsampling unsigned char *pSrc = src.GetData(); unsigned char *pDst = dst.GetData(); wxInt32 src_width = src.GetWidth(); wxInt32 src_height = src.GetHeight(); Engine.Scale(pSrc, src_width, src_height, pDst, dst_width, dst_height); delete pFilter; } return dst; }
void IsoLine::drawIsoLineLabels(GRIBOverlayFactory *pof, wxDC *dc, PlugIn_ViewPort *vp, int density, int first, wxImage &imageLabel) { std::list<Segment *>::iterator it; int nb = first; wxString label; //--------------------------------------------------------- // Ecrit les labels //--------------------------------------------------------- wxRect prev; for (it=trace.begin(); it!=trace.end(); it++,nb++) { if (nb % density == 0) { Segment *seg = *it; // if(vp->vpBBox.PointInBox((seg->px1 + seg->px2)/2., (seg->py1 + seg->py2)/2., 0.)) { wxPoint ab; GetCanvasPixLL(vp, &ab, seg->py1, seg->px1); wxPoint cd; GetCanvasPixLL(vp, &cd, seg->py1, seg->px1); int w = imageLabel.GetWidth(); int h = imageLabel.GetHeight(); int label_offset = 6; int xd = (ab.x + cd.x-(w+label_offset * 2))/2; int yd = (ab.y + cd.y - h)/2; int x = xd - label_offset; wxRect r(x ,yd ,w ,h); r.Inflate(w); if (!prev.Intersects(r)) { prev = r; /* don't use alpha for isobars, for some reason draw bitmap ignores the 4th argument (true or false has same result) */ wxImage img(w, h, imageLabel.GetData(), true); dc->DrawBitmap(img, xd, yd, false); } } } } }
/* static */ String XFace::ConvertImgToXFaceData(wxImage &img) { int l, n, i; int value; String dataString; String tmp; for(l = 0; l < 48; l++) { for(n = 0; n <= 32; n+= 16) { value = 0; for(i = 0; i < 16; i++) { if(img.GetRed(n+i,l) != 0) value += 1; if(i != 15) value <<= 1; } value = value ^ 0xffff; tmp.Printf(_T("0x%04lX"), (unsigned long)value); dataString += tmp; dataString += _T(','); } dataString += _T('\n'); } return dataString; }