コード例 #1
0
        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;
            }
        }
コード例 #2
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;
}
コード例 #3
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()
		}
	}
}
コード例 #4
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;
}
コード例 #5
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;
        }
    }
}
コード例 #6
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;
}
コード例 #7
0
ファイル: graphics.cpp プロジェクト: CodeTickler/wxWidgets
    void OnGLRender(wxPaintEvent& WXUNUSED(event))
    {
        m_glContext->SetCurrent(*m_glCanvas);
        glEnable(GL_TEXTURE_2D);

        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        wxPrintf("Benchmarking %s: ", "OpenGL images");
        fflush(stdout);

        wxStopWatch sw;
        for ( int n = 0; n < opts.numIters; n++ )
        {
            UpdateRGB(g_image.GetData(), n);

            glTexSubImage2D(GL_TEXTURE_2D, 0,
                            0, 0, opts.width, opts.height,
                            GL_RGB, GL_UNSIGNED_BYTE, g_image.GetData());
            glBegin(GL_QUADS);
                glTexCoord2f(0, 0);
                glVertex2f(-1.0, -1.0);

                glTexCoord2f(0, 1);
                glVertex2f(-1.0, 1.0);

                glTexCoord2f(1, 1);
                glVertex2f(1.0, 1.0);

                glTexCoord2f(1, 0);
                glVertex2f(1.0, -1.0);
            glEnd();

            m_glCanvas->SwapBuffers();
        }

        const long t = sw.Time();

        wxPrintf("%ld images done in %ldms = %gus/image or %ld FPS\n",
                 opts.numIters, t, (1000. * t)/opts.numIters,
                 (1000*opts.numIters + t - 1)/t);

        wxTheApp->ExitMainLoop();
    }
