JPEG file headers - where?

Hei !

I have already sent this question yesterday:
How can I read JPEG files (.JPG) into my C/C++-program
like I'm reading Bitmap-files (.BMP):
_hread ( hfReadFile, &bmFile, sizeof(BITMAPFILEHEADER));
_hread ( hfReadFile, &bmInfo, sizeof(BITMAPINFOHEADER));
if     ( bmInfo.biBitCount == 1 )
...

I don't find .JPG - file structures anywhere like .BMP - file structures are in WINGDI.H:
...
* wingdi.h -- GDI procedure declarations, constant definitions and macros *
...
typedef struct tagBITMAPFILEHEADER {
        WORD    bfType;
        DWORD   bfSize;
        WORD    bfReserved1;
        WORD    bfReserved2;
        DWORD   bfOffBits;
} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
...
typedef struct tagBITMAPINFOHEADER{
        DWORD      biSize;
        LONG       biWidth;
        LONG       biHeight;
        WORD       biPlanes;
        WORD       biBitCount;
        DWORD      biCompression;
        DWORD      biSizeImage;
        LONG       biXPelsPerMeter;
        LONG       biYPelsPerMeter;
        DWORD      biClrUsed;
        DWORD      biClrImportant;
} BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
...


I have Windows XP and MS Visual Studio 6.0 C/C++

Rgds Eero Aura
Aarontie 9
51200 Kangasniemi
Finland
eero.aura@fi.abb.com

EeroAuraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fridomCEO/ProgrammerCommented:
Fetch a library from
http://en.wikipedia.org/wiki/Libjpeg


Regards
Friedrich
0
Infinity08Commented:
For file formats, I always visit this site first :

      http://www.wotsit.org/list.asp?al=J

You can find the file format spec docs on there ...
0
ethan_mmgCommented:
If you're interested in using GDI+:

#include <memory>
#include <windows.h>
#include <gdiplus.h>

class ERMemDC
{
    public:
        explicit ERAPI ERMemDC(const HDC hdc=0) ERNOTHROW() :
            p_hdcMem(::CreateCompatibleDC(hdc)),
            p_hwndParent(0),
            p_isMem(true) { }

        explicit ERAPI ERMemDC(const HWND hwnd) ERNOTHROW() :
            p_hdcMem(::GetDC(hwnd)),
            p_hwndParent(hwnd),
            p_isMem(false) { }

        ERAPI ~ERMemDC(void) ERNOTHROW()
        {
            if (p_isMem)
            {
                ::DeleteDC(p_hdcMem);
            }
            else
            {
                ::ReleaseDC(p_hwndParent, p_hdcMem);
            }
            p_hdcMem = 0;
            p_hwndParent = 0;
        }

        const HDC& ERAPI GetHDC(void) ERNOTHROW() { return (p_hdcMem); }

    private:
        ERAPI ERMemDC(const ERMemDC& rhs);
        ERMemDC& ERAPI operator=(const ERMemDC& rhs);

        HDC     p_hdcMem;
        HWND    p_hwndParent;
        Boolean p_isMem;
};


// Step 1: Read the file into an array of bytes called pBytes, save the
// number of bytes read into the variable called len

    const HGLOBAL hMem(::GlobalAlloc(CVTUINT(GMEM_MOVEABLE), CVTSIZET(len)));
    if (hMem != 0)
    {
        ::CopyMemory(::GlobalLock(hMem), pBytes, len);
        IStream* pstm(0);
        if (::CreateStreamOnHGlobal(hMem, FALSE, &pstm) == S_OK)
        {
            std::auto_ptr<Gdiplus::Image> MyImage(Gdiplus::Image::FromStream(pstm, FALSE));
            if (MyImage.get() != 0)
            {
                ERMemDC hdcDisp(0);
                ERMemDC hdcmem;
                const HBITMAP hbmp(::CreateCompatibleBitmap(hdcDisp.GetHDC(),
                    TOINT(MyImage->GetWidth()),
                    TOINT(MyImage->GetHeight())));
                ::SelectObject(hdcmem.GetHDC(), hbmp);

                // Create a bitmap
                Gdiplus::Graphics g(hdcmem.GetHDC());
                NORETURN(g.Clear(CVTDWORD(Gdiplus::Color::Black)));
                NORETURN(g.DrawImage(MyImage.get(),
                                     0,
                                     0,
                                     TOINT(MyImage->GetWidth()),
                                     TOINT(MyImage->GetHeight())));

                // HERE IS WHERE YOU CAN USE THE BITMAP hbmp AS YOU LIKE

                ::DeleteObject(hbmp);
            }
        }
        NORETURN(::GlobalFree(hMem));
    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

EeroAuraAuthor Commented:
ethan mmg :
This was something I really wanted !
( Must try later.. )

Answer from Infinity08 and fridom (Friedrich) were too 'general' (for me) :
http://www.wotsit.org/list.asp?al=J
http://en.wikipedia.org/wiki/Libjpeg

I needed only some headers (like gdiplus.h?) and some C- (/C++) rows

- to read .JPG-files...
- and to display the picture to Windows :
- - device-dependent bitmap 'CreateDIBitmap' ,
    memory device context (DC) compatible with the specified device 'CreateCompatibleDC' ,
- - bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source
    device context into a destination device context 'BitBlt'


Thanks !
Eero Aura
eero.o.aura@kotiportti.fi or
eero.aura@fi.abb.com
0
Infinity08Commented:
>> Answer from Infinity08 and fridom (Friedrich) were too 'general' (for me) :

Well, the way you asked the question, it seemed like you wanted to do something specific with JPEG files, and needed the file specification to achieve that. If that's not the case, then I apologize for having misunderstood you.
0
fridomCEO/ProgrammerCommented:
Well you decide howerver you asked for jpeg stuff and I pointed you to a library for handling jpeg stuff. So I answered you question.

Regards
Friedrich
0
EeroAuraAuthor Commented:
Infinity08, fredom,ethan_mmg :

It's my Fenglish that must have misquided (? fooled...) You.
ethan_mmg's answer was OK but I didn't find C/C++ header (?) gdiplus.h anywhere
even when I installed
Microsoft® Visual C++® 2005 Express Edition
in addition to my old (very old, 1997 something) Visual Studio 6.0 C/C++

Rgds
Erppa
from Kangasniemi, South-Savo, Finland

Thanks anyway and Happy Easter !
0
ethan_mmgCommented:
You can get gdiplus.h and the associated libraries from the Platform SDK (free download from Microsoft)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.