Image Processing Method + Filters.

By mrjos on Dec 22, 2007

This is a collection of image filters that I have created today (22/12/2007).

I haven't scripted much in a long time (picked it up yesterday for the first time in >2 years). If anyone has any tips / recommendations I would like to hear. :)

There is a BIG comment at the top of the code that explains how to use the snippet.

Sample Filters in screenshot:
Image

;jos 22/12/07. 
;Image Processing Method + Filters.

;I'm still trying to get back into Scripting. These are potentially useful to people. I doubt that they will be though.
;The main uses I can think of would probably be a Paint type app in mIRC or some sort of basic file viewer (built into DCC?)
;with a few basic filters. I don't know. If you use it though - let me know, it'd be cool to see if (and how) it's used.
;I've not been scripting in around 2 years, so I'm probably using outdated functions / methods any glaring mistakes? Please
;let me know. Thanks.

;I've made an effort to keep the code readable - this may have had an impact on the performance. If there's anything really
;obvious to speed up the code (without a total rewrite) please feel free to suggest it. :)

;Interface
;Basically everything goes through the command /img.process. The parameters are seperated by comma (,) not space as in most
;mIRC aliases. This is to allow you to use filenames with spaces ( ) in.
;syntax /img.process <in-file>, <out-file>, <filter>
;If the script cannot find <in-file> it will stop processing (without warning - add it if you want - it's early on).
;If there isn't a filter selected it will stop processing (again, without warning). If you'd prefer warnings just add them in,
;it's easy. :)
;If you do not enter an <out-file> the script will leave it's 'working' window open and bring it to focus so you can view the results.

;Examples
;/img.process e:lenna.png, ,img.filter.greyscale
;Greyscale image of file sent to @window

;/img.process e:lenna.png, e:lenna.bmp ,img.filter.oil
;Oil image (default brush size) of file sent to e:lenna.bmp

;/img.process e:lenna.png, e:lenna.bmp ,img.filter.oil 5
;Oil image (5 brush size) of file sent to e:lenna.bmp

;/img.process e:lenna.png, e:lenna.bmp ,img.filter.gamma 1.5
;Gamme correction (+50% to red,green,blue) of image of file sent to e:lenna.bmp

;/img.process e:lenna.png, e:lenna.bmp ,img.filter.gamma 0.5 1 1.5
;Gamme correction (-50% to red, +0% to green, +50% to blue) of image of file sent to e:lenna.bmp

;Filters
;I've made a selection of Filters (for functionality and ...) to demonstrate how you can add your own to the script (might be 
;a little tricky if you're new to scripting).

;Basic Filters (these are quickest / simplest operations)
;These filters only do a dot by dot comparison so they're quicker than more complex operations.

;img.filter.draw
;This filter just draws (dot for dot) a copy of the picture to another destination (I used it to prove the reading of the original
;image) It's a good base, to copy, if you need/want to create your own filters.

;img.filter.greyscale.red
;This filter creates a grey-scale image based on the Red component of each pixel. (Red Channel)

;img.filter.greyscale.green
;This filter creates a grey-scale image based on the Green component of each pixel. (Green Channel)

;img.filter.greyscale.blue
;This filter creates a grey-scale image based on the Blue component of each pixel. (Blue Channel)

;img.filter.greyscale   (or img.filter.greyscale.ave)
;This filter creates a grey-scale image based on the average component of each pixel.

;img.filter.colour.red [intensity]
;This filter creates a red shaded image based on the average component of each pixel. Intensity is a numeric (0 - 1) value (if omitted
;default = 0) 1 = 100% intensity, 0.5 = 50%, 0 = 0%...

;img.filter.colour.green [intensity]
;This filter creates a green shaded image based on the average component of each pixel. Intensity is a numeric (0 - 1) value (if omitted
;default = 0) 1 = 100% intensity, 0.5 = 50%, 0 = 0%...

;img.filter.colour.blue [intensity]
;This filter creates a blue shaded image based on the average component of each pixel. Intensity is a numeric (0 - 1) value (if omitted
;default = 0) 1 = 100% intensity, 0.5 = 50%, 0 = 0%...

;img.filter.gamma <joined-correction>    (or img.filter.gamma <red-correction> <green-correction> <blue-correction>)
;This filter performs a Gamma Correction filter. If you only specify one parameter the filter assumes that you want to correct all 3 (
;Red,Green,Blue components of each pixel by the same amount.)
;If you specify 3 parameters it assumes that you want to use seperate corrections for each component of the pixel.
;Each parameter is a number that modifys the current component by a percentage. Example: 1 = +0% (no change), 0.5 = -50% (50% darker),
;1.5 = +50% (50% lighter)

;Complex Filters (slower processing / harder operations)
;These operations take longer as they have to (usually) look at other pixels close to them to decide on their own colouring.

;img.filter.oil [brush]
;This filter creates a mock oil painted image based on the original. The brush size defaults to 3 (if not entered), you can override it
;to make the image appear more or less 'oily'. - beware though: bigger brush = bigger wait, and a brush < size 3 probably won't be
;noticeable in the generated image.

;img.filter.blur [brush]
;This filter creates a blur based on the surroundings of each pixel. The brush defaults to 2 (if not entered), you can override it to
;make the image appear more or less blurred. - beware though: bigger brush = bigger wait, and a brush < size 3 probably won't be
;noticeable in the generated image.

;img.filter.emboss [intensity]
;This filter creates an embossed (plastic relief) image of the original. The intensity allows you to override the brightness of the filter
;by default it is set to 1 (100% brightness), it works as other intensity fields, 0.5 (50% brightness), 0 (0% brightness) etc...

;img.filter.circle
;This filter creates a circular cutout of the original image.

;Notes
;When saving files, the script will ALWAYS save the file as BMP (bitmap) if you do not want this to be the case, you will have to change
;the code that does drawsave.

;The script uses while loops to read each file pixel by pixel, this is a slow process and locks up mIRC, you cannot respond to events in 
;mIRC and mIRC will not respond to pings from servers (could result in Ping Timeouts). If you want to avoid this you will have to change
;the handling of the file reading to either use /filter or /timer and get them to call aliases for you to do processing.

;mIRC is very slow at processing images using $getdot, you could get a big improvement in speed by doing some caching of images
;(especially for 'simple' filters). The way the script was designed it writes a file that is removed when it's finished. <-- Could with a
;little bit of work change this behavior to either retain the file (with a list saying what file it relates to) then check that it's ok to
;be used as a cache (perhaps store a $crc and check that) then override the processing alias I have that responds to /filter. (just an idea)

;If you're wanting to add this to a custom Paint script, then you can simply drawcopy/drawsave areas you want to run it against, (create a file)
;then drawload/drawcopy the generated file (from the img.process) back to the area the original graphic populated. (Seems simple!)

;The only other thing to really note is that the error checking is very basic (you can break it if you really want to). If you want to use
;this in a script you should either do error checking on everything you pass to it (or edit / add to the existing error checking).

;Good luck guys. :)

