コード例 #1
0
void ImageDrawSelectionField(wxImage& img, int x, int y, int width, int height, unsigned char red, unsigned char green, unsigned char blue) {
	unsigned char* rawdata = img.GetData();
	unsigned char* rawalpha = img.GetAlpha();
	int thick = min(width,height)/100+1;
	int i,j,posx,posy;
	#define MACRO_SETPIXELCOLOR() \
		rawdata[3*(posx+posy)] = red; \
		rawdata[3*(posx+posy)+1] = green; \
		rawdata[3*(posx+posy)+2] = blue; \
		rawalpha[posx+posy] = 0xFF;
	width--;
	height--;
	for (i=0;i<=width;i++) {
		posx = (x+i)%img.GetWidth();
		for (j=0;j<thick;j++) {
			posy = ((y+j)%img.GetHeight())*img.GetWidth();
			MACRO_SETPIXELCOLOR()
			posy = ((y+height-j)%img.GetHeight())*img.GetWidth();
			MACRO_SETPIXELCOLOR()
		}
	}
	for (i=0;i<=height;i++) {
		posy = (y+i)%img.GetHeight()*img.GetWidth();
		for (j=0;j<thick;j++) {
			posx = (x+j)%img.GetWidth();
			MACRO_SETPIXELCOLOR()
			posx = (x+width-j)%img.GetWidth();
			MACRO_SETPIXELCOLOR()
		}
	}
}
コード例 #2
0
ファイル: image_tools.cpp プロジェクト: YY583456235/MinFFS
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;
}
コード例 #3
0
ファイル: ImageRoll.cpp プロジェクト: andreipaga/audacity
void ImageRoll::Init(RollType type, const wxImage &src, wxColour magicColor)
{
   ImageArray images;
   int i;

   mType = type;

   switch(mType) {
   case HorizontalRoll:
      images = SplitH(src, magicColor);

      mMinSize.x = 0;
      mMinSize.y = src.GetHeight();
      mMaxSize.x = 9999;
      mMaxSize.y = src.GetHeight();

      for(i=0; i<(int)images.GetCount(); i++) {
         if (images[i].Ok()) {
            mPieces.Add(wxBitmap(images[i]));
            mMinSize.x += mPieces[i].GetWidth();
         }
         else
            mPieces.Add(wxBitmap());
      }
      break;

   case VerticalRoll:
      images = SplitV(src, magicColor);

      mMinSize.x = src.GetWidth();
      mMinSize.y = 0;
      mMaxSize.x = src.GetWidth();
      mMaxSize.y = 9999;

      for(i=0; i<(int)images.GetCount(); i++) {
         if (images[i].Ok()) {
            mPieces.Add(wxBitmap(images[i]));
            mMinSize.y += mPieces[i].GetHeight();
         }
         else
            mPieces.Add(wxBitmap());
      }
      break;

   case FixedImage:
      mPieces.Add(wxBitmap(src));
      mMinSize.x = src.GetWidth();
      mMinSize.y = src.GetHeight();
      mMaxSize.x = src.GetWidth();
      mMaxSize.y = src.GetHeight();
      break;

   } // switch
}
コード例 #4
0
// Suggestion by Carlos Moreno
wxImage wxAntiAlias2(const wxImage& image)
{
    wxImage anti(image.GetWidth(), image.GetHeight());

  /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */

  for (int y = 1; y < image.GetHeight() - 1; y++)
    for (int x = 1; x < image.GetWidth() - 1; x++)
    {
       long red =
            ((int) image.GetRed( x-1, y-1 )) * 1 +
            ((int) image.GetRed( x, y-1 )) * 4 +
            ((int) image.GetRed( x+1, y-1 )) * 1 +
            ((int) image.GetRed( x+1, y )) * 4 +
            ((int) image.GetRed( x+1, y+1 )) * 1 +
            ((int) image.GetRed( x, y+1 )) * 4 +
            ((int) image.GetRed( x-1, y+1 )) * 1 +
            ((int) image.GetRed( x-1, y )) * 4 +
            ((int) image.GetRed( x, y )) * 20 ;

       red = red/40;

       long green =
            ((int) image.GetGreen( x-1, y-1 )) * 1 +
            ((int) image.GetGreen( x, y-1 )) * 4 +
            ((int) image.GetGreen( x+1, y-1 )) * 1 +
            ((int) image.GetGreen( x+1, y )) * 4 +
            ((int) image.GetGreen( x+1, y+1 )) * 1 +
            ((int) image.GetGreen( x, y+1 )) * 4 +
            ((int) image.GetGreen( x-1, y+1 )) * 1 +
            ((int) image.GetGreen( x-1, y )) * 4 +
            ((int) image.GetGreen( x, y )) * 20 ;

       green = green/40;

       long blue =
            ((int) image.GetBlue( x-1, y-1 )) * 1 +
            ((int) image.GetBlue( x, y-1 )) * 4 +
            ((int) image.GetBlue( x+1, y-1 )) * 1 +
            ((int) image.GetBlue( x+1, y )) * 4 +
            ((int) image.GetBlue( x+1, y+1 )) * 1 +
            ((int) image.GetBlue( x, y+1 )) * 4 +
            ((int) image.GetBlue( x-1, y+1 )) * 1 +
            ((int) image.GetBlue( x-1, y )) * 4 +
            ((int) image.GetBlue( x, y )) * 20 ;

       blue = blue/40;

       anti.SetRGB( x, y, (wxChar) red, (wxChar) green, (wxChar) blue );
    }
    return anti;
}
コード例 #5
0
ファイル: uiutils.cpp プロジェクト: Mailaender/springlobby
/**
 @brief Blends two images based on alpha channel present in foreground image.
 @param foreground Foreground image, must have an alpha channel
 @param background Background image, may have an alpha channel
 @param blend_alpha Whether the returned image will have an alpha channel.
 @return A copy of the background image with the foreground image blended on
 top of it. The returned image will have an alpha channel iff the background
 image has an alpha channel. In that case the alpha channel is blended
 identical to the red/green/blue channels.
*/
wxImage BlendImage( const wxImage& foreground, const wxImage& background, bool blend_alpha )
{
    if ( ( foreground.GetWidth()  != background.GetWidth() ) || ( background.GetHeight() != foreground.GetHeight() ) )
    {
        wxLogDebugFunc(_T("size mismatch while blending"));
        return background;
    }

    bool zhu = blend_alpha && background.HasAlpha();
    if ( foreground.HasAlpha() )
    {
        wxImage ret( background.GetWidth(), foreground.GetHeight() );
        const unsigned char* background_data = background.GetData();
        const unsigned char* foreground_data = foreground.GetData();
        const unsigned char* background_alpha = NULL;
        const unsigned char* foreground_alpha = foreground.GetAlpha();
        unsigned char* result_data = ret.GetData();
        unsigned char* result_alpha = NULL;
        unsigned int pixel_count = background.GetWidth() * background.GetHeight();

        if ( zhu )
        {
          background_alpha = background.GetAlpha();
          ret.InitAlpha();
          result_alpha = ret.GetAlpha();
        }

        for ( unsigned int i = 0, i_a = 0; i < pixel_count * 3; i+=3,  i_a++ )
        {
            unsigned char fore_alpha = foreground_alpha[i_a] ;
            float back_blend_fac = ( 255 - fore_alpha)/255.0;
            float fore_blend_fac = fore_alpha/255.0 ;

            result_data[i]    = foreground_data[i]   * fore_blend_fac + background_data[i]   * back_blend_fac ;
            result_data[i+1]  = foreground_data[i+1] * fore_blend_fac + background_data[i+1] * back_blend_fac ;
            result_data[i+2]  = foreground_data[i+2] * fore_blend_fac + background_data[i+2] * back_blend_fac ;

            if ( zhu )
            {
              unsigned char back_alpha = background_alpha[i_a] ;
              result_alpha[i_a] = fore_alpha           * fore_blend_fac + back_alpha           * back_blend_fac ;
            }
        }
        return ret;
    }
    wxLogDebugFunc(_T("cannot blend without alpha"));
    return background;
}
コード例 #6
0
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 );
}
コード例 #7
0
ファイル: m_image.cpp プロジェクト: beanhome/dev
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
}
コード例 #8
0
ファイル: insticonlist.cpp プロジェクト: sharkman/MultiMC4
wxImage tintImage( wxImage to_colorize, wxColour col)
{
	wxImage highlightIcon(to_colorize.GetWidth(),to_colorize.GetHeight());
	bool do_alpha = false;
	if(to_colorize.HasAlpha())
	{
		highlightIcon.InitAlpha();
		do_alpha = true;
	}
	else if(to_colorize.HasMask())
	{
		highlightIcon.SetMaskFromImage(to_colorize,to_colorize.GetMaskRed(),to_colorize.GetMaskGreen(),to_colorize.GetMaskBlue());
	}
	for(int x = 0; x < highlightIcon.GetWidth(); x++)
	{
		for(int y = 0; y < highlightIcon.GetHeight(); y++)
		{
			to_colorize.GetData();
			unsigned char srcR = to_colorize.GetRed(x,y);
			unsigned char srcG = to_colorize.GetGreen(x,y);
			unsigned char srcB = to_colorize.GetBlue(x,y);
			highlightIcon.SetRGB(x,y,(srcR + col.Red())/2,(srcG + col.Green())/2, (srcB + col.Blue())/2);
			if(do_alpha)
				highlightIcon.SetAlpha(x,y,to_colorize.GetAlpha(x,y));
		}
	}
	return highlightIcon;
}
コード例 #9
0
ファイル: RenderableEffect.cpp プロジェクト: Jchuchla/xLights
void AdjustAndSetBitmap(int size, wxImage &image, wxImage &dbl, wxBitmap&bitmap) {
#ifdef __WXOSX__
    if (dbl.GetHeight() == (2 * size)) {
        bitmap = wxBitmap(dbl, -1, 2.0);
    } else if (dbl.GetHeight() > (2*size)) {
        wxImage scaled = image.Scale(size*2, size*2, wxIMAGE_QUALITY_HIGH);
        bitmap = wxBitmap(scaled, -1, 2.0);
    } else
#endif
    if (image.GetHeight() == size) {
        bitmap = wxBitmap(image);
    } else {
        wxImage scaled = image.Scale(size, size, wxIMAGE_QUALITY_HIGH);
        bitmap = wxBitmap(scaled);
    }
}
コード例 #10
0
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 );
}
コード例 #11
0
ファイル: pseudodc.cpp プロジェクト: goretkin/kwc-ros-pkg
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;
        }
    }
}
コード例 #12
0
ファイル: bitmap.cpp プロジェクト: gitrider/wxsj2
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);
    }
}
コード例 #13
0
/// Gets a rectangle from within another image, INCLUDING the alpha channel
/// \bug in wxWidgets, wxImage::GetSubImage should do this itself.
wxImage GetSubImageWithAlpha( const wxImage & Src,  const wxRect &rect )
{
   //First part of this code is lifted from wxImage::GetSubImage() source code.
   wxImage image;

   wxCHECK_MSG( Src.Ok(), image, wxT("invalid image") );

   wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (
      rect.GetRight()<=Src.GetWidth()) && (rect.GetBottom()<=Src.GetHeight()),
      image, wxT("invalid subimage size") );

   int subwidth=rect.GetWidth();
   const int subheight=rect.GetHeight();

   image.Create( subwidth, subheight, false );

   unsigned char *subdata = image.GetData(), *data=Src.GetData();

   wxCHECK_MSG( subdata, image, wxT("unable to create image") );

   // JKC: Quick hack - don't deal with masks - need to understand macro M_IMGDATA first.
