Best way to decode raw JPEG data?
-
I have an application where I have raw JPEG data in a memory buffer. I need to convert this to a raw image in memory and it needs to be pretty fast. I tried the IJG software, and it works for most images that I have, but I have a number of lossless JPEG images that it dies on. Specifically, it errors out because it encounters an SOF3 tag. I'm targeting Windows 2000/NT/XP for this. My ideas: 1. Wrap my raw JPEG data into a COM class supporting IStream. Send the IStream to GDI+ to create an image. But then what do I do with the image??? I can't figure out how get the raw data out of it without saving it to another IStream as a BMP and then decoding the bitmap. This just seems like a lot of extra overhead and I'd like to find a better solution. 2. Use a codec to do this. However, I've not been able to find information on how to work with a codec. 3. Try to decipher the IJG software and handle/ignore the SOF3 tag. Any other ideas? Anyone know how to use a codec or whether a codec could do this? Thanks. (Sorry if this post appears twice, I pushed submit and it made me login and I don't know if the first submit actually went through)
-
I have an application where I have raw JPEG data in a memory buffer. I need to convert this to a raw image in memory and it needs to be pretty fast. I tried the IJG software, and it works for most images that I have, but I have a number of lossless JPEG images that it dies on. Specifically, it errors out because it encounters an SOF3 tag. I'm targeting Windows 2000/NT/XP for this. My ideas: 1. Wrap my raw JPEG data into a COM class supporting IStream. Send the IStream to GDI+ to create an image. But then what do I do with the image??? I can't figure out how get the raw data out of it without saving it to another IStream as a BMP and then decoding the bitmap. This just seems like a lot of extra overhead and I'd like to find a better solution. 2. Use a codec to do this. However, I've not been able to find information on how to work with a codec. 3. Try to decipher the IJG software and handle/ignore the SOF3 tag. Any other ideas? Anyone know how to use a codec or whether a codec could do this? Thanks. (Sorry if this post appears twice, I pushed submit and it made me login and I don't know if the first submit actually went through)
Keep idea 1 but use Bitmap (inherited from Image). Bitmap has the method LockBits and UnlockBits to access/release the raw bit of the image. Jonathan de Halleux, Belgium.
-
Keep idea 1 but use Bitmap (inherited from Image). Bitmap has the method LockBits and UnlockBits to access/release the raw bit of the image. Jonathan de Halleux, Belgium.
Thanks Jonathon, I did this after getting your message. It works pretty well but, unfortunately, GDI+ also does not recognize the JPEG file that I'm using. Still, I'm going to stick with the GDI+ implementation. I can still read any lossy JPEGs that I've found, I just haven't been able to read the lossless JPEG files. I tested some competing products and they also could not read the lossless JPEGs, so I'm going to ignore the problem for the time being. Thanks again, and here is the uncommented CPP file of the class I wrote: #include "StdAfx.h" #include "JPegDecoderGdiPlus.h" #include "LImage.h" // my image class: contains my IMGFMT_* enumerations using namespace Lorus::UImageProcessing; JPegDecoderGdiPlus::JPegDecoderGdiPlus(void) { m_valid = false; m_gdiPlusBitmap = NULL; GdiplusStartupInput gdiplusStartupInput; GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); } JPegDecoderGdiPlus::~JPegDecoderGdiPlus(void) { m_valid = false; delete m_gdiPlusBitmap; GdiplusShutdown(m_gdiplusToken); } // LDataSource is the source of the raw image data. It has a method 'CreateStream' that // creates an IStream* object. LDataSource is in my lowest-level library and is just a generic way // for me to contain data that other objects can access. bool JPegDecoderGdiPlus::InitializeDecode(LDataSource *imgSource) { m_valid = false; if (!imgSource) return false; IStream *istrm = imgSource->CreateStream(); if (!istrm) return false; m_gdiPlusBitmap = Bitmap::FromStream(istrm); istrm->Release(); return true; } bool JPegDecoderGdiPlus::ReadHeader(void) { return true; } bool JPegDecoderGdiPlus::ReadScanLines(void *dst, ULONG dstStride) { if (!dst) return false; if (!m_gdiPlusBitmap) return false; int width = ImageWidth(); int height = ImageHeight(); int depth = PixelDepth(); if (width==0 || height==0) return false; PixelFormat lockPixelFormat; switch (GetImageFormat()) { case IMGFMT_MONOCHROME1: case IMGFMT_MONOCHROME2: case IMGFMT_PALETTECOLOR: if (depth == 8) lockPixelFormat = PixelFormat8bppIndexed; else lockPixelFormat = PixelFormat16bppGrayScale; break; case IMGFMT_RGB: case IMGFMT_HSV: case IMGFMT_ARGB: case IMGFMT_CMYK: case IMGFMT_YBR_FULL: case IMGFMT_YBR_FULL_422: case IMGFMT_YBR_PARTIAL_422: lockPixelFormat = PixelFormat32bppARGB; break; case IMGFMT
-
I have an application where I have raw JPEG data in a memory buffer. I need to convert this to a raw image in memory and it needs to be pretty fast. I tried the IJG software, and it works for most images that I have, but I have a number of lossless JPEG images that it dies on. Specifically, it errors out because it encounters an SOF3 tag. I'm targeting Windows 2000/NT/XP for this. My ideas: 1. Wrap my raw JPEG data into a COM class supporting IStream. Send the IStream to GDI+ to create an image. But then what do I do with the image??? I can't figure out how get the raw data out of it without saving it to another IStream as a BMP and then decoding the bitmap. This just seems like a lot of extra overhead and I'd like to find a better solution. 2. Use a codec to do this. However, I've not been able to find information on how to work with a codec. 3. Try to decipher the IJG software and handle/ignore the SOF3 tag. Any other ideas? Anyone know how to use a codec or whether a codec could do this? Thanks. (Sorry if this post appears twice, I pushed submit and it made me login and I don't know if the first submit actually went through)
If you don't really need NT 4 support, perhaps you can use the DIB support for JPEG in Win2K/XP. Search MSDN for BI_JPEG. -------- There are 10 types of people in this world. Those who know binary and those who don't.