Passing argument to BitBlt

Karl Ramberg karl.ramberg at chello.se
Sun Jul 1 06:35:55 UTC 2001


I made a experimental hue saturation brightness rule to 
BitBlt (attached) Now I wonder how to pass arguments to 
it. My first thought was using the halftoneForm, so I made
a integer by printing this
hue _ 10.
saturation _ 0.0.
brightness _ 0.05.
hueMask _ 16rFFF.
svMask_ 16rFF.
hShift _ 16.
sShift _ 8.
halfToneForm _
		((hue bitAnd: hueMask) bitShift: hShift) +
		(((saturation * svMask) rounded bitAnd: svMask) bitShift: sShift) +
		 ((brightness * svMask) rounded bitAnd: svMask). -> 655373

And then the doIt:

s _ Form fromFileNamed:'path/to/image'.
half _ Form extent: 1 at 1 depth: 32 bits: 655373 .
(BitBlt
		destForm: Display
		sourceForm: s
		halftoneForm:  half
		combinationRule: 39
		destOrigin: 0 @ 0
		sourceOrigin: 0 @ 0
		extent: s extent
		clipRect: Display computeBoundingBox)copyBitsSimulated .

But for the rule to access the bits I have to use
bits _ halftoneForm bits. 
inside the BitBlt rule. 
Now I wonder if this will work if I want to compile the new BitBlt
rule in a C compiler ?
I also wonder if BitBlt can be compiled as a external plugin. I tried
once a 
few month back and Squeak hang at start up. 
Is there another way to pass the argument ?

Karl
-------------- next part --------------
'From Squeak3.1alpha of 7 March 2001 [latest update: #4164] on 1 July 2001 at 8:16:38 am'!

!BitBltSimulation methodsFor: 'combination rules' stamp: 'kfr 7/1/2001 08:13'!
hsv: sourceWord with: destWord
	| r g b brightness max min saturation span hue i f p q t red green blue componentMax componentMask redShift greenShift rgb adjustHue adjustSaturation adjustBrightness bits |
	bits _ halftoneBase object.
	adjustHue _ (bits bitShift: -16) bitAnd: 16rFFF.
	adjustSaturation _ (bits bitShift: -8) bitAnd: 16rFF.
	adjustBrightness _ bits bitAnd: 16rFF.
	
	adjustSaturation _ (adjustSaturation/ 255) asFloat.
	adjustBrightness _ (adjustBrightness/ 255) asFloat.

          r _ (sourceWord bitShift: -16) bitAnd: 16rFF.
		g _ (sourceWord bitShift: -8) bitAnd: 16rFF.
		b _ sourceWord bitAnd: 16rFF.
	r _ (r/ 255) asFloat.
	g _ (g/ 255) asFloat.
	b _ (b/ 255) asFloat.

	 max _ ((r max: g) max: b).
	min _ ((r min: g) min: b).
     "(max = 1) ifTrue:[self halt]."
	brightness _ max .
	saturation _ ((max - min) max: 0.0) min: 1.0.
	
    saturation _ ((saturation + adjustSaturation) asFloat max: 0.0) min: 1.0.
	brightness _ ((brightness + adjustBrightness) asFloat max: 0.0) min: 1.0.
	span _ (max - min) asFloat.
	span = 0.0 ifTrue: [ hue _ 0.0 ]
				ifFalse:[
						r = max ifTrue: [ hue _ ((g - b) asFloat / span) * 60.0] 
                                      ifFalse: [g = max
			ifTrue: [ hue _ 120.0 + (((b - r) asFloat / span) * 60.0). ]
			ifFalse: [ hue _ 240.0 + (((r - g) asFloat / span) * 60.0) ]].
              hue < 0.0 ifTrue: [ hue _ 360.0 + hue ]].
	hue _ hue + adjustHue.
	(hue < 0.0 or: [hue >= 360.0])
		ifTrue: [hue _ hue - ((hue quo: 360.0) asFloat * 360.0)].
	hue _ hue / 60.0.
	i _ hue asInteger.  "integer part of hue"
	f _ hue fractionPart.         "fractional part of hue"
	p _ (1.0 - saturation) * brightness.
	q _ (1.0 - (saturation * f)) * brightness.
	t _ (1.0 - (saturation * (1.0 - f))) * brightness.

	0 = i ifTrue: [ red _ brightness. green_t .blue_p ].
	1 = i ifTrue: [ red_ q. green_brightness. blue_p ].
	2 = i ifTrue: [ red _ p. green_ brightness. blue_t ].
	3 = i ifTrue: [ red _ p. green_ q. blue _ brightness ].
	4 = i ifTrue: [ red_ t. green_ p. blue_brightness ].
	5 = i ifTrue: [ red_ brightness. green_p. blue_q ].
     componentMax _ 255.0.
     componentMask _ 255.
	redShift _ 16.
	greenShift _ 8.
	
	rgb _
		(((red * componentMax) rounded bitAnd: componentMask) bitShift: redShift) +
		(((green * componentMax) rounded bitAnd: componentMask) bitShift: greenShift) +
		 ((blue * componentMax) rounded bitAnd: componentMask).
	
    ^ rgb.! !

