Beispiel #1
0
ZDC_Off::ZDC_Off(const ZDC& inOther, bool inForceOffscreen)
:	ZDC(inOther)
	{
	// Initially, we copy all settings from inOther, then we attempt to
	// create a new offscreen canvas.
	if (inForceOffscreen || !fCanvas->IsOffScreen())
		{
		ZRect canvasClipRect = this->GetClip().Bounds() + this->GetOrigin();
		ZRef<ZDCCanvas> offCanvas;
		try
			{
			// We allow the offscreen creation to fail if inForceOffscreen is false.
			offCanvas = fCanvas->CreateOffScreen(canvasClipRect);
			}
		catch (...)
			{
			if (inForceOffscreen)
				throw;
			}
		if (offCanvas && offCanvas->IsOffScreen())
			{
			fCanvas = offCanvas;
			this->ZeroChangeCounts();
			fState.fOriginComp = canvasClipRect.TopLeft();
			this->SetOrigin(inOther.GetOrigin());
			this->SetPatternOrigin(inOther.GetPatternOrigin());
			this->SetClip(inOther.GetClip());
			}
		}
	}
Beispiel #2
0
void ZDCCanvas_X_NonWindow::CopyFrom(ZDCState& ioState, const ZPoint& inDestLocation, ZRef<ZDCCanvas> inSourceCanvas, const ZDCState& inSourceState, const ZRect& inSourceRect)
	{
	ZRef<ZDCCanvas_X> sourceCanvasX = ZRefDynamicCast<ZDCCanvas_X>(inSourceCanvas);
	ZAssertStop(kDebug_X, sourceCanvasX != nil);

	if (!fDrawable || !sourceCanvasX->Internal_GetDrawable())
		return;

	SetupLock theSetupLock(this);

	// We can (currently) only copy from one drawable to another if they're on the same display
	//	ZAssertStop(kDebug_X, fXServer == sourceCanvasX->fXServer);

	ZRect destRect = inSourceRect + (ioState.fOrigin + inDestLocation - inSourceRect.TopLeft());
	ZRect sourceRect = inSourceRect + inSourceState.fOrigin;

	ZDCRgn realClip = this->Internal_CalcClipRgn(ioState);

	fXServer->SetRegion(fGC, realClip.GetRegion());
	++fChangeCount_Clip;

	fXServer->SetFunction(fGC, GXcopy);
	++fChangeCount_Mode;

	fXServer->CopyArea(sourceCanvasX->Internal_GetDrawable(), fDrawable, fGC,
				sourceRect.Left(), sourceRect.Top(),
				sourceRect.Width(), sourceRect.Height(),
				destRect.Left(), destRect.Top());
	}
Beispiel #3
0
bool ZRect::operator<(const ZRect &rhs) const
{
    //< is the one that is closer to top corner (as a whole)//

    if(rY < rhs.Y())    //check Ys
        return true;
    else if(rY > rhs.Y())
        return false;
    else
    {
        if(rX < rhs.X())    //check Xs
            return true;
        else if(rX > rhs.X())
            return false;
        else
        {
            if(rHeight < rhs.Height())    //check heights
                return true;
            else if(rHeight > rhs.Height())
                return false;
            else
            {
                if(rWidth < rhs.Width())    //check widths
                    return true;
                else if(rWidth > rhs.Width())
                    return false;
                else
                    return false;    //nothing left to check, they are ==
            }
        }
    }
}
Beispiel #4
0
ZRef<ZDCCanvas> ZDCCanvas_X::CreateOffScreen(const ZRect& inCanvasRect)
	{
	using namespace ZDCPixmapNS;

	SetupLock theSetupLock(this);
	return new ZDCCanvas_X_OffScreen(fXServer, inCanvasRect.Size(), eFormatEfficient_Color_32);
	}
