Surface8u convertGdiplusBitmap( Gdiplus::Bitmap &bitmap )
{	
	Gdiplus::BitmapData bitmapData;
	Gdiplus::Rect rect( 0, 0, bitmap.GetWidth(), bitmap.GetHeight() );

	Gdiplus::PixelFormat requestedFormat = bitmap.GetPixelFormat();
	SurfaceChannelOrder sco;
	bool premult;
	gdiplusPixelFormatToSurfaceChannelOrder( requestedFormat, &sco, &premult );
	if( sco == SurfaceChannelOrder::UNSPECIFIED ) {
		UINT flags = bitmap.GetFlags();
		sco = ( flags & Gdiplus::ImageFlagsHasAlpha ) ? SurfaceChannelOrder::BGRA : SurfaceChannelOrder::BGR;
		requestedFormat = ( flags & Gdiplus::ImageFlagsHasAlpha ) ? PixelFormat32bppARGB : PixelFormat24bppRGB;
	}
	
	bitmap.LockBits( &rect, Gdiplus::ImageLockModeRead, requestedFormat, &bitmapData );
	Surface8u result( bitmap.GetWidth(), bitmap.GetHeight(), sco.hasAlpha(), sco );

	const uint8_t *srcDataBase = (uint8_t*)bitmapData.Scan0;
	int32_t width = bitmap.GetWidth();
	for( uint32_t y = 0; y < bitmap.GetHeight(); ++y ) {
		memcpy( result.getData( Vec2i( 0, y ) ), srcDataBase + y * bitmapData.Stride, width * result.getPixelInc() );
	}

	bitmap.UnlockBits( &bitmapData );
	return result;
}
Beispiel #2
0
		void GDIPlus::DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect pTargetRect, float u1, float v1, float u2, float v2 )
		{
			Gdiplus::Bitmap* pImage = (Gdiplus::Bitmap*) pTexture->data;

			// Missing image, not loaded properly?
			if ( !pImage || pImage->GetType() == Gdiplus::ImageTypeUnknown ) 
				return DrawMissingImage( pTargetRect );

			Translate( pTargetRect );

			Gdiplus::RectF TargetRect( pTargetRect.x, pTargetRect.y, pTargetRect.w, pTargetRect.h );

			// Convert UV to pixel coords
			float fW = pImage->GetWidth();
			float fH = pImage->GetHeight();

			u1 *= fW;
			v1 *= fH;

			u2 *= fW;
			u2 -= u1;

			v2 *= fH;
			v2 -= v1;

			graphics->DrawImage( pImage, TargetRect, u1, v1, u2, v2, Gdiplus::UnitPixel );
			
		}
Surface8u convertGdiplusBitmap( Gdiplus::Bitmap &bitmap, bool premultiplied )
{	
	Gdiplus::BitmapData bitmapData;
	Gdiplus::Rect rect( 0, 0, bitmap.GetWidth(), bitmap.GetHeight() );
	bitmap.LockBits( &rect, Gdiplus::ImageLockModeRead, (premultiplied) ? PixelFormat32bppPARGB : PixelFormat32bppARGB, &bitmapData );
	Surface8u result( bitmap.GetWidth(), bitmap.GetHeight(), true, SurfaceChannelOrder::BGRA );

	const uint8_t *srcDataBase = (uint8_t*)bitmapData.Scan0;
	int32_t width = bitmap.GetWidth();
	for( uint32_t y = 0; y < bitmap.GetHeight(); ++y ) {
		memcpy( result.getData( Vec2i( 0, y ) ), srcDataBase + y * bitmapData.Stride, width * 4 );
	}

	bitmap.UnlockBits( &bitmapData );
	return result;
}
Beispiel #4
0
// hack for stupid GDIplus
void Gdip_RemoveAlpha(Gdiplus::Bitmap& source, Gdiplus::Color color )
{
	using namespace Gdiplus;
	Rect r( 0, 0, source.GetWidth(),source.GetHeight() );
	BitmapData  bdSrc;
	source.LockBits( &r,  ImageLockModeRead , PixelFormat32bppARGB,&bdSrc);

	BYTE* bpSrc = (BYTE*)bdSrc.Scan0;

	//bpSrc += (int)sourceChannel;


	for ( int i = r.Height * r.Width; i > 0; i-- )
	{
		BGRA_COLOR * c = (BGRA_COLOR *)bpSrc;

		if(c->a!=255)
		{
			//c = 255;

			DWORD * d= (DWORD*)bpSrc;
			*d= color.ToCOLORREF();
			c ->a= 255;
		}
		bpSrc += 4;

	}
	source.UnlockBits( &bdSrc );
}
static void getImagePropertiesHelper(vl::ImageShape & shape, Gdiplus::Bitmap & bitmap)
{
  bool grayscale = (bitmap.GetFlags() & ImageFlagsColorSpaceGRAY) ;
  shape.width = bitmap.GetWidth() ;
  shape.height = bitmap.GetHeight() ;
  shape.depth = grayscale ? 1 : 3 ;
}
Beispiel #6
0
HBITMAP TaskbarWnd::GetIconicRepresentation(int nWidth, int nHeight, int scale )
{
    HRESULT hr = E_FAIL;

	Gdiplus::Bitmap* src = Gdiplus::Bitmap::FromHBITMAP( hbm_cached_,0);

	// scale
	Gdiplus::Bitmap  dest( nWidth, nHeight, PixelFormat32bppARGB);
	{
		Gdiplus::RectF rDest(0,0,(Gdiplus::REAL)nWidth, (Gdiplus::REAL)nHeight );
		Gdiplus::Graphics gScale( &dest );

		if ( scale != 1 )
		{
			nWidth  = std::min(nWidth*scale, (int)src->GetWidth());
			nHeight = std::min(nHeight*scale, (int)src->GetHeight());
		}

		gScale.DrawImage( src, rDest,0,0,(Gdiplus::REAL)nWidth,(Gdiplus::REAL)nHeight, Gdiplus::UnitPixel, NULL, NULL, NULL );

	}
	delete src;

	// retval and cleanup
	HBITMAP hBitmap = 0;
	dest.GetHBITMAP(Gdiplus::Color::Black, &hBitmap);
    return hBitmap;
}
Beispiel #7
0
		void GDIPlus::LoadTexture( gwen::Texture* pTexture )
		{
			Gdiplus::Bitmap* pImage = new Gdiplus::Bitmap( pTexture->name.GetUnicode().c_str() );
			pTexture->data = pImage;
			pTexture->width = pImage->GetWidth();
			pTexture->height = pImage->GetHeight();
		}
Beispiel #8
0
void MakeIcon(HICON icon, char* path) {
  Gdiplus::Bitmap* bitmap = Gdiplus::Bitmap::FromFile(ToWChar(path));
  if (bitmap->GetWidth()) {
    bitmap->GetHICON(&icon);
    delete bitmap;
  }
}
void gdiplus_container::get_img_size( litehtml::uint_ptr img, litehtml::size& sz )
{
	Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*) img;
	if(bmp)
	{
		sz.width	= bmp->GetWidth();
		sz.height	= bmp->GetHeight();
	}
}
    Bitmap CanvasGdiplus::ExtractBitmap() const
    {
        DCHECK(!mem_bitmap_.IsNull());

        // 生成一个位图, 绘制画布内容到其中并返回.
        Gdiplus::Bitmap* bitmap = mem_bitmap_.GetNativeBitmap();
        Gdiplus::Rect rc_bitmap(0, 0, bitmap->GetWidth(), bitmap->GetHeight());
        return Bitmap(bitmap->Clone(rc_bitmap, bitmap->GetPixelFormat()));
    }