alias img.process {
  var %img.width, %img.height, %img.pixels, %img.width.rec, %img.height.rec, %img.file, %img.window, %img.name.handle, %img.dot.colour, %img.out.name, %img.out.name.rec, %img.out.name.type
  var %img.process.start = $ctime, %img.process.end, %img.filter.name
  tokenize 44 $1-

  var %img.filter = $3- 
  var %img.name = $+(",$1,")
  var %img.out.name = $+(",$2,")

  if (!$exists(%img.name)) { 
    return
  }

  tokenize 32 %img.filter

  %img.filter.name = $1

  if (!$istok($img.filter.allowed,$1,44)) {
    return
  }

  %img.width = $calc($pic(%img.name).width - 1)
  %img.height = $calc($pic(%img.name).height -1)
  %img.pixels = %img.width * %img.height

  %img.window = $img.window.getname
  %img.file = $img.file.getname
  %img.file.handle = $img.file.handle.getname

  window -hp %img.window 
  drawpic %img.window 0 0 %img.name 

  .fopen -no %img.file.handle %img.file
  %img.width.rec = %img.width

  while (%img.width.rec >= 0) {
    %img.height.rec = %img.height 

    while (%img.height.rec >= 0) {
      if ($1 == img.filter.oil) {
        if (!$2) {
          tokenize 32 $1 3
        }
        %img.dot.colour = $img.dot.oil(%img.window,%img.width.rec,%img.height.rec,$2,%img.width,%img.height)
      }
      elseif ($1 == img.filter.blur) {
        if (!$2) {
          tokenize 32 $1 2
        }
        %img.dot.colour = $img.dot.blur(%img.window,%img.width.rec,%img.height.rec,$2,%img.width,%img.height)
      }
      elseif ($1 == img.filter.emboss) {
        tokenize 32 %img.filter
        if ($2) {
          tokenize 32 $1 $int($calc(($2)*255))
        }
        %img.dot.colour = $img.dot.emboss(%img.window,%img.width.rec,%img.height.rec,%img.width,%img.height,$2)
      }   
      elseif ($1 == img.filter.circle) {
        %img.dot.colour = $img.dot.circle(%img.window,%img.width.rec,%img.height.rec,%img.width,%img.height)
      }  
      else {
        %img.dot.colour = $getdot(%img.window,%img.width.rec,%img.height.rec)
      }

      if (%img.dot.colour) {
        .fwrite -n %img.file.handle %img.filter : %img.window %img.dot.colour %img.width.rec %img.height.rec
      }

      dec %img.height.rec
    }

    dec %img.width.rec
  }

  .fclose %img.file.handle

  clear %img.window 

  filter -fk %img.file img.filter.apply img.filter.*

  drawdot %img.window

  if ($noqt(%img.out.name)) {
    %img.out.name = $noqt(%img.out.name)
    %img.out.name.type = $gettok(%img.out.name,$numtok(%img.out.name,46),46)
    %img.out.name = $deltok(%img.out.name,$numtok(%img.out.name,46),46)

    %img.out.name.type = bmp
    %img.out.name = $+(%img.out.name,%img.out.name.rec,.,%img.out.name.type)

    if ($exists(%img.out.name)) {
      %img.out.name.rec = 0
      %img.out.name.type = $gettok(%img.out.name,$numtok(%img.out.name,46),46)
      %img.out.name = $deltok(%img.out.name,$numtok(%img.out.name,46),46)

      while ($exists($+(%img.out.name,%img.out.name.rec,.,%img.out.name.type))) {
        inc %img.out.name.rec
      }

      %img.out.name = $+(%img.out.name,%img.out.name.rec,.,%img.out.name.type)

    }

    %img.out.name = $qt(%img.out.name)

    window -hr %img.window 0 0 %img.width %img.height

    drawsave %img.window %img.out.name

    window -c %img.window 

  }
  else {
    %img.out.name = %img.window
    window -ar %img.window
  }

  %img.process.end = $ctime

  if ($show) { .echo -s Image Processing Finished: %img.name > %img.out.name [Filter: %img.filter $+ ][Dur: $duration($calc(%img.process.end - %img.process.start)) $+ ] }

  .remove %img.file

}

