tag:blogger.com,1999:blog-563071785757928434.post5203337167357505290..comments2017-12-09T14:17:43.841+01:00Comments on Kodierer [Coder]: Drawing Shapes - Silverlight WriteableBitmap Extensions IIIRene Schultehttps://plus.google.com/112651877959389508127noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-563071785757928434.post-182635794920959792012-04-12T08:54:22.579+02:002012-04-12T08:54:22.579+02:00For almost all .NET-related platforms nowadays.
Se...For almost all .NET-related platforms nowadays.<br />See the CodePlex site: <br /><br />http://writeablebitmapex.codeplex.comRene Schultehttps://www.blogger.com/profile/12777157871967896549noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-58229849173292944042012-04-12T03:56:38.650+02:002012-04-12T03:56:38.650+02:00hi is it suppord wp7 or just desktop applications?...hi is it suppord wp7 or just desktop applications?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-7091761992865976332009-11-11T23:15:49.175+01:002009-11-11T23:15:49.175+01:00no problem :) I knew you did the original DrawRect...no problem :) I knew you did the original DrawRectangle() for the sake of the clean sample.<br />Thanks a lot for the updates!nokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-60548646637160997042009-11-11T22:06:46.971+01:002009-11-11T22:06:46.971+01:00Thanks Nikola that you optimized my naïve DrawRect...Thanks Nikola that you optimized my naïve DrawRectangle() implementation. It was just a quick hack and fast enough, except if one only wants to draw thousands of rectangles.<br />Your comment about the the direct usage of pixels[] as paramter is also absolutely right and I encountered the same, but I wanted to provide WriteableBitmap extension methods. <br />I will create a Codeplex project and after that add methods that use an int[] array directly. This will make it also easier for optimization addicts like you to contribute. :)<br /><br />I&#39;ve updated this blog post and the source code (see above).Rene Schultehttps://www.blogger.com/profile/12777157871967896549noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-36778447182577202202009-11-11T02:44:45.535+01:002009-11-11T02:44:45.535+01:00another idea: check this out :)
http://nokola.com/...another idea: check this out :)<br />http://nokola.com/blog/post/2009/11/11/Best-Way-To-Clear-WriteableBitmap.aspx<br />It&#39;s a 4 times faster than for() loop ClearScreen() routine for WriteableBitmapnokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-11698430895457764712009-11-11T01:09:33.305+01:002009-11-11T01:09:33.305+01:00nevermind the previous DrawRectangle(), this one s...nevermind the previous DrawRectangle(), this one squeezes additional 2 FPS (about 10%) on my PC. The change is in how I use the for() loops<br /> public static void DrawRectangle(int[] pixels, int w, int x1, int y1, int x2, int y2, int color)<br /> {<br /> int startY = y1 * w;<br /> int endY = y2 * w;<br /><br /> int offset2 = endY + x1;<br /> int endOffset = startY + x2;<br /> int startYPlusX1 = startY + x1;<br /><br /> // top and bottom horizontal scanlines<br /> for (int x = startYPlusX1; x &lt;= endOffset; x++)<br /> {<br /> pixels[x] = color; // top horizontal line<br /> pixels[offset2] = color; // bottom horizontal line<br /> offset2++;<br /> }<br /><br /> // offset2 == endY + x2<br /><br /> // vertical scanlines<br /> endOffset = startYPlusX1 + w;<br /> offset2 -= w;<br /><br /> for (int y = startY + x2 + w; y &lt; offset2; y += w)<br /> {<br /> pixels[y] = color; // right vertical line<br /> pixels[endOffset] = color; // left vertical line<br /> endOffset += w;<br /> }<br /> }nokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-64321583933280101052009-11-11T00:50:59.951+01:002009-11-11T00:50:59.951+01:00I think although having the class as extension is ...I think although having the class as extension is great, it is much better for perf if it&#39;s not using extensions, but the int[] pixels object directly. that&#39;s because even a single WriteableBitmap.Pixels per shape incurs significant cost, due to thread-safe checks.<br />I tried drawing rectangles with and without calling .Pixels on every call and the perf goes up from 16 to 20 FPS with 10000 rectangles!!! :)<br /><br />btw, here&#39;s a rectangle routine that&#39;s improved a bit (no multiplication in the second for() and the cycles are consolidated which also saves time with managed code):<br /> public static void DrawRectangle(int[] pixels, int w, int x1, int y1, int x2, int y2, int color)<br /> {<br /> // First scanline<br /> int startY = y1 * w;<br /> int startOffset = startY + x1;<br /> int startOffset1 = startOffset + (y2 - y1) * w;<br /><br /> // top and bottom scanlines<br /> for (int x = x1; x &lt;= x2; x++)<br /> {<br /> pixels[startOffset] = color;<br /> pixels[startOffset1] = color;<br /> startOffset++;<br /> startOffset1++;<br /> }<br /><br /> // vertical scanlines<br /> startOffset = startY + x1;<br /> startOffset1 = startY + x2;<br /> for (int y = y1 + 1; y &lt; y2; y++)<br /> {<br /> pixels[startOffset] = color;<br /> pixels[startOffset1] = color;<br /> startOffset += w;<br /> startOffset1 += w;<br /> }<br /> }nokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-73614708228394119602009-11-09T23:05:59.604+01:002009-11-09T23:05:59.604+01:00Thanks Alex.
Before I setup a Codeplex project I w...Thanks Alex.<br />Before I setup a Codeplex project I want to finish the parts I&#39;ve planned so far (2 more at the moment).<br /><br />@Nokola:<br />Berlin is always great. You should really come and see it and while you are in Germany, you should also visit Dresden. It&#39;s only a 2 hour drive from Berlin away. :)<br />Todays TechEd sessions were not the best for me. The good stuff will hopefully follow the next days.Rene Schultehttps://www.blogger.com/profile/12777157871967896549noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-3311397050967297682009-11-09T19:38:32.406+01:002009-11-09T19:38:32.406+01:00yes I think it&#39;s a great idea too! :)
have fun...yes I think it&#39;s a great idea too! :)<br />have fun in Berlin! I&#39;ve never been there but it might be good to go sometimenokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-82410011666202852772009-11-09T09:21:38.704+01:002009-11-09T09:21:38.704+01:00You really should make a project on codeplex. Your...You really should make a project on codeplex. Your effort deserves a lot more attention. By creating a project you can acomplish this and it&#39;s also better for the quality of the code as people can contribute to it. Keep up the great work!Alexnoreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-32477969000530171382009-11-06T23:58:30.296+01:002009-11-06T23:58:30.296+01:00Hello Nikola,
thanks for the info about the offse...Hello Nikola,<br /><br />thanks for the info about the offset calculation bug. It was spread everywhere thanks to copy &amp; paste. :( And thanks for your optimizations, although the difference is &quot;only&quot; 17% here. <br />I&#39;ve replaced the default DrawLine() function with your optimized DDA implementation and updated this blog post and the source code (see above).<br /><br />I should create a Codeplex project and host the extensions there. I might actually do that when I&#39;m back from Berlin after next week. What do you think?Rene Schultehttps://www.blogger.com/profile/12777157871967896549noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-46756552613441464382009-11-06T23:04:53.732+01:002009-11-06T23:04:53.732+01:00also noticed a bug: you have to multiply y * Pixel...also noticed a bug: you have to multiply y * PixelWidth (not PixelHeight) in all the Line() (maybe other as well?) functionsnokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-52104396624754876362009-11-06T22:46:14.426+01:002009-11-06T22:46:14.426+01:00sorry, it&#39;s only 30% faster (I was comparing w...sorry, it&#39;s only 30% faster (I was comparing with the DDA extension, not Bresenhaim)nokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-22702707158449441452009-11-06T22:41:39.926+01:002009-11-06T22:41:39.926+01:00Hi Rene,
I looked at your DrawLine() code and opt...Hi Rene,<br /><br />I looked at your DrawLine() code and optimized it a bit :)<br /><br />The new version runs 2x faster, feel free to use the code in your library!<br />http://nokola.com/blog/post/2009/11/06/Faster-DrawLine()-in-Silverlight-(400000-linessec).aspx <br /><br />Drawing stuff is pretty exciting!nokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-51221607621791098382009-11-06T21:10:03.728+01:002009-11-06T21:10:03.728+01:00Good. Thanks for subscribing and the info.
I&#39;...Good. Thanks for subscribing and the info.<br /><br />I&#39;ve changed the link to http://feeds.feedburner.com/KodiererRene Schultehttps://www.blogger.com/profile/12777157871967896549noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-76378502563165746332009-11-06T18:33:53.852+01:002009-11-06T18:33:53.852+01:00Figured it out!
This works in my IE8: http://feed...Figured it out!<br /><br />This works in my IE8: http://feeds.feedburner.com/Kodierer<br /><br />This doesn&#39;t:<br />http://feeds2.feedburner.com/Kodierer<br /><br />Not sure why - haven&#39;t looked at the sourcenokolahttp://nokola.myopenid.com/noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-16526728042960560632009-11-06T09:13:01.354+01:002009-11-06T09:13:01.354+01:00Hello Nikola,
Thanks for your compliment I really...Hello Nikola,<br /><br />Thanks for your compliment I really appreciate that. :)<br /><br />When I open this website here and click on the little RSS icon in IE8, it finds the feed and I can subscribe to it. The same works for when I open the FeedBurner URL (http://feeds2.feedburner.com/Kodierer). So it seems to work for me. Strange...Rene Schultehttps://www.blogger.com/profile/12777157871967896549noreply@blogger.comtag:blogger.com,1999:blog-563071785757928434.post-48164896377350831312009-11-06T01:34:02.777+01:002009-11-06T01:34:02.777+01:00Nice!, great work as usual! :)
Thanks for adding t...Nice!, great work as usual! :)<br />Thanks for adding these! <br /><br />btw, Rene I tried subscribing to your blog from IE 8...but didn&#39;t find the RSS feed. When clicking the Subscribe link, I get to http://feeds2.feedburner.com/Kodierer, but IE does not recognize it as valid RSS feed.<br /><br />Do you have some other link to the RSS that might work?<br />(e.g. the link to the .axd like this: http://nokola.com/blog/syndication.axd)nokolahttp://nokola.comnoreply@blogger.com