AKTIVE

warp.tcl at trunk
Login

warp.tcl at trunk

File etc/transformer/structure/warp.tcl artifact e05900c5a3 on branch trunk


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
## -*- mode: tcl ; fill-column: 90 -*-
# # ## ### ##### ######## ############# #####################
## Transformers -- Structural changes (data re-arrangements)

# # ## ### ##### ######## ############# #####################
## Generic warping by means of an origin map and a pixel interpolator.

operator {description spec refs} {
    op::warp::bicubic         bicubic		  bicubic {
	http://en.wikipedia.org/wiki/Bicubic_interpolation
	http://www.paulinternet.nl/?page=bicubic
    }
    op::warp::bilinear	      bilinear	  	  bilinear {
	 https://en.wikipedia.org/wiki/Bilinear_interpolation
    }
    op::warp::lanczos	     {order-3 lanczos}    lanczos {
	https://mazzo.li/posts/lanczos.html
	https://en.wikipedia.org/wiki/Lanczos_resampling
	https://github.com/jeffboody/Lanczos
    }
    op::warp::near-neighbour {nearest neighbour}  nneighbour {
	https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
    }
} {
    op -> _ _ interpolation

    foreach r $refs { ref $r }

    section transform structure warp

    note Returns an image generated by the application of the \
	origin map to the image, with $description interpolation.

    note The result has the domain of the origin map, \
	and the depth of the image.

    note See "<!xref: aktive transform affine>" and its relatives \
	for a set of operations creating origin maps acceptable here.

    input origins	Origin map to wrap the `src` by.
    input src		Image to warp by the `origin`.

    # blit over first input (origins) only.
    # fetch from the second is input dependent, not a scan.
    # bands are not scanned. this is done by the interpolator.
    blit warp {
	{AH {y AY 1 up} {y 0 1 up}}
	{AW {x AX 1 up} {x 0 1 up}}
    } {raw interpolated-fetch {
	aktive_region_fetch_interpolated (srcs->v[1],
					  spec,
					  idomain->depth,
					  srcvalue,
					  dstvalue);
    }}

    state -setup {
	// The domain and location are unchanged, taken from the origin map.
	// The depth becomes the depth of the image.
	aktive_geometry* og = aktive_image_get_geometry (srcs->v[0]);
	aktive_geometry* ig = aktive_image_get_geometry (srcs->v[1]);

	aktive_geometry_copy (domain, og);
	domain->depth = ig->depth;
    }
    pixels {
	aktive_interpolator* spec = aktive_interpolator_@@spec@@ ();

	aktive_rectangle_def_as (subrequest, request);
	TRACE_RECTANGLE_M("fetch", &subrequest);

	// fetch from the map
	aktive_block* src = aktive_region_fetch_area (srcs->v[0], &subrequest);

	// fetch from the input is done through the interpolator,
	// for the declared origin points.

	@@warp@@
    }
}

##
# # ## ### ##### ######## ############# #####################
::return