alias -l img.filter.allowed {
  return img.filter.draw,img.filter.oil,img.filter.blur,img.filter.emboss,img.filter.circle,img.filter.greyscale.green,img.filter.greyscale.red,img.filter.greyscale.blue,img.filter.greyscale.ave,img.filter.greyscale,img.filter.colour.red,img.filter.colour.green,img.filter.colour.blue,img.filter.gamma
}

alias -l img.filter.apply {
  tokenize 58 $1-
  var %img.filter = $1, %img.line = $2-

  tokenize 32 %img.filter

  if (($1 == img.filter.draw) || ($1 == img.filter.oil) || ($1 == img.filter.blur) || ($1 == img.filter.emboss) || ($1 == img.filter.circle)) {
    tokenize 32 %img.line
    drawdot -rn $1-2 1 $3-
  } 
  elseif ($1 == img.filter.greyscale.red) {
    tokenize 32 %img.line
    var %img.dot.rgb = $rgb($2)
    tokenize 44 %img.dot.rgb
    %img.dot.rgb = $rgb($1,$1,$1)
    tokenize 32 %img.line   
    drawdot -rn $1 %img.dot.rgb 1 $3-
  } 
  elseif ($1 == img.filter.greyscale.green) {
    tokenize 32 %img.line
    var %img.dot.rgb = $rgb($2)
    tokenize 44 %img.dot.rgb
    %img.dot.rgb = $rgb($2,$2,$2)
    tokenize 32 %img.line   
    drawdot -rn $1 %img.dot.rgb 1 $3-
  } 
  elseif ($1 == img.filter.greyscale.blue) {
    tokenize 32 %img.line
    var %img.dot.rgb = $rgb($2)
    tokenize 44 %img.dot.rgb
    %img.dot.rgb = $rgb($3,$3,$3)
    tokenize 32 %img.line   
    drawdot -rn $1 %img.dot.rgb 1 $3-
  }  
  elseif (($1 == img.filter.greyscale.ave) || ($1 == img.filter.greyscale)) {
    tokenize 32 %img.line
    var %img.dot.rgb = $rgb($2)
    tokenize 44 %img.dot.rgb
    %img.dot.rgb = $int($calc(($1 + $2 + $3) / 3))
    %img.dot.rgb = $rgb(%img.dot.rgb,%img.dot.rgb,%img.dot.rgb)
    tokenize 32 %img.line   
    drawdot -rn $1 %img.dot.rgb 1 $3-
  } 
  elseif ($1 == img.filter.colour.red) {
    var %img.filter.red.amount = $2
    if ($2 < 0) { %img.filter.red.amount = 0 }
    elseif (($2 > 1) || (!$2)) { %img.filter.red.amount = 1 }
    tokenize 32 %img.line
    var %img.dot.rgb = $rgb($2)
    tokenize 44 %img.dot.rgb
    %img.dot.rgb = $int($calc((($1 + $2 + $3) / 3) * %img.filter.red.amount))
    %img.dot.rgb = $rgb(%img.dot.rgb, 0, 0)
    tokenize 32 %img.line   
    drawdot -rn $1 %img.dot.rgb 1 $3-
  } 
  elseif ($1 == img.filter.colour.green) {
    var %img.filter.green.amount = $2
    if ($2 < 0) { %img.filter.green.amount = 0 }
    elseif (($2 > 1) || (!$2)) { %img.filter.green.amount = 1 }
    tokenize 32 %img.line
    var %img.dot.rgb = $rgb($2)
    tokenize 44 %img.dot.rgb
    %img.dot.rgb = $int($calc((($1 + $2 + $3) / 3) * %img.filter.green.amount))
    %img.dot.rgb = $rgb(0, %img.dot.rgb, 0)
    tokenize 32 %img.line   
    drawdot -rn $1 %img.dot.rgb 1 $3-
  } 
  elseif ($1 == img.filter.colour.blue) {
    var %img.filter.blue.amount = $2
    if ($2 < 0) { %img.filter.blue.amount = 0 }
    elseif (($2 > 1) || (!$2)) { %img.filter.blue.amount = 1 }
    tokenize 32 %img.line
    var %img.dot.rgb = $rgb($2)
    tokenize 44 %img.dot.rgb
    %img.dot.rgb = $int($calc((($1 + $2 + $3) / 3) * %img.filter.blue.amount))
    %img.dot.rgb = $rgb(0, 0, %img.dot.rgb)
    tokenize 32 %img.line   
    drawdot -rn $1 %img.dot.rgb 1 $3-
  } 
  elseif ($1 == img.filter.gamma) {  
    var %img.filter.gamma.correction = $2, %img.filter.gamma.correction.red, %img.filter.gamma.correction.green, %img.filter.gamma.correction.blue
    if (!$2) { %img.filter.gamma.correction = 1 }
    if (!$4) {
      %img.filter.gamma.correction.red = %img.filter.gamma.correction
      %img.filter.gamma.correction.green = %img.filter.gamma.correction
      %img.filter.gamma.correction.blue = %img.filter.gamma.correction
    }
    else {
      %img.filter.gamma.correction.red = $2
      %img.filter.gamma.correction.green = $3
      %img.filter.gamma.correction.blue = $4
    }
    tokenize 32 %img.line
    var %img.dot.rgb = $rgb($2), %img.dot.red, %img.dot.green, %img.dot.blue
    tokenize 44 %img.dot.rgb
    %img.dot.red = $int($calc($1 * %img.filter.gamma.correction.red))
    %img.dot.green = $int($calc($2 * %img.filter.gamma.correction.green))
    %img.dot.blue = $int($calc($3 * %img.filter.gamma.correction.blue))
    if (%img.dot.red < 0) { %img.dot.red = 0 }
    if (%img.dot.green < 0) { %img.dot.green = 0 }
    if (%img.dot.blue < 0) { %img.dot.blue = 0 }
    if (%img.dot.red > 255) { %img.dot.red = 255 }
    if (%img.dot.green > 255) { %img.dot.green = 255 }
    if (%img.dot.blue > 255) { %img.dot.blue = 255 }
    %img.dot.rgb = $rgb(%img.dot.red, %img.dot.green, %img.dot.blue)
    tokenize 32 %img.line   
    drawdot -rn $1 %img.dot.rgb 1 $3-
  }
}