//   if (Src.M_IMGDATA->m_hasMask)
//      image.SetMaskColour( Src.M_IMGDATA->m_maskRed, Src.M_IMGDATA->m_maskGreen, Src.M_IMGDATA->m_maskBlue );

   int subleft=3*rect.GetLeft();
   int width=3*Src.GetWidth();
   subwidth*=3;

   data+=rect.GetTop()*width+subleft;

   for (long j = 0; j < subheight; ++j)
   {
      memcpy( subdata, data, subwidth);
      subdata+=subwidth;
      data+=width;
   }

   // OK, so we've copied the RGB data.
   // Now do the Alpha channel.
   wxASSERT( Src.HasAlpha() );
   image.InitAlpha();

   subleft/=3;
   width/=3;
   subwidth/=3;

   data =Src.GetAlpha();
   subdata =image.GetAlpha();

   data+=rect.GetTop()*width+subleft;

   for (long j = 0; j < subheight; ++j)
   {
      memcpy( subdata, data, subwidth);
      subdata+=subwidth;
      data+=width;
   }
   return image;
}
コード例 #14
0
ファイル: RenderableEffect.cpp プロジェクト: Jchuchla/xLights
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);
    }
}
コード例 #15
0
QImage wxQtConvertImage( const wxImage &image )
{
	bool hasAlpha = image.HasAlpha();
	bool hasMask = image.HasMask();
	wxSize size ( image.GetWidth(), image.GetHeight() );
	QImage qtImage( wxQtConvertSize( size ),
				   ( (hasAlpha || hasMask ) ? QImage::Format_ARGB32 : QImage::Format_RGB32 ) );

	unsigned char *data = image.GetData();
	unsigned char *alpha = hasAlpha ? image.GetAlpha() : NULL;
	QRgb colour;

	QRgb maskedColour;
	if ( hasMask )
	{
		unsigned char r, g, b;
		image.GetOrFindMaskColour( &r, &g, &b );
		maskedColour = ( r << 16 ) + ( g << 8 ) + b;
	}

	for (int y = 0; y < image.GetHeight(); y++)
	{
		for (int x = 0; x < image.GetWidth(); x++)
		{
			if (hasAlpha)
			{
				colour = alpha[0] << 24;
				alpha++;
			}
			else
				colour = 0;

			colour += (data[0] << 16) + (data[1] << 8) + data[2];

			if ( hasMask && colour != maskedColour )
				colour += 0xFF000000; // 255 << 24

			qtImage.setPixel(x, y, colour);

			data += 3;
		}
	}
	return qtImage;
}
コード例 #16
0
ファイル: OpenCVHelper.cpp プロジェクト: SimFaris/Regard3D
void OpenCVHelper::convertWxImageToCVMat(const wxImage &img, cv::Mat &cvimg)
{
	cvimg.create(img.GetHeight(), img.GetWidth(), CV_8UC3);
	cv::Vec3b *cvPtr = cvimg.ptr<cv::Vec3b>(0);
	unsigned char *wxPtr = img.GetData();
	for(int y = 0; y < img.GetHeight(); y++)
	{
		for(int x = 0; x < img.GetWidth(); x++)
		{
/*			img_cv.at<cv::Vec3b>(y, x)[2] = localPreviewImage.GetRed(x, y);
			img_cv.at<cv::Vec3b>(y, x)[1] = localPreviewImage.GetGreen(x, y);
			img_cv.at<cv::Vec3b>(y, x)[0] = localPreviewImage.GetBlue(x, y);*/
			(*cvPtr)[2] = *(wxPtr++);	// OpenCV usually stores BGR, not RGB
			(*cvPtr)[1] = *(wxPtr++);
			(*cvPtr)[0] = *(wxPtr++);
			cvPtr++;
		}
	}
}
コード例 #17
0
ファイル: ImageRoll.cpp プロジェクト: andreipaga/audacity
// 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;
}
コード例 #18
0
ファイル: doc.cpp プロジェクト: KnowNo/test-code-backup
ImageDetailsDocument::ImageDetailsDocument(ImageDocument *parent)
    : wxDocument(parent)
{
    const wxImage image = parent->GetImage();

    m_size.x = image.GetWidth();
    m_size.y = image.GetHeight();
    m_numColours = image.CountColours();
    m_type = image.GetType();
    m_hasAlpha = image.HasAlpha();
}
コード例 #19
0
wxImage wxAntiAlias(const wxImage& image)
{
    wxImage anti(image.GetWidth(), image.GetHeight());
	
	/* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
	
	for (int y = 0; y < image.GetHeight(); y++)
	{
		for (int x = 0; x < image.GetWidth(); x++)
		{
			if (y == 0 || x == 0 ||
				x == (image.GetWidth() - 1) ||
				y == (image.GetHeight() - 1))
			{
				anti.SetRGB(x, y, image.GetRed(x, y), image.GetGreen(x, y), image.GetBlue(x, y));
			}
			else
			{
				int red = (int) image.GetRed( x, y ) +
					(int) image.GetRed( x-1, y ) +
					(int) image.GetRed( x, y+1 ) +
					(int) image.GetRed( x+1, y+1 );
				red = red/4;
				
				int green = (int) image.GetGreen( x, y ) +
					(int) image.GetGreen( x-1, y ) +
					(int) image.GetGreen( x, y+1 ) +
					(int) image.GetGreen( x+1, y+1 );
				green = green/4;
				
				int blue = (int) image.GetBlue( x, y ) +
					(int) image.GetBlue( x-1, y ) +
					(int) image.GetBlue( x, y+1 ) +
					(int) image.GetBlue( x+1, y+1 );
				blue = blue/4;
				anti.SetRGB( x, y, red, green, blue );
			}
		}
	}
	return anti;
}
コード例 #20
0
ファイル: graphics.cpp プロジェクト: CodeTickler/wxWidgets
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());
}
コード例 #21
0
void GOrgueBitmap::ScaleBMP(wxImage& img, double scale, const wxRect& rect, GOrgueBitmap* background)
{
	if (background && img.HasAlpha())
	{
		wxBitmap bmp(img.GetWidth(), img.GetHeight());
		wxBitmap orig(img);
		wxMemoryDC dc;

		dc.SelectObject(bmp);
		dc.DrawBitmap(background->GetBitmap(), -rect.GetX(), -rect.GetY(), false);
		dc.DrawBitmap(orig, 0, 0, true);
		bmp.SetMask(orig.GetMask());
		wxImage img_result = bmp.ConvertToImage();
		img_result.InitAlpha();
		memcpy(img_result.GetAlpha(), img.GetAlpha(), img.GetWidth() * img.GetHeight());

		m_bmp = (wxBitmap)img_result.Scale(img.GetWidth() * scale, img.GetHeight() * scale, wxIMAGE_QUALITY_BICUBIC);
	}
	else
		m_bmp = (wxBitmap)img.Scale(img.GetWidth() * scale, img.GetHeight() * scale, wxIMAGE_QUALITY_BICUBIC);
	m_Scale = scale;
}
コード例 #22
0
ファイル: insticonlist.cpp プロジェクト: sharkman/MultiMC4
bool InstIconList::Add(const wxImage image, const wxImage hlimage, const wxImage image128, const wxString key, const wxString name,
	const wxString filename)
{
	InstIcon *defIcon = nullptr;
	if (iconMap.count(key) > 0)
	{
		defIcon = new InstIcon(iconMap[key]);
	}
	wxImage newbig = image128;
	if(image128.GetWidth() != 128 || image128.GetHeight() != 128)
	{
		newbig.Rescale(128,128);
	}
	
	if (image.GetWidth() != 32 || image.GetHeight() != 32)
	{
		wxImage newImg(image);
		wxImage newHLImg(hlimage);
		newImg.Rescale(32, 32);
		newHLImg.Rescale(32, 32);
#ifdef DEBUG_ICONS
		if(!newImg.HasAlpha())
		{
			wxLogMessage(_("Image %s has no alpha after rescaling."), key.c_str()  );
		}
#endif

		InstIcon newInstIcon(key, name, newImg, newHLImg, newbig, filename, defIcon);
		newInstIcon.deleteDefIconOnDestroy = false;
		iconMap[key] = newInstIcon;
	}
	else
	{
		InstIcon newInstIcon(key, name, image, hlimage, newbig, filename, defIcon);
		newInstIcon.deleteDefIconOnDestroy = false;
		iconMap[key] = newInstIcon;
	}
	return true;
}
コード例 #23
0
ファイル: Ocr.cpp プロジェクト: smallduckinette/medoc
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;
}
コード例 #24
0
wxBitmap gcThemeManager::getSprite(wxImage& img, const char* spriteId, const char* spriteName)
{
	SpriteRectI* rect = getSpriteRect(spriteId, spriteName);

	if (!rect || !img.IsOk())
		return wxBitmap();

	int w = rect->getW();
	int h = rect->getH();
	int x = rect->getX();
	int y = rect->getY();

	if (w < 0)
		w = img.GetWidth();

	if (h < 0)
		h =	img.GetHeight();

	if (w > img.GetWidth())
		w = img.GetWidth();

	if (h > img.GetHeight())
		h =	img.GetHeight();

	if (x < 0)
		x = 0;

	if (x > img.GetWidth() - w)
		x = 0;

	if (y < 0)
		y = 0;

	if (y > img.GetHeight() - h)
		y = 0;

	return wxBitmap( img.GetSubImage( wxRect(x,y,w,h) ) );
}
コード例 #25
0
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;
}
コード例 #26
0
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 );
        }
}
コード例 #27
0
ファイル: wxImage.cpp プロジェクト: Hanmac/rwx
bool check_equal(const wxImage &self, const wxImage &cother)
{
	if(self.GetHeight() != cother.GetHeight()){
		return false;
	}
	if(self.GetWidth() != cother.GetWidth()) {
		return false;
	}
	if(strcmp((char*)self.GetData(), (char*)cother.GetData()) != 0){
		return false;
	}
	if(self.HasAlpha()) {
		if(!cother.HasAlpha())
			return false;
		if(strcmp((char*)self.GetAlpha(), (char*)cother.GetAlpha()) != 0){
			return false;
		}
	} else {
		return !cother.HasAlpha();
	}

	return true;
}
コード例 #28
0
ファイル: OpenCVHelper.cpp プロジェクト: SimFaris/Regard3D
void OpenCVHelper::convertCVMatToWxImage(const cv::Mat &cvimg, wxImage &img)
{
	if(!img.IsOk()
		|| img.GetWidth() != cvimg.cols
		|| img.GetHeight() != cvimg.rows)
	{
		img.Create(cvimg.cols, cvimg.rows, false);
	}
	const cv::Vec3b *cvPtr = cvimg.ptr<cv::Vec3b>(0);
	unsigned char *wxPtr = img.GetData();
	for(int y = 0; y < img.GetHeight(); y++)
	{
		for(int x = 0; x < img.GetWidth(); x++)
		{
/*			localPreviewImage.SetRGB(x, y, img_outcv.at<cv::Vec3b>(y, x)[2],
				img_outcv.at<cv::Vec3b>(y, x)[1],
				img_outcv.at<cv::Vec3b>(y, x)[0]);*/
			*(wxPtr++) = (*cvPtr)[2];
			*(wxPtr++) = (*cvPtr)[1];
			*(wxPtr++) = (*cvPtr)[0];
			cvPtr++;
		}
	}
}
コード例 #29
0
ファイル: PianoEffect.cpp プロジェクト: rickcowan/xLights
//all shapes are loaded from same image file to reduce file I/O and caching
//thiss also allows animated images to be self-contained
void PianoRenderCache::Piano_load_shapes(RenderBuffer &buffer, const wxString& filename)
{
    debug_function(10); //Debug debug("load_shapes('%s')", (const char*)filename.c_str());
    debug(1, "load shapes file '%s'", (const char*)filename.c_str());
    //reload shapes even if file name hasn't changed; color map might be different now
    //    if (!CachedShapeFilename.CmpNoCase(filename)) { debug_more(2, ", no change"); return; } //no change
    if (!wxFileExists(filename)) return;
    Piano_flush_shapes(); //invalidate cached data
    if (!Shapes.LoadFile(filename, wxBITMAP_TYPE_ANY, 0) || !Shapes.IsOk())
    {
        //wxMessageBox("Error loading image file: "+NewPictureName);
        Shapes.Clear();
        return;
    }
    
    if (buffer.GetColorCount() < 2) return; //use colors from shapes file if no user-selected colors
    //    int imgwidth=image.GetWidth();
    //    int imght   =image.GetHeight();
    //    std::hash_map<WXCOLORREF, int> palcounts;
    //TODO: use wxImage.GetData for better performance?
    //TODO: use multiple images within same file?
    for (int y = Shapes.GetHeight() - 1; y >= 0; --y) //bottom->top
        for (int x = 0; x < Shapes.GetWidth(); ++x) //left->right
            if (!Shapes.IsTransparent(x, y))
            {
                xlColor color, mapped;
                color.Set(Shapes.GetRed(x, y), Shapes.GetGreen(x, y), Shapes.GetBlue(x, y));
                if (ColorMap.find(color.GetRGB()) != ColorMap.end()) continue; //already saw this color
                buffer.palette.GetColor(ColorMap.size() % buffer.GetColorCount(), mapped); //assign user-selected colors to shape palette sequentially, loop if run out of colors
                debug(10, "shape color[%d] 0x%x => user-selected color [%d] 0x%x", ColorMap.size(), color.GetRGB(), ColorMap.size() % GetColorCount(), mapped.GetRGB());
                ColorMap[color.GetRGB()] = mapped; //.GetRGB();
                //                ShapePalette.push_back(c.GetRGB()); //keep a list of unique colors in order of occurrence from origin L-R, B-T
            }
    debug(2, "w %d, h %d, #colors %d", Shapes.GetWidth(), Shapes.GetHeight(), ColorMap.size());
    CachedShapeFilename = filename; //don't load same file again
}
コード例 #30
0
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 );
}