Beispiel #11
0
//-------------------------------------------------------------------------------------
void DlgOpenImage::OnFileNameChange()
{
    m_thumb.ApplyEffect (FCEffectFillColor(FCColor(255,255,255))) ;

    CString   szFile = GetPathName() ;

    FCImageProperty   prop ;
    CSize   sizeImage (0,0) ;

    if (PathFileExists(szFile))
    {
        IMAGE_TYPE  imgType = FCImageCodecFactory::GetTypeByFileExt(szFile) ;

        if ( (imgType == IMG_JPG) ||
             (imgType == IMG_BMP) ||
             (imgType == IMG_PNG) ||
             (imgType == IMG_TIF) ||
             (imgType == IMG_GIF) )
        {
            Gdiplus::Bitmap   bmp (szFile) ;
            if (bmp.GetLastStatus() == Gdiplus::Ok)
            {
                sizeImage = CSize (bmp.GetWidth(), bmp.GetHeight()) ;
                FCImageCodec_Gdiplus::GetPropertyFromBitmap(bmp, prop) ;

                // calculate thumb size
                CRect   rc (0, 0, m_thumb.Width(), m_thumb.Height()) ;
                rc = FCObjGraph::CalcFitWindowSize (sizeImage, rc) ;

                FCImageDrawDC   memDC (m_thumb) ;
                Gdiplus::Graphics(memDC).DrawImage (&bmp, rc.left, rc.top, rc.Width(), rc.Height()) ;
            }
        }
    }

    // update size
    CString   s ;
    if (sizeImage.cx && sizeImage.cy)
    {
        s.Format(L"%d x %d", sizeImage.cx, sizeImage.cy) ;
        s = L"Size :" + s ;
    }
    SetDlgItemText(IDC_SIZE_VALUE, s) ;

    // update date
    s = L"" ;
    if (prop.m_ExifDTOrig.length())
    {
        s = L"Date :" + CString(prop.m_ExifDTOrig.c_str()) ;
    }
    SetDlgItemText(IDC_DATE_VALUE, s) ;

    m_ctrl.Invalidate() ;
}
Beispiel #12
0
LRESULT CMediaClipView::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CPaintDC dc(m_hWnd);
	{
		Gdiplus::Graphics graphics(dc.m_hDC);

		Gdiplus::Bitmap* pBitmap;
		GetBitmap(&pBitmap);

		if (pBitmap)
		{
			CRect client;
			GetClientRect(&client);

			graphics.DrawImage(pBitmap, m_videoRect,
				0, 0, pBitmap->GetWidth(), pBitmap->GetHeight(),
				Gdiplus::UnitPixel);
		}
	}

	dc.FillSolidRect(&m_bottomRect, GetSysColor(COLOR_BTNFACE));

	dc.FillSolidRect(&m_sliderRect, RGB(220, 220, 220));

	{
		/*
		CComQIPtr<IMediaSeeking> mediaSeeking = m_dsGraph;

		LONGLONG llpos;
		mediaSeeking->GetCurrentPosition(&llpos);

		double seconds = (double)llpos / 10000000; //seconds;
		*/

		double secondWidth = m_sliderRect.Width() / m_pStream->m_pDocument->m_duration;

		int x = m_sliderRect.left + (m_pStream->m_pDocument->m_currentTime * secondWidth);
		dc.MoveTo(x, m_sliderRect.top);
		dc.LineTo(x, m_sliderRect.bottom);

		double clipBegin = m_pStream->m_pDocument->GetClipBegin();
		double clipEnd = m_pStream->m_pDocument->GetClipEnd();

		x = m_sliderRect.left + (clipBegin * secondWidth);
		dc.DrawText("{", 1, CRect(x-5, m_sliderRect.top, x+5, m_sliderRect.bottom), DT_CENTER | DT_SINGLELINE);

		x = m_sliderRect.left + (clipEnd * secondWidth);
		dc.DrawText("}", 1, CRect(x-5, m_sliderRect.top, x+5, m_sliderRect.bottom), DT_CENTER | DT_SINGLELINE);
	}

	return 0;
}
Beispiel #13
0
view::pixel_t* read(wchar_t *filename){
	Gdiplus::Bitmap *bmp = Gdiplus::Bitmap::FromFile(filename);
	if (bmp->GetLastStatus() != Gdiplus::Ok) return 0;

	Gdiplus::Rect r;
	r.X = 0;
	r.Y = 0;
	r.Width = bmp->GetWidth();
	r.Height = bmp->GetHeight();

	Gdiplus::BitmapData data;
	bmp->LockBits(&r, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &data);

	return (view::pixel_t*)data.Scan0;
}
Beispiel #14
0
Meter::Meter(std::wstring bitmapName, int x, int y, int units) :
_value(0.0f),
_drawnValue(-1.0f),
_units(units),
_drawnUnits(-1) {
    _rect.X = x;
    _rect.Y = y;

    Gdiplus::Bitmap *bmp = Gdiplus::Bitmap::FromFile(
        bitmapName.c_str(), false);
    CLOG(L"Loading meter bitmap: %s\nStatus: %d",
        bitmapName.c_str(), bmp->GetLastStatus());
    _bitmap = bmp;

    _rect.Width = bmp->GetWidth();
    _rect.Height = bmp->GetHeight();
}
int DxFont::GetCharMaxX(Gdiplus::Bitmap & charBitmap)
{
    int width  = charBitmap.GetWidth( );
    int height = charBitmap.GetHeight( );

    for(int x = width - 1; x >= 0; --x )
    {
        for(int y = 0; y < height; ++y)
        {
            Gdiplus::Color color;

            charBitmap.GetPixel(x, y, &color);
            if( color.GetAlpha() > 0)
                return x;
        }
    }

    return width - 1;
}
Beispiel #16
0
void HostResourceLoader::loadFromPNG( BuiltFromResourcePixMap& item ) {
    HRSRC x = ::FindResourceA(  NULL, item.resourceName, "PNG" );
    ProductionAssert(x,item.resourceName);
    DWORD n = SizeofResource( NULL, x); 
    Assert(n);
    HGLOBAL g = ::LoadResource( NULL, x );
    Assert(g);
    const void* r=LockResource(g);
    Assert(r!=NULL);
    HGLOBAL buf = ::GlobalAlloc(GMEM_MOVEABLE, n);
    Assert(buf);
    char* png = (char*)::GlobalLock(buf);
    Assert(png);
    memcpy(png,r,n);
    // Following assertion check that it is a PNG resource.
    Assert(memcmp(png+1,"PNG",3)==0 );
    IStream* s = NULL;
    HRESULT streamCreationStatus = CreateStreamOnHGlobal(buf,FALSE,&s);
    Assert( streamCreationStatus==S_OK );
    Assert(s);
    Gdiplus::Bitmap* bitmap = Gdiplus::Bitmap::FromStream(s,FALSE);
    ProductionAssert(bitmap,"Gdiplus::Bitmap::FromStream returned false");
    Gdiplus::Status fromStreamStatus = bitmap->GetLastStatus();
    ProductionAssert(fromStreamStatus==Gdiplus::Ok,"Gdiplus::Bitmap::FromStream failed");
    s->Release();
    ::GlobalUnlock(buf);
    ::GlobalFree(buf);

    int w=bitmap->GetWidth();
    int h=bitmap->GetHeight();
    const Gdiplus::Rect rect(0,0,w,h);
    Gdiplus::BitmapData lockedBits;
    Gdiplus::Status lockStatus = bitmap->LockBits(&rect,0,PixelFormat32bppARGB,&lockedBits);
	Assert( lockStatus==Gdiplus::Ok);
    NimblePixMap map(w,h,8*sizeof(NimblePixel),lockedBits.Scan0,lockedBits.Stride);
    item.buildFrom(map);
	Gdiplus::Status unlockStatus = bitmap->UnlockBits(&lockedBits);
	delete bitmap;
	Assert(unlockStatus==Gdiplus::Ok);
    return;
}
Beispiel #17
0
//---------------------------------------------------------------------------
int GetCharMaxX(Gdiplus::Bitmap& charBitmap)
{
    using namespace Gdiplus;

	int width  = charBitmap.GetWidth();
	int height = charBitmap.GetHeight();

	for(int x = width-1; x >= 0; --x)
	{
		for(int y = 0; y < height; ++y)
		{
			Color color;
			charBitmap.GetPixel(x, y, &color);
			if(color.GetAlpha() > 0)
			{
				 return x;
			}
		}
	}

	return width-1;
}
Beispiel #18
0
	void* BaseManager::loadImage(int& _width, int& _height, MyGUI::PixelFormat& _format, const std::string& _filename)
	{
		std::string fullname = MyGUI::OpenGL3DataManager::getInstance().getDataPath(_filename);

		void* result = 0;

		Gdiplus::Bitmap* image = Gdiplus::Bitmap::FromFile(MyGUI::UString(fullname).asWStr_c_str());
		if (image)
		{
			_width = image->GetWidth();
			_height = image->GetHeight();
			Gdiplus::PixelFormat format = image->GetPixelFormat();

			if (format == PixelFormat24bppRGB)
				_format = MyGUI::PixelFormat::R8G8B8;
			else if (format == PixelFormat32bppARGB)
				_format = MyGUI::PixelFormat::R8G8B8A8;
			else
				_format = MyGUI::PixelFormat::Unknow;

			if (_format != MyGUI::PixelFormat::Unknow)
			{
				Gdiplus::Rect rect(0, 0, _width, _height);
				Gdiplus::BitmapData out_data;
				image->LockBits(&rect, Gdiplus::ImageLockModeRead, format, &out_data);

				size_t size = out_data.Height * out_data.Stride;
				result = new unsigned char[size];

				convertRawData(&out_data, result, size, _format);

				image->UnlockBits(&out_data);
			}

			delete image;
		}

		return result;
	}
