'From Cuis 2.0 of 24 February 2010 [latest update: #440] on 11 March 2010 at 8:40:56 am'!
!classDefinition: #BitBltTest category: #'GraphicsTests-Primitives'!
TestCase subclass: #BitBltTest
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'GraphicsTests-Primitives'!

!BitBltTest methodsFor: 'bugs' stamp: 'jmv 3/11/2010 08:40'!
testAllAlphasRgbAdd
	"self run: #testAllAlphasRgbAdd"
	| sourceForm destForm blt correctAlphas |
     correctAlphas _ 0.
     0  to: 255 do: [:sourceAlpha |
         sourceForm _ Form extent: 1 @ 1 depth: 32.
         sourceForm bits at: 1 put: sourceAlpha << 24 + (33 << 16) + (25 << 8) + 27.
         0 to: 255 do: [:destAlpha |
             destForm _ Form extent: 1 @ 1 depth: 32.
             destForm bits at: 1 put: destAlpha << 24 + (255 << 16) + (255 << 8) + 255.
              blt _ BitBlt new.
              blt sourceForm: sourceForm.
              blt sourceOrigin: 0 @ 0.
              blt setDestForm: destForm.
              blt destOrigin: 0 @ 0.
              blt combinationRule: 20.	"rgbAdd"
              blt copyBits.
              correctAlphas _ correctAlphas
                + (((blt destForm bits at: 1) digitAt: 4) = (destAlpha + sourceAlpha min: 255)
                         ifTrue: [1]
                         ifFalse: [0])
      ]].
     self assert: correctAlphas = 65536 description: 'Some incorrect alpha values computed for BitBlt rule rgbAdd'! !

!BitBltTest methodsFor: 'bugs' stamp: 'jmv 3/11/2010 08:40'!
testAllAlphasRgbMax
	"self run: #testAllAlphasRgbMax"
	| sourceForm destForm blt correctAlphas |
     correctAlphas _ 0.
     0  to: 255 do: [:sourceAlpha |
         sourceForm _ Form extent: 1 @ 1 depth: 32.
         sourceForm bits at: 1 put: sourceAlpha << 24 + (33 << 16) + (25 << 8) + 27.
         0 to: 255 do: [:destAlpha |
             destForm _ Form extent: 1 @ 1 depth: 32.
             destForm bits at: 1 put: destAlpha << 24 + (255 << 16) + (255 << 8) + 255.
              blt _ BitBlt new.
              blt sourceForm: sourceForm.
              blt sourceOrigin: 0 @ 0.
              blt setDestForm: destForm.
              blt destOrigin: 0 @ 0.
              blt combinationRule: 27.	"rgbMax"
              blt copyBits.
              correctAlphas _ correctAlphas
                + (((blt destForm bits at: 1) digitAt: 4) = (destAlpha max: sourceAlpha)
                         ifTrue: [1]
                         ifFalse: [0])
      ]].
     self assert: correctAlphas = 65536 description: 'Some incorrect alpha values computed for BitBlt rule rgbMax'! !

!BitBltTest methodsFor: 'bugs' stamp: 'jmv 3/11/2010 08:40'!
testAllAlphasRgbMin
	"self run: #testAllAlphasRgbMin"
	| sourceForm destForm blt correctAlphas |
     correctAlphas _ 0.
     0  to: 255 do: [:sourceAlpha |
         sourceForm _ Form extent: 1 @ 1 depth: 32.
         sourceForm bits at: 1 put: sourceAlpha << 24 + (33 << 16) + (25 << 8) + 27.
         0 to: 255 do: [:destAlpha |
             destForm _ Form extent: 1 @ 1 depth: 32.
             destForm bits at: 1 put: destAlpha << 24 + (255 << 16) + (255 << 8) + 255.
              blt _ BitBlt new.
              blt sourceForm: sourceForm.
              blt sourceOrigin: 0 @ 0.
              blt setDestForm: destForm.
              blt destOrigin: 0 @ 0.
              blt combinationRule: 28.	"rgbMin"
              blt copyBits.
              correctAlphas _ correctAlphas
                + (((blt destForm bits at: 1) digitAt: 4) = (destAlpha min: sourceAlpha)
                         ifTrue: [1]
                         ifFalse: [0])
      ]].
     self assert: correctAlphas = 65536 description: 'Some incorrect alpha values computed for BitBlt rule rgbMin'! !

!BitBltTest methodsFor: 'bugs' stamp: 'jmv 3/11/2010 08:39'!
testAllAlphasRgbMinInvert
	"self run: #testAllAlphasRgbMinInvert"
	| sourceForm destForm blt correctAlphas |
     correctAlphas _ 0.
     0  to: 255 do: [:sourceAlpha |
         sourceForm _ Form extent: 1 @ 1 depth: 32.
         sourceForm bits at: 1 put: sourceAlpha << 24 + (33 << 16) + (25 << 8) + 27.
         0 to: 255 do: [:destAlpha |
             destForm _ Form extent: 1 @ 1 depth: 32.
             destForm bits at: 1 put: destAlpha << 24 + (255 << 16) + (255 << 8) + 255.
              blt _ BitBlt new.
              blt sourceForm: sourceForm.
              blt sourceOrigin: 0 @ 0.
              blt setDestForm: destForm.
              blt destOrigin: 0 @ 0.
              blt combinationRule: 29.	"rgbMinInvert"
              blt copyBits.
              correctAlphas _ correctAlphas
                + (((blt destForm bits at: 1) digitAt: 4) = (destAlpha min: 255-sourceAlpha)
                         ifTrue: [1]
                         ifFalse: [0])
      ]].
     self assert: correctAlphas = 65536 description: 'Some incorrect alpha values computed for BitBlt rule rgbMinInvert'! !

