?
Solved

JPEG file headers - where?

Posted on 2007-04-03
10
Medium Priority
?
1,219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Technology Partners: 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!

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

801 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