Image external

Here is where the magnanimous folks that create externals post them (.zip archives only please).

Image external

Postby sctell » Sun Jan 29, 2012 3:01 am

Hi,

Here is an update of my image external.

It has been updated to the latest SC framework and has two added functions:

put image("getPixelColor",@srcImageVar,tX,tY) into tInfo
put image("getAllPixelColors",@srcImageVar) into tInfo

This returns the colour as r,g,b floating point numbers between 0 and 1 for the specified point in the image tX,tY in SC coordinates or all the colours in the case of getAllPixelColors as tab delimited for each x coordinate and return delimited for y coordinates.

In the case of getPixelColor the image is loaded into the external at each pass therefore there will be a performance hit on reading every point in the image due to loading the image for each point. The better solution in this case is getAllPixelColors which loads the image once reads the pixels and then returns the data.

The script of the cd grc containing the image shows an example.

It may have a use.

All the best

Terry

imageExampleFolder.zip
(649.8 KiB) Downloaded 640 times
Last edited by sctell on Mon Feb 06, 2012 12:42 pm, edited 3 times in total.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Image external

Postby sctell » Tue Jan 31, 2012 6:19 am

Hi,

Another update.

This includes the function

put image("getAllPixelColors",@srcImageVar) into tInfo

Also the colours returned are in a format better suited to SC (eg. r,g,b,a = 255,255,255,255)

Each set of colours is tab delimited and each row of the image is return delimited.

The update is at the top of this thread.

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Image external

Postby cburnett » Wed Feb 01, 2012 8:00 pm

Thanks, Terry

The getPixelColor function is great. I see how it works in the test project. However, I'd like to try into out in my own project environment and can't find the Image external resource in SuperEdit. Please help.

All best,

Chris
cburnett
 
Posts: 7
Joined: Mon Jan 23, 2012 7:28 am

Re: Image external

Postby sctell » Thu Feb 02, 2012 12:14 am

Hi chris,

You do not need to install the external into your project.

If you look at the project script of the example you will see this.

Code: Select all
on openproject

put projectPath(this project) & "image.bundle" into bundlePath
load external bundlePath

end openproject


In the example folder you will see the external file "image.bundle"

Just copy this and place it next to your project.

The openProject script will load the external.

-------------
If you don't like this method then open then open the SC Runtime Editor and using Resource Manager from the Utilities menu select your project in the drop down menu click on data fork then using the Actions menu select "import bundle external" then navigate to image.Bundle in the image example folder and click open in the select dialogue box and it will be inserted into your project.
------------
In SuperEdit open your project click on Resources then in the file menu select "import bundled external" then navigate to the example folder and choose image.bundle.
------------

If you have installed it via SC or SE then you do not need the project script.

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Image external

Postby cburnett » Thu Feb 02, 2012 9:37 am

Yes, I found the script to load the image.bundle external, and got it working in my project!

I'm still trying to figure out what's going on with the results. Calling the getPixelColor function for each X,Y pixel seems to produce plausible data for a single line -- but every subsequent vertical line is the same (not so in the image). Calling getAllPixelColors seems to produce accurate results -- and it's fast -- but the number of vertical lines doesn't jib with the original image (about double the number).

Also, I wonder if it would be possible to use optionally the 65535 color space instead of 255 and eliminate the alpha channel?

Thanks for helping with this.

Chris
cburnett
 
Posts: 7
Joined: Mon Jan 23, 2012 7:28 am

Re: Image external

Postby sctell » Thu Feb 02, 2012 12:39 pm

Hi Chris,

cburnett wrote:I'm still trying to figure out what's going on with the results. Calling the getPixelColor function for each X,Y pixel seems to produce plausible data for a single line -- but every subsequent vertical line is the same (not so in the image). Calling getAllPixelColors seems to produce accurate results -- and it's fast -- but the number of vertical lines doesn't jib with the original image (about double the number).


There does not appear to be anything incorrect with the external.

I have had a look at the example script and I have found a mistake.

Here is the modified script which is attached to the cd grc.

Code: Select all
on mouseUp
global gFilePath
put "" into tSrcImage

export the pictureData of cd grc 1 into srcImageVar as png -- as png attached to this line or could be tiff or gif or jpg

if gFilePath is not empty then
put image("getAllPixelColors",@srcImageVar) into tInfo
set the uPixelData of this cd to tInfo
put tInfo into cd fld 1
end if

beep
end mouseUp


