Jump to content
  • Advertisement

Archived

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

Corrosive

Having problem with a JpegLoad function again!!!

This topic is 5971 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

Hey folks... everything fine? good. Well, i´m having problem with my JPeg Load function and wanna some help. Just dont know what to do anymore... my code follows below: IDirectDrawSurface7 JpegLoad(char *FileName, DDSURFACEDESC2 ddsd){ IJLERR jerr; JPEG_CORE_PROPERTIES jcprops; LPDIRECTDRAWSURFACE7 surface = NULL; ZeroMemory( &jcprops, sizeof( JPEG_CORE_PROPERTIES ) ); BYTE* jcpropsdata; jerr = ijlInit(&jcprops); if (jerr != IJL_OK) erro((char *)ijlErrorStr(jerr)); jcprops.JPGFile = const_cast(FileName); jerr = ijlRead(&jcprops, IJL_JFILE_READPARAMS); if (jerr != IJL_OK) erro((char *)ijlErrorStr(jerr)); jcpropsdata = new BYTE[jcprops.JPGWidth * jcprops.JPGHeight * jcprops.JPGChannels]; switch(jcprops.JPGChannels) { case 1: jcprops.JPGColor = IJL_BGR; break; case 3: jcprops.JPGColor = IJL_BGR; break; default: jcprops.DIBColor = (IJL_COLOR)IJL_OTHER; jcprops.JPGColor = (IJL_COLOR)IJL_OTHER; jcprops.DIBChannels = jcprops.JPGChannels; break; } jcprops.DIBWidth = jcprops.JPGWidth; jcprops.DIBHeight = jcprops.JPGHeight; jcprops.DIBPadBytes = IJL_DIB_PAD_BYTES(jcprops.DIBWidth,jcprops.DIBChannels); int jcpropssize = (jcprops.DIBWidth * jcprops.DIBChannels + jcprops.DIBPadBytes) * jcprops.DIBHeight; jcpropsdata = new BYTE[ jcpropssize ]; if(jcpropsdata == NULL) erro("Erro de alocação de memória para JCPROPSDATA!"); jcprops.DIBBytes = reinterpret_cast(jcpropsdata); jerr = ijlRead(&jcprops, IJL_JFILE_READWHOLEIMAGE); if (jerr != IJL_OK){ erro((char *)ijlErrorStr(jerr)); delete[] jcpropsdata; } HBITMAP hbm; hbm = CreateBitmap (jcprops.JPGWidth, jcprops.JPGHeight, 1, 24, jcpropsdata); if(hbm == NULL) erro("Erro ao criar estrutura BitMap"); ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = jcprops.JPGWidth; ddsd.dwHeight = jcprops.JPGHeight; G.ddrval = G.lpdd->CreateSurface(&ddsd, &surface, NULL); if (G.ddrval != DD_OK) erro("Erro ao criar superfície de textura para JPEG"); DDCopyBitmap(surface, hbm, 0, 0, 0, 0); delete[] jcpropsdata; ijlFree(&jcprops); return surface; } maybe the problem is in other part of the code, but it compiels and links well without any error nor warning... It just shows a black screen with white lines and some colored pixels around... Please, any help will be useful... I´m beginner to advanced programmer but have never programmed very much with graphics file formats, and i have little experience in this area. Bye! To code is to make things come to life

Share this post


Link to post
Share on other sites
Advertisement
You don''t say what the problem actually is.

Is the file being read okay, but not being copied to the surface?

Have you tried creating a test image saved as JPEG with (maybe) alternating white black pixels to see if the ''jcpropsdata'' structure is being filled correctly?

Looks like you are using the Intel libraries. Is this correct?
If so, have you tried to get the example loader working?
Can''t help much until you say what you''ve tried!

Share this post


Link to post
Share on other sites
Thanks for replying to my post. Actually, i trried just code implementatios to see what is happening. I teste the loader from Intel Library(Yes, i´m using Intel Library) and it worked fine.
I will try to catch the data inside the jcpropsdata to see if it is filled correctly... And the problem is that, if im correct, it is loading wrong to surface, because i made some error codes as you can see, to see if the function return properly results! It compiles correct, runs, but dont show anything but a black screen with white banners and some pixels lost in the surface, its like garbage of the memory you know!

Havy any other clue of what can be happening? If you need some other information, please ask and i will be happy to post anything else i can...


To code is to make things come to life

Share this post


