Skip to content

Commit

Permalink
BF: Fixed hex colors with Window and stimuli together
Browse files Browse the repository at this point in the history
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 17, 2018
1 parent 1c1be86 commit 6ffa413
Show file tree
Hide file tree
Showing 35 changed files with 39 additions and 9 deletions.
Binary file added psychopy/tests/data/circleHex_cm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_deg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_degFlat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_degFlatPos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_height.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_norm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_normAddBlend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_normNoShade.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_pix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/circleHex_stencil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/dots_normHexbackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/gabor1_normHexbackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/gabor2_normHexbackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/noiseAndRcos_normAddBlend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/numpyImage_normHexbackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added psychopy/tests/data/shape2_1_normHexbackground.png
Binary file added psychopy/tests/data/shape2_2_normHexbackground.png
Binary file added psychopy/tests/data/text1_normHexbackground.png
Binary file added psychopy/tests/data/text2_normHexbackground.png
Binary file added psychopy/tests/data/wedge1_normHexbackground.png
Binary file added psychopy/tests/data/wedge2_normHexbackground.png
42 changes: 36 additions & 6 deletions psychopy/tests/test_all_visual/test_all_stimuli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion psychopy/visual/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions psychopy/visual/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 6ffa413

Please sign in to comment.