Append an image to another image

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

dmeier
Posts: 15
Joined: Mon May 25, 2015 10:52 am

Append an image to another image

Post by dmeier » Wed Jun 17, 2015 5:27 pm

Hi, does anybody know how to append an image e.g. jpeg to an other one? The result would be a long image showing two pictures/pages in portrait format.

Thx for helping.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Append an image to another image

Post by Klaus » Wed Jun 17, 2015 5:45 pm

Hi David,

sorry, no idea about how to manipulate the binary file stuff, so I would simply lay out these two images
on a card in Livecode and then export a snapshot of both images, know what I mean? :D


Best

Klaus

dmeier
Posts: 15
Joined: Mon May 25, 2015 10:52 am

Re: Append an image to another image

Post by dmeier » Sat Jun 20, 2015 3:42 pm

Thank you Klaus

I understand the idea but don't I loose resolution? In my thinking the resulting picture will only have the screen resolution.

Regards David

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Append an image to another image

Post by Klaus » Sat Jun 20, 2015 4:00 pm

Hi David,

yes, true, but not the exact amount of pixels! 8)


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Append an image to another image

Post by FourthWorld » Sat Jun 20, 2015 4:16 pm

Using the older "from rect..." option with the "export snapshot" command obtains the image from the screen buffer, which will be limited to screen resolution. However, I believe using the newer and more useful "from <object>..." option will use the object's resolution, as it obtains the data directly from the object structure itself.

Please let us know if you find otherwise.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Append an image to another image

Post by Mark » Sat Jun 20, 2015 5:12 pm

Hi,

Appending two images is really easy, if the images have the same width. This seems what you want to do.

Code: Select all

on mouseUp
     put the imagedata of img 1 & the imagedata of img 2 into myData
     create img
     set the height of it to the height of img 1 + the height of img 2
     set the width of it to the width of img 1
     set the imagedata of it to myData
end mouseUp
This script appends the imagedata of one image to the imagedata of the second image and uses the new imagedata for a third image. It is important to set the width and height of the third image to the correct dimensions before setting the imagedata.

Use the export command to export he third image as JPEG.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Append an image to another image

Post by Klaus » Sat Jun 20, 2015 5:23 pm

Hi Mark,

wow, that's pretty cool, thanks! :D


Best

Klaus

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Append an image to another image

Post by SparkOut » Sat Jun 20, 2015 7:46 pm

It's slow to process, but you can add two images of different widths if you choose to make the effort to edit the imageData too

Code: Select all

on mouseUp
   --sloppy request for pictures
   answer file "Browse for picture 1"
   put it into tPath1
   
   answer file "Browse for picture 2"
   put it into tPath2
   
   --as per dictionary note, get full res formatted images into LC
   put url ("binfile:" & tPath1) into tImage1
   put tImage1 into image "Image1"
   put url ("binfile:" & tPath2) into tImage2
   put tImage2 into image "Image2"
   
   put the width of image "Image1" into tWidth1
   put the height of image "Image1" into tHeight1
   put the width of image "Image2" into tWidth2
   put the height of image "Image2" into tHeight2
   
   --set the dimensions of the combined image, one on top of the other
   put max(tWidth1,tWidth2) into tMaxWidth
   put tHeight1 + tHeight2 into tTotalHeight
   set the width of image "ImageNew" to tMaxWidth
   set the height of image "ImageNew" to tTotalHeight
   
   --set background colour for new image, here white
   put numToByte(0) & numToByte(255) & numToByte(255) & numToByte(255) into tBackC
   
   put empty into tNewImageData
   --this bit could be optimised, it's only to make a plain background if the images are different widths
   repeat with i=1 to tTotalHeight
      repeat with j=1 to tMaxWidth
         --fill the new image data holder with blank background colour
         put tBackC after tNewImageData
         wait 0 milliseconds with messages
      end repeat
      wait 0 milliseconds with messages
   end repeat
   --fill the blank background
   set the imageData of image "ImageNew" to tNewImageData
   
   --get the image data for the separate images and begin to combine
   put the imageData of image "Image1" into tImageData1
   put the imageData of image "Image2" into tImageData2
   
   --each pixel is 4 bytes of data
   put tWidth1 * 4 into tRowLength
   --horizontal offset to calculate where each row begins if there is any padding
   put (tMaxWidth - tWidth1) * 4 into tOffsetH
   --loop through each "row" of pixel data calculating the start and finish points in 
   --the binary data to be extracted
   repeat with i=1 to tHeight1
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + ((i-1) * tOffsetH) into tNewStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put tNewStartOfRow + tRowLength - 1 into tNewEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData1 into byte tNewStartOfRow to tNewEndOfRow of tNewImageData
      wait 0 milliseconds with messages
   end repeat
   --show progress with 1st image
   set the imageData of image "ImageNew" to tNewImageData
   
   put tHeight1 * tMaxWidth * 4 into tOffsetV
   put tWidth2 * 4 into tRowLength
   put (tMaxWidth - tWidth2) * 4 into tOffsetH
   repeat with i=1 to tHeight2
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + ((i-1) * tOffsetH) +tOffsetV into tNewStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put tNewStartOfRow + tRowLength - 1 into tNewEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData2 into byte tNewStartOfRow to tNewEndOfRow of tNewImageData
      wait 0 milliseconds with messages
   end repeat
   --show the combined image
   set the imageData of image "ImageNew" to tNewImageData
