realbasic-nug
[Top] [All Lists]

Re: Reversing an image

To: realbasic-nug at lists dot realsoftware dot com
Subject: Re: Reversing an image
From: "Craig A. Finseth" <fin at finseth dot com>
Date: Fri, 30 Dec 2005 07:46:36 -0600 (CST)
Cc: realbasic-nug at lists dot realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20051230021806 dot 04F83F9BE45 at lists dot realsoftware dot com> <A81911A6-B133-4D27-B396-9B95E328F284 at farhner dot com> <1C95574E-B766-4462-B673-0672B3022169 at mobleybros dot com>
        ...
   With that in mind, here is how I would optimize the loop:

      Dim xMax As Integer
      Dim yMax As Integer

      xMax = p.Width - 1
      yMax = p.Height - 1

      For j = 0 To yMax
        For i = 0 To xMax
          c = r1.pixel(i,j)
          r2.pixel(i,j) = RGB(255-c.red, 255-c.green, 255-c.blue)
        Next
        progress.prog.value=progress.prog.value+1
      Next

   Set the Progress.Maximum to equal the number of rows (height) instead  
   of the number of pixels like you had before.  Notice that I switched  
   the rows and columns... it is only a theory, but it should be faster  
        ...

In these cases, I also only update progress bars every 25 rows or so
(depends on the image size).  Users can't tell the difference and
there is still a noticable speedup.  In the above example, probably
90% or more of the code is in updating the progress bar.

Craig

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>