~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to raster/r.proj/cubic_f.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Name
 
3
 *  cubic_f.c -- use cubic interpolation with fallback for given row, col
 
4
 *
 
5
 * Description
 
6
 *  cubic interpolation for the given row, column indices.
 
7
 *  If the interpolated value (but not the nearest) is null,
 
8
 *  it falls back to bilinear.  If that interp value is null,
 
9
 *  it falls back to nearest neighbor.
 
10
 */
 
11
 
 
12
#include <grass/gis.h>
 
13
#include <grass/raster.h>
 
14
#include "r.proj.h"
 
15
 
 
16
void p_cubic_f(struct cache *ibuffer,   /* input buffer                  */
 
17
                void *obufptr,  /* ptr in output buffer          */
 
18
                int cell_type,  /* raster map type of obufptr    */
 
19
                double col_idx, /* column index          */
 
20
                double row_idx, /* row index                     */
 
21
            struct Cell_head *cellhd    /* cell header of input layer    */
 
22
    )
 
23
{
 
24
    /* start nearest neighbor to do some basic tests */
 
25
    int row, col;               /* row/col of nearest neighbor   */
 
26
    FCELL cell;
 
27
 
 
28
    /* cut indices to integer */
 
29
    row = (int)floor(row_idx);
 
30
    col = (int)floor(col_idx);
 
31
 
 
32
    /* check for out of bounds - if out of bounds set NULL value     */
 
33
    if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
 
34
        Rast_set_null_value(obufptr, 1, cell_type);
 
35
        return;
 
36
    }
 
37
 
 
38
    cell = CVAL(ibuffer, row, col);
 
39
    /* if nearest is null, all the other interps will be null */
 
40
    if (Rast_is_f_null_value(&cell)) {
 
41
        Rast_set_null_value(obufptr, 1, cell_type);
 
42
        return;
 
43
    }
 
44
 
 
45
    p_cubic(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
 
46
    /* fallback to bilinear if cubic is null */
 
47
    if (Rast_is_f_null_value(obufptr)) {
 
48
        p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
 
49
        /* fallback to nearest if bilinear is null */
 
50
        if (Rast_is_f_null_value(obufptr))
 
51
            Rast_set_f_value(obufptr, cell, cell_type);
 
52
    }
 
53
}