getSetPixel()

Having trouble using an XCmd or XFcn? Post your questions here.

getSetPixel()

Postby cburnett » Wed Jan 25, 2012 3:59 pm

I recently upgraded to 4.7.3 and have problems with getPixelColor() under Lion -- I get almost random, incorrect color values for each pixel. getSetPixel() apparently only reads bitmap style graphics when I need to read placed pictures.

Does anyone know how to use getSetPixel() with placed picture graphics, or know another way to get pixel color values from a rect graphic?

Thanks,

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

Re: getSetPixel()

Postby codegreen » Fri Jan 27, 2012 10:36 am

cburnett wrote:I recently upgraded to 4.7.3 and have problems with getPixelColor() under Lion -- I get almost random, incorrect color values for each pixel.

AFAICR I'm not familiar with getPixelColor, but if it does what it sounds like it should then it probably calls the Toolbox GetCPixel API to do it, so it's no surprise it doesn't work on Lion. To quote Apple's Eric Schlegel:

the issue is that GetCPixel reads directly from video memory (effectively), and as video hardware gets more advanced, we are reaching the point where what's displayed on the screen isn't ever all composited into a single location in memory, so there is no video buffer from which GetCPixel can read."

Steve giveth, and Steve taketh away...

getSetPixel() apparently only reads bitmap style graphics when I need to read placed pictures.

That's correct. It's based on an ancient IT callback that predates buffered pictureData.

Does anyone know how to use getSetPixel() with placed picture graphics, or know another way to get pixel color values from a rect graphic?

By which I take it you mean pictureData? To be honest I doubt anyone else could figure out how to do this reliably nowadays (given the vicissitudes of scaling, quads, and alpha channels). Probably best to file a feature request...

-Mark
codegreen
 
Posts: 1545
Joined: Mon Jul 14, 2008 11:03 pm

Re: getSetPixel()

Postby sctell » Fri Jan 27, 2012 1:12 pm

Hi,

It seems to me that it should be possible.

If one could obtained the image from pictureData as a tiff then created an NSBitmapImageRep from this data then you can obtain the colour at a pixel location using

-----------------------
colorAtX:y:
Returns the color of the pixel at the specified coordinates.

- (NSColor *)colorAtX:(NSInteger)x y:(NSInteger)y
Parameters
x
The x-axis coordinate.

y
The y-axis coordinate.

Return Value
A color object representing the color at the specified coordinates.

Availability
Available in Mac OS X v10.4 and later.
See Also
– setColor:atX:y:
Related Sample Code
RadiantColorPicker
Declared In
NSBitmapImageRep.h

------------------------

This then returns an NSColor from which you can return data to SC.

All you need is someone to do the external.

Perhaps Mark is a willing volunteer?

Also you could setColor this is available in NSBitmapImageRep allowing you to change a colour at the pixel location, returning the tiff to SC.

All the best

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

Re: getSetPixel()

Postby codegreen » Fri Jan 27, 2012 5:16 pm

sctell wrote:It seems to me that it should be possible.

If one could obtained the image from pictureData as a tiff then created an NSBitmapImageRep from this data then you can obtain the colour at a pixel location

Maybe I'm just (as usual) overcomplicating things. If you know exactly which pixel (in x,y offset) of the source image you want, it's not hard. If you only know the screen coordinates (and have to deal with things like scaling, quads, and image filters) things quickly get quite a bit more gruesome.

-Mark
codegreen
 
Posts: 1545
Joined: Mon Jul 14, 2008 11:03 pm

Re: getSetPixel()

Postby sctell » Sat Jan 28, 2012 1:17 am

Hi,


codegreen wrote:Maybe I'm just (as usual) overcomplicating things.


I doubt it, it's probably me not seeing the wood for the trees.

codegreen wrote: If you only know the screen coordinates (and have to deal with things like scaling, quads, and image filters) things quickly get quite a bit more gruesome.


In this case can you not just do a screen (card) grab with export pass it to the external as tiff/png/pict then do the NSBitmapImageRep thing?

Probably me being to simple.

