BoltBait.com

The home of Double-Six Dominoes and other fun things!

Welcome to BoltBait.com Sign in | Join | Help
in Search

How to avoid multi render instances ?

Last post 11-20-2008, 5:27 PM by BoltBait. 3 replies.
Sort Posts: Previous Next
  •  11-05-2008, 2:34 AM 43

    How to avoid multi render instances ?

    Hello BoltBait,

    I use Paint.Net for a few month now and I'm not satisfied by the "Autoadjust" features.
    So I decided to write my own function, hoping that it will help other users.

    I downloaded CodeLab, learnt basics of C# (i know C/C++) and started to work.
    I succeeded to manually modify contrast and light of the image. Basic stuff, but I wanted to start with simple algo ;-)

    Then I started to autodetect min light / max light for the whole picture, to be able to feed to contrast/light adjustment.
    Here I have a problem : I can clearly see the different ROI of Paint.Net (stripes).
    As you explain on your website, the render function has been called for each ROI, thus calculating different min/max for each ROI.
    (I guess).

    My question is : how to run a unique min/max calculation ?

    I'm thinking of 2 solutions :
    - concurrent affectation of min/max (global variables) but this seems forbidden in C# (not in C++).
    - preventing only the "min/max seeking loop" to be multi-instanciated. Kind of #pragma ?

    Any  idea would be appreciated :)

  •  11-06-2008, 3:41 PM 44 in reply to 43

    Re: How to avoid multi render instances ?

    It's not so hard really.  There are a few ways you can go about this:

    Instead of using rect.Top, rect.Left, etc. to loop through and get your min/max data, use 0 and src.Width to loop through the entire src canvas.  On the plus side, it will work in CodeLab.  On the negative side, it will be VERY slow because you will have to calculate it once for each ROI.

    Probably better to switch away from CodeLab at this point.  But, before you do, build your effect into a DLL and check the "View source" check box on the build dll screen.  When your source is shown, select all the code and copy it to a new text document (use notepad) and call it effect.cs (or whatever your effect name is, plus the ".cs" at the end).  Once you have the new file, add a few class variables to hold the min and max values.  Then, edit the OnSetRenderInfo function and calculate your min/max values there.  Finally, just use them in your render function as you would any other Amount1... variable.  This will cause your min/max calculation only to be run once--well, once each time a UI control is changed.

    Here is an effect that I basically did the same thing: http://paintdotnet.forumer.com/viewtopic.php?f=16&t=26579  I had to call the cloud effect in the OnSetRenderInfo function.

    If you don't want to download Microsoft's Visual Studio Express (free) you can always use the command line C# compiler you already have on your system.  Your source code's first line includes the command line options that you need to use in order to compile it.

    Let me know if you need any more help.

    Filed under:
  •  11-19-2008, 2:15 AM 46 in reply to 44

    Re: How to avoid multi render instances ?

    Hello boltbait,

    Thank you for your answer ! I've been overworked theses days, but I look forward to test your recommendations.
    Given the numbers of ROIs I've seen on the image (~50, although I've not a 50 core CPU !), I guess I should NOT run the seeking procedure on global canvas for each ROI..

    If other guys use "OnSetRenderInfo", could it be possible to add it in CodeLab (in a tabbed window ?).
    Your tool is really heasy to handle for fast plugin developpement !

    Congratulations and Best regards,
    Alex

  •  11-20-2008, 5:27 PM 48 in reply to 46

    Re: How to avoid multi render instances ?

    Rick Brewster once said, "The number of 'tiles' you get on a simple selection (rectangle) will always be 75 times the number of CPU's/cores. If you have an irregular selection, then things are different of course."
Powered by Community Server (Personal Edition), by Telligent Systems