FXBltSimulation>>copyLoopPixels?

Yoshiki Ohshima ohshima at is.titech.ac.jp
Thu Feb 8 22:15:14 UTC 2001


  (I wonder if my previous email made it or not.  Sorry if
you read this twice.)

  FXBltSimulation>>copyLoopPixels seems to run over the end
of "destBits," if the right-most pixel is the final pixel in
word.

  A possible fix is attached.

  The behind of story is ...

  What I want to do is to hold a RGB=565, little endian
image in Squeak heap.  For some reason, I call the image as
a ZaurusForm.  ZaurusForm is a subclass of Form.

  I wrote a class-side method of the class as follows, which
I expect to create a ZaurusFrom object from normal Form.
(The class variables are initialized appropriately).  It
seems to work fine now with the fix, but if you guys have
suggestions or better way to do this, please let me know.

ZaurusForm>>fromForm: aForm

	| new bb |
	aForm class = self ifTrue: [^ aForm].
	new _ self basicNew.
	new setExtent: aForm extent depth: Depth bits: (Pixmap new: aForm bitsSize).
	bb _ FXBlt toForm: new.
	bb sourceForm: aForm;
		combinationRule: Form over;
		clipRect: aForm boundingBox;
		destMap: ToARGBMap;
		sourceMap: aForm colormapToARGB;
		colorMap: FromARGBMap.
	bb copyBits.
	^ new.


  -- Yoshiki


-------------- next part --------------
'From Squeak2.9alpha of 13 June 2000 [latest update: #3076] on 8 February 2001 at 10:49:54 am'!

!FXBltSimulation methodsFor: 'inner loop' stamp: 'yo 2/8/2001 09:58'!
copyLoopPixels
	"This version of the inner loop maps source pixels and dest pixels one at a time. This is the most general (and slowest) version which must also keep track of source and dest paint mode by itself."
	| nPix srcShift dstShift destWord srcIndex dstIndex nLines sourceWord lastSrcPix sourcePix srcMask dstMask srcMapped lastDstPix destPix dstMapped resultMapped resultPix srcPaint dstPaint paintMode mergeFn atDestBoundary |
	self inline: false.
	mergeFn _ opTable at: combinationRule+1.
	srcPaint _ srcKeyMode.
	dstPaint _ dstKeyMode.
	paintMode _ srcPaint | dstPaint.

	"Additional inits"
	srcMask _ maskTable at: sourceDepth.
	dstMask _ maskTable at: destDepth.
	sourceIndex _ srcIndex _ sourceBits + (sy * sourcePitch) + ((sx // sourcePPW) *4).
	dstIndex _ destIndex.

	"Precomputed shifts for pickSourcePixels"
	srcShift _ ((sx bitAnd: sourcePPW - 1) * sourceDepth).
	dstShift _ ((dx bitAnd: destPPW - 1) * destDepth).
	atDestBoundary _ dstShift = 0.
	sourceMSB ifTrue:[srcShift _ 32 - sourceDepth - srcShift].
	destMSB ifTrue:[dstShift _ 32 - destDepth - dstShift].

	srcBitShift _ srcShift.
	dstBitShift _ dstShift.

	noSourceMap 
		ifTrue:[pixelDepth _ sourceDepth]
		ifFalse:[pixelDepth _ 32].
	destMask _ -1.
	nLines _ bbH.
	["this is the vertical loop"
		sourceWord _ self srcLongAt: srcIndex.
		destWord _ self dstLongAt: dstIndex.
		"Prefetch first source pixel"
		lastSrcPix _ sourcePix _ sourceWord >> srcShift bitAnd: srcMask.
		srcMapped _ self mapSourcePixel: sourcePix.
		"Prefetch first dest pixel"
		lastDstPix _ destPix _ destWord >> dstShift bitAnd: dstMask.
		dstMapped _ self mapDestPixel: destPix.
		nPix _ bbW.
		["this is the horizontal loop"
			(paintMode) ifTrue:[
				((srcPaint and:[sourcePix = sourceAlphaKey])
					or:[dstPaint and:[destPix ~= destAlphaKey]])
						ifTrue:[resultMapped _ dstMapped]
						ifFalse:[	resultMapped _ self merge: srcMapped with: dstMapped function: mergeFn].
			] ifFalse:[
				resultMapped _ self merge: srcMapped with: dstMapped function: mergeFn.
			].
			(noColorMap and:[resultMapped = dstMapped]) ifFalse:[
				resultPix _ self mapPixel: resultMapped.
				destWord _ destWord bitAnd: (dstMask << dstShift) bitInvert32.
				destWord _ destWord bitOr: (resultPix bitAnd: dstMask) << dstShift.
			].
			sourceMSB ifTrue:[
				"Adjust source if at pixel boundary"
				(srcShift _ srcShift - sourceDepth) < 0 ifTrue:
					[srcShift _ srcShift + 32.
					sourceWord _ self srcLongAt: (srcIndex _ srcIndex + 4)].
			] ifFalse:[
				"Adjust source if at pixel boundary"
				(srcShift _ srcShift + sourceDepth) > 31 ifTrue:
					[srcShift _ srcShift - 32.
					sourceWord _ self srcLongAt: (srcIndex _ srcIndex + 4)].
			].
			destMSB ifTrue:[
				"Adjust dest if at pixel boundary"
				(dstShift _ dstShift - destDepth) < 0 ifTrue:
					[dstShift _ dstShift + 32.
					atDestBoundary _ true.
					self dstLongAt: dstIndex put: destWord.
					destWord _ self dstLongAt: (dstIndex _ dstIndex + 4)
				] ifFalse: [atDestBoundary _ false].
			] ifFalse:[
				"Adjust dest if at pixel boundary"
				(dstShift _ dstShift + destDepth) > 31 ifTrue:
					[dstShift _ dstShift - 32.
					atDestBoundary _ true.
					self dstLongAt: dstIndex put: destWord.
					destWord _ self dstLongAt: (dstIndex _ dstIndex + 4)
				] ifFalse: [atDestBoundary _ false].
			].
		(nPix _ nPix - 1) = 0] whileFalse:[
			"Fetch next source/dest pixel"
			sourcePix _ sourceWord >> srcShift bitAnd: srcMask.
			lastSrcPix = sourcePix ifFalse:[
				srcMapped _ self mapSourcePixel: sourcePix.
				lastSrcPix _ sourcePix].
			destPix _ destWord >> dstShift bitAnd: dstMask.
			lastDstPix = destPix ifFalse:[
				dstMapped _ self mapDestPixel: destPix.
				lastDstPix _ destPix]
		].
	(nLines _ nLines - 1) = 0] whileFalse:[
		"Store last destWord"
		self dstLongAt: dstIndex put: destWord.
		"Advance sourceIndex, destIndex"
		srcIndex _ sourceIndex _ sourceIndex + sourcePitch.
		dstIndex _ destIndex _ destIndex + destPitch.
		srcShift _ srcBitShift.
		dstShift _ dstBitShift.
	].
	atDestBoundary ifFalse: [
		"Store final destWord"
		self dstLongAt: dstIndex put: destWord.
	].! !


More information about the Squeak-dev mailing list