mIRC Home    About    Download    Register    News    Help

Print Thread
#228781 10/01/11 12:47 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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

Last edited by FroggieDaFrog; 10/01/11 01:11 PM.

I am SReject
My Stuff
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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


I am SReject
My Stuff
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #228785 10/01/11 02:50 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Right you are about the -r switch. But actually /drawreplace would be slower for what I'm doing.


I am SReject
My Stuff

Link Copied to Clipboard