Changeset 3641
- Timestamp:
- 18/10/08 19:15:39 (3 months ago)
- Location:
- trunk
- Files:
-
- 5 added
- 1 removed
- 4 modified
-
doc/index.rst (modified) (1 diff)
-
imlib2/doc/Makefile (added)
-
imlib2/doc/conf.py (added)
-
imlib2/doc/epydoc (deleted)
-
imlib2/doc/font.rst (added)
-
imlib2/doc/image.rst (added)
-
imlib2/doc/index.rst (added)
-
imlib2/setup.py (modified) (1 diff)
-
imlib2/src/font.py (modified) (3 diffs)
-
imlib2/src/image.py (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/index.rst
r3637 r3641 135 135 ^^^^^^^^^^ 136 136 137 This module has no description yet 138 139 * Detailed documentation is unavailable. 137 kaa.imlib2 is a simple Python wrapper around imlib2 for fast image 138 processing. 139 140 * See `kaa.imlib2 documentation <imlib2/index.html>`_ for details. 140 141 * Download the latest `release of kaa.imlib2 141 142 <http://sourceforge.net/project/showfiles.php?group_id=46652&package_id=216046>`_ -
trunk/imlib2/setup.py
r3519 r3641 61 61 62 62 setup(module = 'imlib2', 63 version = '0.2. 3',63 version = '0.2.4', 64 64 license = 'LGPL', 65 65 summary = 'Python bindings for Imlib2', 66 epydoc = [ 'doc/epydoc' ],67 66 rpminfo = { 68 67 'requires': 'python-kaa-base >= 0.1.2, imlib2 >= 1.2.1', -
trunk/imlib2/src/font.py
r2604 r3641 83 83 """ 84 84 Get the font metrics for the specified text as rendered by the 85 current font. 86 87 Arguments: 88 text: the text for which to retrieve the metric. 89 90 Returns: a 4-tuple containing the width, height, horizontal advance, 91 and vertical advance of the text when rendered. 85 current font. The given text is used to retrieve the 86 metric. The functions returns a 4-tuple containing the width, 87 height, horizontal advance, and vertical advance of the text 88 when rendered. 92 89 """ 93 90 return self._font.get_text_size(utf8(text)) … … 96 93 def set_color(self, color): 97 94 """ 98 Sets the default color for text rendered with this font. 99 100 Arguments: 101 color: a 3- or 4-tuple holding the red, green, blue, and alpha 102 values of the color in which to render text with this 103 font context. If color is a 3-tuple, the implied alpha 104 is 255. 95 Sets the default color for text rendered with this font. Color 96 is a 3- or 4-tuple holding the red, green, blue, and alpha 97 values of the color in which to render text with this font 98 context. If color is a 3-tuple, the implied alpha is 255. 105 99 """ 106 100 if len(color) == 3: … … 123 117 """ 124 118 Set a text style. Based on the style different color parameter 125 need to be set. 119 need to be set. Depending on the style additional parameter 120 must be set: 126 121 127 Arguments: 128 style: the style to use (disable with TEXT_STYLE_PLAIN) 129 shadow: shadow color for TEXT_STYLE_SHADOW, TEXT_STYLE_OUTLINE_SHADOW, 130 TEXT_STYLE_FAR_SHADOW, TEXT_STYLE_OUTLINE_SOFT_SHADOW, 131 TEXT_STYLE_SOFT_SHADOW and TEXT_STYLE_FAR_SOFT_SHADOW 132 outline: outline color for TEXT_STYLE_OUTLINE, TEXT_STYLE_SOFT_OUTLINE, 133 TEXT_STYLE_OUTLINE_SHADOW and TEXT_STYLE_OUTLINE_SOFT_SHADOW 134 glow: glow color 1 for TEXT_STYLE_GLOW 135 glow2: glow color 2 for TEXT_STYLE_GLOW 122 * TEXT_STYLE_PLAIN 123 * TEXT_STYLE_SHADOW, requires shadow 124 * TEXT_STYLE_OUTLINE, requires outline 125 * TEXT_STYLE_SOFT_OUTLINE, requires outline 126 * TEXT_STYLE_GLOW, requires glow, glow2 127 * TEXT_STYLE_OUTLINE_SHADOW, requires shadow, outline 128 * TEXT_STYLE_FAR_SHADOW, requires shadow 129 * TEXT_STYLE_OUTLINE_SOFT_SHADOW, requires shadow, outline 130 * TEXT_STYLE_SOFT_SHADOW, requires shadow 131 * TEXT_STYLE_FAR_SOFT_SHADOW, requires shadow 136 132 """ 137 133 self.style = style -
trunk/imlib2/src/image.py
r3521 r3641 55 55 class Image(object): 56 56 """ 57 Imlib2 Image class. The constructor can be called directly, or a new 58 Image object may be created via the new() and open() module functions. 57 Imlib2 Image class. The constructor can be called directly, or a 58 new Image object may be created via the new() and open() module 59 functions. Instantiate the image from another Image instance, an 60 instance of the backend's image class or type, or a file name from 61 which to load the image. 59 62 """ 60 63 … … 62 65 """ 63 66 Create a new Image object. 64 65 @param image_or_filename: Instantiate the image from another Image66 instance, an instance of the backend's image67 class or type, or a file name from which to load68 the image.69 67 """ 70 68 if type(image_or_filename) in types.StringTypes: … … 86 84 """ 87 85 Supports these attributes: 88 89 - B{size}: tuple containing the width and height of the image 90 - B{width}: width of the image 91 - B{height}: height of the image 92 - B{format}: format of the image if loaded from file (e.g. PNG, JPEG) 93 - B{rowstride}: number of bytes per row of pixels 94 - B{has_alpha}: True if the image has an alpha channel, False otherwise 95 - B{filename}: filename if loaded from file 86 - size: tuple containing the width and height of the image 87 - width: width of the image 88 - height: height of the image 89 - format: format of the image if loaded from file (e.g. PNG, JPEG) 90 - rowstride: number of bytes per row of pixels 91 - has_alpha: True if the image has an alpha channel, False otherwise 92 - filename: filename if loaded from file 96 93 """ 97 94 if attr in ('width', 'height', 'format', 'mode', 'filename', 'rowstride'): … … 121 118 def get_raw_data(self, format = 'BGRA', write = False): 122 119 """ 123 Returns raw image data for read only access. 124 125 @param format: pixel format of the raw data to be returned. If 'format' is 126 not a supported format, ValueError is raised. Format 127 can be any combination of RGB or RGBA. 128 129 @return: A buffer object representing the raw pixel data. The buffer 130 will be a writable buffer if 'write' was True or if the 131 'format' was non-native (i.e. something other than BGRA). If 132 'format' was BGRA and 'write' was True, you'll need to call 133 put_back_raw_data() when you're done writing to the buffer. 120 Returns raw image data for read only access. *format* is pixel 121 format of the raw data to be returned. If it is not a 122 supported format, ValueError is raised. Format can be any 123 combination of RGB or RGBA. The function returns a buffer 124 object representing the raw pixel data. The buffer will be a 125 writable buffer if 'write' was True or if the 'format' was 126 non-native (i.e. something other than BGRA). If 'format' was 127 BGRA and 'write' was True, you'll need to call 128 put_back_raw_data() when you're done writing to the buffer. 134 129 """ 135 130 if False in map(lambda x: x in 'RGBA', list(format)): … … 148 143 def scale(self, (w, h), src_pos = (0, 0), src_size = (-1, -1)): 149 144 """ 150 Scale the image and return a new image. 151 152 @param w,h: the width and height of the new image. If either argument 153 is -1, that dimension is calculated from the other dimension 154 while retaining the original aspect ratio. 155 156 @return: a new Image instance representing the scaled image. 145 Scale the image and return a new image. If either width or 146 height is -1, that dimension is calculated from the other 147 dimension while retaining the original aspect ratio. 157 148 """ 158 149 src_w, src_h = src_size … … 176 167 def crop(self, (x, y), (w, h)): 177 168 """ 178 Crop the image and return a new image. 179 180 Arguments: 181 x, y, w, h: represents the left, top, width, height region in 182 the image. 183 184 Returns: a new Image instance representing the cropped image. 169 return a new Image which is croped at x,y with the given size. 185 170 """ 186 171 return self.scale((w, h), (x, y), (w, h) ) … … 189 174 def rotate(self, angle): 190 175 """ 191 Rotate the image and return a new image. 192 193 @param angle: the angle in degrees by which to rotate the image. 194 @return: a new Image instance representing the rotated image. 195 196 @bug: imlib2's rotate works all wonky. Doesn't act how I expect. 176 Rotate the image by the angle in degrees and return a new 177 image. Note: imlib2's rotate works all wonky. Doesn't act how 178 expected for angles different than 90, 180 and 270. 197 179 """ 198 180 return Image(self._image.rotate(angle * math.pi / 180)) … … 201 183 def orientate(self, orientation): 202 184 """ 203 Performs 90 degree rotations on the image. 204 205 @param orientation: 206 - 0: no rotation; 207 - 1: rotate clockwise 90 degrees, 208 - 2: rotate clockwise 180 degrees; 209 - 3: rotates clockwise 270 degrees. 210 @return: None 185 Performs 90 degree rotations on the image. Possible values are 186 0 (no rotation), 1 (rotate clockwise 90 degrees), 2 (rotate 187 clockwise 180 degrees) and 3 (rotates clockwise 270 degrees). 211 188 """ 212 189 self._image.orientate(orientation) … … 217 194 """ 218 195 Flips the image on its horizontal axis. 219 220 @return: None.221 196 """ 222 197 self._image.flip(True, False, False) … … 227 202 """ 228 203 Flips the image on its vertical axis. 229 230 @return: None.231 204 """ 232 205 self._image.flip(False, True, False) … … 237 210 """ 238 211 Flips the image on along its diagonal. 239 240 @return: None.241 212 """ 242 213 self._image.flip(False, False, True) … … 247 218 """ 248 219 Blur the image 249 250 @return: None.251 220 """ 252 221 self._image.blur(radius) … … 257 226 """ 258 227 Sharpen the image 259 260 @return: None.261 228 """ 262 229 self._image.sharpen(radius) … … 266 233 def scale_preserve_aspect(self, (w, h)): 267 234 """ 268 Scales the image while retaining the original aspect ratio and return 269 a new image. 270 271 Arguments: 272 w, h: the maximum size of the new image. The new image will be as 273 large as possible, using w, h as the upper limits, while 274 retaining the original aspect ratio. 275 276 Returns: a new Image instance represented the scaled image. 235 Scales the image while retaining the original aspect ratio and 236 return a new image. The given size is the maximum size of the 237 new image. The new image will be as large as possible, using 238 w, h as the upper limits, while retaining the original aspect 239 ratio. 277 240 """ 278 241 if 0 in (w, h): … … 304 267 Copies a region within the image. 305 268 306 Arguments: 307 src_pos: a tuple holding the x, y coordinates marking the top left 308 of the region to be moved. 309 size: a tuple holding the width and height of the region to move. 310 If either dimension is -1, then that dimension extends to 311 the far edge of the image. 312 dst_pos: a tuple holding the x, y coordinates within the image 313 where the region will be moved to. 314 @return: None 269 :param src_pos: a tuple holding the x, y coordinates marking the top left 270 of the region to be moved. 271 :param size: a tuple holding the width and height of the region to move. 272 If either dimension is -1, then that dimension extends to the far edge 273 of the image. 274 :param dst_pos: a tuple holding the x, y coordinates within the image 275 where the region will be moved to. 315 276 """ 316 277 self._image.copy_rect(src_pos, size, dst_pos) … … 324 285 Blends one image onto another. 325 286 326 @param src: the image being blended onto 'self'327 @param dst_pos: a tuple holding the x, y coordinates where the source287 :param src: the image being blended onto 'self' 288 :param dst_pos: a tuple holding the x, y coordinates where the source 328 289 image will be blended onto the destination image. 329 @param src_pos: a tuple holding the x, y coordinates within the source290 :param src_pos: a tuple holding the x, y coordinates within the source 330 291 image where blending will start. 331 @param src_size: a tuple holding the width and height of the source292 :param src_size: a tuple holding the width and height of the source 332 293 image to be blended. A value of -1 for either one 333 294 indicates the full dimension of the source image. 334 @param alpha: the "layer" alpha that is applied to all pixels of the295 :param alpha: the "layer" alpha that is applied to all pixels of the 335 296 image. If an individual pixel has an alpha of 128 and 336 297 this value is 128, the resulting pixel will have an … … 339 300 and 256 is a special value that means alpha blending is 340 301 disabled. 341 @param merge_alpha: if True, the alpha channel is also blended. If False,302 :param merge_alpha: if True, the alpha channel is also blended. If False, 342 303 the destination image's alpha channel is untouched and 343 304 the RGB values are compensated 344 345 @return: None.346 305 """ 347 306 … … 360 319 def clear(self, (x, y) = (0, 0), (w, h) = (-1, -1)): 361 320 """ 362 Clears the image at the specified rectangle, resetting all pixels in 363 that rectangle to fully transparent. 364 365 Arguments: 366 x, y: left and top coordinates of the rectangle to be cleared. 367 Default is the top left corner. 368 w, h: width and height of the rectangle to be cleared. If either 369 value is -1 then the image is cleared to the far edge. 370 371 @return: None 321 Clears the image at the specified rectangle, resetting all 322 pixels in that rectangle to fully transparent. if either width 323 or height of the rectangle to be cleared is -1 then the image 324 is cleared to the far edge. Default values clear the whole image. 372 325 """ 373 326 x = max(0, min(self.width, x)) … … 393 346 alpha channel will be modified. The mask is drawn to the 394 347 full width/height of maskimg. 395 396 @return: None397 348 """ 398 349 … … 404 355 """ 405 356 Creates a copy of the current image. 406 407 @return: a new Image instance with a copy of the current image.408 357 """ 409 358 return Image(self._image.clone()) … … 412 361 def set_font(self, font_or_font_name): 413 362 """ 414 Sets the font context to font_or_font_name. Subsequent calls to 415 draw_text() will be rendered using this font. 416 417 Arguments: 418 font_or_fontname: either a Font object, or a string containing the 419 font's name and size. This string is in the 420 form "Fontname/Size" such as "Arial/16" 421 422 423 Returns: a Font instance represent the specified font. If 424 'font_or_fontname' is already a Font instance, it is simply 425 returned back to the caller. 363 Sets the font context to font_or_font_name. Subsequent calls 364 to draw_text() will be rendered using this font. 365 font_or_fontname is either a Font object, or a string 366 containing the font's name and size. This string is in the 367 form 'Fontname/Size' such as 'Arial/16' 368 369 The function returns a Font instance represent the specified 370 font. If 'font_or_fontname' is already a Font instance, it is 371 simply returned back to the caller. 426 372 """ 427 373 if type(font_or_font_name) in types.StringTypes: … … 434 380 def get_font(self): 435 381 """ 436 Gets the current Font context. 437 438 @return: A Font instance as created by set_font() or None if no font 439 context is defined. 382 Gets the current Font context. Either the Font instance as 383 created by set_font() or None if no font context is defined. 440 384 """ 441 385 return self.font … … 448 392 Draws text on the image. 449 393 450 @param x, y: the left/top coordinates within the current image394 :param x, y: the left/top coordinates within the current image 451 395 where the text will be rendered. 452 @param text: a string holding the text to be rendered.453 @param color: a 3- or 4-tuple holding the red, green, blue, and396 :param text: a string holding the text to be rendered. 397 :param color: a 3- or 4-tuple holding the red, green, blue, and 454 398 alpha values of the color in which to render the 455 399 font. If color is a 3-tuple, the implied alpha 456 400 is 255. If color is None, the color of the font 457 401 context, as specified by set_font(), is used. 458 @param font_or_fontname: either a Font object, or a string containing the402 :param font_or_fontname: either a Font object, or a string containing the 459 403 font's name and size. This string is in the 460 404 form "Fontname/Size" such as "Arial/16". If this 461 405 parameter is none, the font context is used, as 462 406 specified by set_font(). 463 @param style: The style to use. Id style is None, the style from407 :param style: The style to use. Id style is None, the style from 464 408 the font object will be used. 465 409 466 @return: a 4-tuple representing the width, height, horizontal advance,410 :return: a 4-tuple representing the width, height, horizontal advance, 467 411 and vertical advance of the rendered text. 468 412 """ … … 513 457 Draws a rectangle on the image. 514 458 515 @param x, y: the top left corner of the rectangle.516 @param w, h: the width and height of the rectangle.517 @param color: a 3- or 4-tuple holding the red, green, blue, and alpha459 :param x, y: the top left corner of the rectangle. 460 :param w, h: the width and height of the rectangle. 461 :param color: a 3- or 4-tuple holding the red, green, blue, and alpha 518 462 values of the color in which to draw the rectangle. If 519 463 color is a 3-tuple, the implied alpha is 255. 520 @param fill: whether the rectangle should be filled or not. The default464 :param fill: whether the rectangle should be filled or not. The default 521 465 is true. 522 523 @return: None524 466 """ 525 467 if len(color) == 3: … … 532 474 Draws an ellipse on the image. 533 475 534 @param xc, yc: the x, y coordinates of the center of the ellipse.535 @param a, b: the horizontal and veritcal amplitude of the ellipse.536 @param color: a 3- or 4-tuple holding the red, green, blue, and alpha476 :param xc, yc: the x, y coordinates of the center of the ellipse. 477 :param a, b: the horizontal and veritcal amplitude of the ellipse. 478 :param color: a 3- or 4-tuple holding the red, green, blue, and alpha 537 479 values of the color in which to draw the ellipse. If 538 480 color is a 3-tuple, the implied alpha is 255. 539 @param fill: whether the ellipse should be filled or not. The default481 :param fill: whether the ellipse should be filled or not. The default 540 482 is true. 541 542 @return: None543 483 """ 544 484 if len(color) == 3: … … 550 490 def get_pixel(self, (x, y)): 551 491 """ 552 Get the color for the specified pixel. 553 554 @param x, y: Coordinates of the pixel for which to return the color. 555 @return: a 4-tuple representing the color of the pixel. The tuple is 556 in RGBA format, or (red, green, blue, alpha). 492 Get the color for the specified pixel as a 4-tuple 493 representing the color of the pixel. The tuple is in RGBA 494 format, or (red, green, blue, alpha). 557 495 """ 558 496 return self._image.get_pixel((x,y)) … … 561 499 def set_alpha(self, has_alpha): 562 500 """ 563 Enable / disable the alpha layer. 564 565 @param has_alpha: if True, the alpha layer will be enabled, if 566 False disabled 567 @return: None 501 Enable / disable the alpha layer. If has_alpha is True, the 502 alpha layer will be enabled, if False disabled 568 503 """ 569 504 if has_alpha: … … 576 511 def save(self, filename, format = None): 577 512 """ 578 Saves the image to a file. 579 580 @param format: the format of the written file (jpg, png, etc.). If format 581 is None, the format is gotten from the filename extension. 582 583 @return: None. 513 Saves the image to a file. The format for the written file 514 (jpg, png, etc.) is gotten from the filename extension if not 515 format is provided. 584 516 """ 585 517 if not format: … … 590 522 def as_gdk_pixbuf(self): 591 523 """ 592 Convert the image into a gdk.Pixbuf object 593 594 @return: the current image as a gdk.Pixbuf 595 @raise ImportError: if pygtk is unavailable. 524 Convert the image into a gdk.Pixbuf object. This function will 525 either return a gdk.Pixbuf object or raises an ImportError if 526 pygtk is unavailable. 596 527 """ 597 528 import gtk
