An example looks like this:

using Cairo

# prepapration, an image of 2x2 pixels, an target of 8x8 pixels

d = [8 4; 2 1];
d0 = reinterpret(Uint32,d);
cs0 = Cairo.CairoImageSurface(d0,0); # 0 as FORMAT_ARGB32
show(cs0.data)
print('\n')

d2 = zeros(Uint32,8,8);
cs2 = Cairo.CairoImageSurface(d2,0);

p = Cairo.CairoPattern(cs0);

# just scale by using FILTER_NEAREST

pattern_set_filter(p,Cairo.FILTER_NEAREST);
c = Cairo.CairoContext(cs2);
scale(c,4,4);
set_source(c,p);
paint(c);
show(cs2.data)
print('\n')

# now interpolate

d3 = zeros(Uint32,8,8); 
cs3 = Cairo.CairoImageSurface(d3,0);

pattern_set_filter(p,Cairo.FILTER_GOOD);
c = Cairo.CairoContext(cs3);
scale(c,4,4);
set_source(c,p);
paint(c);
show(cs3.data)
print('\n')

and gives on my command line:

julia> include("ca.jl")
Uint32[8 2
       4 1]
Uint32[8 8 8 8 2 2 2 2
       8 8 8 8 2 2 2 2
       8 8 8 8 2 2 2 2
       8 8 8 8 2 2 2 2
       4 4 4 4 1 1 1 1
       4 4 4 4 1 1 1 1
       4 4 4 4 1 1 1 1
       4 4 4 4 1 1 1 1]
Uint32[3 4 4 3 2 1 1 0
       4 6 6 5 3 2 1 1
       4 6 6 5 3 2 1 1
       4 5 5 4 3 2 1 1
       3 4 4 3 2 1 1 0
       2 3 4 3 2 1 0 0
       2 3 3 2 1 1 0 0
       1 2 2 1 1 0 0 0]

But this is just how to handle the data. For interpreting the pixels 
correctly you need to read little bit about the colormodel and pixel 
formats.

Wishing a happy day,
       Andreas

Reply via email to