「Dev:2.4/Source/Python/Image Editing」の版間の差分

提供: wiki
< Dev:2.4‎ | Source‎ | Python
移動先: 案内検索
 
(1版 をインポートしました)
 
(相違点なし)

2018年6月29日 (金) 02:45時点における最新版

-- AustinBenesh - 01 May 2005

Lately I have been improving the image editing abilities of Python API. Here's a few of my latest additions:

Note: all of these are part of the Image class so I'll skip the Image.function

- getPixels(x, y) : returns a list of floats [r,g,b,a] in the range 0.0 - 1.0 for the specified pixel.
- setPixels(x, y, [r,g,b,a]) : similar to above but sets instead of gets.
- getMaxXY() : gets the maximum coordinates of the image (also the width and height)
- getMinXY() : gets the coordinates of the origin
- Save() : this saves the current image buffers to the current image

I have also been considering adding the support for the PIL (Python Imaging Library). But there are a few kinks to work out. First of all, it would not be distributed with Blender, meaning plugins would have to be used (like Yafray). This would mean the user would have to set a PILPATH environment variable. Another question is, if we were to implement PIL, would it be part of the BPy_Image class, or be a seperate, PythonImage class? If it was put in the BPy_Image class, then everytime a PIL function is called, the script would have to check for PIL to see if it's installed. This brings up more issues. Any comments on this subject would be much appreciated.

Data formats

Your setPixel() method raises a design issue about data formats. The native data format for the Blender Image data is integer ( unsigned char, to be specific. ok, packed unsigned char if you want to be specifically specific ). Being able to deal in normalized floats is certainly useful; especially considering the forthcoming support for OpenEXR format. However, since the actual Blender data is integer in the range of 0-255, we should provide support for this mode and not make the user do conversions when using external files or applications.

An OpenGL-like way to do this is by having separate functions ending in the datatype for each format. example::

  • getPixelI() - returns list of integers in the range 0-255
  • getPixelF() - returns list of floats in the range 0.0 - 1.0
  • setPixelI() - takes integer arguments in the range 0-255
  • setPixelF() - takes float arguments in the range 0.0 - 1.0

-- StephenSwaney - 01 May 2005 ---

I understand your logic. I was basically going off the fact that in the Material Editor the colors range from 0.0 - 1.0, not 0 - 255 like in most image editors. This meant that, to get the precision that 0 - 255 gives you, you must specify a number using .000 precision instead of .00. Your functions sound like logical additions. I will work on updating the patches (unless, of course, you get to them before me :) ).

-- AustinBenesh - 02 May 2005