Beispiel #19
0
HRESULT BitmapUtil::MyCreateFromGdiplusBitmap( Gdiplus::Bitmap& bmSrc ) throw()
{
	Gdiplus::PixelFormat eSrcPixelFormat = bmSrc.GetPixelFormat();
	UINT nBPP = 32;
	DWORD dwFlags = 0;
	Gdiplus::PixelFormat eDestPixelFormat = PixelFormat32bppRGB;
	if( eSrcPixelFormat&PixelFormatGDI )
	{
		nBPP = Gdiplus::GetPixelFormatSize( eSrcPixelFormat );
		eDestPixelFormat = eSrcPixelFormat;
	}
	if( Gdiplus::IsAlphaPixelFormat( eSrcPixelFormat ) )
	{
		nBPP = 32;
		dwFlags |= createAlphaChannel;
		eDestPixelFormat = PixelFormat32bppARGB;
	}

	BOOL bSuccess = Create( bmSrc.GetWidth(), bmSrc.GetHeight(), nBPP, dwFlags );
	if( !bSuccess )
	{
		return( E_FAIL );
	}
	Gdiplus::ColorPalette* pPalette = NULL;
	if( Gdiplus::IsIndexedPixelFormat( eSrcPixelFormat ) )
	{
		UINT nPaletteSize = bmSrc.GetPaletteSize();

		pPalette = static_cast< Gdiplus::ColorPalette* >( _alloca( nPaletteSize ) );
		bmSrc.GetPalette( pPalette, nPaletteSize );

		RGBQUAD argbPalette[256];
		ATLASSERT( (pPalette->Count > 0) && (pPalette->Count <= 256) );
		for( UINT iColor = 0; iColor < pPalette->Count; iColor++ )
		{
			Gdiplus::ARGB color = pPalette->Entries[iColor];
			argbPalette[iColor].rgbRed = BYTE( color>>RED_SHIFT );
			argbPalette[iColor].rgbGreen = BYTE( color>>GREEN_SHIFT );
			argbPalette[iColor].rgbBlue = BYTE( color>>BLUE_SHIFT );
			argbPalette[iColor].rgbReserved = 0;
		}

		SetColorTable( 0, pPalette->Count, argbPalette );
	}

	if( eDestPixelFormat == eSrcPixelFormat )
	{
		// The pixel formats are identical, so just memcpy the rows.
		Gdiplus::BitmapData data;
		Gdiplus::Rect rect( 0, 0, GetWidth(), GetHeight() );
		bmSrc.LockBits( &rect, Gdiplus::ImageLockModeRead, eSrcPixelFormat, &data );

		UINT nBytesPerRow = AtlAlignUp( nBPP*GetWidth(), 8 )/8;
		BYTE* pbDestRow = static_cast< BYTE* >( GetBits() );
		BYTE* pbSrcRow = static_cast< BYTE* >( data.Scan0 );
		for( int y = 0; y < GetHeight(); y++ )
		{
			memcpy( pbDestRow, pbSrcRow, nBytesPerRow );
			pbDestRow += GetPitch();
			pbSrcRow += data.Stride;
		}

		bmSrc.UnlockBits( &data );
	}
	else
	{
		// Let GDI+ work its magic
		Gdiplus::Bitmap bmDest( GetWidth(), GetHeight(), GetPitch(), eDestPixelFormat, static_cast< BYTE* >( GetBits() ) );
		Gdiplus::Graphics gDest( &bmDest );

		gDest.DrawImage( &bmSrc, 0, 0 );
	}

	return( S_OK );
}
//// CMarkerStyle
bool CMarkerStyle::Init(const CString& fileName)
{
	if (fileName.Compare(L"") != 0)
		m_ImageFileName_ = fileName;
	if(m_ImageFileName_.Compare(L"") == 0)
		return false;
	// Read the texture bits
	//构建位图对象
	Gdiplus::Bitmap* bmp = Gdiplus::Bitmap::FromFile(m_ImageFileName_);
	m_ImageWidth_ = bmp->GetWidth();
	m_ImageHeight_ = bmp->GetHeight();

	//创建图片内容
	if(m_pdata_ != NULL)
	{
		delete[] m_pdata_;
		m_pdata_ = NULL;
	}
	m_pdata_ = new BYTE[m_ImageWidth_ * m_ImageHeight_ * 4];
	
	//根据位图对象创建GDI位图对象
	HBITMAP hBitMap;
	bmp->GetHBITMAP(Gdiplus::Color::White, &hBitMap);
	
	//根据GDI位图获取句柄给CBitmao
	CBitmap* cbmp = CBitmap::FromHandle(hBitMap);
	if (cbmp == NULL)
		return false;

	//获取图像数据
	DWORD size = cbmp->GetBitmapBits(m_ImageWidth_ * m_ImageHeight_ * 4, m_pdata_);
	for (int i = 0; i < m_ImageWidth_ * m_ImageHeight_; i++)
	{
		BYTE tmp = (m_pdata_[i * 4]);
		m_pdata_[i * 4 + 0] = (m_pdata_[i * 4 + 2]); //r
		m_pdata_[i * 4 + 2] = tmp;//b
	}

	cbmp->DeleteObject();
	DeleteObject(hBitMap);
	DeleteObject(bmp);


	//创建纹理
	if(m_texttureID_ > 0)
	{
		glDeleteTextures(1, &m_texttureID_);
		m_texttureID_ = -1;
	}
	//创建贴图对象
	glGenTextures(1, &m_texttureID_);
	//绑定贴图对象
	//glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //按照一位对齐
	glBindTexture(GL_TEXTURE_2D, m_texttureID_);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_ImageWidth_, m_ImageHeight_, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_pdata_);
	//跟新部分区域
	//glTexSubImage2D(GL_TEXTURE_2D, 0, 100, 100, 56, 56, GL_RGBA, GL_UNSIGNED_BYTE, m_pdata_);
	//过滤模式
	//放大过滤
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
	//超过TS坐标时候的采样
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	return true;
}
Beispiel #21
0
	HBITMAP g_create_hbitmap_from_image(Gdiplus::Bitmap & bm, t_size & cx, t_size & cy, COLORREF cr_back, bool b_reflection)
	{
		HDC dc=NULL, dcc=NULL;
		dc = GetDC(NULL);
		dcc = CreateCompatibleDC(dc);
		//cy = bm.GetHeight();
		if (b_reflection)
			cy = cx;//(cy*11 -7) / 14;
		t_size ocx=cx,ocy=cy;

		t_size cx_source = bm.GetWidth(), cy_source = bm.GetHeight();


		double ar_source = (double)cx_source / (double)cy_source;
		double ar_dest = (double)ocx / (double)ocy;
		//unsigned cx = RECT_CX(rc), cy = RECT_CY(rc);

		if (ar_dest < ar_source)
			cy = (unsigned)floor((double)ocx / ar_source);
		else if (ar_dest > ar_source)
			cx = (unsigned)floor((double)ocy * ar_source);

		//cy = (unsigned)floor((double)ocx / ar_source);
		if ( (ocx - cx) % 2) cx++;

		t_size reflect_cy = b_reflection ? (cy*3)/11 : 0;
		HBITMAP bitmap = CreateCompatibleBitmap(dc, cx, cy + reflect_cy);
		HBITMAP bm_old = SelectBitmap(dcc, bitmap);

		unsigned err = 0;
		Gdiplus::Graphics graphics(dcc);
		err = graphics.GetLastStatus();
		graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
		graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);

		Gdiplus::SolidBrush br(Gdiplus::Color(LOBYTE(LOWORD(cr_back)),HIBYTE(LOWORD(cr_back)),LOBYTE(HIWORD(cr_back)) ));
		graphics.FillRectangle(&br, 0, 0, cx, cy + reflect_cy);

		//if (cx_source>=2 && cy_source>=2)
		{
			{
#if 1
				Gdiplus::ImageAttributes imageAttributes;
				imageAttributes.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
				Gdiplus::Rect destRect(0, 0, cx, cy);
				graphics.DrawImage(&bm, destRect, 0, 0, cx_source, cy_source, Gdiplus::UnitPixel, &imageAttributes);
#else
				if (cx_source == cx && cy_source == cy)
				{
					Gdiplus::Rect destRect(0, 0, cx, cy);
					graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
					graphics.DrawImage(&bm, destRect, 0, 0, cx_source, cy_source, Gdiplus::UnitPixel);
					graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
				}
				else
				{
					Gdiplus::Rect destRect(-1, -1, cx+2, cy+2);
					//Gdiplus::Rect destRect(0, 0, cx, cy);
					graphics.DrawImage(&bm, destRect, 0, 0, cx_source, cy_source, Gdiplus::UnitPixel);
				}
#endif
			}

			{
				Gdiplus::Bitmap scaled(bitmap, NULL);
				t_size i;
				if (reflect_cy)
				{

					Gdiplus::Rect rectref(0, cy, cx, reflect_cy);
					Gdiplus::Color cr_end(255,LOBYTE(LOWORD(cr_back)),HIBYTE(LOWORD(cr_back)),LOBYTE(HIWORD(cr_back)));
					Gdiplus::Color cr_start(148,LOBYTE(LOWORD(cr_back)),HIBYTE(LOWORD(cr_back)),LOBYTE(HIWORD(cr_back)));
					//Gdiplus::Color cr_middle(100,255,255,255);
					Gdiplus::Rect destRect(0, cy, cx, reflect_cy);
					graphics.DrawImage(&scaled, destRect, 0, cy, cx, 0-reflect_cy, Gdiplus::UnitPixel);
					Gdiplus::LinearGradientBrush lgb(rectref, cr_start, cr_end, Gdiplus::LinearGradientModeVertical);
					graphics.FillRectangle(&lgb, rectref);
					//graphics.FillRectangle(&Gdiplus::SolidBrush(cr_middle), rectref);
					/*for (i=0; i<reflect_cy; i++)
					{
						Gdiplus::ImageAttributes attrib;
						Gdiplus::ColorMatrix mtrx = {0};
						mtrx.m[0][0] = 1;
						mtrx.m[1][1] = 1;
						mtrx.m[2][2] = 1;
						mtrx.m[3][3] = float(0.42) - (float(0.42)*(float(i)/float(reflect_cy)));
						mtrx.m[4][4] = 1;

						attrib.SetColorMatrix (&mtrx, Gdiplus::ColorMatrixFlagsDefault, Gdiplus::ColorAdjustTypeDefault);
						//Gdiplus::Rect sourceRect(0, cy-1-i, cx, cy-i);
						Gdiplus::Rect destRect(0, cy+i, cx, 1);
						graphics.DrawImage(&scaled, destRect, 0, cy-i-1, cx, 1, Gdiplus::UnitPixel, &attrib);
					}*/
				}
			}
			err = graphics.GetLastStatus();
		}
		//m_bitmap = pfc::rcnew_t<Gdiplus::CachedBitmap>(&bm, &_graphics);
		//err = m_bitmap->GetLastStatus();

		SelectBitmap(dcc, bm_old);

		DeleteDC(dcc);
		ReleaseDC(NULL, dc);

		return bitmap;
	}
