Imaging Functions

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Luisa Klose
Posts: 48
Joined: Tue Aug 30, 2011 2:24 pm

Re: Imaging Functions

Post by Luisa Klose » Wed Sep 07, 2011 3:33 pm

Hi Bernd,

Solved the problem last night. I figured out how to "paint" into the imageData of an image with the alphaData of another image! You implied that it is a difficult thing to do, and it was. The performance is pretty good, but it will be much better when I add an array to keep track of the mouse coordinates. Unfortunately, I won't be able to work on it until tonight, but I will share it tomorrow.

Warm regards,

Luisa

Luisa Klose
Posts: 48
Joined: Tue Aug 30, 2011 2:24 pm

Re: Imaging Functions

Post by Luisa Klose » Sat Sep 10, 2011 4:11 am

Friends,
After my previous post, I went back to finish the stack and ended up finding the caveats instead. I had not tested it near the edges. The right edge wrapped to the left edge and vice versa. The top edge wrapped to the bottom edge, inverting the color in the process. Going near the bottom edge slowed the algorithm down considerably. And going near the upper corners made the entire image change colors and shift to the right.

To find the solution, I took a different approach, which worked, albeit very slowly. Then I realized that what made that approach work could be incorporated easily into my original approach.

Anyway, here it is. I hope you like it, but I hope even more that you can help me improve it.

Warm regards,
Luisa Klose
Attachments
Alpha_Paint.zip
(7.88 KiB) Downloaded 247 times

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

Re: Imaging Functions

Post by bn » Sat Sep 10, 2011 10:56 am

Hi Luisa,

very nice. And you discovered the joys of manipulating imageData/alphaData :)

Now I see what you mean by alpha painting. I thought you wanted to use all the colors of an image and its alphadata, now you basically use a monochrome image modified by the alphaData ( and opacity)

One thing I noticed is that the screen update is only after you release the mouse. The screen refresh is blocked since you are in a continous repeat loop. To let the engine do the screen update just add a

Code: Select all

wait 0 milliseconds with messages
at the end of your handlers

like:

Code: Select all

   set the imageData of image "canvas" to gCanvas -- Put the imageData of the variable back into the imageData of the canvas.
   wait 0 milliseconds with messages  -- lets the screen update
   unlock screen -- Update the screen.
   lock screen -- Lock it again.
   
end alphaPaint
and

Code: Select all

   set the imageData of image "canvas" to gCanvas
   wait 0 milliseconds with messages -- lets the screen update
   unlock screen
   lock screen
end alphaPaintContinuous
As for the "improve" part: thinking about it, no promises.

Kind regards

Bernd

Luisa Klose
Posts: 48
Joined: Tue Aug 30, 2011 2:24 pm

Re: Imaging Functions

Post by Luisa Klose » Sat Sep 10, 2011 12:22 pm

Hi Bernd,

On this computer, the screen updates the same with or without the "wait" line. I wonder if that has to do with the OS...

I noticed a little problem with my brush at very low opacity values. It looks like I'm getting some negative numbers that are turning 0s into 255s.

I hope you're having a good day. I'm just starting mine.

Luisa

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

Re: Imaging Functions

Post by bn » Sat Sep 10, 2011 1:02 pm

HI Luisa,

here is another take on the paint problem. Now I only use graphics to "paint" and when finished the backgroundImage and the graphic are merged into the backgroundImage via snapshot.

Graphics offer a lot of flexibility in Livecode, a lot more than "real" painting i.e. bytewise imaging. Graphics themselves can have gradients. But look for yourself.

Tell me what you think and if it works and what you would add to this. The interface is similar to the previous version, just some more options. You can paint rectangles, round rectangles, diamonds, ovals, lines and free lines. Not all options are available for all objects.

Kind regards

Bernd
paintGradient_6.livecode.zip
(60.3 KiB) Downloaded 294 times

Luisa Klose
Posts: 48
Joined: Tue Aug 30, 2011 2:24 pm

Re: Imaging Functions

Post by Luisa Klose » Sat Sep 10, 2011 1:49 pm

Heya Bernd,

Yes, I was thinking about your "Simple Paint" stack when I commented in the code that there are more efficient painting algorithms. I will have to experiment more before I make a decision regarding the utility of my algorithm. It may end up being useful if its qualities can't be reproduced more efficiently in other ways.

Your new gradient stack is great. Like a candy store :)

Warm regards,

Luisa

Luisa Klose
Posts: 48
Joined: Tue Aug 30, 2011 2:24 pm

Re: Imaging Functions

Post by Luisa Klose » Mon Sep 12, 2011 3:40 am

Heya Folks,

I improved the performance of my Alpha Paint stack to where it is actually usable, (on this computer), and I added a variant that paints with the colors of the brush instead of a single RGB color like before. My formula for averaging & overlaying color needs improvement, and there are other things that I'll eventually spend time on, but it's time for me to move on to experimenting with other methods.

Warm regards,

Luisa Klose
Attachments
Alpha_Paint_2.zip
(16.81 KiB) Downloaded 267 times

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: Imaging Functions

Post by Kaubs » Fri Oct 07, 2011 8:41 pm

I really hate to bring this one out of the grave and I'm more than willing to create a new post under another topic if you guys would like. I have been searching for a few months as to the best way to handle creating a signature on the iPhone. Bn your paintGradient would make an excellent solution for this however there are a couple things that happen when simulating this on iOS which are kind of strange and I would love to hear some input as to why they happen. If you clear the image area the first time the image area turns gray and your color white, if you clear again you can no longer input data. I hope I've explained this clearly...If anyone has a better solution for a signature please let me know. So far like I've said bn's paintGradient seems to be the smoothest on iOS.

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

Re: Imaging Functions

Post by bn » Fri Oct 07, 2011 9:29 pm

Hi Kaubs,

funny you bring this up right now. There is a discussion about signature on iOS currently here:

http://forums.runrev.com/phpBB2/viewtop ... f=7&t=8449

Dixie posted an example that is using a graphic to draw a signature. I just was playing around with that on my iPhone G3 (the old an slow one) and tried to change Dixie's code a bit.

Currently the redraw speed of LiveCode is not very good for graphics and images. As Jaque pointed out in the other thread there are improvements right around the corner...

Still the basics aply: for a signature try to do it as simple as possible. I added a condition that you can alter the time before the screen updates. The idea is that if you update the screen with every mouseMove you loose a little resolution of the mouseMove sampling. Also the more points you have the more load is put on the graphic update. It works ok for a signature (about the same resolution and speed as the UPS signatures when you receive a parcel)

Also the linesize of the graphic seems to influence the redraw speed.

The slider at the top is to set the intervall for screen updates 10 to 200 milliseconds
The slider at the right is the linesize of the graphic.

You might try this stack and see if it works for you

Kind regards

Bernd
Attachments
Draw2.livecode.zip
(2.27 KiB) Downloaded 181 times

Post Reply

Return to “Feature Proposals”