コード例 #8
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;
}
コード例 #9
0
ファイル: DrawGLUtils.cpp プロジェクト: rickcowan/xLights
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++;
        }
    }
}
コード例 #10
0
ファイル: SIPgSql.cpp プロジェクト: Nadot/wxWherbarium
wxString SIPgSql::wxStringFromWxImage(wxImage image) { // à valider en aller retour !!!
    map <string, string> paramsDic;
    SIPgSql& instancePgSql = SIPgSql::Instance(paramsDic);
    PGconn *pgConn = instancePgSql.getConn();
    wxString string0;
    char * usChar = (char*)image.GetData();
    size_t to_length;
    unsigned char *pgStr = PQescapeByteaConn(pgConn, (const unsigned char *)usChar, strlen(usChar), &to_length);
    string0 = wxString(pgStr);
    return string0;
}
コード例 #11
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());
}
コード例 #12
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;
}
コード例 #13
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;
}
コード例 #14
0
ファイル: usImage.cpp プロジェクト: xeqtr1982/phd2
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;
}
コード例 #15
0
ファイル: Resize.cpp プロジェクト: john-peterson/comical
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;

}
コード例 #16
0
ファイル: IsoLine.cpp プロジェクト: OpenCPN/OpenCPN
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);
                }
            }
        }
    }
}
コード例 #17
0
TestGLContext::TestGLContext(wxGLCanvas *canvas)
             : wxGLContext(canvas)
{
    SetCurrent(*canvas);

    // set up the parameters we want to use
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_TEXTURE_2D);

    // add slightly more light, the default lighting is rather dark
    GLfloat ambient[] = { 0.5, 0.5, 0.5, 0.5 };
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);

    // set viewing projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-0.5f, 0.5f, -0.5f, 0.5f, 1.0f, 3.0f);

    // create the textures to use for cube sides: they will be reused by all
    // canvases (which is probably not critical in the case of simple textures
    // we use here but could be really important for a real application where
    // each texture could take many megabytes)
    glGenTextures(WXSIZEOF(m_textures), m_textures);

    for ( unsigned i = 0; i < WXSIZEOF(m_textures); i++ )
    {
        glBindTexture(GL_TEXTURE_2D, m_textures[i]);

        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

        const wxImage img(DrawDice(256, i + 1));

        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.GetWidth(), img.GetHeight(),
                     0, GL_RGB, GL_UNSIGNED_BYTE, img.GetData());
    }

    CheckGLError();
}
コード例 #18
0
ファイル: image_tools.cpp プロジェクト: YY583456235/MinFFS
void zen::convertToVanillaImage(wxImage& img)
{
    if (!img.HasAlpha())
    {
        const int width  = img.GetWidth ();
        const int height = img.GetHeight();
        if (width <= 0 || height <= 0) return;

        unsigned char mask_r = 0;
        unsigned char mask_g = 0;
        unsigned char mask_b = 0;
        const bool haveMask = img.HasMask() && img.GetOrFindMaskColour(&mask_r, &mask_g, &mask_b);
        //check for mask before calling wxImage::GetOrFindMaskColour() to skip needlessly searching for new mask color

        img.SetAlpha();
        ::memset(img.GetAlpha(), wxIMAGE_ALPHA_OPAQUE, width * height);

        //wxWidgets, as always, tries to be more clever than it really is and f***s up wxStaticBitmap if wxBitmap is fully opaque:
        img.GetAlpha()[width * height - 1] = 254;

        if (haveMask)
        {
            img.SetMask(false);
            unsigned char*       alphaPtr = img.GetAlpha();
            const unsigned char* dataPtr  = img.GetData();

            const int pixelCount = width * height;
            for (int i = 0; i < pixelCount; ++ i)
            {
                const unsigned char r = *dataPtr++;
                const unsigned char g = *dataPtr++;
                const unsigned char b = *dataPtr++;

                if (r == mask_r &&
                    g == mask_g &&
                    b == mask_b)
                    alphaPtr[i] = wxIMAGE_ALPHA_TRANSPARENT;
            }
        }
    }
    else
    {
        assert(!img.HasMask());
    }
}
コード例 #19
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;
}
コード例 #20
0
ファイル: SVGCanvasImageCairo.cpp プロジェクト: KastB/OpenCPN
wxSVGCanvasImageCairoData::wxSVGCanvasImageCairoData(wxImage image) {
	m_count = 1;
	
	int bw = image.GetWidth();
	int bh = image.GetHeight();
	m_buffer = new unsigned char[bw*bh*4];
	wxUint32* data = (wxUint32*) m_buffer;
	
	// Create a surface object and copy the bitmap pixel data to it
	unsigned char* srcPix = image.GetData();
	if (image.HasAlpha()) { // alpha 
		m_surface = cairo_image_surface_create_for_data(m_buffer, CAIRO_FORMAT_ARGB32, bw, bh, bw*4);
		unsigned char* srcAlpha = image.GetAlpha();
		for (int y = 0; y < bh; y++) {
			for (int x = 0; x < bw; x++) {
				// Each pixel in CAIRO_FORMAT_ARGB32 is a 32-bit quantity, with alpha in the upper 8 bits,
				// then red, then green, then blue. The 32-bit quantities are stored native-endian.
				// Pre-multiplied alpha is used.
				unsigned char alpha = srcAlpha != NULL ? (*srcAlpha) : 255;
				if (alpha == 0)
					*data = 0;
				else
					*data = (alpha << 24 | (srcPix[0] * alpha / 255) << 16 | (srcPix[1] * alpha / 255) << 8
							| (srcPix[2] * alpha / 255));
				data++;
				srcPix += 3;
				if (srcAlpha)
					srcAlpha++;
			}
		}
	} else { // no alpha
		m_surface = cairo_image_surface_create_for_data(m_buffer, CAIRO_FORMAT_RGB24, bw, bh, bw * 4);
		for (int y = 0; y < bh; y++) {
			for (int x = 0; x < bw; x++) {
				// Each pixel in CAIRO_FORMAT_RGB24 is a 32-bit quantity, with the upper 8 bits unused.
				// Red, Green, and Blue are stored in the remaining 24 bits in that order.
				// The 32-bit quantities are stored native-endian.
				*data = (srcPix[0] << 16 | srcPix[1] << 8 | srcPix[2]);
				data++;
				srcPix += 3;
			}
		}
	}
}
コード例 #21
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++;
		}
	}
}
コード例 #22
0
ファイル: bitmap.cpp プロジェクト: EdgarTx/wx
// Creates a surface that will use wxImage's pixel data (RGB only)
static wxIDirectFBSurfacePtr CreateSurfaceForImage(const wxImage& image)
{
    wxCHECK_MSG( image.Ok(), NULL, _T("invalid image") );
    // FIXME_DFB: implement alpha handling by merging alpha buffer with RGB
    //            into a temporary RGBA surface
    wxCHECK_MSG( !image.HasAlpha(), NULL, _T("alpha channel not supported") );

    DFBSurfaceDescription desc;
    desc.flags = (DFBSurfaceDescriptionFlags)
        (DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT |
         DSDESC_PREALLOCATED);
    desc.caps = DSCAPS_NONE;
    desc.width = image.GetWidth();
    desc.height = image.GetHeight();
    desc.pixelformat = DSPF_RGB24;
    desc.preallocated[0].data = image.GetData();
    desc.preallocated[0].pitch = 3 * desc.width;

    return wxIDirectFB::Get()->CreateSurface(&desc);
}
コード例 #23
0
ファイル: Map.cpp プロジェクト: xsdj/MapTool
void Map::AssignImgData(ImgData *imgdata, wxImage &img)
{
    if(imgdata == NULL) return;

    if(img.IsOk())
    {
        unsigned char *pixdata, *alphadata;
        int width, height;
        long datasize;

        if(!img.HasAlpha()) img.SetAlpha();
        width = img.GetWidth();
        height = img.GetHeight();
        pixdata = img.GetData();
        alphadata = img.GetAlpha();
        datasize = (long) 4  * width * height;

        (*imgdata).width = (long)width;
        (*imgdata).height = (long)height;
        (*imgdata).data = (unsigned char*)malloc(datasize);
        if((*imgdata).data == NULL) return;

        int pi = 0, ai = 0;
        for(int di = 0; di < datasize;)
        {
            (*imgdata).data[di++] = pixdata[pi++];
            (*imgdata).data[di++] = pixdata[pi++];
            (*imgdata).data[di++] = pixdata[pi++];
            (*imgdata).data[di++] = alphadata[ai++];
        }
    }
    else
    {
        (*imgdata).width = 0;
        (*imgdata).height = 0;
        (*imgdata).data = NULL;
    }
}
コード例 #24
0
ファイル: wxalgos.cpp プロジェクト: re-curse/golly
bool MultiColorImage(wxImage& image)
{
    // return true if image contains at least one color that isn't a shade of gray
    int numpixels = image.GetWidth() * image.GetHeight();
    unsigned char* p = image.GetData();
    // p points to RGBRGB... (ie. no alpha data)
    for (int i = 0; i < numpixels; i++) {
        unsigned char r = *p++;
        unsigned char g = *p++;
        unsigned char b = *p++;
        if (r != g || g != b) {
            if (image.CountColours(2) <= 2) {
                // Golly 2.4 and older treated two-color icons as monochrome
                // so we need to convert the image to black-and-white
                image = image.ConvertToMono(r, g, b);
                return false;   // grayscale image
            } else {
                return true;    // multi-color image
            }
        }
    }
    return false;   // grayscale image
}
コード例 #25
0
ファイル: cursor.cpp プロジェクト: CobaltBlues/wxWidgets
void wxCursor::InitFromImage( const wxImage & image )
{
    const int w = image.GetWidth();
    const int h = image.GetHeight();
    const guchar* alpha = image.GetAlpha();
    const bool hasMask = image.HasMask();
    int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
    int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
    if (hotSpotX < 0 || hotSpotX > w) hotSpotX = 0;
    if (hotSpotY < 0 || hotSpotY > h) hotSpotY = 0;
    GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image.GetData(), GDK_COLORSPACE_RGB, false, 8, w, h, w * 3, NULL, NULL);
    if (alpha || hasMask)
    {
        guchar r = 0, g = 0, b = 0;
        if (hasMask)
        {
            r = image.GetMaskRed();
            g = image.GetMaskGreen();
            b = image.GetMaskBlue();
        }
        GdkPixbuf* pixbuf0 = pixbuf;
        pixbuf = gdk_pixbuf_add_alpha(pixbuf, hasMask, r, g, b);
        g_object_unref(pixbuf0);
        if (alpha)
        {
            guchar* d = gdk_pixbuf_get_pixels(pixbuf);
            const int stride = gdk_pixbuf_get_rowstride(pixbuf);
            for (int j = 0; j < h; j++, d += stride)
                for (int i = 0; i < w; i++, alpha++)
                    if (d[4 * i + 3])
                        d[4 * i + 3] = *alpha;
        }
    }
    m_refData = new wxCursorRefData;
    M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(wxGetRootWindow()), pixbuf, hotSpotX, hotSpotY);
    g_object_unref(pixbuf);
}
コード例 #26
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++;
		}
	}
}
コード例 #27
0
ファイル: wxcms.cpp プロジェクト: ndevenish/Hugin
        void CorrectImage(wxImage& image, const vigra::ImageImportInfo::ICCProfile& iccProfile, const cmsHPROFILE& monitorProfile)
        {
            cmsHPROFILE inputICC = NULL;
            if (!iccProfile.empty())
            {
                inputICC = cmsOpenProfileFromMem(iccProfile.data(), iccProfile.size());
            };
            // check type of input profile
            if (inputICC != NULL)
            {
                if (cmsGetColorSpace(inputICC) != cmsSigRgbData)
                {
                    cmsCloseProfile(inputICC);
                    inputICC = NULL;
                };
            };
            // if there is no icc profile in file fall back to sRGB
            if (inputICC == NULL)
            {
                inputICC = cmsCreate_sRGBProfile();
            };
            // now build transform
            cmsHTRANSFORM transform = cmsCreateTransform(inputICC, TYPE_RGB_8,
                monitorProfile, TYPE_RGB_8,
                INTENT_PERCEPTUAL, cmsFLAGS_BLACKPOINTCOMPENSATION);
            unsigned char* imgData = image.GetData();
            const int imgWidth = image.GetWidth();
            const int imgHeight = image.GetHeight();
#pragma omp parallel for
            for (int y = 0; y < imgHeight; ++y)
            {
                cmsDoTransform(transform, imgData + 3 * y * imgWidth, imgData + 3 * y * imgWidth, imgWidth);
            };
            cmsDeleteTransform(transform);
            cmsCloseProfile(inputICC);
        };
