Esempio n. 1
0
Gdiplus::Bitmap* GdiplusUtilities::FromHICON32(HICON hIcon)
{
	Gdiplus::Bitmap* ret = NULL;
	ICONINFO iconInfo;
	GetIconInfo(hIcon, &iconInfo);
	BITMAP bitmapData;
	GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bitmapData);

	if (bitmapData.bmBitsPixel != 32)
		ret = Gdiplus::Bitmap::FromHICON(hIcon);
	else
	{
		ret = new Gdiplus::Bitmap(bitmapData.bmWidth, bitmapData.bmHeight, PixelFormat32bppARGB);
		Gdiplus::BitmapData bmpData;
		ret->LockBits(&Gdiplus::Rect(0,0,bitmapData.bmWidth, bitmapData.bmHeight), Gdiplus::ImageLockModeWrite, PixelFormat32bppARGB, &bmpData);
#ifndef GetDIBitsVERSION
		//===Version GetBitmapBits
		// THIS FUNCTION IS UNDER TESTING. WHAT IF THE bitmap stride is different? Where will the new data go?
		ASSERT(bmpData.Stride == bmpData.Width * 4);
		::GetBitmapBits(iconInfo.hbmColor, 4 * bitmapData.bmWidth * bitmapData.bmHeight, bmpData.Scan0);
		//===Version GetBitmapBits===END
#else
		//===Version GetDIBits (incomplete)
		::GetDIBits(GetDC(), iconInfo.hbmColor, 0, bitmapData.bm)
			//===Version GetDIBits
#endif
			ret->UnlockBits(&bmpData);
	} 
	DeleteObject(iconInfo.hbmColor);
	DeleteObject(iconInfo.hbmMask);
	return ret;
}
Esempio n. 2
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 );
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
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;
}
Esempio n. 5
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;
}
bool DxFont::BuildFontSheetTexture(Gdiplus::Bitmap & fontSheetBitmap)
{
    Gdiplus::BitmapData bmData;

    fontSheetBitmap.LockBits(&Gdiplus::Rect(0, 0, TexWidth, TexHeight ), Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bmData);  

    D3D11_TEXTURE2D_DESC texDesc;
    texDesc.Width                = TexWidth;
    texDesc.Height               = TexHeight;
    texDesc.MipLevels            = 1;
    texDesc.ArraySize            = 1;
    texDesc.Format               = DXGI_FORMAT_B8G8R8A8_UNORM;
    texDesc.SampleDesc.Count     = 1;
    texDesc.SampleDesc.Quality   = 0;
    texDesc.Usage                = D3D11_USAGE_IMMUTABLE;
    texDesc.BindFlags            = D3D11_BIND_SHADER_RESOURCE;
    texDesc.CPUAccessFlags       = 0;
    texDesc.MiscFlags            = 0;

    D3D11_SUBRESOURCE_DATA data;        
    data.pSysMem            = bmData.Scan0;
    data.SysMemPitch        = TexWidth * 4;
    data.SysMemSlicePitch   = 0;

    if(FAILED(Globals::Get().device.m_device->CreateTexture2D(&texDesc, &data, &FontSheetTex )))
        assert(false);

    D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
    srvDesc.Format                       = DXGI_FORMAT_B8G8R8A8_UNORM;
    srvDesc.ViewDimension                = D3D11_SRV_DIMENSION_TEXTURE2D;
    srvDesc.Texture2D.MipLevels          = 1;
    srvDesc.Texture2D.MostDetailedMip    = 0;

    if(FAILED(Globals::Get().device.m_device->CreateShaderResourceView(FontSheetTex, &srvDesc, &FontSheetSRV)))
        assert(false);

    fontSheetBitmap.UnlockBits(&bmData);  

    return true;
}
Esempio n. 7
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;
	}
