Permalink
Browse files

BF: Fixed hex colors with Window and stimuli together

Commit #1696 made the handling of hex colors correct for stimuli, but
broke it for windows. #1822 did the opposite.

The real fix is not to subtract the [1,1,1] but then make clear to the
Window that the values are rgb255 (i.e. not zero-centered) unlike rgb
colors.

This provides that fix and adds tests for hex colors in stimuli and
Window to the test suite to prevent regression
  • Loading branch information...
peircej committed May 15, 2018
1 parent 1c1be86 commit 6ffa413ab3a4e8477e7395a0ddad2a1eb5c18c2f
Showing with 39 additions and 9 deletions.
  1. BIN psychopy/tests/data/circleHex_cm.png
  2. BIN psychopy/tests/data/circleHex_deg.png
  3. BIN psychopy/tests/data/circleHex_degFlat.png
  4. BIN psychopy/tests/data/circleHex_degFlatPos.png
  5. BIN psychopy/tests/data/circleHex_height.png
  6. BIN psychopy/tests/data/circleHex_norm.png
  7. BIN psychopy/tests/data/circleHex_normAddBlend.png
  8. BIN psychopy/tests/data/circleHex_normHexbackground.png
  9. BIN psychopy/tests/data/circleHex_normNoShade.png
  10. BIN psychopy/tests/data/circleHex_pix.png
  11. BIN psychopy/tests/data/circleHex_stencil.png
  12. BIN psychopy/tests/data/dots_normHexbackground.png
  13. BIN psychopy/tests/data/elarray1_normHexbackground.png
  14. BIN psychopy/tests/data/envelopeandrcos_normHexbackground.png
  15. BIN psychopy/tests/data/gabor1_normHexbackground.png
  16. BIN psychopy/tests/data/gabor2_normHexbackground.png
  17. BIN psychopy/tests/data/greyscaleLowContr_normHexbackground.png
  18. BIN psychopy/tests/data/greyscale_normHexbackground.png
  19. BIN psychopy/tests/data/imageAndGauss_normHexbackground.png
  20. BIN psychopy/tests/data/movFrame1_normHexbackground.png
  21. BIN psychopy/tests/data/noiseAndRcos_normAddBlend.png
  22. BIN psychopy/tests/data/noiseAndRcos_normHexbackground.png
  23. BIN psychopy/tests/data/numpyImage_normHexbackground.png
  24. BIN psychopy/tests/data/numpyLowContr_normHexbackground.png
  25. BIN psychopy/tests/data/ratingscale1_normHexbackground.png
  26. BIN psychopy/tests/data/shape2_1_normHexbackground.png
  27. BIN psychopy/tests/data/shape2_2_normHexbackground.png
  28. BIN psychopy/tests/data/simpleimage1_normHexbackground.png
  29. BIN psychopy/tests/data/text1_normHexbackground.png
  30. BIN psychopy/tests/data/text2_normHexbackground.png
  31. BIN psychopy/tests/data/wedge1_normHexbackground.png
  32. BIN psychopy/tests/data/wedge2_normHexbackground.png
  33. +36 −6 psychopy/tests/test_all_visual/test_all_stimuli.py
  34. +1 −1 psychopy/visual/helpers.py
  35. +2 −2 psychopy/visual/window.py
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
@@ -262,6 +262,20 @@ def test_numpyTexture(self):
utils.compareScreenshot('numpyLowContr_%s.png' %(self.contextName), win)
win.flip()
def test_hexColors(self):
win = self.win
circle = visual.Circle(win, fillColor='#0000FF',
size=2* self.scaleFactor)
circle.draw()
grat = visual.GratingStim(win, ori=20, color='#00AAFF',
pos=[0.6 * self.scaleFactor, -0.6 * self.scaleFactor],
sf=3.0 / self.scaleFactor, size=2 * self.scaleFactor,
interpolate=True)
grat.draw()
utils.compareScreenshot('circleHex_%s.png' %(self.contextName), win)
win.flip()
def test_gabor(self):
win = self.win
#using init
@@ -635,40 +649,54 @@ def test_refresh_rate(self):
class TestPygletNorm(_baseVisualTest):
@classmethod
def setup_class(self):
self.win = visual.Window([128,128], winType='pyglet', pos=[50,50], allowStencil=True, autoLog=False)
self.win = visual.Window([128,128], winType='pyglet', pos=[50,50],
allowStencil=True, autoLog=False)
self.contextName='norm'
self.scaleFactor=1#applied to size/pos values
class TestPygletHexColor(_baseVisualTest):
@classmethod
def setup_class(self):
self.win = visual.Window([128,128], winType='pyglet', pos=[50,50],
color="#FF0099",
allowStencil=True, autoLog=False)
self.contextName='normHexbackground'
self.scaleFactor=1#applied to size/pos values
if not _travisTesting:
class TestPygletBlendAdd(_baseVisualTest):
@classmethod
def setup_class(self):
self.win = visual.Window([128,128], winType='pyglet', pos=[50,50], blendMode='add', useFBO=True)
self.win = visual.Window([128,128], winType='pyglet', pos=[50,50],
blendMode='add', useFBO=True)
self.contextName='normAddBlend'
self.scaleFactor=1#applied to size/pos values
class TestPygletNormFBO(_baseVisualTest):
@classmethod
def setup_class(self):
self.win = visual.Window([128,128], winType='pyglet', pos=[50,50], allowStencil=True, autoLog=False, useFBO=True)
self.win = visual.Window([128,128], winType='pyglet', pos=[50,50],
allowStencil=True, autoLog=False, useFBO=True)
self.contextName='norm'
self.scaleFactor=1#applied to size/pos values
class TestPygletHeight(_baseVisualTest):
@classmethod
def setup_class(self):
self.win = visual.Window([128,64], winType='pyglet', pos=[50,50], allowStencil=False, autoLog=False)
self.win = visual.Window([128,64], winType='pyglet', pos=[50,50],
allowStencil=False, autoLog=False)
self.contextName='height'
self.scaleFactor=1#applied to size/pos values
class TestPygletNormNoShaders(_baseVisualTest):
@classmethod
def setup_class(self):
self.win = visual.Window([128,128], monitor='testMonitor', winType='pyglet', pos=[50,50], allowStencil=True, autoLog=False)
self.win = visual.Window([128,128], monitor='testMonitor',
winType='pyglet', pos=[50,50],
allowStencil=True, autoLog=False)
self.win._haveShaders=False
self.contextName='normNoShade'
self.scaleFactor=1#applied to size/pos values
@@ -677,7 +705,9 @@ def setup_class(self):
class TestPygletNormStencil(_baseVisualTest):
@classmethod
def setup_class(self):
self.win = visual.Window([128,128], monitor='testMonitor', winType='pyglet', pos=[50,50], allowStencil=True, autoLog=False)
self.win = visual.Window([128,128], monitor='testMonitor',
winType='pyglet', pos=[50,50],
allowStencil=True, autoLog=False)
self.contextName='stencil'
self.scaleFactor=1#applied to size/pos values
@@ -211,7 +211,7 @@ def setColor(obj, color, colorSpace=None, operation='',
return
elif color[0] == '#' or color[0:2] == '0x':
# e.g. obj.rgb=[0,0,0]
setattr(obj, rgbAttrib, np.array(colors.hex2rgb255(color))- [1,1,1])
setattr(obj, rgbAttrib, np.array(colors.hex2rgb255(color)))
obj.__dict__[colorSpaceAttrib] = 'hex' # eg obj.colorSpace='hex'
obj.__dict__[colorAttrib] = color # eg Qr='#000000'
setTexIfNoShaders(obj)
@@ -1235,11 +1235,11 @@ def setColor(self, color, colorSpace=None, operation='', log=None):
colorAttrib='color')
# These spaces are 0-centred
if self.colorSpace in ['rgb', 'dkl', 'lms', 'hsv', 'hex']:
if self.colorSpace in ['rgb', 'dkl', 'lms', 'hsv']:
# RGB in range 0:1 and scaled for contrast
desiredRGB = (self.rgb + 1) / 2.0
# rgb255 and named are not...
elif self.colorSpace in ['rgb255', 'named']:
elif self.colorSpace in ['rgb255', 'named', 'hex']:
desiredRGB = self.rgb / 255.0
else: # some array / numeric stuff
msg = 'invalid value %r for Window.colorSpace'

0 comments on commit 6ffa413

Please sign in to comment.