Module: Axon::NearestNeighborScaling

Included in:
NearestNeighborScaler
Defined in:
ext/axon/nearest_neighbor_interpolation.c

Instance Method Summary collapse

Instance Method Details

#interpolate_scanline(original_scanlines, q) ⇒ Object



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
# File 'ext/axon/nearest_neighbor_interpolation.c', line 9

static VALUE
interpolate_scanline(VALUE self, VALUE rb_scanline)
{
    VALUE rb_components, rb_width_ratio, rb_dest_sl, rb_image, rb_width;
    double width_ratio;
    unsigned char *scanline, *dest_sl;
    size_t width, components, i, j;

    rb_width = rb_ivar_get(self, id_width);
    width = FIX2INT(rb_width);

    rb_image = rb_ivar_get(self, id_image);
    rb_components = rb_funcall(rb_image, id_components, 0);
    components = FIX2INT(rb_components);

    rb_width_ratio = rb_ivar_get(self, id_width_ratio);
    width_ratio = NUM2DBL(rb_width_ratio);

    scanline = RSTRING_PTR(rb_scanline);
    
    rb_dest_sl = rb_str_new(0, width * components);
    dest_sl = RSTRING_PTR(rb_dest_sl);

    for (i = 0; i < width; i++)
        for (j = 0; j < components; j++)
            dest_sl[i * components + j] = scanline[(int)(i / width_ratio)];
    
    return rb_dest_sl;
}