From: Grzegorz Wróbel on
Does it exist? The documantation on standard GDI library and
BITMPAPINFOHEADER mentions BI_JPEG and BI_PNG compression types but I
never saw a working code that would took advantage of that. Seems they
never finished this. But I'm pretty certain there must be some functions
provided with Windows that can open those files, most likely within the
shell, since it has possibility to display thumbnails of different images.

I would like to be able to open jpg file and convert it into 24bpp bmp
in memory, but I don't want to rely on any dll or link against external
library for that. Providing my own jpg decompressor doesn't sound like
best idea either. If operating system already has such feature I would
like to use it if possible. Any thoughts?

--
Grzegorz Wr?bel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
From: alex on

"Grzegorz Wr?bel" </dev/null(a)localhost.localdomain> wrote in message
news:ek29ms$fo3$1(a)nemesis.news.tpi.pl...
> Does it exist? The documantation on standard GDI library and
> BITMPAPINFOHEADER mentions BI_JPEG and BI_PNG compression types but I
> never saw a working code that would took advantage of that. Seems they
> never finished this. But I'm pretty certain there must be some functions
> provided with Windows that can open those files, most likely within the
> shell, since it has possibility to display thumbnails of different images.

This had been asked and answered on microsoft.public.win32.programmer.ui


From: Lucian Wischik on
Grzegorz Wr?bel </dev/null(a)localhost.localdomain> wrote:
>Does it exist? The documantation on standard GDI library and
>BITMPAPINFOHEADER mentions BI_JPEG and BI_PNG compression types but I
>never saw a working code that would took advantage of that. Seems they
>never finished this. But I'm pretty certain there must be some functions
>provided with Windows that can open those files, most likely within the
>shell, since it has possibility to display thumbnails of different images.

// LoadJpeg: given an HGLOBAL containing jpeg data, we load it.
HBITMAP LoadJpeg(HGLOBAL hglob)
{ IStream *stream=0; HRESULT
hr=CreateStreamOnHGlobal(hglob,FALSE,&stream);
if (!SUCCEEDED(hr) || stream==0) return 0;
IPicture *pic; hr=OleLoadPicture(stream, 0, FALSE, IID_IPicture,
(LPVOID*)&pic);
stream->Release();
if (!SUCCEEDED(hr) || pic==0) return 0;
HBITMAP hbm0=0; hr=pic->get_Handle((OLE_HANDLE*)&hbm0);
if (!SUCCEEDED(hr) || hbm0==0) {pic->Release(); return 0;}
//
// Now we make a copy of it into our own hbm
DIBSECTION dibs; GetObject(hbm0,sizeof(dibs),&dibs);
int w=dibs.dsBm.bmWidth, h=dibs.dsBm.bmHeight;
dibs.dsBmih.biClrUsed=0; dibs.dsBmih.biClrImportant=0; void *bits;
HDC sdc=GetDC(0);
HBITMAP
hbm1=CreateDIBSection(sdc,(BITMAPINFO*)&dibs.dsBmih,DIB_RGB_COLORS,&bits,0,0);
//
HDC hdc0=CreateCompatibleDC(sdc), hdc1=CreateCompatibleDC(sdc);
HGDIOBJ hold0=SelectObject(hdc0,hbm0),
hold1=SelectObject(hdc1,hbm1);
BitBlt(hdc1,0,0,w,h,hdc0,0,0,SRCCOPY);
SelectObject(hdc0,hold0); SelectObject(hdc1,hold1);
DeleteDC(hdc0); DeleteDC(hdc1);
ReleaseDC(0,sdc);
pic->Release();
return hbm1;
}