xGifInfo_GDIPlus::xGifInfo_GDIPlus(Gdiplus::Bitmap& inPicture)
:xGifInfo()
{
	xGifFrame* fr;
	sLONG nbframe=inPicture.GetFrameCount(&Gdiplus::FrameDimensionTime);
	long propsize;
	Gdiplus::PropertyItem* prop=0;
	
	fLoopCount=0;
	for(long i=0;i<nbframe;i++)
	{
		
		xGif89FrameInfo inInfo;
		sLONG framedelay;
		sBYTE transindex;
		
		inInfo.transparent=0;
		inInfo.delayTime=0;
		inInfo.inputFlag=0;
		inInfo.disposal=0;
		inInfo.transparent_index=0;
		
		
		inPicture.SelectActiveFrame(&Gdiplus::FrameDimensionTime,i);
		fr=new xGifFrame(0,0,inPicture.GetWidth(),inPicture.GetHeight(),false);
		
		
		if(propsize=inPicture.GetPropertyItemSize(PropertyTagFrameDelay))
		{
			prop=(Gdiplus::PropertyItem*)malloc(propsize);
			if(inPicture.GetPropertyItem(PropertyTagFrameDelay,propsize,prop)==Gdiplus::Ok)
			{
				inInfo.delayTime=*((long*)prop->value);
			}
			free((void*)prop);
		}
		if(propsize=inPicture.GetPropertyItemSize(0x5104))
		{
			prop=(Gdiplus::PropertyItem*)malloc(propsize);
			if(inPicture.GetPropertyItem(0x5104,propsize,prop)==Gdiplus::Ok)
			{
				inInfo.transparent_index=*((sBYTE*)prop->value);
			}
			free((void*)prop);
		}
		
		inInfo.transparent=inInfo.transparent_index!=-1;
		
		fr->SetGif89FrameInfo(inInfo);
		fFrameList.push_back(fr);
	}
	if(propsize=inPicture.GetPropertyItemSize(PropertyTagLoopCount))
	{
		prop=(Gdiplus::PropertyItem*)malloc(propsize);
		if(inPicture.GetPropertyItem(PropertyTagLoopCount,propsize,prop)==Gdiplus::Ok)
		{
			fLoopCount=*((short*)prop->value);
		}
		free((void*)prop);
	}
}
Beispiel #23
0
	Texture::Texture(const string& path) {
		int Multiplier2[] = {
			1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096
		};

		wstring wpath;
		wpath.assign(path.begin(), path.end());

		Gdiplus::Bitmap* image = Gdiplus::Bitmap::FromFile(wpath.c_str());
		Gdiplus::Rect rect(0, 0, image->GetWidth(), image->GetHeight());
		Gdiplus::BitmapData bitmapData;

		image->LockBits(&rect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bitmapData);

		DWORD* bitmapDataScan0 = (DWORD*) bitmapData.Scan0;

		_size = Size((float) image->GetWidth(), (float) image->GetHeight());

		for (float width = 1.0f;; width *= 2.0f) {
			if (width >= _size.width) {
				_glSize.width = width;
				break;
			}
		}

		for (float height = 1.0f;; height *= 2.0f) {
			if (height >= _size.height) {
				_glSize.height = height;
				break;
			}
		}

		DWORD* glImage = (DWORD*) malloc(sizeof(DWORD) * (int) _glSize.width * (int) _glSize.height);

		for (int y = 0; y < (int) _glSize.height; y++) {
			if (y < _size.height) {
				memcpy(&glImage[(int) (y * _glSize.width)], &bitmapDataScan0[(int) (y * _size.width)], sizeof(DWORD) * (int) _size.width);
				memset(&glImage[(int) (y * _glSize.width + _size.width)], 0, sizeof(DWORD) * (int) (_glSize.width - _size.width));
			} else {
				memset(&glImage[(int) (y * _glSize.width)], 0, sizeof(DWORD) * (int) _glSize.width);
			}
		}

		image->UnlockBits(&bitmapData);

		glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
		glGenTextures(1, &_textureID);

		glPushAttrib(GL_ALL_ATTRIB_BITS);

		glBindTexture(GL_TEXTURE_2D, _textureID);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei) _glSize.width, (GLsizei) _glSize.height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, glImage);

		glPopAttrib();

		free(glImage);
		delete image;
	}
