mIRC Homepage
Posted By: FroggieDaFrog /drawfill -s - 10/01/11 12:47 PM
While trying to speed my code up I've ran into a snag. My question is with /drawfill -s(Surface Fill), it should go through the entire bitmap in the @win and replace <color2> with <color1> correct?

If so why isn't this working:
Code:
;@GreyScale::Buffer is already created and the %p image is already drawn into it

;Prepare variables for looping
var %w = $pic(%p).width
var %h = $Pic(%p).height
var %y = 0
var %x
var %dot
var %rdot

;Start at the top of the image and work down:
while (%y < %h) {
  %x = 0

  ;move from left to right
  while (%x < %w) {

    ;get the current dots RGB value in the format of "RRR+GGG+BBB"
    %dot = $getdot(@GreyScale::Buffer,%x,%y)
    %rdot = $replace($rgb(%dot),$chr(44),+)

    ;Check to make sure the color isn't already a shade of grey
    if (!$regex(%rdot,/^(\d+)\+\1\+\1$/)) {

      ;get the average of the R,G,B Values (R + G + B)/3
      %n = $calc( ( %rdot )/ 3)


      ;Replace the current dot's color with the ave'ed rgb's
      ;why isn't this working:
      drawfill -s @GreyScale::Buffer $rgb(%n,%n,%n) %dot %x %y


      ;This works but is slow:
      ;drawdot -nr @GreyScale::Buffer $rgb(%n,%n,%n) 1 %x %y


    }
    ;drawdot @GreyScale::Buffer
    inc %x
  }
  inc %y
}


I removed some things to get to the heart of my problem for this post. If something doesn't seem right then it's probably my editing for here and will correct it here when spotted.


Oh and am using v7.17 on 32bit XPsp3
Posted By: FroggieDaFrog Re: /drawfill -s - 10/01/11 12:59 PM
After reading the help file some more, I realised that it doesn't go through the whole bitmap, but replaces the patch of color that is around the specified x,y but that still doesn't explain with this is not working
Posted By: qwerty Re: /drawfill -s - 10/01/11 01:41 PM
Looking at your code very briefly, one problem is that you're not using the -r switch in /drawfill.

If all you're doing is replace one colour with another however, you can just use /drawreplace, which should be much faster than /drawfill-ing in a loop.
Posted By: FroggieDaFrog Re: /drawfill -s - 10/01/11 02:50 PM
Right you are about the -r switch. But actually /drawreplace would be slower for what I'm doing.
© mIRC Discussion Forums