• Advertisement

Archived

This topic is now archived and is closed to further replies.

Image File to Surface

This topic is 6379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i got that intel jpg library and i want to know how to load those images to it to a surface. there is the library http://developer.intel.com/vtune/perflibst/ijl/index.htm Edited by - xmxdf2 on 9/1/00 1:18:03 AM

Share this post


Link to post
Share on other sites
Advertisement
Hi.

This function only works with D3DX library.
Try with this:

LPDIRECTDRAWSURFACE7 LoadJPG(char *jpgFile)
{
JPEG_CORE_PROPERTIES jcprop;
BYTE *mem, *pRGBData;

FILE *fp = fopen(jpgFile, "rb");
fseek(fp, 0, SEEK_END);
DWORD size = ftell(fp);
mem = new char[size];
fseek(fp, 0, SEEK_SET);
fread(mem, 1, size, fp);
fclose(fp);

memset(&jcprop, 0, sizeof(JPEG_CORE_PROPERTIES));

if( ijlInit( &jcprop ) != IJL_OK )
{
return NULL;
}


jcprop.JPGBytes = mem;
jcprop.JPGSizeBytes = size;
if( ijlRead( &jcprop, IJL_JBUFF_READPARAMS ) != IJL_OK )
{
return NULL;
}

int imageSize = jcprop.JPGWidth*jcprop.JPGHeight*jcprop.JPGChannels;

pRGBData = new BYTE[imageSize];
if (!pRGBData)
{
return NULL;
}

jcprop.DIBWidth = jcprop.JPGWidth;
jcprop.DIBHeight = jcprop.JPGHeight;
jcprop.DIBChannels = jcprop.JPGChannels;
jcprop.DIBBytes = pRGBData;

switch(jcprop.JPGChannels)
{
case 1:
jcprop.DIBColor = IJL_G;
break;
default:
case 3:
jcprop.DIBColor = IJL_RGB;
break;
}


if( ijlRead( &jcprop, IJL_JBUFF_READWHOLEIMAGE ) != IJL_OK )
{
delete[] pRGBData;
pRGBData = NULL;
return NULL;
}

if( ijlFree( &jcprop ) != IJL_OK )
{
return NULL;
}

DWORD *pRGBAData = new DWORD[jcprop.JPGWidth*jcprop.JPGHeight];
for(int i = 0; i < jcprop.JPGWidth * jcprop.JPGHeight; i++)
{
BYTE r = pRGBData[i * jcprop.JPGChannels + 0];
BYTE g = pRGBData[i * jcprop.JPGChannels + 1];
BYTE b = pRGBData[i * jcprop.JPGChannels + 2];
BYTE a = 0xff;

pRGBAData = (a << 24L) + (r << 16L) + (g << 8L) + (b);
}
delete[] pRGBData;

LPDIRECTDRAWSURFACE7 pSurface = NULL;

DWORD flags = D3DX_TEXTURE_NOMIPMAP;
DWORD width = jcprop.JPGWidth;
DWORD height = jcprop.JPGHeight;

D3DX_SURFACEFORMAT sf = D3DX_SF_A8R8G8B8;
D3DXCreateTexture(
m_pD3DDev,
&flags,
&width,
&height,
&sf,
NULL,
&pSurface,
0);
D3DXLoadTextureFromMemory(
m_pD3DDev,
pSurface,
0,
(DWORD *)pRGBAData,
NULL,
sf,
0,
NULL,
D3DX_FT_LINEAR);

delete[] pRGBAData;

return pSurface;
}

I hope it helps you!!.

Share this post


Link to post
Share on other sites

  • Advertisement