alias -l img.dot.oil {
  var %img.window, %img.point.x, %img.point.y, %img.point.max.x, %img.point.max.y, %img.point.difference, %img.hash, %img.hash.hmake.size, %img.hash.size, %img.hash.rec = 1
  var %img.point.x.min, %img.point.x.max, %img.point.y.min, %img.point.y.max, %img.point.x.rec, %img.point.y.rec
  var %img.point.colour, %img.point.colour.common, %img.point.colour.common.count

  %img.window = $1
  %img.point.x = $2
  %img.point.y = $3
  %img.point.difference = $4
  %img.point.max.x = $5
  %img.point.max.y = $6

  %img.point.x.min = $calc(%img.point.x - %img.point.difference)
  %img.point.x.max = $calc(%img.point.x + %img.point.difference)

  %img.point.y.min = $calc(%img.point.y - %img.point.difference)
  %img.point.y.max = $calc(%img.point.y + %img.point.difference)

  if (%img.point.x.min < 0) { %img.point.x.min = 0 }
  if (%img.point.y.min < 0) { %img.point.y.min = 0 }

  if (%img.point.x.max > %img.point.max.x) { %img.point.x.max = %img.point.max.x }
  if (%img.point.y.max > %img.point.max.y) { %img.point.y.max = %img.point.max.y }

  %img.hash.size = $calc((%img.point.x.max -  %img.point.x.min) * (%img.point.y.max -  %img.point.y.min))

  %img.hash = $img.hash.getname

  %img.hash.hmake.size = $int($calc(%img.hash.size / 10))

  if (%img.hash.hmake.size < 1) { %img.hash.hmake.size = 1 }

  hmake %img.hash %img.hash.hmake.size

  %img.point.x.rec = %img.point.x.max

  while (%img.point.x.rec >= %img.point.x.min) {
    %img.point.y.rec = %img.point.y.max
    while (%img.point.y.rec >= %img.point.y.min) {
      %img.point.colour = $getdot(%img.window,%img.point.x.rec,%img.point.y.rec)

      if (!$hget(%img.hash,%img.point.colour)) {
        hadd %img.hash %img.point.colour 1
      }
      else {
        hinc %img.hash %img.point.colour
      }

      dec %img.point.y.rec
    }

    dec %img.point.x.rec
  }

  while (%img.hash.rec <= %img.hash.size) {
    if ((!%img.point.colour.common) || ($hget(%img.hash,%img.hash.rec).data > %img.point.colour.common.count)) { 
      %img.point.colour.common = $hget(%img.hash,%img.hash.rec).item
      %img.point.colour.common.count = $hget(%img.hash,%img.hash.rec).data
    }

    inc %img.hash.rec
  }

  hfree %img.hash

  return %img.point.colour.common

}