Esempio n. 8
0
static Image *ReadEMFImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
{
  Gdiplus::Bitmap
    *bitmap;

  Gdiplus::BitmapData
     bitmap_data;

  Gdiplus::GdiplusStartupInput
    startup_input;

  Gdiplus::Graphics
    *graphics;

  Gdiplus::Image
    *source;

  Gdiplus::Rect
    rect;

  GeometryInfo
    geometry_info;

  Image
    *image;

  MagickStatusType
    flags;

  register Quantum
    *q;

  register ssize_t
    x;

  ssize_t
    y;

  ULONG_PTR
    token;

  unsigned char
    *p;

  wchar_t
    fileName[MagickPathExtent];

  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);

  image=AcquireImage(image_info,exception);
  if (Gdiplus::GdiplusStartup(&token,&startup_input,NULL) != 
    Gdiplus::Status::Ok)
    ThrowReaderException(CoderError, "GdiplusStartupFailed");
  MultiByteToWideChar(CP_UTF8,0,image->filename,-1,fileName,MagickPathExtent);
  source=Gdiplus::Image::FromFile(fileName);
  if (source == (Gdiplus::Image *) NULL)
    {
      Gdiplus::GdiplusShutdown(token);
      ThrowReaderException(FileOpenError,"UnableToOpenFile");
    }

  image->resolution.x=source->GetHorizontalResolution();
  image->resolution.y=source->GetVerticalResolution();
  image->columns=(size_t) source->GetWidth();
  image->rows=(size_t) source->GetHeight();
  if (image_info->density != (char *) NULL)
    {
      flags=ParseGeometry(image_info->density,&geometry_info);
      image->resolution.x=geometry_info.rho;
      image->resolution.y=geometry_info.sigma;
      if ((flags & SigmaValue) == 0)
        image->resolution.y=image->resolution.x;
      if ((image->resolution.x > 0.0) && (image->resolution.y > 0.0))
        {
          image->columns=(size_t) floor((Gdiplus::REAL) source->GetWidth() /
            source->GetHorizontalResolution() * image->resolution.x + 0.5);
          image->rows=(size_t)floor((Gdiplus::REAL) source->GetHeight() /
            source->GetVerticalResolution() * image->resolution.y + 0.5);
        }
    }

  bitmap=new Gdiplus::Bitmap((INT) image->columns,(INT) image->rows,
    PixelFormat32bppARGB);
  graphics=Gdiplus::Graphics::FromImage(bitmap);
  graphics->SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
  graphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
  graphics->SetTextRenderingHint(Gdiplus::TextRenderingHintClearTypeGridFit);
  graphics->Clear(Gdiplus::Color((BYTE) ScaleQuantumToChar(
    image->background_color.alpha),(BYTE) ScaleQuantumToChar(
    image->background_color.red),(BYTE) ScaleQuantumToChar(
    image->background_color.green),(BYTE) ScaleQuantumToChar(
    image->background_color.blue)));
  graphics->DrawImage(source,0,0,(INT) image->columns,(INT) image->rows);
  delete graphics;
  delete source;

  rect=Gdiplus::Rect(0,0,(INT) image->columns,(INT) image->rows);
  if (bitmap->LockBits(&rect,Gdiplus::ImageLockModeRead,PixelFormat32bppARGB,
    &bitmap_data) != Gdiplus::Ok)
  {
    delete bitmap;
    Gdiplus::GdiplusShutdown(token);
    ThrowReaderException(FileOpenError,"UnableToReadImageData");
  }

  image->alpha_trait=BlendPixelTrait;
  for (y=0; y < (ssize_t) image->rows; y++)
  {
    p=(unsigned char *) bitmap_data.Scan0+(y*abs(bitmap_data.Stride));
    if (bitmap_data.Stride < 0)
      q=GetAuthenticPixels(image,0,image->rows-y-1,image->columns,1,exception);
    else
      q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
    if (q == (Quantum *) NULL)
      break;

    for (x=0; x < (ssize_t) image->columns; x++)
    {
      SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
      SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
      SetPixelRed(image,ScaleCharToQuantum(*p++),q);
      SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
      q+=GetPixelChannels(image);
    }

    if (SyncAuthenticPixels(image,exception) == MagickFalse)
      break;
  }

  bitmap->UnlockBits(&bitmap_data);
  delete bitmap;
  Gdiplus::GdiplusShutdown(token);
  return(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;
	
}
Esempio n. 10
0
//*************************************************************************************************************
GLuint LoadTexture(const std::wstring& file)
{
	GLuint texid = 0;
	Gdiplus::Bitmap* bitmap = LoadPicture(file);

	if( bitmap )
	{ 
		if( bitmap->GetLastStatus() == Gdiplus::Ok )
		{
			Gdiplus::BitmapData data;
			unsigned char* tmpbuff;

			bitmap->LockBits(0, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &data);

			tmpbuff = new unsigned char[data.Width * data.Height * 4];
			memcpy(tmpbuff, data.Scan0, data.Width * data.Height * 4);

			for( UINT i = 0; i < data.Height; ++i )
			{
				// swap red and blue
				for( UINT j = 0; j < data.Width; ++j )
				{
					UINT index = (i * data.Width + j) * 4;
					std::swap<unsigned char>(tmpbuff[index + 0], tmpbuff[index + 2]);
				}

				// flip on X
				for( UINT j = 0; j < data.Width / 2; ++j )
				{
					UINT index1 = (i * data.Width + j) * 4;
					UINT index2 = (i * data.Width + (data.Width - j - 1)) * 4;

					std::swap<unsigned int>(*((unsigned int*)(tmpbuff + index1)), *((unsigned int*)(tmpbuff + index2)));
				}
			}

			glGenTextures(1, &texid);
			glBindTexture(GL_TEXTURE_2D, texid);

			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

			glBindTexture(GL_TEXTURE_2D, texid);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data.Width, data.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpbuff);
			glBindTexture(GL_TEXTURE_2D, 0);

			GLenum err = glGetError();

			if( err != GL_NO_ERROR )
				MYERROR("Could not create texture")
			else
				std::cout << "Created texture " << data.Width << "x" << data.Height << "\n";

			bitmap->UnlockBits(&data);
			delete[] tmpbuff;
		}

		delete bitmap;
	}
