pictureresize.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. -- picture resize - jul'12, from Paulo Silva
  2. -- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. See <http://www.gnu.org/licenses/>
  3. w,h=getpicturesize()
  4. ok,wn,hn=inputbox("Picture Resize","x",w,0,4096,0,"y",h,0,4096,0);
  5. if ok==true then
  6. if ((w~=wn) or (h~=hn)) then
  7. wnt=w;hnt=h
  8. if wn>w then wnt=wn;end
  9. if hn>h then hnt=hn;end
  10. finalizepicture()
  11. setpicturesize(wnt,hnt)
  12. -- some dirty code below, this can be significantly smaller
  13. if ((wn>=w) and (hn>=h)) then
  14. for y=hn-1,0,-1 do
  15. y2=math.floor((y*h)/hn)
  16. statusmessage("progress:"..(100-math.floor(y*100/hn)).."% " )
  17. for x=wn-1,0,-1 do
  18. x2=math.floor((x*w)/wn)
  19. c=getpicturepixel(x2,y2)
  20. putpicturepixel(x,y,c)
  21. end;end;end
  22. if ((wn<w) and (hn>=h)) then
  23. for y=hn-1,0,-1 do
  24. y2=math.floor((y*h)/hn)
  25. statusmessage("progress:"..(100-math.floor(y*100/hn)).."% " )
  26. for x=0,wn-1,1 do
  27. x2=math.floor((x*w)/wn)
  28. c=getpicturepixel(x2,y2)
  29. putpicturepixel(x,y,c)
  30. end;end;end
  31. if ((wn>=w) and (hn<h)) then
  32. for y=0,hn-1,1 do
  33. y2=math.floor((y*h)/hn)
  34. statusmessage("progress:"..(math.floor(y*100/hn)).."% " )
  35. for x=wn-1,0,-1 do
  36. x2=math.floor((x*w)/wn)
  37. c=getpicturepixel(x2,y2)
  38. putpicturepixel(x,y,c)
  39. end;end;end
  40. if ((wn<w) and (hn<h)) then
  41. for y=0,hn-1,1 do
  42. y2=math.floor((y*h)/hn)
  43. statusmessage("progress:"..(math.floor(y*100/hn)).."% " )
  44. for x=0,wn-1,1 do
  45. x2=math.floor((x*w)/wn)
  46. c=getpicturepixel(x2,y2)
  47. putpicturepixel(x,y,c)
  48. end;end;end
  49. finalizepicture()
  50. setpicturesize(wn,hn)
  51. end
  52. end