alias -l img.dot.blur {
  var %img.window, %img.point.x, %img.point.y, %img.point.max.x, %img.point.max.y, %img.point.difference, %img.hash, %img.hash.hmake.size, %img.hash.size, %img.hash.rec = 1
  var %img.point.x.min, %img.point.x.max, %img.point.y.min, %img.point.y.max, %img.point.x.rec, %img.point.y.rec
  var %img.point.colour, %img.point.colour.red = 0, %img.point.colour.green = 0, %img.point.colour.blue = 0,%img.point.colour.total

  %img.window = $1
  %img.point.x = $2
  %img.point.y = $3
  %img.point.difference = $4
  %img.point.max.x = $5
  %img.point.max.y = $6

  %img.point.x.min = $calc(%img.point.x - %img.point.difference)
  %img.point.x.max = $calc(%img.point.x + %img.point.difference)

  %img.point.y.min = $calc(%img.point.y - %img.point.difference)
  %img.point.y.max = $calc(%img.point.y + %img.point.difference)

  if (%img.point.x.min < 0) { %img.point.x.min = 0 }
  if (%img.point.y.min < 0) { %img.point.y.min = 0 }

  if (%img.point.x.max > %img.point.max.x) { %img.point.x.max = %img.point.max.x }
  if (%img.point.y.max > %img.point.max.y) { %img.point.y.max = %img.point.max.y }

  %img.hash.size = $calc((%img.point.x.max -  %img.point.x.min) * (%img.point.y.max -  %img.point.y.min))

  %img.hash = $img.hash.getname

  %img.hash.hmake.size = $int($calc(%img.hash.size / 10))

  if (%img.hash.hmake.size < 1) { %img.hash.hmake.size = 1 }

  hmake %img.hash %img.hash.hmake.size

  %img.point.x.rec = %img.point.x.max

  while (%img.point.x.rec >= %img.point.x.min) {
    %img.point.y.rec = %img.point.y.max
    while (%img.point.y.rec >= %img.point.y.min) {
      %img.point.colour = $getdot(%img.window,%img.point.x.rec,%img.point.y.rec)

      if (!$hget(%img.hash,%img.point.colour)) {
        hadd %img.hash %img.point.colour 1
      }
      else {
        hinc %img.hash %img.point.colour
      }

      dec %img.point.y.rec
    }

    dec %img.point.x.rec
  }

  while (%img.hash.rec <= %img.hash.size) {
    tokenize 44 $rgb($hget(%img.hash,%img.hash.rec).item)
    %img.point.colour.total = $hget(%img.hash,%img.hash.rec).data

    inc %img.point.colour.red $calc(%img.point.colour.total * $1)
    inc %img.point.colour.green $calc(%img.point.colour.total * $2)
    inc %img.point.colour.blue $calc(%img.point.colour.total * $3)

    inc %img.hash.rec
  }

  hfree %img.hash

  %img.point.colour.red = $int($calc(%img.point.colour.red / %img.hash.size))
  %img.point.colour.green = $int($calc(%img.point.colour.green / %img.hash.size))
  %img.point.colour.blue = $int($calc(%img.point.colour.blue / %img.hash.size))

  if (%img.point.colour.red < 0) { %img.point.colour.red = 0 }
  if (%img.point.colour.green < 0) { %img.point.colour.green = 0 }
  if (%img.point.colour.blue < 0) { %img.point.colour.blue = 0 }
  if (%img.point.colour.red > 255) { %img.point.colour.red = 255 }
  if (%img.point.colour.green > 255) { %img.point.colour.green = 255 }
  if (%img.point.colour.blue > 255) { %img.point.colour.blue = 255 }

  return $rgb(%img.point.colour.red,%img.point.colour.green,%img.point.colour.blue)
}