コード例 #28
0
ファイル: dib.cpp プロジェクト: BloodRedd/gamekit
bool wxDIB::Create(const wxImage& image)
{
    wxCHECK_MSG( image.Ok(), false, wxT("invalid wxImage in wxDIB ctor") );

    const int h = image.GetHeight();
    const int w = image.GetWidth();

    // if we have alpha channel, we need to create a 32bpp RGBA DIB, otherwise
    // a 24bpp RGB is sufficient
    m_hasAlpha = image.HasAlpha();
    const int bpp = m_hasAlpha ? 32 : 24;

    if ( !Create(w, h, bpp) )
        return false;

    // DIBs are stored in bottom to top order (see also the comment above in
    // Create()) so we need to copy bits line by line and starting from the end
    const int srcBytesPerLine = w * 3;
    const int dstBytesPerLine = GetLineSize(w, bpp);
    const unsigned char *src = image.GetData() + ((h - 1) * srcBytesPerLine);
    const unsigned char *alpha = m_hasAlpha ? image.GetAlpha() + (h - 1)*w
                                            : NULL;
    unsigned char *dstLineStart = (unsigned char *)m_data;
    for ( int y = 0; y < h; y++ )
    {
        // copy one DIB line
        unsigned char *dst = dstLineStart;
        if ( alpha )
        {
            for ( int x = 0; x < w; x++ )
            {
                // RGB order is reversed, and we need to premultiply
                // all channels by alpha value for use with ::AlphaBlend.
                const unsigned char a = *alpha++;
                *dst++ = (unsigned char)((src[2] * a + 127) / 255);
                *dst++ = (unsigned char)((src[1] * a + 127) / 255);
                *dst++ = (unsigned char)((src[0] * a + 127) / 255);
                *dst++ = a;
                src += 3;
            }
        }
        else // no alpha channel
        {
            for ( int x = 0; x < w; x++ )
            {
                // RGB order is reversed.
                *dst++ = src[2];
                *dst++ = src[1];
                *dst++ = src[0];
                src += 3;
            }
        }

        // pass to the previous line in the image
        src -= 2*srcBytesPerLine;
        if ( alpha )
            alpha -= 2*w;

        // and to the next one in the DIB
        dstLineStart += dstBytesPerLine;
    }

    return true;
}
コード例 #29
0
ファイル: utilsx11.cpp プロジェクト: Zombiebest/Dolphin
void
wxSetIconsX11(WXDisplay* display, WXWindow window, const wxIconBundle& ib)
{
    size_t size = 0;

    const size_t numIcons = ib.GetIconCount();
    for ( size_t i = 0; i < numIcons; ++i )
    {
        const wxIcon icon = ib.GetIconByIndex(i);

        size += 2 + icon.GetWidth() * icon.GetHeight();
    }

    wxMAKE_ATOM(_NET_WM_ICON, (Display*)display);

    if ( size > 0 )
    {
        unsigned long* data = new unsigned long[size];
        unsigned long* ptr = data;

        for ( size_t i = 0; i < numIcons; ++i )
        {
            const wxImage image = ib.GetIconByIndex(i).ConvertToImage();
            int width = image.GetWidth(),
                height = image.GetHeight();
            unsigned char* imageData = image.GetData();
            unsigned char* imageDataEnd = imageData + ( width * height * 3 );
            bool hasMask = image.HasMask();
            unsigned char rMask, gMask, bMask;
            unsigned char r, g, b, a;

            if( hasMask )
            {
                rMask = image.GetMaskRed();
                gMask = image.GetMaskGreen();
                bMask = image.GetMaskBlue();
            }
            else // no mask, but still init the variables to avoid warnings
            {
                rMask =
                gMask =
                bMask = 0;
            }

            *ptr++ = width;
            *ptr++ = height;

            while ( imageData < imageDataEnd )
            {
                r = imageData[0];
                g = imageData[1];
                b = imageData[2];
                if( hasMask && r == rMask && g == gMask && b == bMask )
                    a = 0;
                else
                    a = 255;

                *ptr++ = ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b;

                imageData += 3;
            }
        }

        XChangeProperty( (Display*)display,
                         WindowCast(window),
                         _NET_WM_ICON,
                         XA_CARDINAL, 32,
                         PropModeReplace,
                         (unsigned char*)data, size );
        delete[] data;
    }
    else
    {
        XDeleteProperty( (Display*)display,
                         WindowCast(window),
                         _NET_WM_ICON );
    }
}
コード例 #30
0
bool MyVideoCaptureWindow::OnProcessFrame(wxImage& wximg)
{
    // This function is only called with a valid wxImage, but for this sample we'll verify that.
    wxCHECK_MSG(wximg.IsOk(), false, wxT("Invalid image to process"));

    bool refresh = true; // return value
    int i, j, jj;
    const int width        = wximg.GetWidth();
    const int height       = wximg.GetHeight();
    const int width_x3     = width*3;
    const int imgdata_size = width*height*3;
    unsigned char *imgdata = wximg.GetData();

    static wxImage lastimage(width, height); // for motion detector

    // Invert the image - negative
    if (m_frame->m_processMenu->IsChecked(ID_IMGPROCESS_NEGATIVE))
    {
        for (i = 0; i < imgdata_size; ++i) imgdata[i] = 255 - imgdata[i];
    }

    // Very basic edge detector
    if (m_frame->m_processMenu->IsChecked(ID_IMGPROCESS_EDGE))
    {
        unsigned char *imgrow = new unsigned char[width_x3];

        if (imgrow)
        {
            unsigned char *rowptr = wximg.GetData();

            for (j = 0; j < height; ++j)
            {
                int jj = j*width_x3;
                memcpy(imgrow, rowptr, width_x3);

                for (i = 3; i < width_x3; i += 3)
                {
                    imgdata[i   + jj] = abs((int)imgrow[i  ] - imgrow[i-3])*4;
                    imgdata[i+1 + jj] = abs((int)imgrow[i+1] - imgrow[i-2])*4;
                    imgdata[i+2 + jj] = abs((int)imgrow[i+2] - imgrow[i-1])*4;
                }

                rowptr += width_x3;
            }

            delete []imgrow;
        }
    }

    // Very basic motion detector,
    //    tweak pixel_threshold, pixels_changed_threshold
    if (m_frame->m_processMenu->IsChecked(ID_IMGPROCESS_MOTION))
    {
        // is the last image still good?
        if (!lastimage.Ok() ||
            (lastimage.GetWidth()  != width) ||
            (lastimage.GetHeight() != height))
        {
            lastimage.Create(width,height);
        }

        unsigned char *lastdata = lastimage.GetData();

        int pixel_threshold          = 64; // each pixel checked has to differ by this
        int pixels_changed_threshold = 10; // this many pixels must change

        int pixels_changed = 0; // # of pixels changed by threshold

        int skip_rows = 3;      // horiz rows to skip
        int skip_cols = 13;     // vert cols to skip

        for (j = 0; j < height; j += skip_rows)
        {
            jj = j*width_x3;

            for (i = 0; i < width_x3; i += skip_cols)
            {
                if(abs((int)imgdata[i+jj] - lastdata[i+jj]) > pixel_threshold)
                    pixels_changed++;
            }
        }

        if (pixels_changed < pixels_changed_threshold) refresh = false;

        memcpy(lastdata, imgdata, sizeof(unsigned char)*imgdata_size);
    }

    return refresh;
}