bool VisualTextureContainer::initWithEncodedData(const char* const bufferData, size_t size) {
	
	bool success = true;
	bool debug = false;
	
	this->releaseTextureData();
	
	uint32* aPixelBuffer = NULL;
	
#if TARGET_OS_WIN
	
	HGLOBAL hGlobal = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, (SIZE_T)size);
	if (!hGlobal)
		return false;
	
	BYTE* pDest = (BYTE*)::GlobalLock(hGlobal);
	
	memcpy(pDest, bufferData, size);
	
	::GlobalUnlock(hGlobal);
	
	IStream* pStream = NULL;
	if (::CreateStreamOnHGlobal(hGlobal, FALSE, &pStream) != S_OK)
		return false;
	
	Gdiplus::Bitmap* bitmap = Gdiplus::Bitmap::FromStream(pStream);
	bitmap->RotateFlip(Gdiplus::RotateNoneFlipY);
	
	this->imageRect.width = bitmap->GetWidth();
	this->imageRect.height = bitmap->GetHeight();
	
	VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
	this->useRectExtension = theVisualGraphics->canUseTextureRectExtension();
	if (this->useRectExtension == false) {
		this->textureRect.width = theVisualGraphics->power2Ceiling(this->imageRect.width);
		this->textureRect.height = theVisualGraphics->power2Ceiling(this->imageRect.height);
	} else {
		this->textureRect.width = this->imageRect.width;
		this->textureRect.height = this->imageRect.height;
	}
	
	aPixelBuffer = (uint32*)malloc(this->imageRect.width * this->imageRect.height * sizeof(uint32));
	Gdiplus::Rect rect(0, 0, this->imageRect.width, this->imageRect.height);
	Gdiplus::BitmapData* bitmapData = new Gdiplus::BitmapData;
	
	bitmapData->Width = this->imageRect.width;
	bitmapData->Height = this->imageRect.height;
	bitmapData->Stride = sizeof(uint32) * bitmapData->Width;
	bitmapData->PixelFormat = PixelFormat32bppARGB;
	bitmapData->Scan0 = (VOID*)aPixelBuffer;
	
	Gdiplus::Status status = Gdiplus::Ok;
	status = bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeUserInputBuf, PixelFormat32bppPARGB, bitmapData);
	
#endif
	
#if TARGET_OS_MAC
	
	CFDataRef dataRef = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, (UInt8*)bufferData, (CFIndex)size, kCFAllocatorDefault);
	
	CFDictionaryRef options = NULL;
	CGImageSourceRef imageSourceRef = CGImageSourceCreateWithData(dataRef, options);
	
	CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSourceRef, 0, options);
	
	this->imageRect.width = CGImageGetWidth(imageRef);
	this->imageRect.height = CGImageGetHeight(imageRef);
	
	VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
	this->useRectExtension = theVisualGraphics->canUseTextureRectExtension();
	if (this->useRectExtension == false) {
		this->textureRect.width = theVisualGraphics->power2Ceiling(this->imageRect.width);
		this->textureRect.height = theVisualGraphics->power2Ceiling(this->imageRect.height);
	} else {
		this->textureRect.width = this->imageRect.width;
		this->textureRect.height = this->imageRect.height;
	}
	
	CGContextRef contextPtr = theVisualGraphics->createBitmapContext(this->imageRect.width, this->imageRect.height);
	
	CGContextTranslateCTM(contextPtr, 0, this->imageRect.height);
	CGContextScaleCTM(contextPtr, 1.0f, -1.0f);
	
	CGRect rect = CGRectMake(0, 0, this->imageRect.width, this->imageRect.height);
	CGContextDrawImage(contextPtr, rect, imageRef);
	
	aPixelBuffer = static_cast<uint32*>(CGBitmapContextGetData(contextPtr));
#endif
	
	PixelColor* interleavedARGBColorPixelBuffer = NULL;
	
	if (debug == true) {
		interleavedARGBColorPixelBuffer = VisualColorTools::createARGBCheckPixels(this->textureRect.width, this->textureRect.height);
	} else {
		interleavedARGBColorPixelBuffer = static_cast<PixelColor*>(aPixelBuffer);
	}
	success = this->initWithARGBPixelData(interleavedARGBColorPixelBuffer, this->imageRect.width, this->imageRect.height);
	