alias -l img.dot.emboss {
  var %img.window, %img.point.x, %img.point.y, %img.point.x.2, %img.point.y.2, %img.point.max.x, %img.point.max.y
  var %img.point.density.max, %img.point.density.max.half, %img.point.colour, %img.point.colour.2
  var %img.point.colour.red, %img.point.colour.green, %img.point.colour.blue
  var %img.point.colour.red.2, %img.point.colour.green.2, %img.point.colour.blue.2
  var %img.point.override.density

  %img.window = $1
  %img.point.x = $2
  %img.point.y = $3
  %img.point.x.2 = %img.point.x + 2
  %img.point.y.2 = %img.point.y + 2
  %img.point.max.x = $4
  %img.point.max.y = $5
  %img.point.override.density = $6

  if (%img.point.x.2 > %img.point.max.x) { %img.point.x.2 = %img.point.max.x }
  if (%img.point.y.2 > %img.point.max.y) { %img.point.y.2 = %img.point.max.y }

  %img.point.colour = $getdot(%img.window,%img.point.x,%img.point.y)
  %img.point.colour.2 = $getdot(%img.window,%img.point.x.2,%img.point.y.2)

  if (!%img.point.override.density) {
    %img.point.density.max = 255
  }
  else {
    %img.point.density.max = %img.point.override.density
  }
  %img.point.density.max.half = $int($calc(%img.point.density.max / 2))

  tokenize 44 $rgb(%img.point.colour.2)

  %img.point.colour.red.2 = $calc(%img.point.density.max.half - $1)
  %img.point.colour.green.2 = $calc(%img.point.density.max.half - $2)
  %img.point.colour.blue.2 = $calc(%img.point.density.max.half - $3)

  tokenize 44 $rgb(%img.point.colour)

  %img.point.colour.red = $int($calc(%img.point.colour.red.2 + $1))
  %img.point.colour.green = $int($calc(%img.point.colour.green.2 + $2))
  %img.point.colour.blue = $int($calc(%img.point.colour.blue.2 + $3))

  if (%img.point.colour.red < 0) { %img.point.colour.red = 0 }
  if (%img.point.colour.green < 0) { %img.point.colour.green = 0 }
  if (%img.point.colour.blue < 0) { %img.point.colour.blue = 0 }
  if (%img.point.colour.red > 255) { %img.point.colour.red = 255 }
  if (%img.point.colour.green > 255) { %img.point.colour.green = 255 }
  if (%img.point.colour.blue > 255) { %img.point.colour.blue = 255 }

  return $rgb(%img.point.colour.red,%img.point.colour.green,%img.point.colour.blue)

}

