Module Image
[hide private]
[frames] | no frames]

Source Code for Module Image

  1  # Blender.Image module and the Image PyType object 
  2   
  3  """ 
  4  The Blender.Image submodule. 
  5   
  6  Image 
  7  ===== 
  8   
  9  B{New}: L{Image.clampX}, L{Image.clampY}. 
 10   
 11  This module provides access to B{Image} objects in Blender. 
 12   
 13  Example:: 
 14          import Blender 
 15          from Blender import Image 
 16          # 
 17          image = Image.Load("/path/to/my/image.png")    # load an image file 
 18          print "Image from", image.getFilename(), 
 19          print "loaded to obj", image.getName()) 
 20          image.setXRep(4)                               # set x tiling factor 
 21          image.setYRep(2)                               # set y tiling factor 
 22          print "All Images available now:", Image.Get() 
 23   
 24  @type Sources: readonly dictionary 
 25  @var Sources: The available Image Source. 
 26                  - STILL: Single image file 
 27                  - MOVIE: Movie file 
 28                  - SEQUENCE: Multiple image files, as sequence 
 29                  - GENERATED: Generated image 
 30  """ 
 31   
32 -def Load (filename):
33 """ 34 Load the image called 'filename' into an Image object. 35 @type filename: string 36 @param filename: The full path to the image file. 37 @rtype: Blender Image 38 @return: A Blender Image object with the data from I{filename}. 39 """
40
41 -def New (name, width, height, depth):
42 """ 43 Create a new Image object. 44 @type name: string 45 @param name: The name of the new Image object. 46 @type width: int 47 @param width: The width of the new Image object, between 1 and 5000. 48 @type height: int 49 @param height: The height of the new Image object, between 1 and 5000. 50 @type depth: int 51 @param depth: The color depth of the new Image object. (32:RGBA 8bit channels, 128:RGBA 32bit high dynamic range float channels). 52 @rtype: Blender Image 53 @return: A new Blender Image object. 54 """
55
56 -def Get (name = None):
57 """ 58 Get the Image object(s) from Blender. 59 @type name: string 60 @param name: The name of the Image object. 61 @rtype: Blender Image or a list of Blender Images 62 @return: It depends on the I{name} parameter: 63 - (name): The Image object called I{name}, None if not found; 64 - (): A list with all Image objects in the current scene. 65 """
66
67 -def GetCurrent ():
68 """ 69 Get the currently displayed Image from Blenders UV/Image window. 70 When multiple images are displayed, the last active UV/Image windows image is used. 71 @rtype: Blender Image 72 @return: The Current Blender Image, If there is no current image it returns None. 73 """
74 75 from IDProp import IDGroup, IDArray
76 -class Image:
77 """ 78 The Image object 79 ================ 80 This object gives access to Images in Blender. 81 @ivar filename: The filename (path) to the image file loaded into this Image 82 object. 83 @type filename: string 84 @ivar size: The [width, height] dimensions of the image (in pixels). 85 @type size: list 86 @ivar depth: The pixel depth of the image, read only. [8, 16, 18, 24, 32, 128 (for 32bit float color channels)] 87 @type depth: int 88 @ivar xrep: Texture tiling: the number of repetitions in the x (horizontal) 89 axis. [1, 16]. 90 @ivar yrep: Texture tiling: the number of repetitions in the y (vertical) 91 axis [1, 16]. 92 @type xrep: int 93 @type yrep: int 94 @ivar start: Texture's animation start frame [0, 128]. 95 @type start: int 96 @ivar end: Texture's animation end frame [0, 128]. 97 @type end: int 98 @ivar speed: Texture's animation speed [1, 100]. 99 @type speed: int 100 @ivar packed: True when the Texture is packed (readonly). 101 @type packed: boolean 102 @ivar has_data: True when the image has pixel data (readonly). 103 @type has_data: boolean 104 @ivar fields: enable or disable the fields option for this image. 105 @type fields: boolean 106 @ivar fields_odd: enable or disable the odd fields option for this image. 107 @type fields_odd: boolean 108 @ivar antialias: enable or disable the antialias option for this image. 109 @type antialias: boolean 110 @ivar premul: premultiply alpha toggle. 111 @type premul: boolean 112 @ivar bindcode: Texture's bind code (readonly). 113 @type bindcode: int 114 @ivar source: Image source type. See L{the Sources dictionary<Sources>} . 115 @type source: int 116 @ivar clampX: When true the image will not tile horizontally. 117 @type clampX: bool 118 @ivar clampY: When true the image will not tile vertically. 119 @type clampY: bool 120 """ 121
122 - def getName():
123 """ 124 Get the name of this Image object. 125 @rtype: string 126 """
127
128 - def getFilename():
129 """ 130 Get the filename of the image file loaded into this Image object. 131 @rtype: string 132 """
133
134 - def getSize():
135 """ 136 Get the [width, height] dimensions (in pixels) of this image. 137 @rtype: list of 2 ints 138 """
139
140 - def getDepth():
141 """ 142 Get the pixel depth of this image. [8,16,24,32,128 for 32bit float images] 143 @rtype: int 144 """
145
146 - def getPixelHDR(x, y):
147 """ 148 Get the the colors of the current pixel in the form [r,g,b,a]. 149 For float image types, returned values can be greater then the useual [0.0, 1.0] range. 150 Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY} 151 @returns: [ r, g, b, a] 152 @rtype: list of 4 floats 153 @type x: int 154 @type y: int 155 @param x: the x coordinate of pixel. 156 @param y: the y coordinate of pixel. 157 """
158
159 - def getPixelF(x, y):
160 """ 161 Get the the colors of the current pixel in the form [r,g,b,a]. 162 Returned values are floats normalized to 0.0 - 1.0. 163 Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY} 164 @returns: [ r, g, b, a] 165 @rtype: list of 4 floats 166 @type x: int 167 @type y: int 168 @param x: the x coordinate of pixel. 169 @param y: the y coordinate of pixel. 170 """
171
172 - def getPixelI(x, y):
173 """ 174 Get the the colors of the current pixel in the form [r,g,b,a]. 175 Returned values are ints normalized to 0 - 255. 176 Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY} 177 @returns: [ r, g, b, a] 178 @rtype: list of 4 ints 179 @type x: int 180 @type y: int 181 @param x: the x coordinate of pixel. 182 @param y: the y coordinate of pixel. 183 """
184
185 - def getMaxXY():
186 """ 187 Get the x & y size for the image. Image coordinates range from 0 to size-1. 188 @returns: [x, y] 189 @rtype: list of 2 ints 190 """
191
192 - def getMinXY():
193 """ 194 Get the x & y origin for the image. Image coordinates range from 0 to size-1. 195 @returns: [x, y] 196 @rtype: list of 2 ints 197 """
198
199 - def getXRep():
200 """ 201 Get the number of repetitions in the x (horizontal) axis for this Image. 202 This is for texture tiling. 203 @rtype: int 204 """
205
206 - def getYRep():
207 """ 208 Get the number of repetitions in the y (vertical) axis for this Image. 209 This is for texture tiling. 210 @rtype: int 211 """
212
213 - def getBindCode():
214 """ 215 Get the Image's bindcode. This is for texture loading using BGL calls. 216 See, for example, L{BGL.glBindTexture} and L{glLoad}. 217 @rtype: int 218 """
219
220 - def getStart():
221 """ 222 Get the Image's start frame. Used for animated textures. 223 @rtype: int 224 """
225
226 - def getEnd():
227 """ 228 Get the Image's end frame. Used for animated textures. 229 @rtype: int 230 """
231
232 - def getSpeed():
233 """ 234 Get the Image's speed (fps). Used for animated textures. 235 @rtype: int 236 """
237
238 - def reload():
239 """ 240 Reloads this image from the filesystem. If used within a loop you need to 241 redraw the Window to see the change in the image, e.g. with 242 Window.RedrawAll(). 243 @warn: if the image file is corrupt or still being written, it will be 244 replaced by a blank image in Blender, but no error will be returned. 245 @returns: None 246 """
247
248 - def updateDisplay():
249 """ 250 Update the display image from the floating point buffer (if it exists) 251 @returns: None 252 """
253
254 - def glLoad():
255 """ 256 Load this image's data into OpenGL texture memory, if it is not already 257 loaded (image.bindcode is 0 if it is not loaded yet). 258 @note: Usually you don't need to call this method. It is only necessary 259 if you want to draw textured objects in the Scripts window and the 260 image's bind code is zero at that moment, otherwise Blender itself can 261 take care of binding / unbinding textures. Calling this method for an 262 image with nonzero bind code simply returns the image's bind code value 263 (see L{getBindCode}). 264 @rtype: int 265 @returns: the texture's bind code. 266 """
267
268 - def glFree():
269 """ 270 Delete this image's data from OpenGL texture memory, only (the image itself 271 is not removed from Blender's memory). Internally, glDeleteTextures (see 272 L{BGL.glDeleteTextures}) is used, but this method also updates Blender's 273 Image object so that its bind code is set to 0. See also L{Image.glLoad}, 274 L{Image.getBindCode}. 275 """
276
277 - def setName(name):
278 """ 279 Set the name of this Image object. 280 @type name: string 281 @param name: The new name. 282 """
283
284 - def setFilename(name):
285 """ 286 Change the filename of this Image object. 287 @type name: string 288 @param name: The new full filename. 289 @warn: use this with caution and note that the filename is truncated if 290 larger than 160 characters. 291 """
292
293 - def setXRep(xrep):
294 """ 295 Texture tiling: set the number of x repetitions for this Image. 296 @type xrep: int 297 @param xrep: The new value in [1, 16]. 298 """
299
300 - def setYRep(yrep):
301 """ 302 Texture tiling: set the number of y repetitions for this Image. 303 @type yrep: int 304 @param yrep: The new value in [1, 16]. 305 """
306
307 - def setStart(start):
308 """ 309 Get the Image's start frame. Used for animated textures. 310 @type start: int 311 @param start: The new value in [0, 128]. 312 """
313
314 - def setEnd(end):
315 """ 316 Set the Image's end frame. Used for animated textures. 317 @type end: int 318 @param end: The new value in [0, 128]. 319 """
320
321 - def setSpeed(speed):
322 """ 323 Set the Image's speed (fps). Used for animated textures. 324 @type speed: int 325 @param speed: The new value in [1, 100]. 326 """
327
328 - def setPixelHDR(x, y, (r, g, b,a )):
329 """ 330 Set the the colors of the current pixel in the form [r,g,b,a]. 331 For float image types, returned values can be greater then the useual [0.0, 1.0] range. 332 Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY} 333 @type x: int 334 @type y: int 335 @type r: float 336 @type g: float 337 @type b: float 338 @type a: float 339 @returns: nothing 340 @rtype: none 341 """
342
343 - def setPixelF(x, y, (r, g, b,a )):
344 """ 345 Set the the colors of the current pixel in the form [r,g,b,a]. 346 Color values must be floats in the range 0.0 - 1.0. 347 Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY} 348 @type x: int 349 @type y: int 350 @type r: float 351 @type g: float 352 @type b: float 353 @type a: float 354 @returns: nothing 355 @rtype: none 356 """
357
358 - def setPixelI(x, y, (r, g, b, a)):
359 """ 360 Set the the colors of the current pixel in the form [r,g,b,a]. 361 Color values must be ints in the range 0 - 255. 362 Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY} 363 @type x: int 364 @type y: int 365 @type r: int 366 @type g: int 367 @type b: int 368 @type a: int 369 @returns: nothing 370 @rtype: none 371 """
372
373 - def save():
374 """ 375 Saves the current image to L{filename} 376 @note: New images created in Blender will always save as Targa regardless of filename. 377 @note: Saving to a directory that doent exist will raise an error. 378 @note: Saving a packed image will make a unique (numbered) name if the file alredy exists. Remove the file first to be sure it will not be renamed. 379 @returns: None 380 """
381
382 - def pack():
383 """ 384 Packs the image into the current blend file. 385 386 Since 2.44 new images without valid filenames can be packed. 387 388 If the image is alredy packed, it will be repacked. 389 390 @returns: nothing 391 @rtype: none 392 """
393
394 - def unpack(mode):
395 """ 396 Unpacks the image to the images filename. 397 @param mode: One of the values in L{Blender.UnpackModes}. 398 @note: An error will be raised if the image is not packed or the filename path does not exist. 399 @returns: nothing 400 @rtype: none 401 @type mode: int 402 """
403 - def makeCurrent():
404 """ 405 Set the currently displayed Image from Blenders UV/Image window. 406 When multiple images are displayed, the last active UV/Image windows image is used. 407 @warn: Deprecated, set bpy.data.images.active = image instead. 408 @rtype: bool 409 @return: True if the current image could be set, if no window was available, return False. 410 """
411 import id_generics 412 Image.__doc__ += id_generics.attributes 413