Skip to content

Commit

Permalink
#1553 clip the colors, so we can see which values actually make a dif…
Browse files Browse the repository at this point in the history
…ference

git-svn-id: https://xpra.org/svn/Xpra/trunk@16331 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 13, 2017
1 parent 9d7e84f commit eec2cc2
Showing 1 changed file with 54 additions and 20 deletions.
74 changes: 54 additions & 20 deletions src/xpra/client/gtk_base/example/colors_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,63 @@ class ColorGradientWindow(gtk.Window):

def __init__(self):
super(ColorGradientWindow, self).__init__()
self.set_title("Color Gradient")
self.set_position(WIN_POS_CENTER)
self.set_default_size(1024, 768)
self.set_app_paintable(True)
self.set_events(KEY_PRESS_MASK)
self.bpc = 16
if is_gtk3():
self.connect("draw", self.area_draw)
else:
self.connect("expose-event", self.do_expose_event)
self.connect("configure_event", self.configure_event)
#self.connect('resize', changed)
self.connect("destroy", gtk.main_quit)
self.connect("key_press_event", self.on_key_press)
self.show_all()

def configure_event(self, *args):
self.queue_draw()

def on_key_press(self, *args):
self.bpc = ((self.bpc-2) % 16)+1
self.queue_draw()

def do_expose_event(self, *args):
#print("do_expose_event")
cr = self.get_window().cairo_create()
self.area_draw(self, cr)

def area_draw(self, widget, cr):
#Clear everything:
cr.save()
cr.set_operator(cairo.OPERATOR_CLEAR)
w, h = widget.get_size()
cr.rectangle(0, 0, w, h)
cr.fill()
cr.restore()

count = 11
self.index = 0
bh = h//count
def paint_block(R=255, G=255, B=255, label=""):
y = h*self.index//count
blocks = 12
bh = h//blocks
M = 2**16-1
mask = 0
for i in range(16-self.bpc):
mask = mask*2+1
mask = 0xffff ^ mask
def normv(v):
assert 0<=v<=M
iv = int(v) & mask
return max(0, float(iv)/M)
def paint_block(R=M, G=M, B=M, label=""):
y = h*self.index//blocks
self.index += 1
cr.set_operator(cairo.OPERATOR_SOURCE)
for i in range(w):
v = float(i)/float(w)
cr.save()
r = max(0, float(R)*v/255.0)
g = max(0, float(G)*v/255.0)
b = max(0, float(B)*v/255.0)
r = normv(R*v)
g = normv(G*v)
b = normv(B*v)
cr.set_source_rgb(r, g, b)
cr.rectangle(i, y, 1, bh)
cr.fill()
Expand All @@ -61,19 +81,33 @@ def paint_block(R=255, G=255, B=255, label=""):
cr.move_to(w//2-12, y+bh//2+8)
cr.show_text(label)

paint_block(255, 0, 0, "R")
paint_block(0, 254, 0, "G")
paint_block(0, 0, 253, "B")
paint_block(0, 252, 252, "C")
paint_block(251, 0, 251, "M")
paint_block(251, 251, 0, "Y")
#top block for title, all white:
cr.save()
cr.set_source_rgb(1, 1, 1)
cr.rectangle(0, 0, w, bh)
cr.fill()
cr.restore()
#title
cr.set_font_size(32)
cr.set_source_rgb(0, 0, 0)
txt = "Clipped to %i bytes per pixel" % self.bpc
cr.move_to(w//2-8*len(txt), bh//2+8)
cr.show_text(txt)

self.index = 1
paint_block(M, 0, 0, "R")
paint_block(0, M-1, 0, "G")
paint_block(0, 0, M-2, "B")
paint_block(0, M-3, M-3, "C")
paint_block(M-4, 0, M-4, "M")
paint_block(M-5, M-5, 0, "Y")
paint_block(0, 0, 0, "K")
#Black Shade Blocks:
paint_block(255, 255, 255)
paint_block(127, 127, 127)
paint_block(63, 63, 63)
paint_block(31, 31, 31)
paint_block(15, 15, 15)
paint_block(M, M, M)
paint_block(M//2, M//2, M//2)
paint_block(M//4, M//4, M//4)
paint_block(M//8, M//8, M//8)
paint_block(M//16, M//16, M//16)


def main():
Expand Down

0 comments on commit eec2cc2

Please sign in to comment.