Solved

JPEG file headers - where?

Posted on 2007-04-03
10
1,204 Views
Last Modified: 2013-12-14
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
Comment
Question by:EeroAura
  • 2
  • 2
  • 2
  • +1
10 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 18848698
Fetch a library from
http://en.wikipedia.org/wiki/Libjpeg


Regards
Friedrich
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 18848817
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
 
LVL 5

Accepted Solution

by:
ethan_mmg earned 500 total points
ID: 18852600
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
 

Author Comment

by:EeroAura
ID: 18856231
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 53

Expert Comment

by:Infinity08
ID: 18856242
>> 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
 
LVL 24

Expert Comment

by:fridom
ID: 18856407
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
 

Author Comment

by:EeroAura
ID: 18864964
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
 
LVL 5

Expert Comment

by:ethan_mmg
ID: 18864999
You can get gdiplus.h and the associated libraries from the Platform SDK (free download from Microsoft)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now