alias -l img.dot.circle {
  var %img.window, %img.point.x, %img.point.y, %img.point.max.x, %img.point.max.y, %img.point.circle

  %img.window = $1
  %img.point.x = $2
  %img.point.y = $3
  %img.point.max.x = $4
  %img.point.max.y = $5

  if $inellipse(%img.point.x,%img.point.y,0,0,%img.point.max.x,%img.point.max.y) {
    return $getdot(%img.window,%img.point.x,%img.point.y)
  }
  else {
    return
  }
}

alias -l img.hash.getname {
  var %img.hash.prefix = img.hash., %img.hash.suffix.rec = 0

  while ($hget($+(%img.hash.prefix,%img.hash.suffix.rec))) {
    inc %img.hash.suffix.rec
  }

  return $+(%img.hash.prefix,%img.hash.suffix.rec)
}

alias -l img.window.getname {
  var %img.window.prefix = @img.window., %img.window.suffix.rec = 0

  while ($window($+(%img.window.prefix,%img.window.suffix.rec))) {
    inc %img.window.suffix.rec
  }

  return $+(%img.window.prefix,%img.window.suffix.rec)
}

alias -l img.file.getname {
  var %img.file.prefix = img, %img.file.suffix.rec = 0, %img.file.suffix = .lines

  while ($exists($+(%img.file.prefix,%img.file.suffix.rec,%img.file.suffix))) {
    inc %img.file.suffix.rec
  }

  return $+(",%img.file.prefix,%img.file.suffix.rec,%img.file.suffix,")
}

alias -l img.file.handle.getname {
  var %img.file.handle.prefix = img, %img.file.handle.suffix.rec = 0

  while ($fopen($+(%img.file.handle.prefix,%img.file.handle.suffix.rec))) {
    inc %img.file.handle.suffix.rec
  }

  return $+(%img.file.handle.prefix,%img.file.handle.suffix.rec)
}

Comments

Sign in to comment.
Korvin   -  Mar 09, 2009

who would vote this 8?? :0 this is incredibly creative, and really useful. 10/10

 Respond  
baseballer790   -  Mar 09, 2009

WHAT IS IT

 Respond  
Noutrious   -  Dec 25, 2007

I think this is something i couldnt do and it really deserves 9.

 Respond  
TropNul   -  Dec 23, 2007

Good job.

When I\'ll have some time, I\'ll read through it but the screenshot says it all. If it does all that, then it\'s a very good source.

Cordialement

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.