end mouseUp
Edit: but it might be dangerous with image files more than a couple of hundred pixels in any dimension, seems to crash here - I think the tNewImageData variable may become too large?
Edit again: Maybe because numToChar and char have been deprecated for 7.0.x and I should have used numToByte and byte above?
Last edited by SparkOut on Sat Jun 20, 2015 8:42 pm, edited 2 times in total.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Append an image to another image

Post by Mark » Sat Jun 20, 2015 8:02 pm

Actually, you don't need to do that, if you glue the top of one image to the bottom of another. You can just take the width of the widest image, but you'll end up with a black area. You can replace this area with the desired colour using the replace command or you can add an alpha mask.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Append an image to another image

Post by SparkOut » Sat Jun 20, 2015 8:14 pm

Really? Where am I going wrong?

Code: Select all

   put the width of image "Image1" into tWidth1
   put the height of image "Image1" into tHeight1
   put the width of image "Image2" into tWidth2
   put the height of image "Image2" into tHeight2
   
   --set the dimensions of the combined image, one on top of the other
   put max(tWidth1,tWidth2) into tMaxWidth
   put tHeight1 + tHeight2 into tTotalHeight
   set the width of image "ImageNew" to tMaxWidth
   set the height of image "ImageNew" to tTotalHeight

   --get the image data for the separate images and combine
   put the imageData of image "Image1" into tImageData1
   put the imageData of image "Image2" into tImageData2
   put tImageData1 & tImageData2 into tNewImageData

   set the imageData of image "ImageNew" to tNewImageData
If the dimensions are similar enough I can see a vague semblance of the images being combined but there is no glueing together with plain black background for the empty space.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Append an image to another image

Post by Mark » Sat Jun 20, 2015 11:06 pm

Hi,

Apparently, you can't glue image files of different widths without further adjustment, but if you have two images of equal width and a third image that is wider, you can set the imagedata of the third image to the appended imagedata of the first two images and you'll see the two pictures and a black area.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Append an image to another image

Post by SparkOut » Mon Jun 22, 2015 9:17 am

Nope, that doesn't work either. I can't see how it would as there is no "end of row" marker in the data, it's just pure binary. That's why images get garbled if the image is set to the wrong dimensions when manipulating by other means, surely.

I made a revision to my trial above and it works OK, creating a blank image placeholder is much simpler just to put white into a single pixel and then resize it rather than fill an image of the correct size pixel by pixel, duh!

[edit]"corrected" below to include the whole script - see Bernd's comment in a later post

