vray.VRayImage

class vray.VRayImage

Bases: object

Contains raw image data in full 32-bit floating point format. Methods allow for some basic image manipulation and saving to popular 8-bit and 16-bit image file formats. Supports sequence, buffer and memoryview protocols.

Attributes

gamma

Gets/sets the output gamma for 8-bit images.

height

Pixel height of this object.

host

Host name that produced the image, if available.

width

Pixel width of this object.

x

Bucket horizontal (left) position.

y

Bucket vertical (top) position.

Methods

__init__(*args, **kwargs)

addColor

Adds the color to the image with blending.

calculateWhiteBalanceMultiplier

Returns a color multiplier to pass to mulColor function.

changeContrast

Changes the image contrast by the specified value (-1, 1).

changeExposure

Increases the image exposure by the specified exposure value (EV).

changeGamma

Applies the specified gamma correction to the image.

changeSRGB

Applies or removes an sRGB correction curve to/from this image.

compress

Compresses a V-Ray Image and returns its memoryview.

createFromBuffer

Creates a new VRayImage from a bytearray

draw

Draws a V-Ray Image over the current image.

getCropped

Creates a new VRayImage from a region in the source one.

getCutIn

Creates a new resized VRayImage preserving source aspect ratio, touching the specified rectangle from outside and cropping the new image to fit the rectangle.

getDownscaled

Creates a new resized VRayImage.

getDownscaledCropped

Creates a new resized VRayImage from a region in the source one.

getFitIn

Creates a new resized VRayImage preserving source aspect ratio and touching the specified rectangle from inside.

getFitOut

Creates a new resized VRayImage preserving source aspect ratio and touching the specified rectangle from outside.

getResized

Creates a new resized VRayImage.

getResizedCropped

Creates a new resized VRayImage from a region in the source one.

load

Creates a new VRayImage from a file Supported formats: png, jpg, bmp, exr, hdr, sgi/rgb/rgba, pic, tiff, tga, psd, dds Positional (in this order) or keyword arguments:

loadSize

Helper method to get image size from a file.

makeNegative

Makes this a negative image.

save

Saves VRayImage to file.

toBitmapData

Creates a buffer (memoryview) and fills it with the 8-bit bitmap data from this image (without the BMP headers that VRayImage.compress(type=’bmp’) includes).

toIntList

Creates an IntList from the image data that can be directly assigned to RawBitmapBuffer.pixels

addColor()

Adds the color to the image with blending.

Positional arguments:

  • color, Color or AColor - the color to add to each pixel

Returns True on success.

calculateWhiteBalanceMultiplier()

Returns a color multiplier to pass to mulColor function.

Positional argument:

  • type, string or int:

    ‘Average’ (or 1) ‘WeightedAverage’ (or 2) ‘Highlights’ (or 3)

Returns AColor.

changeContrast()

Changes the image contrast by the specified value (-1, 1).

Positional arguments:

  • contrast, float - normalized contrast change factor

Returns True on success.

changeExposure()

Increases the image exposure by the specified exposure value (EV).

Positional arguments:

  • ev, float - target EV difference

Returns True on success.

changeGamma()

Applies the specified gamma correction to the image.

Positional arguments:

  • gamma, float - reciprocal of the exponent to apply to each pixel’s color

Returns True on success.

changeSRGB()

Applies or removes an sRGB correction curve to/from this image. This is different from the gamma property. Positional arguments:

  • apply, boolean - True to apply or False to remove sRGB

Returns True on success.

compress()

Compresses a V-Ray Image and returns its memoryview.

Positional (in this order) or keyword arguments, all optional:

  • quality, int - image quality value (1-9 for png, 1-99 for jpeg)

  • preserveAlpha, bool - whether to keep the alpha channel (PNG, BMP). Defaults to false

  • swapChannels, bool - by default RGBA, but if True swap to BGRA

  • type, string - file type

  • renderer, VRayRenderer - if passed, it will be used to output errors

createFromBuffer()

Creates a new VRayImage from a bytearray

draw()

Draws a V-Ray Image over the current image.

Positional (in this order) or keyword arguments:

  • image, VRayImage - the source image

  • x, optional int - left pixel index from where to draw

  • y, optional int - top pixel index from where to draw

  • mode, optional string - drawing mode:
    • “copy” - overwrite destination image pixels with the source image pixels(default)

    • “blendFast” - alpha blend using only the source image alpha but keep the original destination image alpha unchanged.

Returns True on success.

getCropped()

Creates a new VRayImage from a region in the source one.

Positional (in this order) or keyword arguments, all obligatory:

  • x, int - left border pixel coordinate (in image space) of the crop region

  • y, int - top border pixel coordinate (in image space) of the crop region

  • width, int - pixel width of the crop region

  • height, int - pixel height of the crop region

getCutIn()

Creates a new resized VRayImage preserving source aspect ratio, touching the specified rectangle from outside and cropping the new image to fit the rectangle.