Beispiel #5
0
bool ZRect::isInFrontOf(const ZRect& zrect) const {
	if(z > zrect.z || (z == zrect.z && getId() > zrect.getId())) {
		return true;
	} else {
		return false;
	}
}
Beispiel #6
0
void ZDCCanvas_X::FrameRect(ZDCState& ioState, const ZRect& inRect)
	{
	if (!fDrawable)
		return;
	if (!ioState.fInk)
		return;
	if (ioState.fPenWidth <= 0)
		return;
	if (inRect.IsEmpty())
		return;

	if (ioState.fPenWidth == 1)
		{
		SetupLock theSetupLock(this);
		SetupClip theSetupClip(this, ioState);
		if (theSetupClip.IsEmpty())
			return;
		SetupInk theSetupInk(this, ioState);
		ZRect realRect = inRect + ioState.fOrigin;
		fXServer->DrawRectangle(fDrawable, fGC, inRect.left + ioState.fOrigin.h, inRect.top + ioState.fOrigin.v, inRect.Width() - 1, inRect.Height() - 1);
		}
	else
		{
		this->Line(ioState, inRect.left, inRect.top, inRect.right - ioState.fPenWidth, inRect.top);
		this->Line(ioState, inRect.right - ioState.fPenWidth, inRect.top, inRect.right - ioState.fPenWidth, inRect.bottom - ioState.fPenWidth);
		this->Line(ioState, inRect.right - ioState.fPenWidth, inRect.bottom - ioState.fPenWidth, inRect.left, inRect.bottom - ioState.fPenWidth);
		this->Line(ioState, inRect.left, inRect.bottom - ioState.fPenWidth, inRect.left, inRect.top);
		}
	}
Beispiel #7
0
static void sReadImageData(const ZStreamR& iStream,
	bool iInterlaced, const ZRect& iBounds, ZRef<ZDCPixmapRaster> ioRaster)
	{
	uint8 initialCodeSize = iStream.ReadUInt8();

	StreamR_Chunk theSIC(iStream);
	ZStreamR_LZWDecode theSILZW(initialCodeSize, theSIC);

	ZDCPixmapNS::PixvalDesc sourcePixvalDesc(8, true);

	void* destBaseAddress = ioRaster->GetBaseAddress();

	ZDCPixmapNS::RasterDesc destRasterDesc = ioRaster->GetRasterDesc();

	vector<uint8> theRowBufferVector(iBounds.Width());
	void* theRowBuffer = &theRowBufferVector[0];

	if (iInterlaced)
		{
		for (int pass = 0; pass < 4; ++pass)
			{
			for (ZCoord currentY = iBounds.top + sInterlaceStart[pass];
				currentY < iBounds.bottom; currentY += sInterlaceIncrement[pass])
				{
				theSILZW.Read(theRowBuffer, iBounds.Width());
				void* destRowAddress = destRasterDesc.CalcRowAddress(destBaseAddress, currentY);

				ZDCPixmapNS::sBlitRowPixvals(theRowBuffer, sourcePixvalDesc, 0,
					destRowAddress, destRasterDesc.fPixvalDesc, iBounds.left,
					iBounds.Width());
				}
			}
		}
	else
		{
		for (ZCoord currentY = iBounds.top; currentY < iBounds.bottom; ++currentY)
			{
			theSILZW.Read(theRowBuffer, iBounds.Width());
			void* destRowAddress = destRasterDesc.CalcRowAddress(destBaseAddress, currentY);

			ZDCPixmapNS::sBlitRowPixvals(theRowBuffer, sourcePixvalDesc, 0,
				destRowAddress, destRasterDesc.fPixvalDesc, iBounds.left,
				iBounds.Width());
			}
		}
	}
Beispiel #8
0
void ZDCCanvas_X::InvertRoundRect(ZDCState& ioState, const ZRect& inRect, const ZPoint& inCornerSize)
	{
	if (!fDrawable)
		return;
	if (inRect.IsEmpty())
		return;

	this->InvertRegion(ioState, ZDCRgn::sRoundRect(inRect, inCornerSize));
	}
