« Lecture #Syllabus for all sect | Main | Another CSyllabus for all sect »
January 25, 2006
Faster grSyllabus for all sect
Andrew Arnott sent me this gradient calculator that is much faster than the one I wrote. Feel free to use it. In Andrew's code, it is a different class that works as a class within his GrayBitmap class(which is his version of the GrayImage class), so I've included both of his classes.
GradientBitmap.cs
GrayBitmap.cs
Posted by jones at January 25, 2006 04:28 PM
Comments
It appears you've left out the DirectBitmapWriter.cs file, which is a dependency for GrayBitmap.
Posted by: Andrew Arnott
at January 25, 2006 07:44 PM
any news on a DirectBitmapWriter yet?
i'm also erroring on "frmMain.SegmentPointRegex" in GrayBitmap line148. i assume frmMain is the main form....but what is the SegmentPointRegex business?......maybe i need to understand this stuff better..
Posted by: Daniel Larsen
at January 25, 2006 08:17 PM
Oops. I have posted a copy of DirectBitmapWriter.cs.
Mike.
Posted by: Mike Jones
at January 25, 2006 08:55 PM
The SegmentPointRegex is defined like this:
public static readonly string SegmentPointRegex = @"\((\d+), *(\d+)\)";
When Dr. Jones fixes the link to the distribution on this page, visit that link for what will likely be an intact distribution that has all the latest optimizations, without any missing stuff.
Posted by: Andrew Arnott
at January 26, 2006 01:22 PM
Andrew's optimized code works GREAT, but it took me a while to figure out how "ProgressCallback"s worked, so I thought I'd share, for anyone else who might get hung up on it. Basically just create a method in the same class where you will be needing a "ProgressCallback" (such as in Form1) with a void return type and one argument of type integer. Next, give the name of that funcion as the "ProgressCallback" parameter to GrayBitmap.Load, GrayBitmap.GenerateGradientBitmap, etc. Example:
// My ProgressCallback Method
void refreshPercent(int percent)
{
  statusText.Clear();
  statusText.AppendText("Progress: " + percent.ToString() + '%' + Environment.NewLine);
}
...
  // To open a file
  FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
  string segPts;
  image.Load(fs, out segPts, refreshPercent);
...
  // To QUICKLY create the gradient view in Form1! (Woohoo!)
  image.Gradient.GenerateGradientBitmap(refreshPercent);
  gradientView.Image = image.Gradient.Bitmap;
Or, to make the above run approximately 140% faster, just leave the "refreshPercent" method empty, and it wont output anything to the log. Hope that helps someone.
Posted by: Alan Olsen
at January 26, 2006 09:31 PM
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)