#if TARGET_OS_MAC
	CGContextRelease(contextPtr);
	CGImageRelease(imageRef);
#endif
	
#if TARGET_OS_WIN
	bitmap->UnlockBits(bitmapData);
#endif
	
	return success;
	
}
Beispiel #25
0
void IrisBitmap::IrisDrawText(const IrisFont* fontIris, int x, int y, int width, int height, wstring str, int align){
	this->needRefreshTexture = true;

	if (x > this->width || y > this->height || x < 0 || y < 0)
		return;

	//this->needRefreshTexture = true;

	int size = IrisFont::defaultSize;
	IrisColor *color;
	wstring name;
	bool bold, shadow, italic;

	if(fontIris == NULL){
		name = IrisFont::defaultName;
		bold = IrisFont::defaultBold;
		shadow = IrisFont::defaultShadow;
		italic = IrisFont::defaultItalic;
		color = IrisFont::defaultColor;
	}
	else
	{
		name = fontIris->name;
		bold = fontIris->bold;
		shadow = fontIris->shadow;
		italic = fontIris->italic;
		color = fontIris->color;
	}

	// release
	

	Gdiplus::Bitmap *tBitmap = this->bitmap->Clone(0, 0, this->bitmap->GetWidth(), this->bitmap->GetHeight(), PixelFormat32bppARGB);
	Graphics tg(tBitmap);

	Gdiplus::FontFamily fontFamily(name.c_str());
	int fs = FontStyleRegular;
	
	if(bold)
		fs |= FontStyleBold;

	if(italic)
		fs |= FontStyleItalic;

	//lfont.lfWeight = 1000;
	Gdiplus::Font font(&fontFamily, (REAL)size, fs, UnitPixel);

	StringFormat strFormat;

	switch(align){
	case 0:
		strFormat.SetAlignment(StringAlignmentNear);
		break;
	case 1:
		strFormat.SetAlignment(StringAlignmentCenter);
		break;
	}

	Brush *brush;

	if(shadow)
		brush = new HatchBrush(HatchStyle90Percent, Color(color->red, color->green, color->blue));
	else
		brush = new SolidBrush(Color(color->red, color->green, color->blue));

	strFormat.SetFormatFlags(StringFormatFlagsNoWrap);
	Gdiplus::RectF r((REAL)x, (REAL)y, (REAL)width, (REAL)height);
	tg.SetSmoothingMode(SmoothingModeAntiAlias);
	tg.SetInterpolationMode(InterpolationModeHighQualityBicubic);
	Gdiplus::GraphicsPath path;
	path.AddString(str.c_str(), str.size(), &fontFamily, FontStyleRegular, 20, r, &strFormat);
	Gdiplus::Pen pen(Color(color->red, color->green, color->blue), 2);
	tg.DrawPath(&pen, &path);
	tg.FillPath(brush, &path);

	if(this->bitmap != 0){
		delete this->bitmap;
		this->bitmap = 0;
	}

	this->bitmap = tBitmap->Clone(0, 0, tBitmap->GetWidth(), tBitmap->GetHeight(), PixelFormat32bppARGB);

	//CLSID encoderClsid;
	//ModuleIrisGraphics::GetEncoderClsid(L"image/png", &encoderClsid);
	//this->bitmap->Save(L"string.png", &encoderClsid, NULL);

	delete brush;
	delete tBitmap;
	
}
Beispiel #26
0
void NativeWindow::Init(char* url, Settings* settings) {
  url_ = url;

  HINSTANCE hInstance = GetModuleHandle(NULL);

  if (is_main_window_) {
    dwmapiDLL = LoadLibrary(TEXT("dwmapi.dll"));
    if (dwmapiDLL != NULL) {
      DwmExtendFrameIntoClientArea = (DWMEFICA)GetProcAddress(dwmapiDLL, "DwmExtendFrameIntoClientArea");
      DwmEnableBlurBehindWindow = (DWMEBBW)GetProcAddress(dwmapiDLL, "DwmEnableBlurBehindWindow");
      DwmDefWindowProc = (DWMWP)GetProcAddress(dwmapiDLL, "DwmDefWindowProc");
    }

    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    WCHAR* wSmallIconPath = icons->getString("small",L"");
    WCHAR* wBigIconPath = icons->getString("big",L"");

    Gdiplus::Bitmap* smallIconBitmap = Gdiplus::Bitmap::FromFile(wSmallIconPath);
    Gdiplus::Bitmap* bigIconBitmap = Gdiplus::Bitmap::FromFile(wBigIconPath);

    if (smallIconBitmap->GetWidth()) {
      smallIconBitmap->GetHICON(&smallIcon);
      delete[] wSmallIconPath;
      delete smallIconBitmap;
    }

    if (bigIconBitmap->GetWidth()) {
      bigIconBitmap->GetHICON(&bigIcon);
      delete[] wBigIconPath;
      delete bigIconBitmap;
    }

    strcpy(szWindowClass,"AppjsWindow");
    MyRegisterClass(hInstance);
  }

  browserSettings = settings;

  if (rect_.left < 0 || rect_.top < 0) {
    rect_.left = (GetSystemMetrics(SM_CXSCREEN) - rect_.width) / 2;
    rect_.top = (GetSystemMetrics(SM_CYSCREEN) - rect_.height) / 2;
  }
  browser_ = NULL;
  handle_ = CreateWindowEx(NULL, szWindowClass,"", WS_OVERLAPPEDWINDOW,
                           rect_.left, rect_.top, rect_.width, rect_.height,
                           NULL, NULL, hInstance, NULL);

  SetWindowLongPtr(handle_, GWLP_USERDATA, (LONG)this);

  if (alpha_) {
    SetAlpha(true);
  }

  SetResizable(resizable_);

  if (fullscreen_) {
    fullscreen_ = false;
    Fullscreen();
  } else if (!show_chrome_) {
    SetShowChrome(false);
  }

  UpdateWindow(handle_);

  Cef::Run();
};
Beispiel #27
0
void NativeWindow::Init(char* url, Settings* settings) {
  url_ = url;

  if( !g_handler->GetBrowserHwnd() ) {

    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    WCHAR* wSmallIconPath = icons->getString("small",L"");
    WCHAR* wBigIconPath = icons->getString("big",L"");

    Gdiplus::Bitmap* smallIconBitmap = Gdiplus::Bitmap::FromFile(wSmallIconPath);
    Gdiplus::Bitmap* bigIconBitmap = Gdiplus::Bitmap::FromFile(wBigIconPath);

    if( smallIconBitmap->GetWidth() ) {
      smallIconBitmap->GetHICON(&smallIcon);
      delete[] wSmallIconPath;
      delete smallIconBitmap;
    }

    if( bigIconBitmap->GetWidth() ) {
      bigIconBitmap->GetHICON(&bigIcon);
      delete[] wBigIconPath;
      delete bigIconBitmap;
    }
  }

  HINSTANCE hInstance = GetModuleHandle(NULL);
  strcpy(szWindowClass,"AppjsWindow");
  browserSettings = settings;


  if(!MyRegisterClass(hInstance)){
    //TODO send error to node
    if( GetLastError() != 1410 ) { //1410: Class Already Registered
      fprintf(stderr,"Error occurred: ");
      fprintf(stderr,"%d\n",GetLastError());
      return;
    }
  };

  DWORD style = show_chrome ? WS_OVERLAPPEDWINDOW : WS_SIZEBOX | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU;

  if (!resizable) {
    style &= ~WS_SIZEBOX;
  }

  if (left_ < 0 || top_ < 0) {
    left_ = (GetSystemMetrics(SM_CXSCREEN) - width_) / 2;
    top_ = (GetSystemMetrics(SM_CYSCREEN) - height_) / 2;
  }
  browser_ = NULL;
  handle_ = CreateWindowEx(NULL, szWindowClass,"", style, top_, left_, width_, height_, NULL, NULL, hInstance, NULL);

  if (!handle_) {
    fprintf(stderr,"Error occurred: ");
    fprintf(stderr,"%d\n",GetLastError());
    return;
  }

  SetWindowLongPtr(handle_, GWLP_USERDATA, (LONG)this);

  if (alpha) {
    SetNCWidth(handle_, -1);
  }

  if (fullscreen) {
    SetFullscreen(handle_);
  } else if (!show_chrome) {
    UpdateStyle(handle_, GWL_STYLE, GetWindowLong(handle_, GWL_STYLE) & ~WS_CAPTION);
  }

  UpdateWindow(handle_);

  Cef::Run();
};
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
bool PngTextureLoader::Load(void* data, int32_t size, bool rev)
{
#if __PNG_DDI
	auto global = GlobalAlloc(GMEM_MOVEABLE,size);
	auto buf = GlobalLock(global);
	CopyMemory(buf, data, size);
	GlobalUnlock(global);
	LPSTREAM stream = NULL;
	CreateStreamOnHGlobal( global, false, &stream);
	Gdiplus::Bitmap* bmp = Gdiplus::Bitmap::FromStream(stream);
	ES_SAFE_RELEASE(stream);
	GlobalFree(global);


	if( bmp != NULL && bmp->GetLastStatus() == Gdiplus::Ok )
	{
		textureWidth = bmp->GetWidth();
		textureHeight = bmp->GetHeight();
		textureData.resize(textureWidth * textureHeight * 4);

		if(rev)
		{
			for(auto y = 0; y < textureHeight; y++ )
			{
				for(auto x = 0; x < textureWidth; x++ )
				{
					Gdiplus::Color  color;
					bmp->GetPixel(x, textureHeight - y - 1, &color);

					textureData[(x + y * textureWidth) * 4 + 0] = color.GetR();
					textureData[(x + y * textureWidth) * 4 + 1] = color.GetG();
					textureData[(x + y * textureWidth) * 4 + 2] = color.GetB();
					textureData[(x + y * textureWidth) * 4 + 3] = color.GetA();
				}
			}
		}
		else
		{
			for(auto y = 0; y < textureHeight; y++ )
			{
				for(auto x = 0; x < textureWidth; x++ )
				{
					Gdiplus::Color  color;
					bmp->GetPixel(x, y, &color);

					textureData[(x + y * textureWidth) * 4 + 0] = color.GetR();
					textureData[(x + y * textureWidth) * 4 + 1] = color.GetG();
					textureData[(x + y * textureWidth) * 4 + 2] = color.GetB();
					textureData[(x + y * textureWidth) * 4 + 3] = color.GetA();
				}
			}
		}
		
		return true;
	}
	else
	{
		ES_SAFE_DELETE(bmp);
		return false;
	}
#else
	uint8_t* data_ = (uint8_t*) data;

	/* pngアクセス構造体を作成 */
	png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	
	/* リードコールバック関数指定 */
	png_set_read_fn(png, &data_, &PngReadData);

	/* png画像情報構造体を作成 */
	png_infop png_info = png_create_info_struct(png);

	/* エラーハンドリング */
	if (setjmp(png_jmpbuf(png)))
	{
		png_destroy_read_struct(&png, &png_info, NULL);
		return false;
	}

	/* IHDRチャンク情報を取得 */
	png_read_info(png, png_info);
	png_uint_32 width, height;
	int bit_depth, color_type, interlace_type, comp_type, filter_type;
	png_get_IHDR(png, png_info, &width, &height, &bit_depth, &color_type, &interlace_type,
				 &comp_type, &filter_type);

	/* RGBA8888フォーマットに変換する */
	if (bit_depth < 8)
	{
		png_set_packing(png);
	}
	else if (bit_depth == 16)
	{
		png_set_strip_16(png);
	}

	uint32_t pixelBytes = 4;
	switch (color_type)
	{
	case PNG_COLOR_TYPE_PALETTE:
		png_set_palette_to_rgb(png);
		pixelBytes = 4;
		break;
	case PNG_COLOR_TYPE_GRAY:
		png_set_expand_gray_1_2_4_to_8(png);
		pixelBytes = 3;
		break;
	case PNG_COLOR_TYPE_RGB:
		pixelBytes = 3;
		break;
	case PNG_COLOR_TYPE_RGBA:
		break;
	}

	uint8_t* image = new uint8_t[width * height * pixelBytes];
	uint32_t pitch = width * pixelBytes;

	/* イメージデータを読み込む */

	textureWidth = width;
	textureHeight = height;
	textureData.resize(textureWidth * textureHeight * 4);

	if (rev)
	{
		for (uint32_t i = 0; i < height; i++)
		{
			png_read_row(png, &image[(height - 1 - i) * pitch], NULL);
		}
	}
	else
	{
		for (uint32_t i = 0; i < height; i++)
		{
			png_read_row(png, &image[i * pitch], NULL);
		}
	}

	if (pixelBytes == 4)
	{
		memcpy(textureData.data(), image, width * height * pixelBytes);
	}
	else
	{
		for (int32_t y = 0; y < height; y++)
		{
			for (int32_t x = 0; x < width; x++)
			{
				int32_t src = (x + y * width) * 3;
				int32_t dst = (x + y * width) * 4;
				textureData[dst + 0] = image[src + 0];
				textureData[dst + 1] = image[src + 1];
				textureData[dst + 2] = image[src + 2];
				textureData[dst + 3] = 255;
			}
		}
	}
	
	delete [] image;
	png_destroy_read_struct(&png, &png_info, NULL);

	return true;
#endif
}
Beispiel #29
0
HRESULT CPDFExport::Export(TCHAR* pathName, IPDDocument* pddoc)
{
	HRESULT hr = E_FAIL;

//	CPDFDoc* pDoc = new CPDFDoc;

//	pDoc.CreateInstance(__uuidof(pDoc));
	hr = m_pdfdoc.CreateInstance("LPDF.PDFPDDoc");

	if (m_pdfdoc)
	{
		if (SUCCEEDED(m_pdfdoc->Create()))
		{
			m_pddoc = pddoc;

	/*

Title// text string (Optional; PDF 1.1) The document’s title.
Author// text string (Optional) The name of the person who created the document.
Subject// text string (Optional; PDF 1.1) The subject of the document.
Keywords// text string (Optional; PDF 1.1) Keywords associated with the document.
Creator// text string (Optional) If the document was converted to PDF from another format, the
name of the application (for example, Adobe FrameMaker®) that created the
original document from which it was converted.
Producer// text string (Optional) If the document was converted to PDF from another format, the
name of the application (for example, Acrobat Distiller) that converted it to
PDF.
CreationDate// date (Optional) The date and time the document was created, in human-readable
form (see Section 3.8.2, “Dates”).
ModDate// date (Optional; PDF 1.1) The date and time the document was most recently
modi.ed, in human-readable form (see Section 3.8.2, “Dates”).
Trapped// name
  */
			m_pdfdoc->SetInfo(L"Title", L"Test PDF dokument");
			m_pdfdoc->SetInfo(L"Author", L"Sigurd Lerstad");
			m_pdfdoc->SetInfo(L"Creator", L"PageDesigner");
			m_pdfdoc->SetInfo(L"Producer", L"PageDesigner");
			//CreationDate
			//ModDate

		// Save images
			CComPtr<IObjectMap> images;
			m_pddoc->get_images(&images);

			long nimages;
			images->get_length(&nimages);

			for (int nimage = 0; nimage < nimages; nimage++)
			{
				CComPtr<IPDImage> image;
				images->item(nimage, (IUnknown**)&image);
				long width, height;
				image->get_width(&width);
				image->get_height(&height);

				LPDFLib::IPDFCosStreamPtr pCosImage = m_pdfdoc->GetCosDoc()->CosNewStream(VARIANT_TRUE, NULL);
				LPDFLib::IPDFCosDictPtr pDict = pCosImage->CosStreamDict();

				image->SetProp(L"cos-image", (DWORD)pCosImage);

				LPDFLib::IPDFCosNamePtr pType = m_pdfdoc->GetCosDoc()->CosNewName(VARIANT_FALSE, "XObject");
				pDict->CosDictPut(L"Type", pType);

				LPDFLib::IPDFCosNamePtr pSubtype = m_pdfdoc->GetCosDoc()->CosNewName(VARIANT_FALSE, "Image");
				pDict->CosDictPut(L"Subtype", pSubtype);

				LPDFLib::IPDFCosIntegerPtr pWidth = m_pdfdoc->GetCosDoc()->CosNewInteger(VARIANT_FALSE, width);
				pDict->CosDictPut(L"Width", pWidth);

				LPDFLib::IPDFCosIntegerPtr pHeight = m_pdfdoc->GetCosDoc()->CosNewInteger(VARIANT_FALSE, height);
				pDict->CosDictPut(L"Height", pHeight);

				LPDFLib::IPDFCosIntegerPtr pBitsPerComponent = m_pdfdoc->GetCosDoc()->CosNewInteger(VARIANT_FALSE, 8);
				pDict->CosDictPut(L"BitsPerComponent", pBitsPerComponent);

				LPDFLib::IPDFCosNamePtr pColorSpace = m_pdfdoc->GetCosDoc()->CosNewName(VARIANT_FALSE, L"DeviceRGB");
				pDict->CosDictPut(L"ColorSpace", pColorSpace);

				{
					LPDFLib::IPDFCosNamePtr pFilter = m_pdfdoc->GetCosDoc()->CosNewName(VARIANT_FALSE, L"ASCIIHexDecode");
					pDict->CosDictPut("Filter", pFilter);

					Gdiplus::Bitmap* pBitmap;
					image->get_privateImage((DWORD*)&pBitmap);

#if 0
					FILE* fp = pCosImage->OpenFStream("wb");
					if (fp)
					{
						Gdiplus::BitmapData bitmapData;
						pBitmap->LockBits(
							&Gdiplus::Rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()),
							Gdiplus::ImageLockModeRead,
							PixelFormat24bppRGB,//PixelFormat32bppARGB,
							&bitmapData);

						for (int y = 0; y < bitmapData.Height; y++)
						{
							BYTE* src = (BYTE*)bitmapData.Scan0 + bitmapData.Stride*y;

							for (int x = 0; x < bitmapData.Width; x++)
							{
								fprintf(fp, "%2.2X%2.2X%2.2X", src[2], src[1], src[0]);
								src += 3;

								if (((y*bitmapData.Width+x) % 200) == 0)
								{
									fprintf(fp, "\r\n");
								}
							}
						}

						pBitmap->UnlockBits(&bitmapData);

						pCosImage->CloseFStream(fp);
					}
#endif
				}
			}

		// Save pages
			CComPtr<IObjectMap> pages;
			m_pddoc->get_pages(&pages);

			long npages;
			pages->get_length(&npages);

			double pageWidth;
			double pageHeight;
			m_pddoc->get_pageWidth(&pageWidth);
			m_pddoc->get_pageHeight(&pageHeight);

			for (int npage = 0; npage < npages; npage++)
			{
				CComPtr<IPDPage> page;
				pages->item(npage, (IUnknown**)&page);

				RectD mediaBox;
				mediaBox.X = 0;
				mediaBox.Y = 0;
				mediaBox.Width = pageWidth;
				mediaBox.Height = pageHeight;

				LPDFLib::IPDFPDPagePtr pPage;
				pPage = m_pdfdoc->CreatePage(npage, 0, 0, pageWidth, pageHeight);
				if (pPage)
				{
					LPDFLib::IPDFEContentPtr pContent;
					pContent = pPage->AcquirePDEContent();

					if (pContent)
					{
						RectD pageRect;
						page->getPageRect(&pageRect);

						CComPtr<IPDMatrix> matpdf;
						{
							CComPtr<IPDMatrix> mat0;
							mat0.CoCreateInstance(CLSID_PDMatrix);

							CComPtr<IPDMatrix> mat1;
							mat0->translate(-pageRect.X, 0, &mat1);

							CComPtr<IPDMatrix> mat2;
							mat1->scaleNonUniform(1, -1, &mat2);

							mat2->translate(0, pageRect.Height, &matpdf);
						}

					// Save objects
						CComPtr<IPDSpread> spread;
						page->get_ownerSpread(&spread);

						CComPtr<IObjectMap> layergroups;
						spread->get_layergroups(&layergroups);

						long nlayergroups;
						layergroups->get_length(&nlayergroups);
						for (long nlayergroup = 0; nlayergroup < nlayergroups; nlayergroup++)
						{
							CComPtr<IPDObjectGroup> pdgroup;
							layergroups->item(nlayergroup, (IUnknown**)&pdgroup);

							SaveObjectGroup(pContent, pdgroup, matpdf, pageRect);
						}

						pPage->ReleasePDEContent();
					}
				}
			}

			hr = m_pdfdoc->Save(pathName);
		}
	}

	return hr;
}
Beispiel #30
-1
static std::pair<bool, String> save_png_gdiplus(const Path &filename, const ImageBW &img)
{
	// gdi+ does not support URIs
	Path winname(filename);
	winname.ToWindows();
	const auto newsize = winname.Size() + 1;
	auto wcstring = std::vector<wchar_t>(newsize);
	auto convertedChars = size_t(0);
	mbstowcs_s(&convertedChars, wcstring.data(), newsize, winname.CStr(), _TRUNCATE);

	Gdiplus::Bitmap *outbm = outbm = new Gdiplus::Bitmap(INT(img.GetWidth()), INT(img.GetHeight()), PixelFormat1bppIndexed);
	if (!outbm)
	{
		return std::make_pair(false, String(_("Cannot create bitmap")));
	}
	Gdiplus::BitmapData bitmapData;
	auto clip = Gdiplus::Rect(0, 0, outbm->GetWidth(), outbm->GetHeight());
	outbm->LockBits(&clip, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, &bitmapData);
	auto *pixels = (uint8_t*)bitmapData.Scan0;
	//#pragma omp parallel for
	FOREACHPIXEL(x, y, img)
	{
		size_t poffset = x / 8 + y * bitmapData.Stride;
		if (img.At(x, y))
		{
			uint8_t b = 1 << (7 - (x % 8));
			pixels[poffset] |= b;
		}
	}