Beispiel #9
0
void ZDCCanvas_X::InvertRegion(ZDCState& ioState, const ZDCRgn& inRgn)
	{
	if (!fDrawable)
		return;

	SetupLock theSetupLock(this);

	if (ZDCRgn localRgn = this->Internal_CalcClipRgn(ioState) & (inRgn + ioState.fOrigin))
		{
		ZRect localBounds = localRgn.Bounds();

		fXServer->SetRegion(fGC, localRgn.GetRegion());
		++fChangeCount_Clip;

		fXServer->SetFunction(fGC, GXinvert);
		++fChangeCount_Mode;

		fXServer->FillRectangle(fDrawable, fGC, localBounds.left, localBounds.top, localBounds.Width(), localBounds.Height());
		}
	}
Beispiel #10
0
void ZDCCanvas_X::FrameEllipse(ZDCState& ioState, const ZRect& inBounds)
	{
	if (!fDrawable)
		return;
	if (!ioState.fInk)
		return;
	if (ioState.fPenWidth <= 0)
		return;
	if (inBounds.IsEmpty())
		return;

	SetupLock theSetupLock(this);
	SetupClip theSetupClip(this, ioState);
	if (theSetupClip.IsEmpty())
		return;

	SetupInk theSetupInk(this, ioState);
	ZPoint ellipseSize = inBounds.Size();
	ZCoord twicePenWidth = ioState.fPenWidth * 2;
	if (twicePenWidth >= ellipseSize.h || twicePenWidth >= ellipseSize.v)
		{
		fXServer->FillArc(fDrawable, fGC,
			inBounds.left + ioState.fOrigin.h,
			inBounds.top + ioState.fOrigin.v,
			ellipseSize.h,
			ellipseSize.v,
			0, 360*64);
		}
	else
		{
		ZCoord halfPenWidth = ioState.fPenWidth / 2;
		fXServer->DrawArc(fDrawable, fGC,
			inBounds.left + ioState.fOrigin.h + halfPenWidth,
			inBounds.top + ioState.fOrigin.v + halfPenWidth,
			ellipseSize.h - 2 * halfPenWidth,
			ellipseSize.v - 2 * halfPenWidth,
			0, 360 * 64);
		}
	}
Beispiel #11
0
void ZDCCanvas_X::FrameRoundRect(ZDCState& ioState, const ZRect& inRect, const ZPoint& inCornerSize)
	{
	if (!fDrawable)
		return;
	if (!ioState.fInk)
		return;
	if (ioState.fPenWidth <= 0)
		return;
	if (inRect.IsEmpty())
		return;

	this->FrameRegion(ioState, ZDCRgn::sRoundRect(inRect, inCornerSize));
	}
Beispiel #12
0
void ZDCCanvas_X::FrameRegion(ZDCState& ioState, const ZDCRgn& inRgn)
	{
	if (!fDrawable)
		return;
	if (!ioState.fInk)
		return;
	if (ioState.fPenWidth <= 0)
		return;

	SetupLock theSetupLock(this);

	if (ZDCRgn localRgn = this->Internal_CalcClipRgn(ioState) & ((inRgn - inRgn.Inset(ioState.fPenWidth, ioState.fPenWidth)) + ioState.fOrigin))
		{
		SetupInk theSetupInk(this, ioState);
		ZRect localBounds = localRgn.Bounds();

		fXServer->SetRegion(fGC, localRgn.GetRegion());
		++fChangeCount_Clip;

		fXServer->FillRectangle(fDrawable, fGC, localBounds.left, localBounds.top, localBounds.Width(), localBounds.Height());
		}
	}