Link to post
Share on other sites
Thanks for replying to my post. Actually, i trried just code implementatios to see what is happening. I teste the loader from Intel Library(Yes, i´m using Intel Library) and it worked fine.
I will try to catch the data inside the jcpropsdata to see if it is filled correctly... And the problem is that, if im correct, it is loading wrong to surface, because i made some error codes as you can see, to see if the function return properly results! It compiles correct, runs, but dont show anything but a black screen with white banners and some pixels lost in the surface, its like garbage of the memory you know!

Have any other clue of what can be happening? If you need some other information, please ask and i will be happy to post anything else i can...


To code is to make things come to life

Share this post


Link to post
Share on other sites
No, it was wrong and i made it to retur IDirectDrawSurface7 * now... but still having the same problem...

I rewrote all the code by a different implementation this morning and it does not work, as i can see the problem is that it is not reading the image right.. Because i alocate the buffer correctly in the DX surface. I wonder what is wrong!

this is my new code: (its long...)

IDirectDrawSurface7 *JpegLoad(char *FileName, DDSURFACEDESC2 ddsd){

IJLERR jerr;
JPEG_CORE_PROPERTIES jcprops;
LPDIRECTDRAWSURFACE7 surface = NULL;
bool bres;

ZeroMemory( &jcprops, sizeof( JPEG_CORE_PROPERTIES ) );

BYTE* jcpropsdata;

DWORD x = 0;
DWORD y = 0;
DWORD c = 0;
DWORD wholeimage;
DWORD dib_line_width;
DWORD dib_pad_bytes;
BITMAPINFOHEADER* bmih;

bres = TRUE;

__try
{
jerr = ijlInit(&jcprops);
if(IJL_OK != jerr)
{
bres = FALSE;
__leave;
}

jcprops.JPGFile = const_cast(FileName);
jerr = ijlRead(&jcprops, IJL_JFILE_READPARAMS);
if(IJL_OK != jerr)
{
bres = FALSE;
__leave;
}
x = jcprops.JPGWidth;
y = jcprops.JPGHeight;
c = 3;

dib_line_width = x * c;
dib_pad_bytes = IJL_DIB_PAD_BYTES(x,c);

wholeimage = (dib_line_width + dib_pad_bytes) * y;

jcpropsdata = new BYTE[sizeof(BITMAPINFOHEADER) + wholeimage];
if(NULL == jcpropsdata)
{
bres = FALSE;
__leave;
}

bmih = reinterpret_cast(jcpropsdata);

bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = x;
bmih->biHeight = y;
bmih->biPlanes = 1;
bmih->biBitCount = 24;
bmih->biCompression = BI_RGB;
bmih->biSizeImage = 0;
bmih->biXPelsPerMeter = 0;
bmih->biYPelsPerMeter = 0;
bmih->biClrUsed = 0;
bmih->biClrImportant = 0;



jcprops.DIBWidth = x;
jcprops.DIBHeight = y;
jcprops.DIBChannels = c;
jcprops.DIBColor = IJL_BGR;
jcprops.DIBPadBytes = dib_pad_bytes;
jcprops.DIBBytes = reinterpret_cast(jcpropsdata + sizeof(BITMAPINFOHEADER));


switch(jcprops.JPGChannels)
{
case 1:
{
jcprops.JPGColor = IJL_G;
break;
}
case 3:
{
jcprops.JPGColor = IJL_YCBCR;
break;
}
default:
{
jcprops.DIBColor = (IJL_COLOR)IJL_OTHER;
jcprops.JPGColor = (IJL_COLOR)IJL_OTHER;
break;
}
}

jerr = ijlRead(&jcprops, IJL_JFILE_READWHOLEIMAGE);
if(IJL_OK != jerr)
{
bres = FALSE;
__leave;
}

HBITMAP hbm;

hbm = CreateBitmap (bmih->biWidth, bmih->biHeight, 1, 24, jcpropsdata);
if(hbm == NULL)

erro("Erro ao criar estrutura BitMap");


ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bmih->biWidth;
ddsd.dwHeight = bmih->biHeight;

G.ddrval = G.lpdd->CreateSurface(&ddsd, &surface, NULL);
if (G.ddrval != DD_OK)

erro("Erro ao criar superfície de textura para JPEG");


DDCopyBitmap(surface, hbm, 0, 0, 0, 0);
}

__finally
{
if(FALSE == bres)
{
if(NULL != jcpropsdata)
{
delete [] jcpropsdata;
jcpropsdata = NULL;
}
}
ijlFree(&jcprops);
}

return surface;

}


To code is to make things come to life

Share this post


Link to post
Share on other sites
Just to get up to date, i still didn´t come to a solution with the problem!!!

To code is to make things come to life

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!