Click here to Skip to main content
15,911,141 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHide and show the Menu of a MDI application Pin
Cristiano G.6-Nov-02 3:00
sussCristiano G.6-Nov-02 3:00 
GeneralRe: Hide and show the Menu of a MDI application Pin
Hans Ruck6-Nov-02 6:45
Hans Ruck6-Nov-02 6:45 
GeneralRe: Hide and show the Menu of a MDI application Pin
Cristiano G-6-Nov-02 23:30
sussCristiano G-6-Nov-02 23:30 
GeneralRe: Hide and show the Menu of a MDI application Pin
Hans Ruck7-Nov-02 0:03
Hans Ruck7-Nov-02 0:03 
GeneralNewbie help: Trouble with CVMRotaryFaderCtrl custom control Pin
Andy C6-Nov-02 2:46
Andy C6-Nov-02 2:46 
QuestionBest way to decode raw JPEG data? Pin
jstonge6-Nov-02 2:10
jstonge6-Nov-02 2:10 
AnswerRe: Best way to decode raw JPEG data? Pin
Jonathan de Halleux6-Nov-02 4:30
Jonathan de Halleux6-Nov-02 4:30 
GeneralRe: Best way to decode raw JPEG data? Pin
jstonge6-Nov-02 9:47
jstonge6-Nov-02 9:47 
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_INVALID_OR_UNKNOWN:
default:
return false;
}

Rect rect(0, 0, width, height);
BitmapData bitmapData;
m_gdiPlusBitmap->LockBits(&rect, ImageLockModeRead, lockPixelFormat, &bitmapData);

UCHAR *sptr = (UCHAR*)bitmapData.Scan0;
UCHAR *dptr = (UCHAR*)dst;
ULONG bmapStride = bitmapData.Stride;
ULONG bytesToCopy = bmapStride;
if (bmapStride > dstStride) bytesToCopy = dstStride;
for (int yy=0 ; yy<height ;="" yy++)
="" {
="" ::memcpy(dptr,="" sptr,="" bytestocopy);
="" sptr="" +="bmapStride;
" dptr="" }

="" m_gdiplusbitmap-="">UnlockBits(&bitmapData);

return true;
}

bool JPegDecoderGdiPlus::AbortDecode(void)
{
m_valid = false;
FinishDecode();
return true;
}

bool JPegDecoderGdiPlus::FinishDecode(void)
{
delete m_gdiPlusBitmap;
m_gdiPlusBitmap = NULL;
return true;
}


int JPegDecoderGdiPlus::GetImageFormat(void)
{
// Lorus formats:
//IMGFMT_INVALID_OR_UNKNOWN,
//IMGFMT_MONOCHROME1,
//IMGFMT_MONOCHROME2,
//IMGFMT_PALETTECOLOR,
//IMGFMT_RGB,
//IMGFMT_HSV,
//IMGFMT_ARGB,
//IMGFMT_CMYK,
//IMGFMT_YBR_FULL,
//IMGFMT_YBR_FULL_422,
//IMGFMT_YBR_PARTIAL_422,
//return m_cinfo.out_color_space;
if (!m_gdiPlusBitmap) return IMGFMT_INVALID_OR_UNKNOWN;
UINT bmapFlags = m_gdiPlusBitmap->GetFlags();
if (bmapFlags & ImageFlagsColorSpaceGRAY)
return IMGFMT_MONOCHROME2;
if (bmapFlags & ImageFlagsColorSpaceRGB)
return IMGFMT_RGB;
if (bmapFlags & ImageFlagsColorSpaceCMYK)
return IMGFMT_CMYK;
if (bmapFlags & ImageFlagsColorSpaceYCBCR)
return IMGFMT_RGB;
return IMGFMT_INVALID_OR_UNKNOWN;
}

int JPegDecoderGdiPlus::ImageWidth(void)
{
if (!m_gdiPlusBitmap) return 0;
return m_gdiPlusBitmap->GetWidth();
}

int JPegDecoderGdiPlus::ImageHeight(void)
{
if (!m_gdiPlusBitmap) return 0;
return m_gdiPlusBitmap->GetHeight();
}