Beispiel #13
0
ZRect ZRect::Intersection(const ZRect &rect) const
{
    float tempX=0,tempY=0,tempW=0,tempH=0;

    //can only grab the intersection if they intersect
    if(Intersects(rect))
    {
        tempX = rX > rect.X() ? rX : rect.X();
        tempY = rY > rect.Y() ? rY : rect.Y();
        tempW = rX+rWidth < rect.Right() ? rX+rWidth : rect.Right();
        tempH = rY+rHeight < rect.Bottom() ? rY+rHeight : rect.Bottom();

        tempW -= tempX;        //adjust width and height
        tempH -= tempY;
    }

    return ZRect(tempX,tempY,tempW,tempH);
}
Beispiel #14
0
void ZDCCanvas_X::InvertRect(ZDCState& ioState, const ZRect& inRect)
	{
	if (!fDrawable)
		return;
	if (inRect.IsEmpty())
		return;

	SetupLock theSetupLock(this);
	SetupClip theSetupClip(this, ioState);
	if (theSetupClip.IsEmpty())
		return;

	fXServer->SetFunction(fGC, GXinvert);
	++fChangeCount_Mode;

	fXServer->FillRectangle(fDrawable, fGC, inRect.left + ioState.fOrigin.h, inRect.top + ioState.fOrigin.v, inRect.Width(), inRect.Height());
	}
Beispiel #15
0
void ZDCCanvas_X::InvertEllipse(ZDCState& ioState, const ZRect& inBounds)
	{
	if (!fDrawable)
		return;
	if (inBounds.IsEmpty())
		return;

	SetupLock theSetupLock(this);
	SetupClip theSetupClip(this, ioState);
	if (theSetupClip.IsEmpty())
		return;

	fXServer->SetFunction(fGC, GXinvert);
	++fChangeCount_Mode;

	fXServer->FillArc(fDrawable, fGC, inBounds.left + ioState.fOrigin.h, inBounds.top + ioState.fOrigin.v, inBounds.Width(), inBounds.Height(), 0, 360*64);
	}
Beispiel #16
0
void ZDCCanvas_X::FillRect(ZDCState& ioState, const ZRect& inRect)
	{
	if (!fDrawable)
		return;
	if (!ioState.fInk)
		return;
	if (inRect.IsEmpty())
		return;

	SetupLock theSetupLock(this);
	SetupClip theSetupClip(this, ioState);
	if (theSetupClip.IsEmpty())
		return;

	SetupInk theSetupInk(this, ioState);

	fXServer->FillRectangle(fDrawable, fGC, inRect.left + ioState.fOrigin.h, inRect.top + ioState.fOrigin.v, inRect.Width(), inRect.Height());
	}
Beispiel #17
0
void ZDCCanvas_X::FillEllipse(ZDCState& ioState, const ZRect& inBounds)
	{
	if (!fDrawable)
		return;
	if (!ioState.fInk)
		return;
	if (inBounds.IsEmpty())
		return;

	SetupLock theSetupLock(this);
	SetupClip theSetupClip(this, ioState);
	if (theSetupClip.IsEmpty())
		return;

	SetupInk theSetupInk(this, ioState);

	fXServer->FillArc(fDrawable, fGC, inBounds.left + ioState.fOrigin.h, inBounds.top + ioState.fOrigin.v, inBounds.Width(), inBounds.Height(), 0, 360*64);
	}
Beispiel #18
0
void ZDCCanvas_X_NonWindow::Scroll(ZDCState& ioState, const ZRect& inRect, ZCoord hDelta, ZCoord vDelta)
	{
	if (!fDrawable)
		return;
	SetupLock theSetupLock(this);

	++fChangeCount_Clip;

	ZPoint offset(hDelta, vDelta);

	// destRgn is the pixels we want and are able to draw to.
	ZDCRgn destRgn = ((ioState.fClip + ioState.fClipOrigin) & (inRect + ioState.fOrigin));

	// srcRgn is the set of pixels we're want and are able to copy from.
	ZDCRgn srcRgn = ((destRgn - offset) & (inRect + ioState.fOrigin));

	// drawnRgn is the destination pixels that will be drawn by the CopyBits call, it's the srcRgn
	// shifted back to the destination.
	ZDCRgn drawnRgn = srcRgn + offset;

	// invalidRgn is the destination pixels we wanted to draw but could not because they were
	// outside the visRgn, or were in the excludeRgn
	ZDCRgn invalidRgn = destRgn - drawnRgn;

	// And set the clip (drawnRgn)
	fXServer->SetRegion(fGC, drawnRgn.GetRegion());
	++fChangeCount_Clip;

	fXServer->SetFunction(fGC, GXcopy);
	++fChangeCount_Mode;

	ZRect drawnBounds = drawnRgn.Bounds();

	fXServer->CopyArea(fDrawable, fDrawable, fGC,
				drawnBounds.Left() - offset.h, drawnBounds.Top() - offset.v,
				drawnBounds.Width(), drawnBounds.Height(),
				drawnBounds.Left(), drawnBounds.Top());
	}
