Exemple #1
0
		Pixmap::Pixmap(const Pixmap& other)
		{
			m_width= other.width();
			m_height = other.height();
			m_depth = other.depth();
			m_bitmap = new U8[m_width * m_height * m_depth];
			memcpy(m_bitmap, other.const_data(), m_width * m_height * m_depth);
		}
Exemple #2
0
Icon::Icon(const Pixmap &pm, SpritesHolder &h) : normal(h.load(pm)) {
  Pixmap d = Pixmap(pm.width(),pm.height(),pm.hasAlpha());
  const uint8_t* p = pm.const_data();

  if(pm.hasAlpha()){
    for(int r=0; r<pm.height(); ++r)
      for(int i=0; i<pm.width(); ++i){
        //0.299, 0.587, 0.114
        uint8_t cl = uint8_t(p[0]*0.299 + p[1]*0.587 + p[2]*0.114);
        d.set(i,r,Pixmap::Pixel{cl,cl,cl,p[3]});
        p += 4;
        }
    } else {
    for(int r=0; r<pm.height(); ++r)
      for(int i=0; i<pm.width(); ++i){
        //0.299, 0.587, 0.114
        uint8_t cl = uint8_t(p[0]*0.299 + p[1]*0.587 + p[2]*0.114);
        d.set(i,r,Pixmap::Pixel{cl,cl,cl,255});
        p += 3;
        }
    }

  disabled = h.load(d);
  }
Exemple #3
0
static
HCURSOR pixmapToCursor( const Pixmap& pinput,
                        int hotSpotX,
                        int hotSpotY ) {
  if( pinput.isEmpty() ) {
    return 0;
    }

  Pixmap pm = pinput;
  pm.setFormat( Pixmap::Format_RGBA );

  ICONINFO iconInfo;
  ZeroMemory(&iconInfo, sizeof(iconInfo));
  iconInfo.fIcon = false;

  iconInfo.xHotspot = hotSpotX;
  iconInfo.yHotspot = hotSpotY;

  HBITMAP hBitmap     = 0;
  HBITMAP hMonoBitmap = CreateBitmap( pm.width(), pm.height(), 1,1, NULL);
  iconInfo.hbmMask  = hMonoBitmap;

  {
    BITMAPV5HEADER bi;
    ZeroMemory(&bi,sizeof(BITMAPV5HEADER));
    bi.bV5Size            = sizeof(BITMAPV5HEADER);
    bi.bV5Width           = pm.width();
    bi.bV5Height          = pm.height();
    bi.bV5Planes   = 1;
    bi.bV5BitCount = 32;
    bi.bV5Compression = BI_BITFIELDS;
    // The following mask specification specifies a supported 32 BPP
    // alpha format for Windows XP.

    bi.bV5RedMask   =  0x00FF0000;
    bi.bV5GreenMask =  0x0000FF00;
    bi.bV5BlueMask  =  0x000000FF;
    bi.bV5AlphaMask =  0xFF000000;

    HDC hdc = GetDC(NULL);

    uint8_t *lpBits;
    const uint8_t* input = pm.const_data();

    hBitmap = CreateDIBSection( hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS,
                                (void **)&lpBits, NULL, (DWORD)0 );

    size_t bperRow = pm.width()*4;
    for( int i=0; i<pm.height(); ++i ){
      memcpy( lpBits + bperRow*i,
              input  + bperRow*(pm.height()-i-1),
              bperRow );
      }

    size_t bsz = pm.width()*pm.height()*4;
    for( size_t i=0; i<bsz; i+=4 ){
      uint8_t a     = *(lpBits+i);
      *(lpBits+i)   = *(lpBits+i+2);
      *(lpBits+i+2) = a;
      }

    iconInfo.hbmColor = hBitmap;
    }

  HICON hicon = CreateIconIndirect(&iconInfo);

  DeleteObject(hBitmap);
  DeleteObject(hMonoBitmap);
  return (HCURSOR)hicon;
  }