efl.evas.Image Class

class efl.evas.Image(Canvas canvas, file=None, **kwargs)

Introduction

Image will consider the object’s geometry as the area to paint with tiles as described by fill and the real pixels (image data) will be stored as described by image_size. This can be tricky to understand at first, but gives flexibility to do everything.

If an image is loaded from file, it will have image_size set to its original size, unless some other size was set with load_size, load_dpi or load_scale_down.

Pixels will be scaled to match size specified by fill using either sampled or smooth methods, these can be specified with smooth_scale. The scale will consider borders as specified by border and border_center_fill, while the former specify the border dimensions (top and bottom will scale horizontally, while right and left will do vertically, corners are kept unscaled), the latter says whenever the center of the image will be used (useful to create frames).

Contents will be tiled using fill information in order to paint geometry, so if you want an image to be drawn just once, you should match every geometry = x, y, w, h by a call to fill = 0, 0, w, h. FilledImage does that for you.

Pixel data and buffer API

Images implement the Python Buffer API, so it’s possible to use it where buffers are expected (ie: file.write()). Available data will depend on alpha, colorspace and image_size, lines should be considered multiple of stride, with the following considerations about colorspace:

  • EVAS_COLORSPACE_ARGB8888: This pixel format is a linear block of

    pixels, starting at the top-left row by row until the bottom right of the image or pixel region. All pixels are 32-bit unsigned int’s with the high-byte being alpha and the low byte being blue in the format ARGB. Alpha may or may not be used by evas depending on the alpha flag of the image, but if not used, should be set to 0xff anyway. This colorspace uses premultiplied alpha. That means that R, G and B cannot exceed A in value. The conversion from non-premultiplied colorspace is:

    R = (r * a) / 255; G = (g * a) / 255; B = (b * a) / 255;
    

    So 50% transparent blue will be: 0x80000080. This will not be “dark” - just 50% transparent. Values are 0 == black, 255 == solid or full red, green or blue.

  • EVAS_COLORSPACE_RGB565_A5P: In the process of being implemented in

    1 engine only. This may change. This is a pointer to image data for 16-bit half-word pixel data in 16bpp RGB 565 format (5 bits red, 6 bits green, 5 bits blue), with the high-byte containing red and the low byte containing blue, per pixel. This data is packed row by row from the top-left to the bottom right. If the image has an alpha channel enabled there will be an extra alpha plane after the color pixel plane. If not, then this data will not exist and should not be accessed in any way. This plane is a set of pixels with 1 byte per pixel defining the alpha values of all pixels in the image from the top-left to the bottom right of the image, row by row. Even though the values of the alpha pixels can be 0 to 255, only values 0 through to 31 are used, 31 being solid and 0 being transparent. RGB values can be 0 to 31 for red and blue and 0 to 63 for green, with 0 being black and 31 or 63 being full red, green or blue respectively. This colorspace is also pre-multiplied like EVAS_COLORSPACE_ARGB8888 so:

    R = (r * a) / 32; G = (g * a) / 32; B = (b * a) / 32;
    

Note

if an image is resized it will tile it’s contents respecting geometry set by fill, so if you want the contents to be scaled you need to call fill with x=0, y=0, w=new_width, h=new_height, or you should use FilledImage instead.

Parameters
  • canvas (Canvas) – Evas canvas for this object

  • file (string or tuple) – File name or (File name, key)

  • **kwargs – All the remaining keyword arguments are interpreted as properties of the instance

efl.evas.FilledImage Class

class efl.evas.FilledImage(Canvas canvas, **kargs)

This Image subclass already calls Image.fill on resize so it will match and so be scaled to fill the whole area.

Parameters
  • canvas (Canvas) – The evas canvas for this object

  • **kwargs – All the remaining keyword arguments are interpreted as properties of the instance