Imagedata row order

Trevor DeVore lists at mangomultimedia.com
Sun Jul 23 13:25:07 EDT 2006


On Jul 21, 2006, at 12:55 PM, J. Landman Gay wrote:

> I am trying to figure out how to set an image's imageData to a  
> repeating pattern. I have a pattern that is 8 x 8 pixels. I want to  
> repeat this pattern 16 times in order to fill a 32-pixel square image.
>
> If I repeat the pattern 4 times, I get a nice column of four  
> repeating patterns going down the left edge of the image. If I  
> repeat it 16 times I get junk. In what order are the pixels laid  
> down, and what determines where and when they wrap?

Jacque,

I need to experiment with this for a project I'm working on so I  
worked in this handler yesterday.  You just provide the long id of a  
src image (the image to tile) and the destination image (the image to  
perform the tiling in).  I've only tested this on OS X with Rev 2.7.x  
but it is working well here.

By the way, it seems that in 2.7.x that backgroundPatterns can be any  
size.  There is a note in the What's New.txt file that says this is  
the case for graphics but I tried setting the backgroundPattern of a  
field to an image that was 405 x 29 and it appeared correctly on OS  
X.  The pattern evens scrolls with the field which is cool.  If  
backgroundPatterns behave like this on Windows as well then perhaps  
there is no need to roll your own tiling handler.

-- 
Trevor DeVore
Blue Mango Learning Systems - www.bluemangolearning.com
trevor at bluemangolearning.com




ON TileImage pSrcImg, pDestImg, pUseAlpha
     local pixelCharCount = 4

     put the width of pSrcImg into theSrcWidth
     put the height of pSrcImg into theSrcHeight

     put the width of pDestImg into theDestWidth
     put the height of pDestImg into theDestHeight

     put theDestWidth div theSrcWidth into theColumns
     put theDestHeight div theSrcHeight into theRows
     put theDestWidth mod theSrcWidth into theLeftOverWidth
     put theDestHeight mod theSrcHeight into theLeftOverHeight

     put pixelCharCount * theLeftOverWidth into theLastColCharCount
     put pixelCharCount * theLeftOverHeight into theLastRowCharCount
     put theDestWidth * pixelCharCount into theRowWidthCharCount	#  
number of image data chars in one row

     put theRowWidthCharCount * theLastRowCharCount into  
theLastRowTotalImageCharCount	# how many total pixels does last  
partial row take up?
     put theDestWidth * theLeftOverHeight into  
theLastRowTotalAlphaCharCount

     put the imagedata of pSrcImg into theImageData
     IF pUseAlpha THEN put the alphadata of pSrcImg into theAlphaData

     REPEAT with theRow = 1 to theSrcHeight	# cache one entire row
         put (theRow - 1) * (theSrcWidth * 4) + 1 into theStartPixel	 
# separate src image into rows
         put theStartPixel + (theSrcWidth * 4) - 1 into theEndPixel
         put char theStartPixel to theEndPixel of theImageData into  
theRowImgDataA[theRow,"full"]
         put char 1 to theLastColCharCount of theRowImgDataA 
[theRow,"full"] into theRowImgDataA[theRow,"partial"]	# partial  
column at right side of dest img

         IF pUseAlpha THEN	# same for alpha
             put (theRow - 1) * theSrcWidth into theStartPixel
             put theStartPixel + theSrcWidth into theEndPixel
             put char theStartPixel to theEndPixel of theAlphaData  
into theRowAlphaDataA[theRow,"full"]
             put char 1 to theLastColCharCount of theAlphaData into  
theRowAlphaDataA[theRow,"partial"]
         END IF

         REPEAT with theCol = 1 to theColumns	# insert src row into  
each column for dest row
             put theRowImgDataA[theRow,"full"] after theRowImageData
             IF pUseAlpha THEN put theRowAlphaDataA[theRow,"full"]  
after theRowAlphaData
         END REPEAT
         IF theLeftOverWidth > 0 THEN
             put theRowImgDataA[theRow,"partial"] after theRowImageData
             IF pUseAlpha THEN put theRowAlphaDataA[theRow,"partial"]  
after theRowAlphaData
         END IF
     END REPEAT

     lock screen
     IF theRows > 1 THEN	# tile rows if need be
         REPEAT with theRow = 1 to theRows
             put theRowImageData after theNewImageData
             IF pUseAlpha THEN put theRowAlphaData after theNewAlphaData
         END REPEAT

         IF theLeftOverHeight > 0 THEN
             put char 1 to theLastRowTotalImageCharCount of  
theRowImageData after theNewImageData	# fill in the last row
             IF pUseAlpha THEN
                 put char 1 to theLastRowTotalAlphaCharCount of  
theRowAlphaData after theNewAlphaData
             END IF
         END IF

         set the imagedata of pDestImg to theNewImageData
         IF pUseAlpha THEN
             set the alphadata of pDestImg to theNewAlphaData
         END IF
     ELSE	# we have all data we need for single row
         IF theLeftOverHeight > 0 THEN
             put char 1 to theLastRowTotalImageCharCount of  
theRowImageData after theRowImageData	# fill in the last row
             IF pUseAlpha THEN
                 put char 1 to theLastRowTotalAlphaCharCount of  
theRowAlphaData after theRowAlphaData
             END IF
         END IF

         set the imagedata of pDestImg to theRowImageData
         IF pUseAlpha THEN
             set the alphadata of pDestImg to theRowAlphaData
         END IF
     END IF
     unlock screen
END TileImage







More information about the use-livecode mailing list