[Vm-dev] VM Maker: VMMaker.oscog-nice.3249.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Aug 22 18:02:42 UTC 2022


Nicolas Cellier uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-nice.3249.mcz

==================== Summary ====================

Name: VMMaker.oscog-nice.3249
Author: nice
Time: 22 August 2022, 8:02:32.900315 pm
UUID: 6b05b927-1aad-484c-b8df-95147a9ca6b4
Ancestors: VMMaker.oscog-nice.3248

...and fix missing bitAnd: for safely multiplexing the division by 255...

This is a better fix for https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/643.
Sorry for the noise

=============== Diff against VMMaker.oscog-nice.3248 ===============

Item was changed:
  ----- Method: BitBltSimulation>>alphaBlendConst:with:paintMode: (in category 'combination rules') -----
  alphaBlendConst: sourceWord with: destinationWord paintMode: paintMode
  	"Blend sourceWord with destinationWord using a constant alpha.
  	Alpha is encoded as 0 meaning 0.0, and 255 meaning 1.0.
  	The blend produced is alpha*source + (1.0-alpha)*dest, with the
  	computation being performed independently on each color component.
  	This function could eventually blend into any depth destination,
  	using the same color averaging and mapping as warpBlt.
  	paintMode = true means do nothing if the source pixel value is zero."
  
  	"This first implementation works with dest depths of 16 and 32 bits only.
  	Normal color mapping will allow sources of lower depths in this case,
  	and results can be mapped directly by truncation, so no extra color maps are needed.
  	To allow storing into any depth will require subsequent addition of two other
  	colormaps, as is the case with WarpBlt."
  
  	| pixMask destShifted sourceShifted destPixVal rgbMask sourcePixVal unAlpha result pixBlend shift blend maskShifted bitsPerColor blendAG blendRB |
  	<inline: false>
  	<returnTypeC: 'unsigned int'>
  	<var: 'sourceWord' type: #'unsigned int'>
  	<var: 'destinationWord' type: #'unsigned int'>
  	<var: 'blendRB' type: #'unsigned int'>
  	<var: 'blendAG' type: #'unsigned int'>
  	<var: 'result' type: #'unsigned int'>
  	<var: 'sourceAlpha' type: #'unsigned int'>
  	<var: 'unAlpha' type: #'unsigned int'>
  	<var: 'sourceShifted' type: #'unsigned int'>
  	<var: 'destShifted' type: #'unsigned int'>
  	<var: 'maskShifted' type: #'unsigned int'>
  	<var: 'pixMask' type: #'unsigned int'>
  	<var: 'rgbMask' type: #'unsigned int'>
  	<var: 'pixBlend' type: #'unsigned int'>
  	<var: 'blend' type: #'unsigned int'>
  	destDepth < 16 ifTrue: [^ destinationWord "no-op"].
  	unAlpha := 255 - sourceAlpha.
  	result := destinationWord.
  	destPPW = 1 ifTrue:["32bpp blends include alpha"
  		paintMode & (sourceWord = 0)  "painting a transparent pixel" ifFalse:[
  
  				blendRB := ((sourceWord bitAnd: 16rFF00FF) * sourceAlpha) +
  						((destinationWord bitAnd: 16rFF00FF) * unAlpha) + 16r800080.	"blend red and blue"
  
  				blendAG := ((sourceWord>> 8 bitAnd: 16rFF00FF) * sourceAlpha) +
  						((destinationWord>>8 bitAnd: 16rFF00FF) * unAlpha) + 16r800080.	"blend alpha and green"
  
+ 				blendRB := (blendRB >> 8 bitAnd: 16rFF00FF) + blendRB >> 8 bitAnd: 16rFF00FF.	"divide by 255"
+ 				blendAG := (blendAG >> 8 bitAnd: 16rFF00FF) + blendAG >> 8 bitAnd: 16rFF00FF.
- 				blendRB := blendRB >> 8 + blendRB >> 8 bitAnd: 16rFF00FF.	"divide by 255"
- 				blendAG := blendAG >> 8 + blendAG >> 8 bitAnd: 16rFF00FF.
  				result := blendRB bitOr: blendAG<<8.
  		].
  	] ifFalse:[
  		pixMask := maskTable at: destDepth.
  		bitsPerColor := 5.
  		rgbMask := 16r1F.
  		maskShifted := destMask.
  		destShifted := destinationWord.
  		sourceShifted := sourceWord.
  		1 to: destPPW do:[:j |
  			sourcePixVal := sourceShifted bitAnd: pixMask.
  			((maskShifted bitAnd: pixMask) = 0  "no effect if outside of dest rectangle"
  				or: [paintMode & (sourcePixVal = 0)  "or painting a transparent pixel"])
  			ifFalse:
  				[destPixVal := destShifted bitAnd: pixMask.
  				pixBlend := 0.
  				1 to: 3 do:
  					[:i | shift := (i-1)*bitsPerColor.
  					blend := (((sourcePixVal>>shift bitAnd: rgbMask) * sourceAlpha)
  								+ ((destPixVal>>shift bitAnd: rgbMask) * unAlpha))
  						 	+ 128. "+128 for rounding"
  					blend := blend >> 8 + blend >> 8 bitAnd: rgbMask. "divide by 255"
  					pixBlend := pixBlend bitOr: blend<<shift].
  				result := (result bitAnd: (pixMask << (j-1*16)) bitInvert32)
  								bitOr: pixBlend << (j-1*16)].
  			maskShifted := maskShifted >> destDepth.
  			sourceShifted := sourceShifted >> destDepth.
  			destShifted := destShifted >> destDepth].
  	].
  	^ result
  !