All the best

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

Re: getSetPixel()

Postby codegreen » Sat Jan 28, 2012 2:02 am

sctell wrote:In this case can you not just do a screen (card) grab with export pass it to the external as tiff/png/pict then do the NSBitmapImageRep thing?

Probably me being to simple.

Sure you can; it's just swatting a fly with a steam shovel. If all you need to know is one pixel (and you can wait a significant fraction of a second or more to find out) then that solution should work fine. It's not going to be very satisfying as a 'real-time' approach though...

-Mark
codegreen
 
Posts: 1545
Joined: Mon Jul 14, 2008 11:03 pm

Re: getSetPixel()

Postby cburnett » Sat Jan 28, 2012 9:24 am

Thanks all -- It's good to have perspective on the problem of reading pixels under Lion.

In my application, I don't necessarily have to read pictureData on the screen -- reading a tiff image would be fine. But I don't know how to use the NSBitmapImageRep routine.

Any help would be appreciated!

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

Re: getSetPixel()

Postby sctell » Sat Jan 28, 2012 12:42 pm

Hi,

cburnett wrote:In my application, I don't necessarily have to read pictureData on the screen -- reading a tiff image would be fine. But I don't know how to use the NSBitmapImageRep routine.


Can you explain exactly what you want to do?

Eg,

Do you want to read the pixel colour for an image placed in a cd grc?
Where has that image come from?
Is the image scaled, rotated or skewed in the cd grc.

Do you want to read the pixel colour for an image in a file?

Do you want to read the pixel colour of any point on the screen?

How are you obtaining the co-ordinates of the pixel?

Any more info would allow me to decide whether I can do this or not.

------------
If you need it from the screen it is looking a little grim.
There is a Cocoa function NSReadPixel, this seems to be now broken along with the QuickDraw call Mark referred to.
It was possible to create a transparent Cocoa overlay window which would allow a call to NSReadPixel.
I have tried this, it does not seem to work.
I have also tried the NSBitmapImageRep routine by grabbing the focusedViewrect of a Cocoa window and this also does not seem to work.
------------
If you need it from an image that can be passed to the external this may be possible which is why I need your feedback.


All the best

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

Re: getSetPixel()

Postby cburnett » Sat Jan 28, 2012 3:53 pm

sctell wrote:Do you want to read the pixel colour for an image placed in a cd grc?
Where has that image come from?
Is the image scaled, rotated or skewed in the cd grc.

Do you want to read the pixel colour for an image in a file?

Do you want to read the pixel colour of any point on the screen?

How are you obtaining the co-ordinates of the pixel?



Ideally I could read the pixel color from each X,Y pixel of an image placed in a cd grc. That way I could scale as needed before scanning the pixels.

I use nested repeat loops to get the x,y values and output the rgb pixel color data to an text file. (I use the data to manipulate with applescript the background color of each cell of a spread sheet -- sounds crazy but its fun).

Thanks much,

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

Re: getSetPixel()

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

Hi Chris,

cburnett wrote:I use nested repeat loops to get the x,y values and output the rgb pixel color data to an text file.


Please have a look at my image external which I have updated with a getPixelColor subroutine.

You can get it here:

http://forums.supercard.us/viewtopic.php?f=16&t=1602

Please provide any feedback in the external thread and I will see what I can do.

All the best

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

Re: getSetPixel()

Postby sctell » Sun Jan 29, 2012 7:48 am

Hi,

To speed up the process I have (not completed yet) a function "getAllPixelColors" which returns all the pixel colours as follows.

Each row of pixels returned comprises r,g,b,a tab r,g,b,a tab etc.

Each row then has a return appended.

So for an image of width 300 and height 400

There are 400 lines of data consisting of 300 r,g,b,a tab combinations

Obviously depending on the image size this produces a large amount of text data.

I am not actually sure of the SC limits in this area.

I just out of curiosity dumped some data into a userProperty and when I started scrolling through the data there appeared to be visual discrepancies.

I didn't think there was a limit for userProps and variables but I may be wrong.

Also what is the limit for fields.

