grc2coreGrc Showcase

Experimental projects, hacks, and other exploration of what is possible with SuperCard. Graphic files and .zip archives only.
Forum rules
Help keep this area clean by deleting attachments from existing posts that have been updated, or are no longer relevant.

Re: grc2coreGrc Showcase

Postby Dan_Kelleher » Tue Mar 01, 2011 11:37 am

Thanks Lorenz, I understand that and I should have chosen my words more carefully;
-dan
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: grc2coreGrc Playground - Polygon

Postby witness » Sun Mar 06, 2011 2:41 pm

LorenzT wrote:Because of the anti-aliasing lines with lineWidth <=1 pixel seem to be dimmed. Maybe that's why the lineWidth in the mentioned app defaults to 2.


You're drawing between pixels. In Quartz, coordinates go past each pixel on the top left. When you draw a pixel, its line width is centered around the coordinate you give. Since the pixels are not centered around the coordinate, but rather separated by it, the line you request when you draw from 1,1 to 4,1 would lie half on the top pixels and half on the bottom pixels. Since your screen can only draw whole pixels, the two halves of each pixel get averaged against each other. 50% of the pixel black + 50% of the pixel white / 2 gives one whole pixel in 50% grey. So you get a 50% grey line that is two pixels wide.

This illustration may help:

Image

Top is just the coordinate system, with our line start/end marked. The second one is the ideal line you are asking for, and the third one is the approximation Quartz makes from it.

To get a clear, crisp black line, what you have to do is move your coordinates so they end up exactly in the middle of the pixels, e.g. draw from 1.5,1.5 to 4.5,1.5 in this example, which gives you the crisp line in the bottom row of pixels shown in the fourth part of the illustration.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are Everywhere..."
http://www.zathras.de
User avatar
witness
 
Posts: 57
Joined: Thu Jul 17, 2008 2:24 pm

Re: grc2coreGrc Showcase

Postby Dan_Kelleher » Sun Mar 06, 2011 5:28 pm

I've been assuming that both the "CG" XFcn and the "THGraphics" XFcn are implementations of the NSBezierPath class.

Is that correct?
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: grc2coreGrc Showcase

Postby 1nperson0z » Sun Mar 06, 2011 7:08 pm

Not exactly - the CG external doesn't use NSBezierPath at all - it uses functions from the Core Graphics library, also it's not written in Objective-C/Cocoa, whereas I'm pretty sure Terry has written THGraphics that way. I think NSBezierPath uses CG under the hood, which is why that have the same kinds of functionality. If I was doing CG again (with the benefit of much acquired knowledge in the meantime) it would probably be done as a Cocoa external too.

Ian B
MacBook Pro 2.4Ghz i7 8Gb 10.11.3
1nperson0z
 
Posts: 78
Joined: Wed Jul 09, 2008 3:31 pm
Location: Blue Mountains Australia

Re: grc2coreGrc Showcase

Postby Dan_Kelleher » Sun Mar 06, 2011 7:28 pm

Thanks Ian.
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: grc2coreGrc Showcase

Postby LorenzT » Sun Mar 06, 2011 11:31 pm

Thank you Uli for this interesting explanation.
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: grc2coreGrc Showcase

Postby LorenzT » Tue Mar 15, 2011 8:49 am

Say hello to SC 4.7.1!
With an updated grc2coreGrc Showcase project and SC 4.7.1 you can create scripted gradients (axial and radial) and apply them as a backdrop to your projects (see example). Furthermore there is an example of a pie chart made with coreGraphics.

backdrop.jpg
backdrop.jpg (23.36 KiB) Viewed 10886 times


As always the latest project can be found in the first message of this thread.
Enjoy!
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: grc2coreGrc Showcase

Postby sctell » Tue Mar 15, 2011 10:08 am

Hi Lorenz,

I am getting errors again. Is it NOT compatible with 4.6.3?

Rotation in rounded rectangle returned "never heard of that function name"

put textWidthMax(dObject) into item number(items of dData)+1 of dData
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: grc2coreGrc Showcase

Postby LorenzT » Tue Mar 15, 2011 11:36 am

