• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1229
  • Last Modified:

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

0
EeroAura
Asked:
EeroAura
  • 2
  • 2
  • 2
  • +1
1 Solution
 
fridomCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
fridomCommented:
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now