int JPegDecoderGdiPlus::PixelDepth(void)
{
if (!m_gdiPlusBitmap) return 0;
PixelFormat pixFormat = m_gdiPlusBitmap->GetPixelFormat();
switch (pixFormat)
{
case PixelFormat1bppIndexed:
return 1;
case PixelFormat4bppIndexed:
case PixelFormat8bppIndexed:
return 8;
case PixelFormat16bppGrayScale:
return 16;
case PixelFormat16bppARGB1555:
case PixelFormat16bppRGB555:
case PixelFormat16bppRGB565:
case PixelFormat24bppRGB:
case PixelFormat32bppARGB:
case PixelFormat32bppPARGB:
case PixelFormat32bppRGB:
case PixelFormat48bppRGB:
case PixelFormat64bppARGB:
case PixelFormat64bppPARGB:
return 32;
}
return 0;
}

int JPegDecoderGdiPlus::SamplesPerPixel(void)
{
if (!m_gdiPlusBitmap) return 0;
PixelFormat pixFormat = m_gdiPlusBitmap->GetPixelFormat();
switch (pixFormat)
{
case PixelFormat1bppIndexed:
return 1;
case PixelFormat4bppIndexed:
case PixelFormat8bppIndexed:
case PixelFormat16bppGrayScale:
return 1;
case PixelFormat16bppARGB1555:
case PixelFormat16bppRGB555:
case PixelFormat16bppRGB565:
case PixelFormat24bppRGB:
case PixelFormat32bppARGB:
case PixelFormat32bppPARGB:
case PixelFormat32bppRGB:
case PixelFormat48bppRGB:
case PixelFormat64bppARGB:
case PixelFormat64bppPARGB:
return 3;
}
return 0;
}
AnswerRe: Best way to decode raw JPEG data? Pin
JT Anderson6-Nov-02 10:14
JT Anderson6-Nov-02 10:14 
QuestionWhen a WebBrowser2 control navigate a Web Page,how to drop selected range's html source to a EditBox control? Pin
ChengMing Liu6-Nov-02 1:57
ChengMing Liu6-Nov-02 1:57 
AnswerRe: When a WebBrowser2 control navigate a Web Page,how to drop selected range's html source to a EditBox control? Pin
Stephane Rodriguez.6-Nov-02 2:01
Stephane Rodriguez.6-Nov-02 2:01 
GeneralRe: When a WebBrowser2 control navigate a Web Page,how to drop selected range's html source to a EditBox control? Pin
ChengMing Liu6-Nov-02 14:13
ChengMing Liu6-Nov-02 14:13 
Questionshowing more than one line of text inside the listcontrols cells? Pin
Joan M6-Nov-02 1:08
professionalJoan M6-Nov-02 1:08 
AnswerRe: showing more than one line of text inside the listcontrols cells? Pin
Paul M Watt6-Nov-02 5:07
mentorPaul M Watt6-Nov-02 5:07 
GeneralOLBs & TLBs Pin
AJ1236-Nov-02 1:05
AJ1236-Nov-02 1:05 
GeneralRe: OLBs & TLBs Pin
Christian Graus6-Nov-02 1:05
protectorChristian Graus6-Nov-02 1:05 
GeneralRe: OLBs & TLBs Pin
Stephane Rodriguez.6-Nov-02 1:40
Stephane Rodriguez.6-Nov-02 1:40 
GeneralPeculiar Resouce problem Pin
Anonymous6-Nov-02 0:37
Anonymous6-Nov-02 0:37 
GeneralClear List Box Pin
Ayush5-Nov-02 23:57
Ayush5-Nov-02 23:57 
GeneralRe: Clear List Box Pin
Anonymous6-Nov-02 0:28
Anonymous6-Nov-02 0:28 
GeneralRe: Clear List Box Pin
RuiSantiago6-Nov-02 5:21
RuiSantiago6-Nov-02 5:21 
GeneralProblem with ownerdrawn menus Pin
Chopper5-Nov-02 23:28
Chopper5-Nov-02 23:28 
GeneralRe: Problem with ownerdrawn menus Pin
includeh106-Nov-02 3:15
includeh106-Nov-02 3:15 
GeneralPrinting made easy with MFC Pin
Ruca5-Nov-02 22:33
Ruca5-Nov-02 22:33 
GeneralRe: Printing made easy with MFC Pin
Roger Allen6-Nov-02 3:14
Roger Allen6-Nov-02 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.