I could always dump the data in the external to a file if the path is given to the external.

Any comments.

All the best

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

Re: getSetPixel()

Postby Dan_Kelleher » Mon Jan 30, 2012 11:09 am

I'd say actual tests of the ability to store( in various ways; field, UserProp, various kinds of variable-containers) and reuse the data is the crucial thing.
And to be able to alter the data data in-situ, then re-use.
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: getSetPixel()

Postby codegreen » Mon Jan 30, 2012 5:10 pm

sctell wrote:I just out of curiosity dumped some data into a userProperty and when I started scrolling through the data there appeared to be visual discrepancies.

Yeah it looks like WASTE gets very unhappy when scrolling horizontally past the limits of QD space. I guess I'll have to fix that (oh joy... :x ).

I didn't think there was a limit for userProps and variables but I may be wrong.

Theoretically they can be up to just shy of 2GB long, but of course a project can only be 2GB too so it depends on what else is in the file.

Also what is the limit for fields.

IIRC it's 600000000 bytes. WASTE is probably too inefficient for a field that big to actually be usable, but YMMV.

-Mark
codegreen
 
Posts: 1545
Joined: Mon Jul 14, 2008 11:03 pm

Re: getSetPixel()

Postby sctell » Tue Jan 31, 2012 12:07 am

Hi Mark,

codegreen wrote:Yeah it looks like WASTE gets very unhappy when scrolling horizontally past the limits of QD space. I guess I'll have to fix that (oh joy... ).


Is the data there though and it's just a scrolling issue because in this case it's just somewhere to dump the data.


All the best

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

Re: getSetPixel()

Postby codegreen » Tue Jan 31, 2012 6:18 am

sctell wrote:Is the data there though and it's just a scrolling issue

The underlying data is fine; it just draws mugly in the editor...

-Mark
codegreen
 
Posts: 1545
Joined: Mon Jul 14, 2008 11:03 pm

Re: getSetPixel()

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

Hi Chris and Mark,

codegreen wrote:The underlying data is fine; it just draws mugly in the editor...


Thanks Mark

Chris,

I have updated the external again.

Please see here:

http://forums.supercard.us/viewtopic.php?f=16&t=1602&p=8029#p8029

basically added a function

Code: Select all
put image("getAllPixelColors",@srcImageVar) into tInfo
set the uPixelData of this cd to tInfo


see the script attached to the cd grc.

and

changed the r,g,b,a to for example 255,255,255,255 which is more suited to SC as it consumes less text space.

All the best

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

Re: getSetPixel()

Postby gonetriadrr » Tue Jan 31, 2012 7:31 am

Pardon my ignorance (sill stuck in SC 4.6 OS 10.4.11 here), but has pictdata export changed in some fundamental way?
Or are we just tending toward the day that all Pict related support vanishes?

I ask because it's easy enough (at least in OS 10.4) to parse pixel values directly from exported pictdata.
Binary pictdata, though large compared to compressed formats, is a fraction of the size of comma delimited numerical equivalents. Though passing binary with nulls back to an Xthing I suspect would be an issue.

DCS
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: getSetPixel()

Postby codegreen » Tue Jan 31, 2012 5:46 pm

gonetriadrr wrote:Pardon my ignorance (sill stuck in SC 4.6 OS 10.4.11 here), but has pictdata export changed in some fundamental way?

No.

I ask because it's easy enough (at least in OS 10.4) to parse pixel values directly from exported pictdata.
Binary pictdata, though large compared to compressed formats, is a fraction of the size of comma delimited numerical equivalents. Though passing binary with nulls back to an Xthing I suspect would be an issue.

Passing params to externals by reference circumvents that constraint.

However FWIW you don't actually need an external to do what you're suggesting, since for some time now it's been possible to export pictureData (either scaled and buffered or raw) directly into a variable.

HTH,
-Mark
codegreen
 
Posts: 1545
Joined: Mon Jul 14, 2008 11:03 pm


Return to Using Externals

Who is online

Users browsing this forum: No registered users and 1 guest

cron