Item was changed:
  ----- Method: BitBltSimulation>>alphaBlendScaled:with: (in category 'combination rules') -----
  alphaBlendScaled: sourceWord with: destinationWord
  	"Blend sourceWord with destinationWord using the alpha value from sourceWord.
  	Alpha is encoded as 0 meaning 0.0, and 255 meaning 1.0.
  	In contrast to alphaBlend:with: the color produced is
  
  		srcColor + (1-srcAlpha) * dstColor
  
  	e.g., it is assumed that the source color is already scaled."
  	<returnTypeC: #'unsigned int'>
  	<inline: false>	"Do NOT inline this into optimized loops"
  	| unAlpha rb ag |
  	<var: 'sourceWord' type: #'unsigned int'>
  	<var: 'destinationWord' type: #'unsigned int'>
  	<var: 'rb' type: #'unsigned int'>
  	<var: 'ag' type: #'unsigned int'>
  	<var: 'unAlpha' type: #'unsigned int'>
  	unAlpha := 255 - (sourceWord >> 24).  "High 8 bits of source pixel is source opacity (ARGB format)"
  	rb := (destinationWord bitAnd: 16rFF00FF) * unAlpha + 16r800080. "add 16r80 for rounding division to nearest byte"
- 	rb := rb >> 8 + rb >> 8. "divide by 255"
- 	rb := (rb bitAnd: 16rFF00FF) + (sourceWord bitAnd: 16rFF00FF). "blend red and blue components"
  	ag := (destinationWord >> 8 bitAnd: 16rFF00FF) * unAlpha + 16r800080. "add 16r80 for rounding division to nearest byte"
+ 	rb := (rb >> 8 bitAnd: 16rFF00FF) + rb >> 8. "divide by 255"
+ 	ag := (ag >> 8 bitAnd: 16rFF00FF) + ag >> 8. "divide by 255"
+ 	rb := (rb bitAnd: 16rFF00FF) + (sourceWord bitAnd: 16rFF00FF). "blend red and blue components"
- 	ag := ag >> 8 + ag >> 8. "divide by 255"
  	ag := (ag bitAnd: 16rFF00FF) + (sourceWord >> 8 bitAnd: 16rFF00FF). "blend alpha and green components"
  	rb := (rb bitAnd: 16rFF00FF) bitOr: (rb bitAnd: 16r01000100) * 16rFF >> 8. "saturate red and blue components if there is a carry"
  	ag := (ag bitAnd: 16rFF00FF) << 8 bitOr: (ag bitAnd: 16r01000100) * 16rFF. "saturate alpha and green components if there is a carry"
  	^ag bitOr: rb "recompose"!



More information about the Vm-dev mailing list