Beispiel #19
0
void ZDCPixmapEncoder_GIF::Imp_Write(const ZStreamW& iStream,
	const void* iBaseAddress,
	const ZDCPixmapNS::RasterDesc& iRasterDesc,
	const ZDCPixmapNS::PixelDesc& iPixelDesc,
	const ZRect& iBounds)
	{
	ZRef<ZDCPixmapNS::PixelDescRep_Indexed> thePixelDescRep_Indexed
		= ZRefDynamicCast<ZDCPixmapNS::PixelDescRep_Indexed>(iPixelDesc.GetRep());
	ZAssertStop(2, thePixelDescRep_Indexed);

	if (fTransparent)
		iStream.WriteString("GIF89a");
	else
		iStream.WriteString("GIF87a");
	iStream.WriteUInt16LE(iBounds.Width());
	iStream.WriteUInt16LE(iBounds.Height());

	uint8 globalStrmFlags = 0;
	globalStrmFlags |= 0x80; // hasGlobalColorTable
	globalStrmFlags |= 0x70; // colorResolution (8 bits per component)
	// globalStrmFlags |= 0x08; // set this if the color table is sorted in priority order

	ZAssertStop(2, iRasterDesc.fPixvalDesc.fDepth > 0 && iRasterDesc.fPixvalDesc.fDepth <= 8);
	
	globalStrmFlags |= iRasterDesc.fPixvalDesc.fDepth - 1; // globalColorTableSize & depth
	iStream.WriteUInt8(globalStrmFlags);

	iStream.WriteUInt8(0); // backgroundColorIndex
	iStream.WriteUInt8(0); // Pixel aspect ratio -- 0 == none specified.

	const ZRGBColorPOD* theColors;
	size_t theColorsCount;
	thePixelDescRep_Indexed->GetColors(theColors, theColorsCount);
	sWriteColorTable(iStream, theColors, theColorsCount, 1 << iRasterDesc.fPixvalDesc.fDepth);

	if (fTransparent)
		{
		iStream.WriteUInt8('!'); // Extension block
		iStream.WriteUInt8(0xF9); // Graphic Control Extension
		iStream.WriteUInt8(4); // Block size
		// The next byte encodes four fields:
		// 3 bits, Reserved == 0
		// 3 bits, Disposal Method == none (0),
		// 1 bit, User Input Flag == none (0)
		// 1 bit, Transparent Color Flag = yes (1)
		iStream.WriteUInt8(1);
		iStream.WriteUInt16LE(0); // Delay time
		iStream.WriteUInt8(fTransparentPixval);
		iStream.WriteUInt8(0); // Block terminator
		}

	iStream.WriteUInt8(','); // Start of image
	iStream.WriteUInt16LE(0); // Origin h
	iStream.WriteUInt16LE(0); // Origin v
	iStream.WriteUInt16LE(iBounds.Width());
	iStream.WriteUInt16LE(iBounds.Height());

	uint8 localStrmFlags = 0;
//	localStrmFlags |= 0x80; // hasLocalColorTable
	if (fInterlace)
		localStrmFlags |= 0x40; // interlaced
//	localStrmFlags |= 0x20; // sorted
//	localStrmFlags |= 0x70; // localColorTableSize
	iStream.WriteUInt8(localStrmFlags);

	iStream.WriteUInt8(iRasterDesc.fPixvalDesc.fDepth); // Initial code size.

	{ // Scope theSC.
	StreamW_Chunk theSC(iStream);

	ZStreamW_LZWEncode* theSLZW = nil;
	ZStreamW_LZWEncodeNoPatent* theSLZWNP = nil;

	ZStreamW* theStream;
	if (fNoPatent)
		{
		theSLZWNP = new ZStreamW_LZWEncodeNoPatent(iRasterDesc.fPixvalDesc.fDepth, theSC);
		theStream = theSLZWNP;
		}
	else
		{
		theSLZW = new ZStreamW_LZWEncode(iRasterDesc.fPixvalDesc.fDepth, theSC);
		theStream = theSLZW;
		}

	ZDCPixmapNS::PixvalDesc destPixvalDesc(8, true);

	vector<uint8> theRowBufferVector(iBounds.Width());
	void* theRowBuffer = &theRowBufferVector[0];

	try
		{
		if (fInterlace)
			{
			for (int pass = 0; pass < 4; ++pass)
				{
				for (ZCoord currentY = iBounds.top + sInterlaceStart[pass];
					currentY < iBounds.bottom; currentY += sInterlaceIncrement[pass])
					{
					const void* sourceRowAddress
						= iRasterDesc.CalcRowAddress(iBaseAddress, currentY);

					ZDCPixmapNS::sBlitRowPixvals(
						sourceRowAddress, iRasterDesc.fPixvalDesc, iBounds.left,
						theRowBuffer, destPixvalDesc, 0,
						iBounds.Width());

					theStream->Write(theRowBuffer, iBounds.Width());
					}
				}
			}
		else
			{
			for (ZCoord currentY = iBounds.top; currentY < iBounds.bottom; ++currentY)
				{
				const void* sourceRowAddress
					= iRasterDesc.CalcRowAddress(iBaseAddress, currentY);

				ZDCPixmapNS::sBlitRowPixvals(
					sourceRowAddress, iRasterDesc.fPixvalDesc, iBounds.left,
					theRowBuffer, destPixvalDesc, 0,
					iBounds.Width());
				theStream->Write(theRowBuffer, iBounds.Width());
				}
			}
		}
	catch (...)
		{
		delete theSLZW;
		delete theSLZWNP;
		throw;
		}

	delete theSLZW;
	delete theSLZWNP;
	}

	iStream.WriteUInt8(';'); // Trailer.
	}
