Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKshitij Kumar <kshitijakumar@gmail.com>2013-01-14 14:26:10 (GMT)
committer Kshitij Kumar <kshitijakumar@gmail.com>2013-01-14 14:26:10 (GMT)
commit9467fd9cef95c791b49c6374780cd14ea189a5c6 (patch)
tree63b907d4bd7bc662f0adf2e81d9fc2a8ab58074b
parent1db51734219d25e82c7d03f0084515c8dd70c13f (diff)
added sample code to replace mask_pixbuf - on line #339 till #439HEADmaster
-rwxr-xr-xmoon.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/moon.py b/moon.py
index 6a0e839..3e0910c 100755
--- a/moon.py
+++ b/moon.py
@@ -335,11 +335,108 @@ class MoonActivity(activity.Activity):
mask_pixbuf.draw_arc(kgc, True, HALF_SIZE - int(arc_scale / 2), 0, arc_scale, IMAGE_SIZE, 5760, 11520)
maskgc = self.image_pixbuf.new_gc(clip_mask=mask_pixbuf)
'''
+
+ # SAMPLE CODE BEGINS
# Modified image based on public domain photo by John MacCooey
moon_pixbuf = self.moon_stamp.scale_simple(IMAGE_SIZE, IMAGE_SIZE,
GdkPixbuf.InterpType.BILINEAR)
self.image.set_from_pixbuf(moon_pixbuf)
+
+ #mask_pixbuf fix
+
+ surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 200, 200)
+
+ source = cairo.ImageSurface(cairo.FORMAT_RGB24, 200, 200)
+
+ mask = cairo.ImageSurface(cairo.FORMAT_A1, 200, 200)
+
+ # create mask
+ cr = cairo.Context(mask)
+ cr.set_operator(cairo.OPERATOR_SOURCE)
+
+ cr.set_source_rgba(0,0,0,1)
+ cr.paint()
+
+ cr.set_source_rgba(0,0,0,0)
+ cr.move_to(90,90)
+ cr.line_to(110,90)
+ cr.line_to(110,110)
+ cr.line_to(90,110)
+ cr.line_to(90,90)
+ cr.fill()
+
+ mask.write_to_png("mask.png")
+
+ # create a source image
+ cr = cairo.Context(source)
+ cr.set_operator(cairo.OPERATOR_SOURCE)
+ cr.set_source_rgb(1,0,0)
+ cr.move_to(50,50)
+ cr.line_to(150,50)
+ cr.line_to(150,150)
+ cr.line_to(50,150)
+ cr.line_to(50,50)
+ cr.fill()
+ source.write_to_png("source.png")
+
+ # create final surface image
+ cr = cairo.Context(surface)
+ cr.set_operator(cairo.OPERATOR_SOURCE)
+
+ # create a small green block and then write over with a larger block
+ cr.set_source_rgb(0,1,0)
+ cr.move_to(50,50)
+ cr.line_to(150,50)
+ cr.line_to(150,150)
+ cr.line_to(50,150)
+ cr.line_to(50,50)
+ cr.fill()
+
+ # apply source image through mask
+ cr.set_source_surface(source)
+ cr.mask_surface(mask)
+
+ surface.write_to_png("surface.png")
+
+ # now try the same thing with a greyscale (alpha) surface
+
+ surface = cairo.ImageSurface(cairo.FORMAT_A8, 200, 200)
+
+ source = cairo.ImageSurface(cairo.FORMAT_A8, 200, 200)
+
+ # create a source image
+ cr = cairo.Context(source)
+ cr.set_operator(cairo.OPERATOR_SOURCE)
+ cr.set_source_rgba(0,0,0,0.5)
+ cr.move_to(50,50)
+ cr.line_to(150,50)
+ cr.line_to(150,150)
+ cr.line_to(50,150)
+ cr.line_to(50,50)
+ cr.fill()
+ source.write_to_png("source_8.png")
+
+ # create final surface image
+ cr = cairo.Context(surface)
+ cr.set_operator(cairo.OPERATOR_SOURCE)
+
+ # create a small green block and then write over with a larger block
+ cr.set_source_rgba(0,0,0,0.2)
+ cr.move_to(50,50)
+ cr.line_to(150,50)
+ cr.line_to(150,150)
+ cr.line_to(50,150)
+ cr.line_to(50,50)
+ cr.fill()
+
+ # apply source image through mask
+ cr.set_source_surface(source)
+ cr.mask_surface(mask)
+
+ surface.write_to_png("surface_8.png")
+
+ # SAMPLE CODE ENDS HERE
'''
# Composite bright Moon image and semi-transparant Moon for shadow detail