HBITMAP Load(const tstring fn)
{ if (fn.length()==0) return 0;
HBITMAP hbm;
tstring ext = ExtractFileExt(fn);
if (_tcsicmp(_T(".bmp"),ext.c_str())==0)
{
hbm=(HBITMAP)LoadImage(hInstance,fn.c_str(),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
return hbm;
}
HANDLE hf =
CreateFile(fn.c_str(),GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
if (hf==INVALID_HANDLE_VALUE) return 0;
DWORD size=GetFileSize(hf,0);
HGLOBAL hglob = GlobalAlloc(GMEM_MOVEABLE,size);
void *buf=GlobalLock(hglob);
DWORD red; ReadFile(hf,buf,size,&red,0);
GlobalUnlock(hglob);
hbm = LoadJpeg(hglob);
GlobalFree(hglob);
CloseHandle(hf);
return hbm;
}


--
Lucian
From: Grzegorz Wróbel on
alex wrote:
> "Grzegorz Wr?bel" </dev/null(a)localhost.localdomain> wrote in message
> news:ek29ms$fo3$1(a)nemesis.news.tpi.pl...
>> Does it exist? The documantation on standard GDI library and
>> BITMPAPINFOHEADER mentions BI_JPEG and BI_PNG compression types but I
>> never saw a working code that would took advantage of that. Seems they
>> never finished this. But I'm pretty certain there must be some functions
>> provided with Windows that can open those files, most likely within the
>> shell, since it has possibility to display thumbnails of different images.
>
> This had been asked and answered on microsoft.public.win32.programmer.ui
>

Thanks for the tip. I've scanned microsoft.public.win32.programmer.ui.
I found one answer that might be usable for me, it's Microsoft's LoadPic
sample, which uses IPicture interface. I've run on this sample before
but I'd prefer pure WINAPI solution if it were available.


--
Grzegorz Wr?bel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
From: Grzegorz Wróbel on
Lucian Wischik wrote:
> // LoadJpeg: given an HGLOBAL containing jpeg data, we load it.
> HBITMAP LoadJpeg(HGLOBAL hglob)
> { IStream *stream=0; HRESULT
> hr=CreateStreamOnHGlobal(hglob,FALSE,&stream);
> if (!SUCCEEDED(hr) || stream==0) return 0;
> IPicture *pic; hr=OleLoadPicture(stream, 0, FALSE, IID_IPicture,
> (LPVOID*)&pic);
> stream->Release();
> if (!SUCCEEDED(hr) || pic==0) return 0;
> HBITMAP hbm0=0; hr=pic->get_Handle((OLE_HANDLE*)&hbm0);
> if (!SUCCEEDED(hr) || hbm0==0) {pic->Release(); return 0;}
> //
> // Now we make a copy of it into our own hbm
> DIBSECTION dibs; GetObject(hbm0,sizeof(dibs),&dibs);
> int w=dibs.dsBm.bmWidth, h=dibs.dsBm.bmHeight;
> dibs.dsBmih.biClrUsed=0; dibs.dsBmih.biClrImportant=0; void *bits;
> HDC sdc=GetDC(0);
> HBITMAP
> hbm1=CreateDIBSection(sdc,(BITMAPINFO*)&dibs.dsBmih,DIB_RGB_COLORS,&bits,0,0);
> //
> HDC hdc0=CreateCompatibleDC(sdc), hdc1=CreateCompatibleDC(sdc);
> HGDIOBJ hold0=SelectObject(hdc0,hbm0),
> hold1=SelectObject(hdc1,hbm1);
> BitBlt(hdc1,0,0,w,h,hdc0,0,0,SRCCOPY);
> SelectObject(hdc0,hold0); SelectObject(hdc1,hold1);
> DeleteDC(hdc0); DeleteDC(hdc1);
> ReleaseDC(0,sdc);
> pic->Release();
> return hbm1;
> }
>
> HBITMAP Load(const tstring fn)
> { if (fn.length()==0) return 0;
> HBITMAP hbm;
> tstring ext = ExtractFileExt(fn);
> if (_tcsicmp(_T(".bmp"),ext.c_str())==0)
> {
> hbm=(HBITMAP)LoadImage(hInstance,fn.c_str(),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
> return hbm;
> }
> HANDLE hf =
> CreateFile(fn.c_str(),GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
> if (hf==INVALID_HANDLE_VALUE) return 0;
> DWORD size=GetFileSize(hf,0);
> HGLOBAL hglob = GlobalAlloc(GMEM_MOVEABLE,size);
> void *buf=GlobalLock(hglob);
> DWORD red; ReadFile(hf,buf,size,&red,0);
> GlobalUnlock(hglob);
> hbm = LoadJpeg(hglob);
> GlobalFree(hglob);
> CloseHandle(hf);
> return hbm;
> }
>

Thanks Lucian, that's pretty neat code.



--
Grzegorz Wr?bel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D