Hmm, somehow this 'bug' must have found its way again into the project...

Anyway, I uploaded a version that works around the missing textWidthMax function im SC 4.6.3.

But you still won't be able to produce the beautiful backdrops! :cry:
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: grc2coreGrc Showcase

Postby sctell » Tue Mar 15, 2011 11:38 pm

Another 4.7 only:

export the raw pictureData of cd grc "myGradRect" to file it
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: grc2coreGrc Showcase

Postby sctell » Tue Mar 15, 2011 11:42 pm

LorenzT wrote:Furthermore there is an example of a pie chart made with coreGraphics.


Can you add some thickness to the pie and arrange the script so it shows instantaneously rather than showing all the CG calls?
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: grc2coreGrc Showcase

Postby LorenzT » Wed Mar 16, 2011 12:52 am

I didn't know that the raw export was 4.7 only. Anyhow, I removed the 'raw' in the export of the pictureData as it isn't needed.

PieChart: Thickness
To add thickness to the pie would mean to calculate more complex geometrical objects, to add shading and use clipping. I don't think that I could do that without investing a lot of time.

PieChart: show sectors instantanously
If you comment the command 'unlock screen' in the repeat loop of the script of the btn 'Create PieChart' all sections will be shown at once. I thought it was nicer to animate the pie chart by showing the sectors one after another.

An updated project (without raw export) can be downloaded from the first message of this thread.
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland

Re: grc2coreGrc Showcase

Postby Dan_Kelleher » Wed Mar 16, 2011 6:23 am

I don't even see "raw" in the list of "All Words" in the SC4.7.1 Help project.

What does it mean?
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: grc2coreGrc Showcase

Postby codegreen » Wed Mar 16, 2011 9:21 am

Dan_Kelleher wrote:What does it mean?

It means export the actual stored image data rather than drawing (and thus possible rasterizing, scaling, and dithering) it into an offscreen GWorld and then capturing and exporting that.

BTW that code was added over four years ago, so it's definitely NOT a 4.7 only feature...

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

Re: grc2coreGrc Showcase

Postby gonetriadrr » Wed Mar 16, 2011 9:29 am

codegreen wrote:
Dan_Kelleher wrote:What does it mean?

It means export the actual stored image data ...
Mark


Does it follow that picturedata from tiff, png, etc. sources are exported in original format?

DCS

To answer my own question... Not quite.
Looks like the source image data is wrapped in a pict header/footer.

if original source was a mac tiff...
export raw pictdata of grcdesc into var
delete char 1 to offset("MM" &null& "*",var)-1 of var

SuperCard recognizes the modified contents of var as tiff retaining transparency. May work with other apps as well.

if original format = png the string to match is the lower case a-ring character followed by 'PNG', IIRC.

Unknown if footer length is constant and reliably strippable for tiff.
Png data includes an 'END' tag which would make stripping footer easy and reliable. Consult PNG specification for details.

DCS
Last edited by gonetriadrr on Wed Mar 16, 2011 12:42 pm, edited 4 times in total.
gonetriadrr
 
Posts: 170
Joined: Fri Jan 08, 2010 6:50 pm

Re: grc2coreGrc Showcase

Postby Dan_Kelleher » Wed Mar 16, 2011 10:04 am

Looks like a case for the powers of BBEdit applied to a verytiny "image" and exported this-way-and that... but not-just-now.
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: grc2coreGrc Showcase

Postby sctell » Wed Mar 16, 2011 10:26 am

sctell wrote:Another 4.7 only:

export the raw pictureData of cd grc "myGradRect" to file it



Apologies I found raw under the export command of the SCLG. It seems it was added in 4.6.3.


However, this line:

Code: Select all
export the raw pictureData of cd grc "myGradRect" to file it


was causing an error in the project. It must therefore be something else.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: grc2coreGrc Showcase

Postby codegreen » Wed Mar 16, 2011 2:15 pm

gonetriadrr wrote:
codegreen wrote:
Dan_Kelleher wrote:What does it mean?

It means export the actual stored image data ...
Mark