Code: Select all

   --sloppy request for pictures
   answer file "Browse for picture 1"
   put it into tPath1
   
   answer file "Browse for picture 2"
   put it into tPath2
   
   --as per dictionary note, get full res formatted images into LC
   put url ("binfile:" & tPath1) into tImage1
   put tImage1 into image "Image1"
   put url ("binfile:" & tPath2) into tImage2
   put tImage2 into image "Image2"
   
   put the milliseconds into tStart
   lock cursor
   set the cursor to watch
   
   put the width of image "Image1" into tWidth1
   put the height of image "Image1" into tHeight1
   put the width of image "Image2" into tWidth2
   put the height of image "Image2" into tHeight2
   put max(tWidth1,tWidth2) into tMaxWidth
   put tHeight1 + tHeight2 into tTotalHeight
   
   --make a small image and clear the background
   set the width of image "ImageNew" to 1
   set the height of image "ImageNew" to 1
   
   --set background colour for new image, here white
   put numToByte(0) & numToByte(255) & numToByte(255) & numToByte(255) into tBackC
   set the imageData of image "ImageNew" to tBackC
   
   set the width of image "ImageNew" to tMaxWidth
   set the height of image "ImageNew" to tTotalHeight
   set the topLeft of image "ImageNew" to 30,30
   set the layer of image "ImageNew" to top
   put the imageData of image "ImageNew" into tNewImageData
   
   --get the image data for the separate images and begin to combine
   put the imageData of image "Image1" into tImageData1
   put the imageData of image "Image2" into tImageData2
   
   --each pixel is 4 bytes of data
   put tWidth1 * 4 into tRowLength
   --horizontal offset to calculate where each row begins if there is any padding
   put (tMaxWidth - tWidth1) * 4 into tOffsetH
   --loop through each "row" of pixel data calculating the start and finish points in 
   --the binary data to be extracted
   repeat with i=1 to tHeight1
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + ((i-1) * tOffsetH) into tNewStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put tNewStartOfRow + tRowLength - 1 into tNewEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData1 into byte tNewStartOfRow to tNewEndOfRow of tNewImageData
      wait 0 milliseconds with messages
   end repeat
   --show progress with 1st image
   set the imageData of image "ImageNew" to tNewImageData
   
   put tHeight1 * tMaxWidth * 4 into tOffsetV
   put tWidth2 * 4 into tRowLength
   put (tMaxWidth - tWidth2) * 4 into tOffsetH
   repeat with i=1 to tHeight2
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + ((i-1) * tOffsetH) +tOffsetV into tNewStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put tNewStartOfRow + tRowLength - 1 into tNewEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData2 into byte tNewStartOfRow to tNewEndOfRow of tNewImageData
      wait 0 milliseconds with messages
   end repeat
   --show the combined image
   set the imageData of image "ImageNew" to tNewImageData
   put "finished in" && the milliseconds - tStart && "milliseconds"
   unlock cursor
Then I tried to optimise it a bit because I thought it would be better not to have to calculate and insert the data into the right place in the binary string, but simply append line by line with an appropriate padding appended if necessary.

Code: Select all

   --sloppy request for pictures
   answer file "Browse for picture 1"
   put it into tPath1
   
   answer file "Browse for picture 2"
   put it into tPath2
   
   --as per dictionary note, get full res formatted images into LC
   put url ("binfile:" & tPath1) into tImage1
   put tImage1 into image "Image1"
   put url ("binfile:" & tPath2) into tImage2
   put tImage2 into image "Image2"
   
   put the milliseconds into tStart
   lock cursor
   set the cursor to watch
   
   put the width of image "Image1" into tWidth1
   put the height of image "Image1" into tHeight1
   put the width of image "Image2" into tWidth2
   put the height of image "Image2" into tHeight2
   put max(tWidth1,tWidth2) into tMaxWidth
   put tHeight1 + tHeight2 into tTotalHeight
   
   --set a background colour for new image, here white
   put numToByte(0) & numToByte(255) & numToByte(255) & numToByte(255) into tBackC
   
   put empty into tPad1
   put empty into tPad2
   put tMaxWidth - tWidth1 into tPadWidth1
   put tMaxWidth - tWidth2 into tPadWidth2
   
   repeat while tPadWidth1 > 0
      put tBackC after tPad1
      subtract 1 from tPadWidth1
   end repeat
   repeat while tPadWidth2 > 0
      put tBackC after tPad2
      subtract 1 from tPadWidth2
   end repeat
   
   put empty into tNewImageData
   
   --get the image data for the separate images and begin to combine
   put the imageData of image "Image1" into tImageData1
   put the imageData of image "Image2" into tImageData2
   
   --each pixel is 4 bytes of data
   put tWidth1 * 4 into tRowLength
   --loop through each "row" of pixel data calculating the start and finish points in 
   --the binary data to be extracted
   repeat with i=1 to tHeight1
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData1 & tPad1 after tNewImageData
      wait 0 milliseconds with messages
   end repeat
   
   put tWidth2 * 4 into tRowLength
   repeat with i=1 to tHeight2
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData2 & tPad2 after tNewImageData
      wait 0 milliseconds with messages
   end repeat
   --show the combined image
   set the width of image "ImageNew" to tMaxWidth
   set the height of image "ImageNew" to tTotalHeight
   set the topLeft of image "ImageNew" to 30,30
   set the layer of image "ImageNew" to top
   set the imageData of image "ImageNew" to tNewImageData
   put "finished in" && the milliseconds - tStart && "milliseconds"
   unlock cursor
If the images are small then both do the job in a matter of milliseconds - the new version is slightly quicker. Oddly though, if the images are bigger (say 400 x 400 as a rough cross-over point) the first example works faster. At about 800px or so it's roughly twice as fast (~700ms vs ~1350ms) but over 2000px the difference is vast, and the calculation-intensive start-and-end-point-finding routine in the first code finished in about 48 seconds vs ~200 seconds.
Last edited by SparkOut on Mon Jun 22, 2015 8:34 pm, edited 3 times in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Append an image to another image

