4 The python binding maps mostly to the C API with the 'GP_' prefix stripped.
6 Structures like 'GP_Context' are not created by the 'GP_ContextAlloc()'
7 function but have proper constructor and destructor to keep the Python
8 reference counting happy.
10 There there are more complicated problems like 'GP_ProgressCallback' which
11 needs a proxy function to call the python callback from the C code.
17 -------------------------------------------------------------------------------
18 import gfxprim.core as core
20 # Create 100x100 RGB888 context
21 c = core.Context(100, 100, core.C.PIXEL_RGB888)
23 print("w={} h={} bpp={}".format(c.w, c.h, c.bpp))
25 -------------------------------------------------------------------------------
27 Creates a context of a particular size and pixel type.
29 First two parameters are 'width' and 'height' third is pixel type which is an
32 May raise 'OSError' with 'ENOMEM' errno if allocation has failed.
35 -------------------------------------------------------------------------------
36 import gfxprim.core as core
38 pixel = context.GetPixel(x, y)
40 -------------------------------------------------------------------------------
42 Returns a pixel value at x and y. If coordinates are outside the image zero is
46 -------------------------------------------------------------------------------
47 import gfxprim.core as core
49 context.PutPixel(x, y, pixel)
51 -------------------------------------------------------------------------------
53 Puts a pixel at specified coordinates. If coordinates are outside of the
54 image nothing is done.
56 NOTE: You may want to see link:coordinate_system.html[coordinate system]
60 -------------------------------------------------------------------------------
61 import gfxprim.core as core
63 grayscale = context.Convert(core.C.PIXEL_G8)
65 -------------------------------------------------------------------------------
67 Returns context converted into the desired pixel format.
69 The conversion is naive i.e. the values are just divided/multiplied.
71 //TODO: link to dithering filters etc.
74 -------------------------------------------------------------------------------
75 import gfxprim.core as core
77 # Blits context to target starting at
78 # sx and sy in the source context
79 # tx and ty in in the target
80 context.Blit(sx, sy, target, tx, ty, w, h)
82 # Alternatively the size can be described by
83 # coordinates in the source or target
84 context.Blit(sx, sy, target, tx, ty, sx2=, sy2=)
85 context.Blit(sx, sy, target, tx, ty, tx2=, ty2=)
87 -------------------------------------------------------------------------------
89 Copy a rectangle from self to target.
91 The blits can do simple conversions same as the 'Convert' functions however
92 such blits are slower.
96 TIP: See link:example_py_showimage.html[example] Blit usage.
102 Pixel in gfxprim is a number large enough to store a pixel value. Pixel is
103 passed as a parameter to all drawing functions.
105 Color is a more abstract representation for example RGB triplet.
107 There are several functions to create a pixel value for a particular pixel
111 -------------------------------------------------------------------------------
112 import gfxprim.core as core
114 # You can create a pixel from RGB and pixel type
115 black = core.RGBToPixel(0, 0, 0, core.C.PIXEL_G1)
117 # Or using shortcut from context
118 black = context.RGBToPixel(0, 0, 0)
120 -------------------------------------------------------------------------------
122 These functions creates a pixel suitable for drawing into a bitmap with
123 particular pixel type.
127 -------------------------------------------------------------------------------
128 import gfxprim.core as core
130 # Print all supported pixel types
131 for i in core.PixelTypes:
132 print("Pixel type '{}' size {}".format(i.name, i.size))
134 -------------------------------------------------------------------------------
136 The PixelTypes array stores all supported pixel types
142 -------------------------------------------------------------------------------
143 import gfxprim.core as core
145 core.GP_SetDebugLevel(10)
147 level = core.GP_GetDebugLevel()
148 -------------------------------------------------------------------------------
150 Sets and gets the GFXprim debug level. See link:debug.html[debug messages]
151 description for more details.
156 These are basic 'Context' methods from core module. Importing other modules
157 will add some other (for example gfx module adds all drawing functions).