Esempio n. 11
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;
	}
Esempio n. 12
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 );
}
Esempio n. 13
0
void OutlineText::GdiRenderFontShadow(	
   Gdiplus::Graphics* pGraphics, 
   LOGFONTW* pLogFont,
   const wchar_t*pszText, 
   Gdiplus::Rect rtDraw)
{
	Gdiplus::Bitmap* pBmpMask = 
		m_pBkgdBitmap->Clone(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight(), PixelFormat32bppARGB);

	Gdiplus::Bitmap* pBmpFontBodyBackup = 
		m_pBkgdBitmap->Clone(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight(), PixelFormat32bppARGB);

	Gdiplus::Graphics graphicsMask((Gdiplus::Image*)(pBmpMask));
	Gdiplus::SolidBrush brushBlack(Gdiplus::Color(0,0,0));
	graphicsMask.FillRectangle(&brushBlack, 0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight() );

	Gdiplus::Bitmap* pBmpDisplay = 
		m_pBkgdBitmap->Clone(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight(), PixelFormat32bppARGB);
	Gdiplus::Graphics graphicsBkgd((Gdiplus::Image*)(pBmpDisplay));

	graphicsMask.SetCompositingMode(pGraphics->GetCompositingMode());
	graphicsMask.SetCompositingQuality(pGraphics->GetCompositingQuality());
	graphicsMask.SetInterpolationMode(pGraphics->GetInterpolationMode());
	graphicsMask.SetSmoothingMode(pGraphics->GetSmoothingMode());
	graphicsMask.SetTextRenderingHint(pGraphics->GetTextRenderingHint());
	graphicsMask.SetPageUnit(pGraphics->GetPageUnit());
	graphicsMask.SetPageScale(pGraphics->GetPageScale());

	graphicsBkgd.SetCompositingMode(pGraphics->GetCompositingMode());
	graphicsBkgd.SetCompositingQuality(pGraphics->GetCompositingQuality());
	graphicsBkgd.SetInterpolationMode(pGraphics->GetInterpolationMode());
	graphicsBkgd.SetSmoothingMode(pGraphics->GetSmoothingMode());
	graphicsBkgd.SetTextRenderingHint(pGraphics->GetTextRenderingHint());
	graphicsBkgd.SetPageUnit(pGraphics->GetPageUnit());
	graphicsBkgd.SetPageScale(pGraphics->GetPageScale());

	m_pFontBodyShadow->GdiDrawString(
		&graphicsMask, 
		pLogFont,
		pszText, 
		rtDraw );

	m_pShadowStrategy->GdiDrawString(		
		&graphicsBkgd, 
		pLogFont,
		pszText, 
		rtDraw);

	UINT* pixelsSrc = NULL;
	UINT* pixelsDest = NULL;
	UINT* pixelsMask = NULL;

	using namespace Gdiplus;

	BitmapData bitmapDataSrc;
	BitmapData bitmapDataDest;
	BitmapData bitmapDataMask;
	Rect rect(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight() );

	pBmpFontBodyBackup->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataSrc );

	pBmpDisplay->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataDest );

	pBmpMask->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataMask );


	// Write to the temporary buffer provided by LockBits.
	pixelsSrc = (UINT*)bitmapDataSrc.Scan0;
	pixelsDest = (UINT*)bitmapDataDest.Scan0;
	pixelsMask = (UINT*)bitmapDataMask.Scan0;

	if( !pixelsSrc || !pixelsDest || !pixelsMask)
		return;

	UINT col = 0;
	int stride = bitmapDataDest.Stride >> 2;
	if(m_bDiffuseShadow&&!m_bExtrudeShadow)
	{
		for(UINT row = 0; row < bitmapDataDest.Height; ++row)
		{
			for(col = 0; col < bitmapDataDest.Width; ++col)
			{
				using namespace Gdiplus;
				UINT index = row * stride + col;
				BYTE nAlpha = pixelsMask[index] & 0xff;
				UINT clrShadow = 0xff000000 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
				if(nAlpha>0)
				{
					UINT clrtotal = clrShadow;
					for(int i=2;i<=m_nShadowThickness; ++i)
						pixelsSrc[index] = Alphablend(pixelsSrc[index],clrtotal,m_clrShadow.GetA());

					pixelsDest[index] = pixelsSrc[index];
				}
			}
		}
	}
	else
	{
		for(UINT row = 0; row < bitmapDataDest.Height; ++row)
		{
			for(col = 0; col < bitmapDataDest.Width; ++col)
			{
				using namespace Gdiplus;
				UINT index = row * stride + col;
				BYTE nAlpha = pixelsMask[index] & 0xff;
				UINT clrShadow = 0xff000000 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
				if(nAlpha>0)
					pixelsDest[index] = Alphablend(pixelsSrc[index],clrShadow,m_clrShadow.GetA());
			}
		}
	}
	pBmpMask->UnlockBits(&bitmapDataMask);
	pBmpDisplay->UnlockBits(&bitmapDataDest);
	pBmpFontBodyBackup->UnlockBits(&bitmapDataSrc);

	pGraphics->DrawImage(pBmpDisplay,0,0,pBmpDisplay->GetWidth(),pBmpDisplay->GetHeight());

	if(pBmpMask)
	{
		delete pBmpMask;
		pBmpMask = NULL;
	}
	if(pBmpFontBodyBackup)
	{
		delete pBmpFontBodyBackup;
		pBmpFontBodyBackup = NULL;
	}
	if(pBmpDisplay)
	{
		delete pBmpDisplay;
		pBmpDisplay = NULL;
	}
}
Esempio n. 14
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;
}
Esempio n. 15
0
bool PngOutlineText::RenderFontShadow(	
	Gdiplus::Graphics* pGraphicsDrawn, 
	Gdiplus::Graphics* pGraphicsMask,
	Gdiplus::Bitmap* pBitmapDrawn,
	Gdiplus::Bitmap* pBitmapMask,
	Gdiplus::FontFamily* pFontFamily,
	Gdiplus::FontStyle fontStyle,
	int nfontSize,
	const wchar_t*pszText, 
	Gdiplus::Rect rtDraw, 
	Gdiplus::StringFormat* pStrFormat)
{
	if(!pGraphicsDrawn||!pGraphicsMask||!pBitmapDrawn||!pBitmapMask) return false;

	Gdiplus::Bitmap* pBitmapShadowMask = 
		m_pPngBitmap->Clone(0, 0, m_pPngBitmap->GetWidth(), m_pPngBitmap->GetHeight(), PixelFormat32bppARGB);

	Gdiplus::Graphics* pGraphicsShadowMask = new Gdiplus::Graphics((Gdiplus::Image*)(pBitmapShadowMask));
	Gdiplus::SolidBrush brushBlack(Gdiplus::Color(0,0,0));
	pGraphicsShadowMask->FillRectangle(&brushBlack, 0, 0, m_pPngBitmap->GetWidth(), m_pPngBitmap->GetHeight() );

	pGraphicsShadowMask->SetCompositingMode(pGraphicsDrawn->GetCompositingMode());
	pGraphicsShadowMask->SetCompositingQuality(pGraphicsDrawn->GetCompositingQuality());
	pGraphicsShadowMask->SetInterpolationMode(pGraphicsDrawn->GetInterpolationMode());
	pGraphicsShadowMask->SetSmoothingMode(pGraphicsDrawn->GetSmoothingMode());
	pGraphicsShadowMask->SetTextRenderingHint(pGraphicsDrawn->GetTextRenderingHint());
	pGraphicsShadowMask->SetPageUnit(pGraphicsDrawn->GetPageUnit());
	pGraphicsShadowMask->SetPageScale(pGraphicsDrawn->GetPageScale());

	bool b = false;

	b = m_pFontBodyShadowMask->DrawString(
		pGraphicsMask, 
		pFontFamily,
		fontStyle,
		nfontSize,
		pszText, 
		rtDraw, 
		pStrFormat);

	if(!b) return false;

	b = m_pShadowStrategyMask->DrawString(		
		pGraphicsShadowMask, 
		pFontFamily,
		fontStyle,
		nfontSize,
		pszText, 
		rtDraw, 
		pStrFormat);

	if(!b) return false;

	b = m_pFontBodyShadow->DrawString(
		pGraphicsDrawn, 
		pFontFamily,
		fontStyle,
		nfontSize,
		pszText, 
		rtDraw, 
		pStrFormat);

	if(!b) return false;

	b = m_pShadowStrategy->DrawString(		
		pGraphicsDrawn, 
		pFontFamily,
		fontStyle,
		nfontSize,
		pszText, 
		rtDraw, 
		pStrFormat);

	if(!b) return false;

	UINT* pixelsDest = NULL;
	UINT* pixelsMask = NULL;
	UINT* pixelsShadowMask = NULL;

	using namespace Gdiplus;

	BitmapData bitmapDataDest;
	BitmapData bitmapDataMask;
	BitmapData bitmapDataShadowMask;
	Rect rect(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight() );

	pBitmapDrawn->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataDest );

	pBitmapMask->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataMask );

	pBitmapShadowMask->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataShadowMask );

	pixelsDest = (UINT*)bitmapDataDest.Scan0;
	pixelsMask = (UINT*)bitmapDataMask.Scan0;
	pixelsShadowMask = (UINT*)bitmapDataShadowMask.Scan0;

	if( !pixelsDest || !pixelsMask || !pixelsShadowMask )
		return false;

	UINT col = 0;
	int stride = bitmapDataDest.Stride >> 2;
	for(UINT row = 0; row < bitmapDataDest.Height; ++row)
	{
		for(col = 0; col < bitmapDataDest.Width; ++col)
		{
			using namespace Gdiplus;
			UINT index = row * stride + col;
			BYTE nAlpha = pixelsMask[index] & 0xff;
			BYTE nAlphaShadow = pixelsShadowMask[index] & 0xff;
			if(nAlpha>0&&nAlpha>nAlphaShadow)
			{
				pixelsDest[index] = nAlpha << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
			}
			else if(nAlphaShadow>0)
			{
				pixelsDest[index] = nAlphaShadow << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
				pixelsMask[index] = pixelsShadowMask[index];
			}
		}
	}

	pBitmapShadowMask->UnlockBits(&bitmapDataShadowMask);
	pBitmapMask->UnlockBits(&bitmapDataMask);
	pBitmapDrawn->UnlockBits(&bitmapDataDest);

	if(pGraphicsShadowMask)
	{
		delete pGraphicsShadowMask;
		pGraphicsShadowMask = NULL;
	}

	if(pBitmapShadowMask)
	{
		delete pBitmapShadowMask;
		pBitmapShadowMask = NULL;
	}

	return true;
}
Esempio n. 16
0
void Bitmap::UnlockBits(BitmapData* data) {
    Gdiplus::BitmapData* bd = reinterpret_cast<Gdiplus::BitmapData*>(data->_private);
    Gdiplus::Bitmap* gdiBitmap = dynamic_cast<Gdiplus::Bitmap*>(reinterpret_cast<Gdiplus::Image*>(_private));
    gdiBitmap->UnlockBits(bd);
}
Esempio n. 17
-1
//---------------------------------------------------------------------------
HRESULT CreateAtlasTexture(ID3D11Device* device, Gdiplus::Bitmap& fontSheetBitmap, const FontAtlasSizeInfo* pSizeInfo,
    ID3D11Texture2D** ppD3dTexture, ID3D11ShaderResourceView** ppD3dShaderResourceView )
{
    using namespace Gdiplus;

	HRESULT hr = S_OK;

	// Lock the bitmap for direct memory access
	BitmapData bmData;
    Rect rect(0, 0, pSizeInfo->atlasTextureWidth, pSizeInfo->atlasTextureHeight );
	fontSheetBitmap.LockBits(&rect,ImageLockModeRead, PixelFormat32bppARGB, &bmData);  

	// Copy into a texture.
	D3D11_TEXTURE2D_DESC texDesc;
	texDesc.Width  = pSizeInfo->atlasTextureWidth;
	texDesc.Height = pSizeInfo->atlasTextureHeight;
	texDesc.MipLevels = 1;
	texDesc.ArraySize = 1;
	texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	texDesc.SampleDesc.Count = 1;
	texDesc.SampleDesc.Quality = 0;
	texDesc.Usage = D3D11_USAGE_IMMUTABLE;
	texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0;
	texDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA data;        
	data.pSysMem = bmData.Scan0;
	data.SysMemPitch = pSizeInfo->atlasTextureWidth * 4;
	data.SysMemSlicePitch = 0;

	hr = device->CreateTexture2D(&texDesc, &data, ppD3dTexture );
	if(FAILED(hr))
		return hr;

	D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
	srvDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	srvDesc.Texture2D.MipLevels = 1;
	srvDesc.Texture2D.MostDetailedMip = 0;

	hr = device->CreateShaderResourceView(*ppD3dTexture, &srvDesc, ppD3dShaderResourceView );
	if(FAILED(hr))
		return hr;

	fontSheetBitmap.UnlockBits(&bmData);  

	return hr;
}