!BitBltSimulation methodsFor: 'initialize-release' stamp: 'kfr 6/30/2001 09:19'!
initBBOpTable
	self cCode: 'opTable[0+1] = (int)clearWordwith'.
	self cCode: 'opTable[1+1] = (int)bitAndwith'.
	self cCode: 'opTable[2+1] = (int)bitAndInvertwith'.
	self cCode: 'opTable[3+1] = (int)sourceWordwith'.
	self cCode: 'opTable[4+1] = (int)bitInvertAndwith'.
	self cCode: 'opTable[5+1] = (int)destinationWordwith'.
	self cCode: 'opTable[6+1] = (int)bitXorwith'.
	self cCode: 'opTable[7+1] = (int)bitOrwith'.
	self cCode: 'opTable[8+1] = (int)bitInvertAndInvertwith'.
	self cCode: 'opTable[9+1] = (int)bitInvertXorwith'.
	self cCode: 'opTable[10+1] = (int)bitInvertDestinationwith'.
	self cCode: 'opTable[11+1] = (int)bitOrInvertwith'.
	self cCode: 'opTable[12+1] = (int)bitInvertSourcewith'.
	self cCode: 'opTable[13+1] = (int)bitInvertOrwith'.
	self cCode: 'opTable[14+1] = (int)bitInvertOrInvertwith'.
	self cCode: 'opTable[15+1] = (int)destinationWordwith'.
	self cCode: 'opTable[16+1] = (int)destinationWordwith'.
	self cCode: 'opTable[17+1] = (int)destinationWordwith'.
	self cCode: 'opTable[18+1] = (int)addWordwith'.
	self cCode: 'opTable[19+1] = (int)subWordwith'.
	self cCode: 'opTable[20+1] = (int)rgbAddwith'.
	self cCode: 'opTable[21+1] = (int)rgbSubwith'.
	self cCode: 'opTable[22+1] = (int)OLDrgbDiffwith'.
	self cCode: 'opTable[23+1] = (int)OLDtallyIntoMapwith'.
	self cCode: 'opTable[24+1] = (int)alphaBlendwith'.
	self cCode: 'opTable[25+1] = (int)pixPaintwith'.
	self cCode: 'opTable[26+1] = (int)pixMaskwith'.
	self cCode: 'opTable[27+1] = (int)rgbMaxwith'.
	self cCode: 'opTable[28+1] = (int)rgbMinwith'.
	self cCode: 'opTable[29+1] = (int)rgbMinInvertwith'.
	self cCode: 'opTable[30+1] = (int)alphaBlendConstwith'.
	self cCode: 'opTable[31+1] = (int)alphaPaintConstwith'.
	self cCode: 'opTable[32+1] = (int)rgbDiffwith'.
	self cCode: 'opTable[33+1] = (int)tallyIntoMapwith'.
	self cCode: 'opTable[34+1] = (int)alphaBlendScaledwith'.
	self cCode: 'opTable[35+1] = (int)alphaBlendScaledwith'.
	self cCode: 'opTable[36+1] = (int)alphaBlendScaledwith'.	
	self cCode: 'opTable[37+1] = (int)rgbMulwith'.
	self cCode: 'opTable[38+1] = (int)pixSwapwith'.
	self cCode: 'opTable[39+1] = (int)hsvwith'.! !


!BitBltSimulation class methodsFor: 'initialization' stamp: 'kfr 6/30/2001 09:40'!
initializeRuleTable
	"BitBltSimulation initializeRuleTable"
	"**WARNING** You MUST change initBBOpTable if you change this"
	OpTable _ #(
		"0" clearWord:with:
		"1" bitAnd:with:
		"2" bitAndInvert:with:
		"3" sourceWord:with:
		"4" bitInvertAnd:with:
		"5" destinationWord:with:
		"6" bitXor:with:
		"7" bitOr:with:
		"8" bitInvertAndInvert:with:
		"9" bitInvertXor:with:
		"10" bitInvertDestination:with:
		"11" bitOrInvert:with:
		"12" bitInvertSource:with:
		"13" bitInvertOr:with:
		"14" bitInvertOrInvert:with:
		"15" destinationWord:with:
		"16" destinationWord:with: "unused - was old paint"
		"17" destinationWord:with: "unused - was old mask"
		"18" addWord:with:
		"19" subWord:with:
		"20" rgbAdd:with:
		"21" rgbSub:with:
		"22" OLDrgbDiff:with:
		"23" OLDtallyIntoMap:with:
		"24" alphaBlend:with:
		"25" pixPaint:with:
		"26" pixMask:with:
		"27" rgbMax:with:
		"28" rgbMin:with:
		"29" rgbMinInvert:with:
		"30" alphaBlendConst:with:
		"31" alphaPaintConst:with:
		"32" rgbDiff:with:
		"33" tallyIntoMap:with:
		"34" alphaBlendScaled:with:

		"35" alphaBlendScaled:with:	"unused here - only used by FXBlt"
		"36" alphaBlendScaled:with:	"unused here - only used by FXBlt"
		"37" rgbMul:with:
		"38" pixSwap:with:
		"39" hsv:with:
	).
	OpTableSize _ OpTable size + 1.  "0-origin indexing"
! !



More information about the Squeak-dev mailing list