Beispiel #20
0
void ZDCPixmapEncoder_JPEGLib::Imp_Write(const ZStreamW& iStream,
	const void* iBaseAddress,
	const ZDCPixmapNS::RasterDesc& iRasterDesc,
	const ZDCPixmapNS::PixelDesc& iPixelDesc,
	const ZRect& iBounds)
	{
	jpeg_compress_struct theJCS;
	JPEGErrorMgr theEM;
	theJCS.err = &theEM;
	::jpeg_create_compress(&theJCS);

	theJCS.image_width = iBounds.Width();
	theJCS.image_height = iBounds.Height();

	JPEGWriter theJW(iStream);
	theJCS.dest = &theJW;

	vector<uint8> rowBufferVector;
	try
		{
		ZDCPixmapNS::PixvalDesc destPixvalDesc;
		ZDCPixmapNS::PixelDesc destPixelDesc;

		ZRef<ZDCPixmapNS::PixelDescRep> thePixelDescRep = iPixelDesc.GetRep();

		if (ZDCPixmapNS::PixelDescRep_Gray* thePixelDescRep_Gray
			= ZRefDynamicCast<ZDCPixmapNS::PixelDescRep_Gray>(thePixelDescRep))
			{
			theJCS.input_components = 1;
			theJCS.in_color_space = JCS_GRAYSCALE;
			rowBufferVector.resize(iBounds.Width());

			destPixelDesc = ZDCPixmapNS::PixelDesc(ZDCPixmapNS::eFormatStandard_Gray_8);
			destPixvalDesc.fDepth = 8;
			destPixvalDesc.fBigEndian = true;
			}
		else
			{
			theJCS.input_components = 3;
			theJCS.in_color_space = JCS_RGB;
			rowBufferVector.resize(3 * iBounds.Width());

			destPixelDesc = ZDCPixmapNS::PixelDesc(ZDCPixmapNS::eFormatStandard_RGB_24);
			destPixvalDesc.fDepth = 24;
			destPixvalDesc.fBigEndian = true;
			}

		::jpeg_set_defaults(&theJCS);
		::jpeg_set_quality(&theJCS, fQuality, TRUE);
		theJCS.dct_method = JDCT_FASTEST;

		::jpeg_start_compress(&theJCS, TRUE);

		JSAMPROW rowPtr[1];
		rowPtr[0] = &rowBufferVector[0];
		for (size_t y = iBounds.top; y < iBounds.bottom; ++y)
			{
			const void* sourceRowAddress = iRasterDesc.CalcRowAddress(iBaseAddress, y);

			ZDCPixmapNS::sBlitRow(
				sourceRowAddress, iRasterDesc.fPixvalDesc, iPixelDesc, iBounds.left,
				rowPtr[0], destPixvalDesc, destPixelDesc, 0,
				iBounds.Width());

			::jpeg_write_scanlines(&theJCS, rowPtr, 1);
			}

		::jpeg_finish_compress(&theJCS);
		}
	catch (...)
		{
		::jpeg_destroy(reinterpret_cast<j_common_ptr>(&theJCS));
		throw;
		}

	::jpeg_destroy(reinterpret_cast<j_common_ptr>(&theJCS));
	}
