Reading the multi-size image

Pixel by pixel
One line at a time
Resetting

Pixel by pixel

Once you have rescaled the image, you can read out the result through this function:

gboolean lqr_carver_scan( gint*  x,
  gint*  y,
  guchar**  rgb);

Here, x and y are pointers to the varaibles which will hold the pixel coordinate, while rgb is a pointer to an array which will contain the pixel colour information.

The return value is FALSE when the end of the image is reached, TRUE otherwise.

Each time this function is invoked, it will store the coordinates and rgb information in the output pointers and move to the next pixel. If it reaches the end, it resets the reader and returns FALSE.

Here is a sample code usage:

Example 2.1. A simple readout example

gint x, y;
guchar *rgb;

while (lqr_carver_scan (carver, &x, &y, &rgb)
  {
    my_plot (x, y, rgb[0], rgb[1], rgb[2]);
  }
						


In this example, it is assumed that the image has 3 colour channels, and that there exist some function my_plot which writes out the pixels somewhere.

Important

The rgb array is internal to the carver object, so it doesn't need initialization (but don't use pointers to it or its elements, always copy the contents as in the example).

One line at a time

The image can also be read one line at a time, but it is not possible to freely decide if it is to be read by row or by column. Instead, this has to be queried by calling this function:

gboolean lqr_carver_scan_by_row(LqrCarver*  carver);

The function returns TRUE if the image is read by row, and FALSE if it is read by column.

Then, the image can be read through this function:

gboolean lqr_carver_scan_line(LqrCarver*  carver,
 gint*  n,
 guchar**  rgb);

This function works exactly the same way as lqr_carver_scan, but only one coordinate is stored (either the row or the column number), and the rgb array will contain a whole line.

Here is a sample code usage:

Example 2.2. Line-by-line readout example

gint n;
guchar *rgb;
gboolean by_row;

by_row = lqr_carver_scan_by_row (carver);

while (lqr_carver_scan_line (carver, &n, &rgb)
  {
    by_row ? my_plot_row (n, rgb) : my_plot_col (n, rgb);
  }
						


where, as before, it is assumed that the my_plot_row and my_plot_col functions have been previously defined and "know what to do".

Resetting

Normally, it is not needed to reset the image scan. However, if the scan has been stopped at same intermediate step for some reason, the following function can be used to restart from the beginning:

void lqr_carver_scan_reset(LqrCarver*  carver);