Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
Speed up scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
evanmiller committed Mar 26, 2013
1 parent 6d34bdf commit 836eed7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/erl_img.erl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ crop(IMG, Width, Height, XOffset, YOffset) when Width < IMG#erl_image.width ->
width = Width},
crop(IMG1, Width, Height, XOffset, YOffset).

sort_rows(IMG) ->
IMG#erl_image{
pixmaps = lists:map(fun(Pixmap) ->
Pixmap#erl_pixmap{
pixels = lists:sort(fun({RowA, _}, {RowB, _}) ->
RowA < RowB
end, Pixmap#erl_pixmap.pixels)}
end, IMG#erl_image.pixmaps)
}.

interpolate_cubic(X, A, B, C, D) ->
B + 0.5 * X * (C - A + X * (2*A - 5*B + 4*C - D + X * (3*(B-C) + D - A))).
Expand All @@ -310,10 +319,7 @@ get_pixel_bytes(IMG, X, Y) ->
Y >= PixMap#erl_pixmap.height + PixMap#erl_pixmap.top ->
Pixel;
(PixMap, _Pixel) ->
{_, Data} = lists:nth(Y - PixMap#erl_pixmap.top + 1,
lists:sort(fun({RowA, _}, {RowB, _}) ->
RowA < RowB
end, PixMap#erl_pixmap.pixels)),
{_, Data} = lists:nth(Y - PixMap#erl_pixmap.top + 1, PixMap#erl_pixmap.pixels),
binary:part(Data, (X - PixMap#erl_pixmap.left) * IMG#erl_image.bytes_pp, IMG#erl_image.bytes_pp)
end, undefined, IMG#erl_image.pixmaps).

Expand Down Expand Up @@ -424,6 +430,6 @@ scale(IMG, XScaleFactor, YScaleFactor) ->
top = 0,
width = NewWidth,
height = NewHeight,
pixels = resample_pixels(IMG, NewWidth, NewHeight)}],
pixels = resample_pixels(sort_rows(IMG), NewWidth, NewHeight)}],
width = NewWidth,
height = NewHeight }.

0 comments on commit 836eed7

Please sign in to comment.