Append an image to another image
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Append an image to another image
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.
Thx for helping.
Re: Append an image to another image
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?
Best
Klaus
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?
Best
Klaus
Re: Append an image to another image
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
I understand the idea but don't I loose resolution? In my thinking the resulting picture will only have the screen resolution.
Regards David
Re: Append an image to another image
Hi David,
yes, true, but not the exact amount of pixels!
Best
Klaus
yes, true, but not the exact amount of pixels!
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9850
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Append an image to another image
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.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Append an image to another image
Hi,
Appending two images is really easy, if the images have the same width. This seems what you want to do.
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
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Append an image to another image
Hi Mark,
wow, that's pretty cool, thanks!
Best
Klaus
wow, that's pretty cool, thanks!
Best
Klaus
Re: Append an image to another image
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 tooEdit: 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?
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 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.
Re: Append an image to another image
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Append an image to another image
Really? Where am I going wrong?
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.
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
Re: Append an image to another image
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Append an image to another image
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 postThen 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. 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.
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
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
Last edited by SparkOut on Mon Jun 22, 2015 8:34 pm, edited 3 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 4016
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Append an image to another image
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 for solution 2
Kind regards
Bernd
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: 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
Bernd
Re: Append an image to another image
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 4016
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Append an image to another image
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.It's still interesting that putting data "after" the container takes longer than putting data into a specific place in the container.
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