!BitBltTest methodsFor: 'bugs' stamp: 'jmv 3/11/2010 08:39'!
testAllAlphasRgbMul
	"self run: #testAllAlphasRgbMul"
	| sourceForm destForm blt correctAlphas |
     correctAlphas _ 0.
     0  to: 255 do: [:sourceAlpha |
         sourceForm _ Form extent: 1 @ 1 depth: 32.
         sourceForm bits at: 1 put: sourceAlpha << 24 + (33 << 16) + (25 << 8) + 27.
         0 to: 255 do: [:destAlpha |
             destForm _ Form extent: 1 @ 1 depth: 32.
             destForm bits at: 1 put: destAlpha << 24 + (255 << 16) + (255 << 8) + 255.
              blt _ BitBlt new.
              blt sourceForm: sourceForm.
              blt sourceOrigin: 0 @ 0.
              blt setDestForm: destForm.
              blt destOrigin: 0 @ 0.
              blt combinationRule: 37.	"rgbMul"
              blt copyBits.
              correctAlphas _ correctAlphas
                + (((blt destForm bits at: 1) digitAt: 4) = ((destAlpha+1) * (sourceAlpha+1)- 1 // 256)
                         ifTrue: [1]
                         ifFalse: [0])
      ]].
     self assert: correctAlphas = 65536 description: 'Some incorrect alpha values computed for BitBlt rule rgbMul'! !

!BitBltTest methodsFor: 'bugs' stamp: 'jmv 3/11/2010 08:39'!
testAllAlphasRgbSub
	"self run: #testAllAlphasRgbSub"
	| sourceForm destForm blt correctAlphas |
     correctAlphas _ 0.
     0  to: 255 do: [:sourceAlpha |
         sourceForm _ Form extent: 1 @ 1 depth: 32.
         sourceForm bits at: 1 put: sourceAlpha << 24 + (33 << 16) + (25 << 8) + 27.
         0 to: 255 do: [:destAlpha |
             destForm _ Form extent: 1 @ 1 depth: 32.
             destForm bits at: 1 put: destAlpha << 24 + (255 << 16) + (255 << 8) + 255.
              blt _ BitBlt new.
              blt sourceForm: sourceForm.
              blt sourceOrigin: 0 @ 0.
              blt setDestForm: destForm.
              blt destOrigin: 0 @ 0.
              blt combinationRule: 21.	"rgbSub"
              blt copyBits.
              correctAlphas _ correctAlphas
                + (((blt destForm bits at: 1) digitAt: 4) = (destAlpha - sourceAlpha) abs
                         ifTrue: [1]
                         ifFalse: [0])
      ]].
     self assert: correctAlphas = 65536 description: 'Some incorrect alpha values computed for BitBlt rule rgbSub'! !

!BitBltTest methodsFor: 'bugs' stamp: 'sd 6/5/2005 10:12'!
testAlphaCompositing
	"self run: #testAlphaCompositing"

	| bb f1 f2 mixColor result eps |
	f1 := Form extent: 1@1 depth: 32.
	f2 := Form extent: 1@1 depth: 32.
	eps := 0.5 / 255.
	0 to: 255 do:[:i|
		f1 colorAt: 0@0 put: Color blue.
		mixColor := Color red alpha: i / 255.0.
		f2 colorAt: 0@0 put: mixColor.
		mixColor := f2 colorAt: 0@0.
		bb := BitBlt toForm: f1.
		bb sourceForm: f2.
		bb combinationRule: Form blend.
		bb copyBits.
		result := f1 colorAt: 0@0.
		self assert: (result red - mixColor alpha) abs < eps.
		self assert: (result blue - (1.0 - mixColor alpha)) abs < eps.
		self assert: result alpha = 1.0.
	].! !

!BitBltTest methodsFor: 'bugs' stamp: 'sd 6/5/2005 10:12'!
testAlphaCompositing2
	"self run: #testAlphaCompositing2"

	| bb f1 f2 mixColor result eps |
	f1 := Form extent: 1@1 depth: 32.
	f2 := Form extent: 1@1 depth: 32.
	eps := 0.5 / 255.
	0 to: 255 do:[:i|
		f1 colorAt: 0@0 put: Color transparent.
		mixColor := Color red alpha: i / 255.0.
		f2 colorAt: 0@0 put: mixColor.
		mixColor := f2 colorAt: 0@0.
		bb := BitBlt toForm: f1.
		bb sourceForm: f2.
		bb combinationRule: Form blend.
		bb copyBits.
		result := f1 colorAt: 0@0.
		self assert: (result red - mixColor alpha) abs < eps.
		self assert: result alpha = mixColor alpha.
	].! !

!BitBltTest methodsFor: 'bugs' stamp: 'sd 6/5/2005 10:13'!
testPeekerUnhibernateBug
	"self run: #testPeekerUnhibernateBug"

	| bitBlt |
	bitBlt := BitBlt bitPeekerFromForm: Display.
	bitBlt destForm hibernate.
	self shouldnt:[bitBlt pixelAt: 1@1] raise: Error.! !

!BitBltTest methodsFor: 'bugs' stamp: 'sd 6/5/2005 10:14'!
testPokerUnhibernateBug
	"self run: #testPokerUnhibernateBug"

	| bitBlt |
	bitBlt := BitBlt bitPokerToForm: Display.
	bitBlt sourceForm hibernate.
	self shouldnt:[bitBlt pixelAt: 1@1 put: 0] raise: Error.! !

