clear SM;
SM = [];

blend_width = 20;

lastStartingImage = images(imgseq(size(imgseq,1),6)).cdata;

movfile = sprintf('show_%u.avi', size(imgseq,1));

mov = avifile(movfile);


clear startingImages;

for i = size(imgseq,1) : -1 : 1
    im1 = images(imgseq(i,5)).cdata;
    im2 = lastStartingImage;
    zx = imgseq(i,2);
    zy = imgseq(i,3);
    lowest_dist_scale = imgseq(i,4);
    lastStartingImage = zoom2(im1, im2, zx, zy, lowest_dist_scale, 0, 1);
    startingImages(i) = im2frame(lastStartingImage);
    fprintf('.');
end
fprintf('\n');


for i = 1 : size(imgseq,1)
    fprintf('computing transition %u of %u...\n', i, size(imgseq,1));
    im1 = images(imgseq(i,5)).cdata;
    if (i == size(imgseq,1))
        im2 = images(imgseq(i,6)).cdata;
    else
        im2 = startingImages(i+1).cdata;
    end

    zx = imgseq(i,2);
    zy = imgseq(i,3);
    lowest_dist_scale = imgseq(i,4);
    mm;
    lastStartingImage = M(1).cdata;
    %SM = [M SM];
    %movfile = sprintf('ss_%u.avi', size(imgseq,1) - i + 1);
    %movie2avi(SM, movfile, 'compression', 'Cinepak');
    %movie2avi(SM, movfile);

    %{
    for f = 1 : size(M,2)
        mov = addframe(mov,M(f).cdata);
    end
    %}
    mov = addframe(mov, M);
    
    movfile = sprintf('show_%u_partial_%u.avi', size(imgseq,1), i);
    partialMov = avifile(movfile);
    partialMov = addframe(partialMov, M);
    partialMov = close(partialMov);
    
end

mov = close(mov);
