Example #1
0
void ZUtil_Win::sPixmapsFromHICON(HICON iHICON,
	ZDCPixmap* oColorPixmap, ZDCPixmap* oMonoPixmap, ZDCPixmap* oMaskPixmap)
	{
	ZAssertStop(2, iHICON);
	ICONINFO theICONINFO;
	::GetIconInfo(iHICON, &theICONINFO);

	HDC dummyHDC = ::GetDC(nullptr);

	ZDCPixmap monoPixmap(new ZDCPixmapRep_DIB(dummyHDC, theICONINFO.hbmMask));

	if (theICONINFO.hbmColor)
		{
		if (oColorPixmap)
			*oColorPixmap = ZDCPixmap(new ZDCPixmapRep_DIB(dummyHDC, theICONINFO.hbmColor));
		if (oMaskPixmap)
			*oMaskPixmap = monoPixmap;
		}
	else
		{
		// theICONINFO.hbmColor is nullptr, so theICONINFO.hbmMask (and thus monoPixmap) contains
		// the mono pixmap and the mask stacked on top of each other.
		ZPoint monoSize = monoPixmap.Size();
		if (oMonoPixmap)
			*oMonoPixmap = ZDCPixmap(monoPixmap, ZRect(0, 0, monoSize.h, monoSize.v / 2));
		if (oMaskPixmap)
			*oMaskPixmap = ZDCPixmap(monoPixmap, ZRect(0, monoSize.v / 2, monoSize.h, monoSize.v));
		}

	if (oMaskPixmap)
		oMaskPixmap->Munge(spMungeProc_Invert, nullptr);

	if (theICONINFO.hbmMask)
		::DeleteObject(theICONINFO.hbmMask);
	if (theICONINFO.hbmMask)
		::DeleteObject(theICONINFO.hbmColor);

	::ReleaseDC(nullptr, dummyHDC);
	}
Example #2
0
static void spDecompose(
	int iMaxDim, int iBaseDim, const PixmapRegName& iPRN, vector<PixmapRegName>& ioPRNs)
	{
	vector<ZRectPOD> theRects;

	// Quantized region.
	{
	ZBigRegionAccumulator quant;
	const int q = iBaseDim;
	const ZBigRegion theRgn = spRegion(iPRN.f0);
	const ZRectPOD theBounds = theRgn.Bounds();
	const vector<ZRectPOD> decomposed = spDecompose(theRgn);
	foreachv (const ZRectPOD& theRect, decomposed)
		{
		const ZRectPOD current = sRectPOD(
			(L(theRect) / q) * q, (T(theRect) / q) * q,
			(R(theRect + q - 1) / q) * q, (B(theRect + q - 1) / q) * q);
		
		quant.Include(theBounds & current);
		}

	quant.Get().Decompose(theRects);
	}

	// We have a list of rectangles within the source.
	// Now let's break up any that are too big.
	vector<ZRectPOD> smallRects;
	foreachv (const ZRectPOD& theRect, theRects)
		{
		for (int theTop = T(theRect); theTop < B(theRect); /*no inc*/)
			{
			const int theBottom = sMin(theTop + iMaxDim, B(theRect));
			for (int theLeft = L(theRect); theLeft < R(theRect); /*no inc*/)
				{
				const int theRight = sMin(theLeft + iMaxDim, R(theRect));
				smallRects.push_back(sRectPOD(theLeft, theTop, theRight, theBottom));
				theLeft = theRight;
				}
			theTop = theBottom;
			}
		}

	// Append chunks to ioPRNs
	foreachv (const ZRectPOD& theRect, smallRects)
		{		
		ioPRNs.push_back(
			PixmapRegName(ZDCPixmap(iPRN.f0, theRect), iPRN.f1 - LT(theRect), iPRN.f2));
		}
Example #3
0
void ZDCPixmapDecoder_JPEGLib::Imp_Read(const ZStreamR& iStream, ZDCPixmap& oPixmap)
	{
	struct jpeg_decompress_struct theJDS;
	JPEGErrorMgr theEM;
	theJDS.err = &theEM;
			  
	::jpeg_create_decompress(&theJDS);

	JPEGReader theJR(iStream);
	theJDS.src = &theJR;
	try
		{
		::jpeg_read_header(&theJDS, TRUE);
		::jpeg_start_decompress(&theJDS);

		ZDCPixmapNS::PixelDesc sourcePixelDesc;
		ZDCPixmapNS::PixvalDesc sourcePixvalDesc;
		vector<uint8> rowBufferVector;
		if (theJDS.out_color_space == JCS_GRAYSCALE)
			{
			sourcePixelDesc = ZDCPixmapNS::PixelDesc(ZDCPixmapNS::eFormatStandard_Gray_8);
			rowBufferVector.resize(theJDS.image_width);

			sourcePixvalDesc.fDepth = 8;
			sourcePixvalDesc.fBigEndian = true;

			oPixmap = ZDCPixmap(ZPoint(theJDS.image_width, theJDS.image_height),
				ZDCPixmapNS::eFormatEfficient_Gray_8);
			}
		else if (theJDS.out_color_space == JCS_RGB)
			{
			sourcePixelDesc = ZDCPixmapNS::PixelDesc(ZDCPixmapNS::eFormatStandard_RGB_24);
			rowBufferVector.resize(3 * theJDS.image_width);

			sourcePixvalDesc.fDepth = 24;
			sourcePixvalDesc.fBigEndian = true;

			oPixmap = ZDCPixmap(ZPoint(theJDS.image_width, theJDS.image_height),
				ZDCPixmapNS::eFormatEfficient_Color_24);
			}
		else
			{
			// TODO. What about other color spaces?
			ZUnimplemented();
			}

		ZDCPixmapNS::PixelDesc destPixelDesc = oPixmap.GetPixelDesc();
		ZDCPixmapNS::RasterDesc destRasterDesc = oPixmap.GetRasterDesc();
		void* destBaseAddress = oPixmap.GetBaseAddress();

		JSAMPROW rowPtr[1];
		rowPtr[0] = &rowBufferVector[0];
		while (theJDS.output_scanline < theJDS.output_height)
			{
			int scanlinesRead = ::jpeg_read_scanlines(&theJDS, rowPtr, 1);
			ZAssertStop(1, scanlinesRead == 1);

			void* destRowAddress
				= destRasterDesc.CalcRowAddress(destBaseAddress, theJDS.output_scanline - 1);

			ZDCPixmapNS::sBlitRow(
				rowPtr[0], sourcePixvalDesc, sourcePixelDesc, 0,
				destRowAddress, destRasterDesc.fPixvalDesc, destPixelDesc, 0,
				theJDS.image_width);
			}
		::jpeg_finish_decompress(&theJDS);
		}
	catch (...)
		{
		::jpeg_destroy_decompress(&theJDS);
		throw;
		}

	::jpeg_destroy_decompress(&theJDS);
	}
Example #4
0
	ZDCPixmap GetPixmap()
		{ return ZDCPixmap(fPixmap, sRectPOD(fUsedX, fUsedY)); }