Positional (in this order) or keyword arguments, all obligatory:

  • width, int - target width in pixels

  • height, int - target height in pixels

getDownscaled()

Creates a new resized VRayImage.

Positional (in this order) or keyword arguments, all obligatory:

  • width, int - target width in pixels

  • height, int - target height in pixels

getDownscaledCropped()

Creates a new resized VRayImage from a region in the source one.

Positional (in this order) or keyword arguments, all obligatory:

  • x, int - left border pixel coordinate (in image space) of the croped source region

  • y, int - top border pixel coordinate (in image space) of the croped source region

  • srcWidth, int - pixel width of the cropped source region

  • srcHeight, int - pixel height of the croped source region

  • dstWidth, int - target width in pixels

  • dstHeight, int - target height in pixels

getFitIn()

Creates a new resized VRayImage preserving source aspect ratio and touching the specified rectangle from inside.

Positional (in this order) or keyword arguments, all obligatory:

  • width, int - target width in pixels

  • height, int - target height in pixels

getFitOut()

Creates a new resized VRayImage preserving source aspect ratio and touching the specified rectangle from outside.

Positional (in this order) or keyword arguments, all obligatory:

  • width, int - target width in pixels

  • height, int - target height in pixels

getResized()

Creates a new resized VRayImage.

Positional (in this order) or keyword arguments, all obligatory:

  • width, int - target width in pixels

  • height, int - target height in pixels

getResizedCropped()

Creates a new resized VRayImage from a region in the source one.

Positional (in this order) or keyword arguments, all obligatory:

  • x, int - left border pixel coordinate (in image space) of the croped source region

  • y, int - top border pixel coordinate (in image space) of the croped source region

  • srcWidth, int - pixel width of the cropped source region

  • srcHeight, int - pixel height of the croped source region

  • dstWidth, int - target width in pixels

  • dstHeight, int - target height in pixels

load()

Creates a new VRayImage from a file Supported formats: png, jpg, bmp, exr, hdr, sgi/rgb/rgba, pic, tiff, tga, psd, dds Positional (in this order) or keyword arguments:

  • fileName, string - relative or absolute file path and name

Returns a VRayImage.

static loadSize()

Helper method to get image size from a file. Supported formats: png, jpg, bmp, exr, hdr, sgi/rgb/rgba, pic, tiff, tga, psd, dds Positional (in this order) or keyword arguments:

  • fileName, string - relative or absolute file path and name

Returns the image size as a tuple.

makeNegative()

Makes this a negative image. In other words, replaces colors with their complementary colors.

save()

Saves VRayImage to file. Format is deduced from the extension.

Positional (in this order) or keyword arguments, all optional:

  • fileName, string - relative or absolute file path and name

  • quality, int - image quality value (1-9 for png, 1-99 for jpeg)

  • preserveAlpha, bool - whether to keep the alpha channel (PNG, BMP). Defaults to true

  • swapChannels, bool - by default RGBA, but if True swap to BGRA

  • type, string - file type

  • renderer, VRayRenderer - if passed, it will be used to output errors

Returns True on success.

toBitmapData()

Creates a buffer (memoryview) and fills it with the 8-bit bitmap data from this image (without the BMP headers that VRayImage.compress(type=’bmp’) includes).

Positional (in this order) or keyword arguments, all optional:

  • preserveAlpha, bool - False: BGR/RGB (bytes_per_pixel = 3), True: BGRA/RGBA (bytes_per_pixel = 4). Defaults to False

  • swapChannels, bool - False: BGR(A) order, True: BRGB(A) order. Defaults to False

  • reverseY, bool - False: fill top-bottom bitmap, True: fill bottom-top bitmap. Defaults to False

  • stride, int - the byte offset between the beginning of two consecutive rows of the output bitmap:

    if (stride > 0) use max(stride, width*bytes_per_pixel) if (stride== 0) use width*bytes_per_pixel rounded up to the smallest factor of 4 (this is the default for BMP) if (stride < 0) use width*bytes_per_pixel rounded up to the smallest factor of -stride; -stride must be a power of 2

  • alphaValue, int - force the alpha channel to the given value in the [0, 255] range; forces BGRA/RGBA format

Returns memoryview.

toIntList()

Creates an IntList from the image data that can be directly assigned to RawBitmapBuffer.pixels

Positional or keyword argument:

  • type, string or int:

    ‘bgra’ (or ‘bgra_byte’ or 0) (default) ‘bgr’ (or ‘bgr_byte’ or 4) ‘rgba16’ (or ‘rgba_16bit’ or 3) ‘rgba32’ (or ‘rgba_float’ or 1) - sRGB or gamma won’t be applied automatically

Returns IntList.

gamma

Gets/sets the output gamma for 8-bit images. Affects the methods compress() and save()

height

Pixel height of this object.

host

Host name that produced the image, if available.

width

Pixel width of this object.

x

Bucket horizontal (left) position.

y

Bucket vertical (top) position.