Trim Image

paolo mazza mazzapaolo at libero.it
Sat Sep 21 00:13:01 EDT 2002


If anybody needs to trim images in Rev I wrote this code.
In my Mac PPC and OSX it works. (Thanks Kevin for your article about Mask
data) 
As you can see I resized the image before triming in order to speed up the
process.
I wuold like to blend two images with transparent backgrounds and  get  one
single image. I know i can use the "import snapshot" command, but I would
like to blend the images off-screen.
Any suggestions?

Thanks,   Paolo
>>>

local NNN

on MouseUp
  put the ID of the last image into NNN
  put trunc((the width of  image ID NNN)/10) into XX
  put trunc((the height of  image  ID NNN) /10)  into YY
  clone image ID NNN
  set the width of the last image to XX
  set the height of the last image to YY
  put (XX*YY) into TOTPIXY
 
 
  repeat with VAL=1 to  TOTPIXY
    if chartonum(char VAL of the maskData of the last image) <> 0 then
      put trunc(VAL/XX) into NORD
      exit repeat
    end if
  end repeat
 
  repeat with VAL=TOTPIXY  down to 1
    if chartonum(char VAL of the maskData of the last image) <> 0 then
      put trunc(VAL/XX) into SUD
      put YY-SUD-1 into SUD
      exit repeat
    end if
  end repeat
 
  put (NORD*10)  & comma & (SUD*10)  & comma &  (CONTROLLODX(XX,YY) *10)  &
comma & (CONTROLLOSX(XX,YY)*10)  into COORDINATE
 
  delete last image
 
  -- put COORDINATE into message
 
  CANCELLARIGHE COORDINATE
 
  beep 1
end MouseUp

function CONTROLLODX XX,YY
  repeat with Q=1 to XX
    repeat with K=0 to (YY-1)
      put Q+(K*XX) into VAL
      if chartonum(char VAL of the maskData of the last image) <> 0 then
        return  (Q-1)
        exit CONTROLLODX
      end if
    end repeat
  end repeat
end CONTROLLODX

function CONTROLLOSX XX,YY
  repeat with Q=XX down to 1
    repeat with K=(YY-1) down to 0
      put Q+(K*XX) into VAL
      if chartonum(char VAL of the maskData of the last image) <> 0 then
        put XX-Q-1 into Q
       return Q
        exit CONTROLLOSX
      end if
    end repeat
  end repeat
end CONTROLLOSX

on  CANCELLARIGHE COORDINATE
  put the MaskData of image ID NNN into  TheMaskData1
  put the imagedata of image ID NNN into  Theimagedata1
  put the width of image ID NNN into XXX
  put the height of image ID NNN into YYY

  -- riduzione NORD
  put item 1 of COORDINATE  into VAR1
  put XXX*YYY into TOTVAR
  put 4*XXX*YYY into TOTVAR4
  put VAR1*XXX into TOTVAR1
  delete char 1 to TOTVAR1 of TheMaskData1
  put TOTVAR1*4 into TOTVAR1
  delete char 1 to TOTVAR1 of Theimagedata1
  put (YYY-VAR1) into YYY

  -- riduzione SUD
  put item 2 of COORDINATE  into VAR1
  put XXX*YYY into TOTVAR
  put 4*XXX*YYY into TOTVAR4
  put VAR1*XXX into TOTVAR1
  delete char (TOTVAR-TOTVAR1+1) to TOTVAR of TheMaskData1
  put TOTVAR1*4 into TOTVAR1
  delete char (TOTVAR4-TOTVAR1+1)  to TOTVAR4 of Theimagedata1
  put (YYY-VAR1) into YYY

  -- riduzione EST-OVEST

  put empty into TheMaskData2
  put empty into Theimagedata2
  put item 3 of COORDINATE  into VarEst
  put item 4 of COORDINATE  into VarWest

  put XXX-VarEst-VarWest into FASCIA

  repeat with M=0 to (YYY-1)
    repeat with K=(VarEst+1) to (XXX-VarWest)
      put K+(M*XXX) into NUM2
      put char NUM2   of TheMaskdata1 after TheMaskdata2
      put (NUM2-1)*4  into NUM2
       put NUM2+1 into NUM2
      put char NUM2 of Theimagedata1 after Theimagedata2
      put NUM2+1 into NUM2
      put char NUM2 of Theimagedata1  after Theimagedata2
      put NUM2+1 into NUM2
      put char NUM2 of Theimagedata1  after Theimagedata2
      put NUM2+1 into NUM2
      put char NUM2 of Theimagedata1  after Theimagedata2
    end repeat
  end repeat

  -- put length(TheMaskData2)  &&  length(Theimagedata2)/4 into message
  if length(TheMaskData2)  is  length(Theimagedata2)/4 then
    put empty into image ID NNN
    set the width of image ID NNN to FASCIA
    set the height of image ID NNN to YYY
    set the MaskData of image ID NNN  to TheMaskData2
    set the imagedata of image ID NNN  to  Theimagedata2
  else
    beep 1
  end if

end CANCELLARIGHE




More information about the Use-livecode mailing list