Post by bn » Mon Jun 22, 2015 2:51 pm

Hi Sparkout,

thanks for posting your solutions.

I had a look at them and did some small changes.

Solution 1 was incomplete and I added the routing for image2 in the logic of your script

For both solutions I added lock screen and lock messages

With these small changes the time it took is considerably shorter than what you reported.

I took as the worst case 2 images of 3072x2204 as image1 and image2
Solution 1 took about 7200 milliseconds and Solution 2 took about 7800 milliseconds

This is on a Mac Intel i5 2.53 GHz 10.9.5 Livecode 7.0.6 RC1

By the way I am impressed about the speed increase in the 7.x.x series. It used to be a lot slower for this type of operation than the 6.7.x series. Now it is on par.
And both versions are faster than pre 6.7 versions
Hats off to Edinburgh

here is the code for solution 1

Code: Select all

   
on mouseUp
   --sloppy request for pictures
   answer file "Browse for picture 1"
   put it into tPath1
   
   answer file "Browse for picture 2"
   put it into tPath2
   
   --as per dictionary note, get full res formatted images into LC
   put url ("binfile:" & tPath1) into tImage1
   put tImage1 into image "Image1"
   put url ("binfile:" & tPath2) into tImage2
   put tImage2 into image "Image2"
   
   lock screen
   lock messages
   
   put the milliseconds into tStart
   lock cursor
   set the cursor to watch
   
   put the width of image "Image1" into tWidth1
   put the height of image "Image1" into tHeight1
   put the width of image "Image2" into tWidth2
   put the height of image "Image2" into tHeight2
   put max(tWidth1,tWidth2) into tMaxWidth
   put tHeight1 + tHeight2 into tTotalHeight
   
   --make a small image and clear the background
   set the width of image "ImageNew" to 1
   set the height of image "ImageNew" to 1
   
   --set background colour for new image, here white
   put numToByte(0) & numToByte(255) & numToByte(255) & numToByte(255) into tBackC
   set the imageData of image "ImageNew" to tBackC
   
   set the width of image "ImageNew" to tMaxWidth
   set the height of image "ImageNew" to tTotalHeight
   set the topLeft of image "ImageNew" to 30,30
   set the layer of image "ImageNew" to top
   put the imageData of image "ImageNew" into tNewImageData
   
   --get the image data for the separate images and begin to combine
   put the imageData of image "Image1" into tImageData1
   put the imageData of image "Image2" into tImageData2
   
   --each pixel is 4 bytes of data
   put tWidth1 * 4 into tRowLength
   --horizontal offset to calculate where each row begins if there is any padding
   put (tMaxWidth - tWidth1) * 4 into tOffsetH
   --loop through each "row" of pixel data calculating the start and finish points in 
   --the binary data to be extracted
   repeat with i=1 to tHeight1
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + ((i-1) * tOffsetH) into tNewStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put tNewStartOfRow + tRowLength - 1 into tNewEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData1 into byte tNewStartOfRow to tNewEndOfRow of tNewImageData
      --set the imageData of image "ImageNew" to tNewImageData
      --wait 0 milliseconds with messages
   end repeat
   --show progress with 1st image
   
   put tNewEndOfRow + tOffsetH into tAddToBegin
   --each pixel is 4 bytes of data
   put tWidth2 * 4 into tRowLength
   --horizontal offset to calculate where each row begins if there is any padding
   put (tMaxWidth - tWidth2) * 4 into tOffsetH
   --loop through each "row" of pixel data calculating the start and finish points in 
   --the binary data to be extracted
   repeat with i=1 to tHeight2
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + ((i-1) * tOffsetH) + tAddToBegin into tNewStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put tNewStartOfRow + tRowLength - 1 into tNewEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData2 into byte tNewStartOfRow to tNewEndOfRow of tNewImageData
      --set the imageData of image "ImageNew" to tNewImageData
      --wait 0 milliseconds with messages
   end repeat
   
   
   set the imageData of image "ImageNew" to tNewImageData
   put the milliseconds - tStart && the milliseconds
   
   unlock cursor
   unlock messages
   unlock screen
   
end mouseUp
code for solution 2

Code: Select all

