Manipulating imagedata - quickest technique?

Mark Smith mark at maseurope.net
Mon Apr 3 06:58:23 EDT 2006


I just knocked this up quickly, it loads the image data into an array,
lightens all the rgb values and sets the image to the new data,
I've no idea how this relates to what you're doing, but it takes about
17 seconds to complete on my system (Mac 1.5Ghz Powerbook), of which
about 7 seconds is spent populating the array - I used a 1.2 megabyte
image.

I'm sure David is right that externals are the way to this sort of
stuff, if speed matters at all.


on doLighten imageName
  put 1 into pixCount
  put 0 into charCount
  repeat for each char pix in the imageData of image imageName
    add 1 to  charCount
    if charCount = 1 then
      next repeat
    else if charCount = 2 then
      put charToNum(pix) into pixArray[pixCount,"r"]
    else if charCount = 3 then
      put charToNum(pix) into pixArray[pixCount,"g"]
    else if charCount = 4 then
      put charToNum(pix) into pixArray[pixCount,"b"]
      put 0 into charCount
      add 1 to pixCount
    end if
  end repeat


  repeat for each line L in the keys of pixArray
    put min(pixArray[L] * 1.5,255) into pixArray[L]
  end repeat

  subtract 1 from pixCount
  repeat with n = 1 to pixCount
    put binaryEncode("C","0") after newImageData
    put binaryEncode("C",pixArray[n,"r"]) after newImageData
    put binaryEncode("C",pixArray[n,"g"]) after newImageData
    put binaryEncode("C",pixArray[n,"b"]) after newImageData
  end repeat

  set the imageData of image imageName to newImageData
end doLighten


Best,

Mark

On 3 Apr 2006, at 11:03, David Bovill wrote:

What's the quickest technique? This script is based on some of Chipps
work... baiscally it loops through the whole imageData 4 chars at a
time and manipulates each chunk before adding it to the new data.

A few questions:

   1) Is this the fastest way?

   2) Can someone explain the use of binaryEncode - is this faster or slower?

   3) Is there a way to cash some intermediary form of data that is
faster to manipulate?

For the last point - imagine having sliders for HSV values. At the
moment the script converts rgb in the imageData to hsv and back again
- by caching the original images HSV data this could speed things up
nearly 200%? So what sort of format would make the most sense to store
this data in - some sort of table / array?

on colour_SetBrightness imageObject, somePercent
    set the cursor to watch
        put the imageData of imageObject into someImageData
    put 0 into tPos
    put the length of someImageData / 4 into binaryPixelNum
         repeat for binaryPixelNum times
        put tPos + 4 into tPos
                put charToNum(char tPos + 1 of someImageData) into r
        put charToNum(char tPos + 2 of someImageData) into g
        put charToNum(char tPos + 3 of someImageData) into b
                colour_LightenRGB somePercent, r, g, b
                put binaryEncode("CCCC", 0, r, g, b) after newImageData
    end repeat
    -- put newImageData
    set the imageData of imageObject to newImageData
end colour_SetBrightness


_______________________________________________
use-revolution mailing list
use-revolution at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution



More information about the use-livecode mailing list