Does it follow that picturedata from tiff, png, etc. sources are exported in original format?

DCS

To answer my own question... Not quite.
Looks like the source image data is wrapped in a pict header/footer.

if original source was a mac tiff...
export raw pictdata of grcdesc into var
delete char 1 to offset("MM" &null& "*",var)-1 of var

SuperCard recognizes the modified contents of var as tiff retaining transparency. May work with other apps as well.

if original format = png the string to match is the lower case a-ring character followed by 'PNG', IIRC.

Unknown if footer length is constant and reliably strippable for tiff.
Png data includes an 'END' tag which would make stripping footer easy and reliable. Consult PNG specification for details.

DCS

Currently all embedded pictureData is stored internally in PICT format. Nowadays for many source formats that means little more than wrapping the original image data in a handful of opcodes that identify the bounds, opcolor, compressor component, clip region, etc. to QuickDraw. If you don't include 'raw' in the export command though, you'll note that the data often bloats up by a factor of ten or more because it's unpacked, drawn, and then captured as a traditional uncompressed 32-bit raster PICT before export.

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

Re: grc2coreGrc Showcase

Postby sctell » Thu Mar 17, 2011 12:13 am

codegreen wrote:Nowadays for many source formats that means little more than wrapping the original image data in a handful of opcodes that identify the bounds, opcolor, compressor component, clip region, etc. to QuickDraw.



Can you please post a code snippet of how to get this raw data (containing say a tiff) into an NSBitmapImageRep.


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

Re: grc2coreGrc Showcase

Postby codegreen » Thu Mar 17, 2011 6:22 am

sctell wrote:Can you please post a code snippet of how to get this raw data (containing say a tiff) into an NSBitmapImageRep.

You mean something like this?

Code: Select all
NSBitmapImageRep *bmp = [[[NSBitmapImageRep alloc] initWithData:[NSData dataWithBytes:*pict length:GetHandleSize((Handle)pict)]] autorelease];

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

Re: grc2coreGrc Showcase

Postby sctell » Thu Mar 17, 2011 6:50 am

codegreen wrote:You mean something like this?



Will this maintain any transparency contained in the pictureData if the pictureData contains a PICT.
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: grc2coreGrc Showcase

Postby codegreen » Thu Mar 17, 2011 7:16 am

sctell wrote:Will this maintain any transparency contained in the pictureData if the pictureData contains a PICT.

Beats me...

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

Re: grc2coreGrc Showcase

Postby sctell » Thu Mar 17, 2011 7:34 am

Sorry but I am rather confused.

codegreen wrote:Currently all embedded pictureData is stored internally in PICT format. Nowadays for many source formats that means little more than wrapping the original image data in a handful of opcodes that identify the bounds, opcolor, compressor component, clip region, etc. to QuickDraw. If you don't include 'raw' in the export command though, you'll note that the data often bloats up by a factor of ten or more because it's unpacked, drawn, and then captured as a traditional uncompressed 32-bit raster PICT before export.


What is the format of the image data when it is exported in the raw. :oops:
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: grc2coreGrc Showcase

Postby sctell » Thu Mar 17, 2011 7:44 am

Sorry again,

codegreen wrote:Beats me...


I noticed in the docs the raw is purely a PICT with header?

I have been through this before NSImage and NSBitmapImageRep (initWithData) do not recognise transparency in PICT (not as Apple's spec).

However, you can do it by stripping the header off and supplying the raw (my raw) data into

NSBitmapImageRep

- (id)initWithBitmapDataPlanes:(unsigned char **)planes pixelsWide:(NSInteger)width pixelsHigh:(NSInteger)height bitsPerSample:(NSInteger)bps samplesPerPixel:(NSInteger)spp hasAlpha:(BOOL)alpha isPlanar:(BOOL)isPlanar colorSpaceName:(NSString *)colorSpaceName bitmapFormat:(NSBitmapFormat)bitmapFormat bytesPerRow:(NSInteger)rowBytes bitsPerPixel:(NSInteger)pixelBits
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Previous

Return to The Lab

Who is online

Users browsing this forum: No registered users and 1 guest