Note the modification to the export line. The external does not play well with the pict format of SC.

I can remove the alpha if you wish.

I created a 16 X 16 image with rows repeating black,red,green,blue.

And the data produced is correct.

The external (Apple's Cocoa Framework) actually returns the colours as floating point numbers between 0 and 1 and any fractional number between.

Perhaps it would be better if I returned the data in this format without alpha and then you can do any additional calculations you require in SC. This would be more versatile for any other users who need other formats.

if all components are 0 = black
if all components are 1 = white

What do you think?

or maybe add another parameter specifying the format to be returned.

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Image external

Postby cburnett » Thu Feb 02, 2012 4:02 pm

Hi Terry,

I found my mistake in the apparent doubling of vertical lines: I resized the screen image in my application forgetting that it's the exported picturedata, not the screen image, that the function is using. Indeed, the data is accurate.

sctell wrote:The external (Apple's Cocoa Framework) actually returns the colours as floating point numbers between 0 and 1 and any fractional number between.

Perhaps it would be better if I returned the data in this format without alpha and then you can do any additional calculations you require in SC. This would be more versatile for any other users who need other formats.

if all components are 0 = black
if all components are 1 = white

What do you think?

or maybe add another parameter specifying the format to be returned.


For myself, I'd prefer having the raw floating point data and, as you say, make the needed calculations from there. Additional parameters for controlling the format would be brilliant.

Cheers,

Chris
cburnett
 
Posts: 7
Joined: Mon Jan 23, 2012 7:28 am

Re: Image external

Postby sctell » Fri Feb 03, 2012 12:07 am

Hi Chris,

cburnett wrote:I found my mistake in the apparent doubling of vertical lines: I resized the screen image in my application forgetting that it's the exported picturedata, not the screen image, that the function is using. Indeed, the data is accurate.


I am sure you are already aware but reminders are good (for me anyway).

Don't forget you can export your resized image by capturing a visible portion of the card.

export {card | [the] picture[Data] of graphicDescriptor} [from topLeft to bottomRight] {to {[fileType] [file] FilePath} | into variableIdentifier [as format]} [with qualitySpec [quality]]
export {card | [the] picture[Data] of graphicDescriptor} [from topLeft to bottomRight] to clipboard
export [the] [raw] picture[Data] of graphicDescriptor {to clipboard | file filename}
export [the] [raw] picture[Data] of graphicDescriptor into myVariable
export [the] text of fieldDescriptor to {TEXT|utxt|UTF8|RTF|RTFd|Word_98|Word_xml} file FilePath


And...

You can also scale rotate and other goodies with the image external, see the ReadMe.

I will update the external to floating point no alpha later today.

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Image external

Postby sctell » Fri Feb 03, 2012 1:15 am

Hi,

sctell wrote:I will update the external to floating point no alpha later today.


I have now updated the external it returns r,g,b values for each of the two functions

getPixelColor
getAllPixelColors

Each value is floating point between 0 and 1.

The alpha value is not returned.

The update is at the top of the thread.

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Image external

Postby cburnett » Sat Feb 04, 2012 10:18 am

Hi,

I'm having problems with is latest version. The program hangs up and I have to force quit SC. Here's the script I'm using:

put the long id of cd grc 1 of wd "pictDisplay" into tGRC
export the pictureData of tGRC into srcImageVar as png
put image("getAllPixelColors",@srcImageVar) into tInfo
put tInfo into bg fld "fld2"

The pictureData is about 300 x 500 pixels.

Many thanks,

Chris
cburnett
 
Posts: 7
Joined: Mon Jan 23, 2012 7:28 am

Re: Image external

Postby sctell » Sun Feb 05, 2012 11:52 am

Hi Chris,

Been away for a few days, will look into it.

Have you seen this thread? You may find it interesting.

http://forums.supercard.us/viewtopic.php?f=17&t=1604&p=8049#p8049

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Image external

Postby sctell » Sun Feb 05, 2012 12:03 pm

Hi Chris,

I can't make my tests crash.

I have uploaded a test image at the top of this thread.

See if this crashes or better still can you provide the image that is hanging your machine and I will test it here.


Thanks

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Image external

Postby sctell » Mon Feb 06, 2012 12:43 pm

Hi,

An update that has tidied up some memory leaks.

Download at the top of this thread.


All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am


Return to XCmds, XFcns, and XRtns

Who is online

Users browsing this forum: No registered users and 1 guest