WIC WINCODEC_ERR_BADHEADER only for JPEG images

0

I have a simple encoding/ decoding application using Windows Imaging Component API. The issue I'm having is that when I use either the JPEGXR or BMP formats, everything works fine. However, when I use the JPEG codec - the encoder works fine and I can visually verify the generated JPEG image, but when I try to decode that stream, I get a WINCODEC_ERR_BADHEADER (0x88982f61)

Here's the line that fails:

    hr = m_pFactory->CreateDecoderFromStream(
                                    pInputStream, 
                                    NULL,
                                    WICDecodeMetadataCacheOnDemand,
                                    &pDecoder);

Here pInputStream is an IStream created from a byte array (output of the encoder - a black box which outputs a byte vector).

Please help! This is driving me nuts!

c++
jpeg
codec
wic
asked on Stack Overflow Oct 17, 2012 by Sau • edited Oct 17, 2012 by Sau

1 Answer

2

When passing stream as an argument, make sure to pre-seek it to proper initial position (esp. seek it back to the beginning if you just wrote data into it and expect further retrieval). APIs are typically not expected to seek, because this way they let you provide data in the middle of a bigger stream.

answered on Stack Overflow Oct 17, 2012 by Roman R.

User contributions licensed under CC BY-SA 3.0