---
name: "lqr_carver_bias_set_energy_function"
section: "3"
platform: "linux"
package: "liblqr-1-0-dev"
version: "0.4.1-2"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/lqr_carver_bias_set_energy_function"
---

# lqr\_carver\_bias\_set\_energy\_function(3)

set a custom energy function for a LqrCarver object

## NAME

lqr\_carver\_bias\_set\_energy\_function - set a custom energy function for a LqrCarver object

## SYNOPSIS

```
#include <lqr.h>
```

**LqrRetVal lqr\_carver\_set\_energy\_function(LqrCarver\*** *carver***, LqrEnergyFunc** *en\_func***, gint** *radius***, LqrEnergyReaderType** *reader\_type***, gpointer** *extra\_data***);**

## DESCRIPTION

The function **lqr\_carver\_set\_energy\_function** assigns the energy function *en\_func* to the LqrCarver object pointed to by *carver* (see below for more details on custom functions definitions).

The parameter *radius* determines the size of the square region which affects the computation around each pixel (the side of the square will be 2 \* *radius* + 1 pixels long).

The parameter *reader\_type* sets the reader type used when reading the image, and therefore it determines what quantity will be passed on to the function *en\_func* (see below for more details on reader types).

The parameter *extra\_data* is a (void) pointer which can be used to pass on additional values to the function *ef\_func*.

## CUSTOM FUNCTIONS DEFINITION

The function *en\_func* must be of type LqrEnergyFunc, whose prototype is defined by:

```
typedef gfloat (*LqrEnergyFunc) (gint x, gint y, gint img_width, gint img_height, LqrReadingWindow * rwindow, gpointer extra_data);
```

Such a function is expected to compute the energy at pixel *x*, *y* based on the knowledge of the current image size (obtained from *width* and *height*) and the content of the image in a square around that pixel, which is passed through the *rwindow* reading window.

In most cases, the parameters *x*, *y*, *width* and *height* would only be used to determine whether the region under consideration is at the image boundary or not.

The *rwindow* content must be read using the function [**lqr\_rwindow\_read**(3)](/lqr_rwindow_read/3.md).

## READER TYPES

The **LqrEnergyReaderType** is an enum which can take these values (also noted is the number of channels of the corresponging reading window):

LQR\_ER\_BRIGHTNESS

brightness (1 channel)

LQR\_ER\_BRIGHTNESS

luma (1 channel)

LQR\_ER\_RGBA

RGBA (4 channels)

LQR\_ER\_CUSTOM

read the normalised image channels as they are (as many channels as the image has)

These readouts always return values beetween 0 and 1.

Note that these readouts may have special meanings depending on the image type:

• for LQR\_GREY\_IMAGE, LQR\_GREYA\_IMAGE and LQR\_CUSTOM\_IMAGE images, the LQR\_ER\_LUMA readout will yield the same result as LQR\_ER\_BRIGHTNESS

• for LQR\_CUSTOM\_IMAGE images, the LQR\_ER\_BRIGHTNESS readout will return the average pixel value (additive, i.e. if a black channel is present the channel values will be inverted and multiplied by the black channel inverse), multiplied by the alpha channel value.

• for LQR\_CUSTOM\_IMAGE images, the LQR\_ER\_RGBA readout *cannot be used*: it will always return 0

## RETURN VALUE

The return value follows the Liquid Rescale library signalling system.

## SEE ALSO

**lqr\_carver\_set\_energy\_function\_builtin**(3), [**lqr\_carver\_get\_energy**(3)](/lqr_carver_get_energy/3.md), [**lqr\_rwindow\_read**(3)](/lqr_rwindow_read/3.md), [**lqr\_rwindow\_get\_read\_t**(3)](/lqr_rwindow_get_read_t/3.md), [**lqr\_rwindow\_get\_radius**(3)](/lqr_rwindow_get_radius/3.md), [**lqr\_rwindow\_get\_channels**(3)](/lqr_rwindow_get_channels/3.md)

## COPYRIGHT

Copyright © 2007-2009 Carlo Baldassi\
