예제 #1
0
ALERROR rawConvertToDDB (int cxWidth, int cyHeight, RAWPIXEL *pRaw, DWORD dwFlags, HPALETTE hPalette, HBITMAP *rethBitmap)

//	rawConvertToDDB
//
//	Converts a raw image to a screen compatible bitmap
//
//	cxWidth: The width of the raw image array in pixels
//	cyHeight: The height of the raw image array in pixels
//	pRaw: The actual array of raw image data. The image is a 2-dimensional
//		array cxWidth by cyHeight pixels. Each pixel is a 32bit value.
//	dwFlags: Unused
//	hPalette: Current palette being used by the main window (may be NULL)
//
//	rethBitmap: Returns a DDB compatible with the screen

{
    ALERROR error;
    HBITMAP hDIB;

    //	Start by converting to a DIB

    if (error = rawConvertTo16bitDIB(cxWidth, cyHeight, pRaw, dwFlags, &hDIB))
        return error;

    //	Now convert to a DDB

    error = dibConvertToDDB(hDIB, hPalette, rethBitmap);
    DeleteObject(hDIB);
    if (error)
        return error;

    return NOERROR;
}
예제 #2
0
ALERROR JPEGLoadFromMemory (char *pImage, int iSize, DWORD dwFlags, HPALETTE hPalette, HBITMAP *rethBitmap)

//	JPEGLoadFromMemory
//
//	Load from a memory stream

	{
	ALERROR error;
	IJLERR jerr;

	//	Initialize library

	JPEG_CORE_PROPERTIES jcprops;
	jerr = ijlInit(&jcprops);
	if (jerr != IJL_OK)
		return ERR_FAIL;

	//	Point to the buffer

	jcprops.JPGFile = NULL;
	jcprops.JPGBytes = (BYTE *)pImage;
	jcprops.JPGSizeBytes = iSize;

	//	Read parameters

	jerr = ijlRead(&jcprops, IJL_JBUFF_READPARAMS);
	if (jerr != IJL_OK)
		{
		ijlFree(&jcprops);
		return ERR_FAIL;
		}

	DWORD width = jcprops.JPGWidth;
	DWORD height = jcprops.JPGHeight;
	DWORD nchannels = 3;	//	24-bits
	DWORD dib_line_width = width * nchannels;
	DWORD dib_pad_bytes = IJL_DIB_PAD_BYTES(width,nchannels);

	//	Allocate a dib

	HBITMAP hBitmap;
	BYTE *p24BitPixel;
	if (error = dibCreate24bitDIB(width,
			height,
			0,
			&hBitmap,
			&p24BitPixel))
		{
		ijlFree(&jcprops);
		return error;
		}

	//	Setup the library to load into the dib format

	jcprops.DIBWidth = width;
	jcprops.DIBHeight = -(int)height;
	jcprops.DIBChannels = nchannels;
	jcprops.DIBColor = IJL_BGR;
	jcprops.DIBPadBytes = dib_pad_bytes;
	jcprops.DIBBytes = p24BitPixel;

	//	Setup the color space

	switch (jcprops.JPGChannels)
		{
		case 1:
			jcprops.JPGColor = IJL_G;
			break;

		case 3:
			jcprops.JPGColor = IJL_YCBCR;
			break;

		default:
			{
			jcprops.DIBColor = (IJL_COLOR)IJL_OTHER;
			jcprops.JPGColor = (IJL_COLOR)IJL_OTHER;
			}
		}

	//	Load the data in the buffer

	jerr = ijlRead(&jcprops, IJL_JBUFF_READWHOLEIMAGE);
	if (jerr != IJL_OK)
		{
		::DeleteObject(hBitmap);
		ijlFree(&jcprops);
		return ERR_FAIL;
		}

	//	Done

	ijlFree(&jcprops);

	//	If we want a DIB, just return that; otherwise,
	//	convert to DDB and return that

	if (dwFlags & JPEG_LFR_DIB)
		*rethBitmap = hBitmap;
	else
		{
		HBITMAP hDDB;
		error = dibConvertToDDB(hBitmap, hPalette, &hDDB);
		::DeleteObject(hBitmap);
		if (error)
			return error;

		*rethBitmap = hDDB;
		}

	return NOERROR;
	}