<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 06/22/2017 02:42 AM, Nikolay Nikolov
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:f2740e92-9782-8646-f5ec-a1a137167f7a@gmail.com">
      <br>
      <br>
      On 06/22/2017 01:21 AM, James Richters wrote:
      <br>
      <blockquote type="cite">
        <blockquote type="cite">putimage can be accelerated, although it
          would still have to do a memory copy.
          <br>
        </blockquote>
        Like this?
        <br>
<a class="moz-txt-link-freetext" href="https://github.com/Zaaphod/ptcpas/compare/Zaaphod_Custom?expand=1#diff-fb31461e009ff29fda5c35c5115978b4">https://github.com/Zaaphod/ptcpas/compare/Zaaphod_Custom?expand=1#diff-fb31461e009ff29fda5c35c5115978b4</a>
        <br>
        <br>
        This is amazingly faster.   I ran a test of just
        ptcgraph.putimage() in a loop, putting the same image over and
        over 1000 times and timing it.  The original ptcgraph.putimage()
        took 18.017 seconds.  After I applied this, the same loop took
        1.056 seconds.  Quite an improvement!    It's still nowhere near
        as fast as just drawing stuff with ptcgraph directly, but for
        doing a memory copy of the entire screen, it's very fast
        <br>
      </blockquote>
      Yes, that's a good start. That was exactly what I meant :)
      <br>
      <blockquote type="cite">
        <br>
        I have an idea on how I could speed it up even further....
        <br>
        If I set up a second array with 1 bit per pixel, then (somehow)
        aggpas could set bits in this array to 1 whenever it changed a
        corresponding bit.  Now by analyzing the 'pixel changed' array
        one word at a time, (or maybe longword or qword at a time)  I
        could just skip over all the words that =0 and when I come
        across a word that <> 0   I could do a binary search of
        that word to only change the pixels that need to be changed.  If
        very little on the screen has changed, this would be quite a bit
        faster because the pixel changed array would be 1/16 the size of
        the full buffer.
        <br>
        <br>
        The only way this would be of any benefit though is if aggpas
        set the bits in the 'pixel changed' array while it was changing
        the pixels of the buffer, because at that time it already has
        the array position and the fact that something changed
        available.  If I had to analyze the buffer separately and create
        the 'pixels changed' array, it would take too long.
        <br>
      </blockquote>
      That sounds like a little bit of a special case - it'll work where
      you're using putimage for a large area, that has very few pixels
      set. Perhaps just reimplementing the general algorithm in inline
      asm, by using SSE (or MMX) vector instructions would be the
      fastest, but maybe it's not worth the pain and the pascal
      implementation is fast enough for you. Just experiment and see
      what works best :)
      <br>
    </blockquote>
    Btw, I looked at your code again and saw a quick and cheap
    optimization - just move the case statement (<span
      class="blob-code-inner"><span class="pl-k">case</span> BitBlt <span
        class="pl-k">of</span></span>) outside the inner loop (<span
      class="blob-code-inner"><span class="pl-k">for</span> i:=X <span
        class="pl-k">to</span> X1 <span class="pl-k">do</span></span>),
    so the value of BitBlt is not checked once every pixel, but once per
    row.<br>
    <br>
    Nikolay<br>
  </body>
</html>