Beispiel #21
0
static void sReadPixmap(const ZStreamR& inStream, ZDCPixmap& outPixmap)
	{
	uint16 rowBytes = inStream.ReadUInt16();
	if (!(rowBytes & 0x8000))
		::sThrowBadFormat();
	rowBytes &= 0x7FFF;

	ZRect bounds;
	bounds.top = inStream.ReadInt16();
	bounds.left = inStream.ReadInt16();
	bounds.bottom = inStream.ReadInt16();
	bounds.right = inStream.ReadInt16();
	inStream.ReadInt16(); // version
	inStream.ReadInt16(); // packType
	inStream.ReadInt32(); // packSize
	inStream.ReadInt32(); // hRes
	inStream.ReadInt32(); //vRes
	short pixelType = inStream.ReadInt16(); // pixelType
	short pixelSize = inStream.ReadInt16(); // pixelSize
	short cmpCount = inStream.ReadInt16(); // cmpCount
	short cmpSize = inStream.ReadInt16(); // cmpSize
	inStream.ReadInt32(); // planeBytes
	inStream.ReadInt32(); // pmTable
	inStream.ReadInt32(); // pmReserved

	// We only deal with pixel type of 0 (indexed pixels)
	if (pixelType != 0)
		::sThrowUnsupportedFormat();

	// indexed pixels have a cmpCount of 1
	if (cmpCount != 1)
		::sThrowBadFormat();

	// pixelSize and cmpSize should be equal for indexed pixels
	if (pixelSize != cmpSize)
		::sThrowBadFormat();

	// Next on the stream is the color table
	vector<ZRGBColor> theColorTable;
	inStream.ReadInt32(); // ctSeed
	inStream.ReadInt16(); // ctFlags
	short ctSize = inStream.ReadInt16();
	for (int i = 0; i <= ctSize; ++i)
		{
		inStream.ReadInt16(); // colorSpecIndex
		ZRGBColor theColor;
		theColor.red = inStream.ReadUInt16();
		theColor.green = inStream.ReadUInt16();
		theColor.blue = inStream.ReadUInt16();
		theColorTable.push_back(theColor);
		}

	// Now we have the source rect
	inStream.Skip(8);

	// and the destination rect
	inStream.Skip(8);

	// Penultimately we have the mode
	inStream.ReadUInt16();

	// The remaining data is the packed pixels. Allocate our ZDCPixmap
	// using the size we read in, but with no initialized data.
	ZDCPixmap thePixmap(bounds.Size(), ZDCPixmapNS::eFormatEfficient_Color_32);
	void* baseAddress = thePixmap.GetBaseAddress();
	ZDCPixmapNS::RasterDesc theRasterDesc = thePixmap.GetRasterDesc();
	ZDCPixmapNS::PixelDesc thePixelDesc = thePixmap.GetPixelDesc();
	::sUnpackFromStream(inStream,
		bounds.Width(), bounds.Height(),
		rowBytes, pixelSize,
		&theColorTable[0], theColorTable.size(),
		baseAddress, theRasterDesc, thePixelDesc);

	outPixmap = thePixmap;
	}
