fast code to add rounded corners
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: fast IM code to add rounded corners to image with known
Might there be a virtual canvas left behind each corner. Have you tried adding +repage before writing to .mpc?
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: fast IM code to add rounded corners to image with known
@Fred: Thank you!ls -al RoundCorner8NWmpc
-rw-rw-r-- 1 nicolas nicolas 271 2012-03-15 19:45 RoundCorner8NW.mpc
Code: Select all
convert -size 16x16 xc:none -draw "fill white rectangle 0,0 15,15 fill black circle 15,15 15,0" -background white -alpha shape +repage -strip RoundCorner8NW.mpc
convert -size 16x16 xc:none -draw "fill white rectangle 0,0 15,15 fill black circle 0,15 0,0" -background white -alpha shape +repage -strip RoundCorner8NE.mpc
convert -size 16x16 xc:none -draw "fill white rectangle 0,0 15,15 fill black circle 15,0 0,0" -background white -alpha shape +repage -strip RoundCorner8SW.mpc
convert -size 16x16 xc:none -draw "fill white rectangle 0,0 15,15 fill black circle 0,0 15,0" -background white -alpha shape +repage -strip RoundCorner8SE.mpc
convert RogerRabbit.mpc \
RoundCorner8NW.mpc -gravity northwest -composite \
RoundCorner8NE.mpc -gravity northeast -composite \
RoundCorner8SW.mpc -gravity southwest -composite \
RoundCorner8SE.mpc -gravity southeast -composite \
-quality 70 FramedRogerRabbit.jpg
-rw-rw-r-- 1 nicolas nicolas 271 2012-03-15 19:45 RoundCorner8NW.mpc

Last edited by NicolasRobidoux on 2012-03-16T04:28:08-07:00, edited 4 times in total.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: fast IM code to add rounded corners to image with known
And, while I am on the topic of speed, I may as well mention that on my machine (Intel Core i3) ImageMagick/libomp/gcc sets the default number of threads to 4 (the recommended number for this chip), but that the key step runs faster with that is, with two less threads than the chip recommended default. This is doing benchmarks with convert -bench 100. If I set the thread limit directly and use the *nix time command a bunch of times (this keeps runs "more separate") as well as take the minimum run time (to factor out disk I/O of other processes somewhat) instead of the average like -bench essentially does, MAGICK_THREAD_LIMIT=3 comes out slightly ahead. (See viewtopic.php?f=1&t=20510#p81969.)
P.S. Tests with a later revision of 7.0.0 and a quieter machine suggests that the default (MAGICK_THREAD_LIMIT=4, on this machine) wins.
Code: Select all
MAGICK_THREAD_LIMIT=2 convert RogerRabbit.mpc RoundCorner8NW.mpc -gravity northwest -composite RoundCorner8NE.mpc -gravity northeast -composite RoundCorner8SW.mpc -gravity southwest -composite RoundCorner8SE.mpc -gravity southeast -composite -quality 70 FramedRogerRabbit.jpg
P.S. Tests with a later revision of 7.0.0 and a quieter machine suggests that the default (MAGICK_THREAD_LIMIT=4, on this machine) wins.
Last edited by NicolasRobidoux on 2012-03-28T16:38:24-07:00, edited 2 times in total.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: fast IM code to add rounded corners to image with known
From your examples I gather tha tyou are saying that re-drawing the corners is faster than flipping and floping.
also reading prepared MPC files is faster that fliping and flopping using parenthesis?
Now that I find interesting!
also reading prepared MPC files is faster that fliping and flopping using parenthesis?
Now that I find interesting!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: fast IM code to add rounded corners to image with known
I actually don't know. See below. But it would not surprise me.anthony wrote:From your examples I gather tha tyou are saying that re-drawing the corners is faster than flipping and floping
Warning: I never include the time it takes to prepare the .mpc mask files because for my target use they are recycled for every incoming original image, and are put in ramdisk. That is: they are "hoisted out of the loop."anthony wrote:also reading prepared MPC files is faster that fliping and flopping using parenthesis?
Now that I find interesting!
If you are going to use them only once, I have no clue whether .mpc is better than .mpr is better than parentheses. I did not perform this comparison because it's not relevant to my client. But I suspect that parentheses (possibly without flip/flop, that is, drawing directly each mask, B/C these tasks can run concurrently) win.
Last edited by NicolasRobidoux on 2012-03-16T13:37:17-07:00, edited 1 time in total.
-
- Posts: 1944
- Joined: 2010-08-28T11:16:00-07:00
- Authentication code: 8675308
- Location: Montreal, Canada
Re: fast IM code to add rounded corners to image with known
I figured as much: You're going for "transparent and standardized code structure" and I'm going for speed at all cost.anthony wrote:...Basically I divided the operations into 'setup' or 'initialization' operations set, and then a 'apply to image' operations set...