on mouseUp
   lock screen
   lock messages
   --sloppy request for pictures
   answer file "Browse for picture 1"
   put it into tPath1
   
   answer file "Browse for picture 2"
   put it into tPath2
   
   --as per dictionary note, get full res formatted images into LC
   put url ("binfile:" & tPath1) into tImage1
   put tImage1 into image "Image1"
   put url ("binfile:" & tPath2) into tImage2
   put tImage2 into image "Image2"
   --   
   put the milliseconds into tStart
   
   lock cursor
   set the cursor to watch
   
   put the width of image "Image1" into tWidth1
   put the height of image "Image1" into tHeight1
   put the width of image "Image2" into tWidth2
   put the height of image "Image2" into tHeight2
   put max(tWidth1,tWidth2) into tMaxWidth
   put tHeight1 + tHeight2 into tTotalHeight
   
   --set a background colour for new image, here white
   put numToByte(0) & numToByte(255) & numToByte(255) & numToByte(255) into tBackC
   
   put empty into tPad1
   put empty into tPad2
   put tMaxWidth - tWidth1 into tPadWidth1
   put tMaxWidth - tWidth2 into tPadWidth2
   
   repeat while tPadWidth1 > 0
      put tBackC after tPad1
      subtract 1 from tPadWidth1
   end repeat
   repeat while tPadWidth2 > 0
      put tBackC after tPad2
      subtract 1 from tPadWidth2
   end repeat
   
   put empty into tNewImageData
   
   --get the image data for the separate images and begin to combine
   put the imageData of image "Image1" into tImageData1
   put the imageData of image "Image2" into tImageData2
   
   --each pixel is 4 bytes of data
   put tWidth1 * 4 into tRowLength
   --loop through each "row" of pixel data calculating the start and finish points in 
   --the binary data to be extracted
   repeat with i=1 to tHeight1
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData1 & tPad1 after tNewImageData
      --- wait 0 milliseconds with messages
   end repeat
   
   put tWidth2 * 4 into tRowLength
   repeat with i=1 to tHeight2
      put ((i-1)* tRowLength) +1 into tStartOfRow
      put tStartOfRow + tRowLength - 1 into tEndOfRow
      put byte tStartOfRow to tEndOfRow of tImageData2 & tPad2 after tNewImageData
      wait 0 milliseconds with messages
   end repeat
   --show the combined image
   set the width of image "ImageNew" to tMaxWidth
   set the height of image "ImageNew" to tTotalHeight
   set the topLeft of image "ImageNew" to 30,30
   set the layer of image "ImageNew" to top
   set the imageData of image "ImageNew" to tNewImageData
   put "finished in" && the milliseconds - tStart && "milliseconds"
   unlock cursor
   unlock messages
   unlock screen
end mouseUp
Kind regards

Bernd

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Append an image to another image

Post by SparkOut » Mon Jun 22, 2015 8:17 pm

Thanks Bernd! and oops, yes, it's a hazard of copy/pasting, I didn't manage to select all the script before copying. I edited above to put my complete script in the earlier post just in case anyone was unaware.
It didn't occur to me to lock messages, as with a long repeat loop I always felt it will lock up and lead to an app showing "not responding" on Windows. That's the purpose of the wait 0 milliseconds with messages. I see that with care it should be good to lock messages a bit more freely than I'm used to. It's still interesting that putting data "after" the container takes longer than putting data into a specific place in the container. On my Windows 7 laptop 4GB RAM, i5 @ 2.4GHz, with screen and messages locked it took 32 seconds to combine images of 2984 x 4208 and 1775 x 2384 pixels using routine 1 and 212 seconds with routine 2.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Append an image to another image

Post by bn » Mon Jun 22, 2015 8:50 pm

It's still interesting that putting data "after" the container takes longer than putting data into a specific place in the container.
After "optimizing" I varied your code quite a bit, among other things, to fill the variable tNewImageData with white pixel beforehand and not taking the imageData from the enlarged image "imageNew", it was a bit slower than your solution to just enlarge the white 1 by 1 pixel image "imageNew" to the final size and using the imageDate from there.

One of the nice things about this exercise was to see that replacing bytes was faster than appending bytes and especially slow was conctenating bytes as in solution 2. That was not always the case and I usually tend to append binary data. Things change, though. Especially in 7.x.x.

I did not find a faster combination of techniques than what you showed. :(, :)

(BTW I forgot to block 1 "wait 0 milliseconds with messages" in the second repeat loop of solution 2)

As for locking messages: I don't know about Windows but I tend to use it when you change dimensions of controls and such that send a message of that change up the message path. Housekeeping is blocked in a tight loop anyways as far as I understand (like releasing memory etc.) I don't do lock messages routinely but occasionally. But locking the screen I do routinely, unnecessary screen updates consume time.

Anyways, it was a nice test, thank you again

Kind regards
Bernd

Post Reply

Return to “Multimedia”