Beispiel #22
0
ZRect::ZRect(const ZRect &rhs) :
    rEngine(ZEngine::GetInstance()),
    rX(rhs.X()),rY(rhs.Y()),rWidth(rhs.Width()),rHeight(rhs.Height())
{
}
Beispiel #23
0
bool ZRect::Contains(const ZRect &rect) const
{
    //contains all 4 points
    return Contains(rect.Left(),rect.Top()) && Contains(rect.Right(),rect.Top()) &&
        Contains(rect.Left(),rect.Bottom()) && Contains(rect.Right(),rect.Bottom());
}
Beispiel #24
0
bool ZRect::Intersects(const ZRect &rect) const
{
    return !(rX > rect.Right() || rect.Left() > rX+rWidth ||
        rY > rect.Bottom() || rect.Top() > rY+rHeight);
}
Beispiel #25
0
void ZDCCanvas_X::DrawPixmap(ZDCState& ioState, const ZPoint& inLocation, const ZDCPixmap& inSourcePixmap, const ZDCPixmap* inMaskPixmap)
	{
	if (!fDrawable)
		return;

	if (!inSourcePixmap)
		return;

	ZRect realSourceBounds = inSourcePixmap.Size();

	ZPoint realLocation = inLocation + ioState.fOrigin;

	if (inMaskPixmap)
		{
		if (!*inMaskPixmap)
			return;

		SetupLock theSetupLock(this);

		ZDCRgn sourceBoundsRgn = ZRect(realSourceBounds.Size());
		ZDCRgn realClip = (this->Internal_CalcClipRgn(ioState) - realLocation) & sourceBoundsRgn;
		if (realClip.IsEmpty())
			return;

		// Take a one bit copy of the mask
		Pixmap monoPixmap = fXServer->CreateBitmapFromDCPixmap(fDrawable, *inMaskPixmap, realSourceBounds, false);
		ZAssert(monoPixmap != None);

		// Paint with zeroes the area of the mask that's not part of the clip, if any
		if (ZDCRgn inverseClip = sourceBoundsRgn - realClip)
			{
			XGCValues values;
			values.graphics_exposures = 0;
			GC monoGC = fXServer->CreateGC(monoPixmap, GCGraphicsExposures, &values);
			fXServer->SetRegion(monoGC, inverseClip.GetRegion());
			fXServer->SetForeground(monoGC, 0);
			fXServer->FillRectangle(monoPixmap, monoGC, 0, 0, realSourceBounds.Width(), realSourceBounds.Height());
			fXServer->FreeGC(monoGC);
			}

		fXServer->SetFunction(fGC, GXcopy);
		++fChangeCount_Mode;
		fXServer->SetClipMask(fGC, monoPixmap);
		fXServer->SetClipOrigin(fGC, realLocation.h, realLocation.v);
		++fChangeCount_Clip;
		fXServer->DrawDCPixmap(fDrawable, fGC, realLocation, inSourcePixmap, realSourceBounds);
		fXServer->SetClipMask(fGC, None);
		fXServer->SetClipOrigin(fGC, 0, 0);
		fXServer->FreePixmap(monoPixmap);
		}
	else
		{
		SetupLock theSetupLock(this);
		SetupClip theSetupClip(this, ioState);
		if (theSetupClip.IsEmpty())
			return;
		fXServer->SetFunction(fGC, GXcopy);
		++fChangeCount_Mode;
		fXServer->DrawDCPixmap(fDrawable, fGC, realLocation, inSourcePixmap, realSourceBounds);
		}
	}