Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

shfill: /ShadingType 2, computed parameters

144 views
Skip to first unread message

jdaw1

unread,
Mar 8, 2010, 4:24:26 PM3/8/10
to
I am failing to get shfill to work for me. Below is a simplified
version of what is going on: several of the numbers (1 7 div) are
actually references to other PostScript variables the value of which
are not yet known. Please, what's wrong?

%!

100 100 moveto 100 500 lineto
3 setlinewidth


strokepath
<<
/ShadingType 2 /ColorSpace /DeviceRGB /Extend [true true]
/Function
<<
/FunctionType 0 /N 1 /Domain [0 1] /Range [0 1 0 1 0 1] /
Order 1 /Size [2]
/DataSource [
1 7 div 1 0.75 gsave sethsbcolor currentrgbcolor grestore 0
2 7 div 1 0.75 gsave sethsbcolor currentrgbcolor grestore 1
]
>>
/Coords [
500 200
500 400
]
>>
shfill

showpage


Thank you.

ken

unread,
Mar 9, 2010, 8:43:46 AM3/9/10
to
In article <be046966-b3b4-452b-80b6-a2df7b6d6b69
@q15g2000yqj.googlegroups.com>, jdawi...@gmail.com says...

> I am failing to get shfill to work for me. Below is a simplified
> version of what is going on: several of the numbers (1 7 div) are
> actually references to other PostScript variables the value of which
> are not yet known. Please, what's wrong?

For a type 0 (sampled) function the DataSource is defined to be either a
string or a positionable file providing the sample data. You have
provided a PostScript procedure. This will raise a typecheck error.

For a Type 0 function you *must* supply a BitsPerSample value, which is
not present.

You cannot use a PostScript function as the basis for the data in a
Function dictionary.


Ken

jdaw1

unread,
Mar 9, 2010, 9:45:11 AM3/9/10
to
> You cannot use a PostScript function as the basis for the data in a Function dictionary.

But is it possible to convert computed PostScript-function data to
either of the formats allowed in a function dictionary? And if so,
please, how?

ken

unread,
Mar 9, 2010, 12:07:23 PM3/9/10
to
In article <a3c02902-55e0-42a2-8e43-c2d2de83c113
@a18g2000yqc.googlegroups.com>, jdawi...@gmail.com says...

> But is it possible to convert computed PostScript-function data to
> either of the formats allowed in a function dictionary? And if so,
> please, how?

Run the PostScript functions on a number of potential input values to
generate the output data points. Take those data points, convert into
string data, supply the string as a DataSource to the type 0 Function.

Interpolation will generate the intermediate points. FOr more accuracy,
run more samples, cost is only more string data.

Ken

jdaw1

unread,
Mar 9, 2010, 2:57:59 PM3/9/10
to
Thank you. As I'm happy for it to be linear, only the start and end
points are needed. Please, how can one

> convert into string data, supply the string as a DataSource to the type 0 Function.
?

Olle

unread,
Mar 9, 2010, 4:30:47 PM3/9/10
to

Converting to string: cvs

If you need a function for appending to an existing string, see
comp.lang.postscript faqs (7.8 How can I concatenate two strings
together?)

Thanks,

Olle

jdaw1

unread,
Mar 9, 2010, 6:01:14 PM3/9/10
to
I have a Concatenate function. But how do I convert numbers on the
stack, like 0.3284, to an appropriate strong format?

/ConcatenateOverflowErrorsSuppressed false def
/Concatenate
{
2 copy type exch type
2 copy /stringtype ne exch /stringtype ne or
{
2 copy /arraytype eq exch /arraytype eq 4 2 roll /packedarraytype eq
exch /packedarraytype eq
3 -1 roll or 3 1 roll or and not
{
(Error: Concatenate, types either unsuitable or non-matching)
OutputToLog == == stop
} {false} ifelse % not both arrays
} {pop pop true} ifelse % either not a string
3 1 roll 2 copy length exch length add dup 65535 le
{
4 -1 roll {string} {array} ifelse dup dup
0 5 index putinterval
4 -1 roll length 4 -1 roll putinterval
}
{
% bool A B joint-size
pop 3 -1 roll
{
1 index length 65535 ge
{
pop
ConcatenateOverflowErrorsSuppressed not
{
(Error: Concatenate, first string of maximal size. Suppressing
reporting of further such errors.) OutputToLog
/ConcatenateOverflowErrorsSuppressed true store
} if % ConcatenateOverflowErrorsSuppressed not
}
{
ConcatenateOverflowErrorsSuppressed not
{
(Error: Concatenate -- truncation, as objects jointly too long.
Suppressing reporting of further such errors.) OutputToLog
/ConcatenateOverflowErrorsSuppressed true store
} if % ConcatenateOverflowErrorsSuppressed not
65535 string dup dup % A B string string string
0 5 index putinterval % A B string string
4 -1 roll length dup 65535 exch sub % B string string |A| 65535-|
A|
5 -1 roll 0 3 -1 roll getinterval % string string |A| B'
dup length 0 gt {putinterval} {pop pop} ifelse % string
} ifelse % First object maximal length
dup 65532 (...) putinterval
}
{
ConcatenateOverflowErrorsSuppressed not
{
(Error: Concatenate, objects jointly too large, returning only
first object. Suppressing reporting of further such errors.)
OutputToLog
/ConcatenateOverflowErrorsSuppressed true store
} if % ConcatenateOverflowErrorsSuppressed not
pop
} ifelse % string
} ifelse % fits within architectural limits
} bind def % /Concatenate

jdaw1

unread,
Mar 9, 2010, 6:16:16 PM3/9/10
to
Of course by “strong” I meant “string”.

Olle

unread,
Mar 10, 2010, 3:55:04 PM3/10/10
to
On Mar 9, 4:16 pm, jdaw1 <jdawise...@gmail.com> wrote:
> Of course by “strong” I meant “string”.

Well, using cvs is pretty straightforward, you just have to check that
your argument is a number.

Something like this might work for you:

% integer/real *CeeVeeEss* string true
% other *CeeVeeEss* other false
/CeeVeeEss
{
dup type dup /integertype eq exch /realtype eq or
{20 string cvs true}{false}
ifelse
}
bind def

/ConcatenateOverflowErrorsSuppressed false def
/Concatenate
{
CeeVeeEss {( ) Concatenate} if exch
CeeVeeEss {( ) Concatenate} if exch


2 copy type exch type

...

If an argument was converted to a string a space will be appended to
it.

Thanks,

Olle

jdaw1

unread,
Mar 10, 2010, 6:40:15 PM3/10/10
to
OK, let me replace things with constants I understand and then, later,
manufacture those constants.

Why does the following give me a typecheck in shfill?

strokepath
<<
/ShadingType 2 /ColorSpace /DeviceRGB /Extend [true true]
/Function
<<
/FunctionType 0 /N 1 /Domain [0 1] /Range [0 1 0 1 0 1] /Order 1 /
Size [2]

/DataSource [(0.115385 0.75 0.0 0 0.115385 0.0 0.75 1 )]
>>
/Coords [814.958 553.151 814.958 289.594]
>>
shfill

Splitting the DataSource into two strings doesn't help: [(0.115385
0.75 0.0 0) ( 0.115385 0.0 0.75 1 )]

James Cloos

unread,
Mar 10, 2010, 7:16:59 PM3/10/10
to
Wouldn't a type1 shading work better for that?

PS type1 shadings are functions which take two values from the stack and
push N values, one per colour component.

It seems better to use a type1 than to use ps code to create a string to
use with a type2 shading.

-JimC
--
James Cloos <cl...@jhcloos.com> OpenPGP: 1024D/ED7DAEA6

jdaw1

unread,
Mar 11, 2010, 4:35:07 AM3/11/10
to
> Wouldn't a type1 shading work better for that?
Looked more complicated.

There is a path, consisting of a single curveto with the two internal
control points being the same, so the path not self-intersecting.
There are computed RGB values for the colours at the two ends. In
between I want the colour to shift gradually from one to the other,
and I don't care about the speed of colour variation.

Please, given real values X0 Y0 X1 Y1 X3 Y3, R0 G0 B0, R3 G3 B3, show
me the code that makes it happen.

Scott Prouty

unread,
Mar 11, 2010, 2:49:13 PM3/11/10
to

The /DataSource is still an array. Try:

ken

unread,
Mar 11, 2010, 3:23:51 PM3/11/10
to
In article <7b228915-dc3e-47b7-8ff7-c47f527f5794
@e7g2000yqf.googlegroups.com>, scott....@solimarsystems.com says...

> > Splitting the DataSource into two strings doesn't help: [(0.115385
> > 0.75 0.0 0) ( 0.115385 0.0 0.75 1 )]
>
> The /DataSource is still an array. Try:
>
> /DataSource (0.115385 0.75 0.0 0 0.115385 0.0 0.75 1 )

In this case the data must be binary, not ASCII, eg:

<0001020304> = 0x01 0x02 0x03 0x04 etc

To map the integer hex values into the domain of the function output you
must supply a Decode array. Depending on the input, you may also find it
necessary to supply an Encode array as well.

Ken

jdaw1

unread,
Mar 11, 2010, 4:24:25 PM3/11/10
to
> To map the integer hex values into the domain of the function output you
> must supply a Decode array. Depending on the input, you may also find it
> necessary to supply an Encode array as well.

Thank you. But, please, would it be easy to post some code that could
convert real variables R0 G0 B0 R3 G3 B3 into the appropriately-
formatted DataSource / Encode / BitsPerSample data?

I have plenty of spare memory so BitsPerSample could happily be large.
Unless that introduces new problems.

jdaw1

unread,
Mar 11, 2010, 7:08:20 PM3/11/10
to
Thank you all for comments. The thing I was missing was put'ting
integers directly into a string: now it works.

Note to self:

/RaysStrokeCode
{
ThisName (Julian) eq {0.75 setgray stroke}
{
0.36 setlinewidth
WithinPage0 WithinPage1 eq
{
GlassesOnSheets SheetNum get length dup dup 4 div CoprimeNear
WithinPage0 mul 1 index mod exch div 1 1 sethsbcolor stroke
}
{
strokepath clipsave clip
<<
/Function
<<
/DataSource
GlassesOnSheets SheetNum get length dup dup 4 div CoprimeNear
WithinPage0 mul 1 index mod exch div 1 1 gsave sethsbcolor
currentrgbcolor grestore
GlassesOnSheets SheetNum get length dup dup 4 div CoprimeNear
WithinPage1 mul 1 index mod exch div 1 1 gsave sethsbcolor
currentrgbcolor grestore
(123456) % 6 numbers, one byte each; can re-use string so will
5 -1 0 {exch dup 4 2 roll exch 255 mul 0.5 add floor cvi put}
for
/BitsPerSample 8
/FunctionType 0 /Domain [0 1] /Range [0 1 0 1 0 1] /
Order 1 /Size [2] /N 1
>>
/Coords [ X0 Y0 X1 Y1 ]
/ShadingType 2 /ColorSpace /DeviceRGB /Extend [true dup]
>>
shfill cliprestore newpath
} ifelse % WithinPage0 WithinPage1 eq
} ifelse % ThisName ...
} def % /RaysStrokeCode

jdaw1

unread,
Mar 11, 2010, 7:38:42 PM3/11/10
to
Another note to self:

/RaysStrokeCode
{
ThisName (Julian) eq {0.75 setgray stroke}
{
0.36 setlinewidth
WithinPage0 WithinPage1 eq
{

RaysAngle0 90 add RaysAngleOffset sub 1 mul 360 div {dup 1 ge {1
sub} {exit} ifelse} loop 1 0.8 sethsbcolor stroke
}
{
strokepath clipsave clip
% Help received at groups.google.com/group/comp.lang.postscript/
browse_thread/thread/888d4167a7eaadb2
<<
/Function
<<
/DataSource
RaysAngle0 90 add RaysAngleOffset sub 1 mul 360 div {dup 1 ge {1
sub} {exit} ifelse} loop 1 0.8 gsave sethsbcolor currentrgbcolor
grestore
RaysAngle1 90 add RaysAngleOffset sub 1 mul 360 div {dup 1 ge {1
sub} {exit} ifelse} loop 1 0.8 gsave sethsbcolor currentrgbcolor

Don Lancaster

unread,
Mar 12, 2010, 1:29:02 PM3/12/10
to


You can easily use a PostScript function as the basis for the data in a
function dictionary.

That is one of PostScript's strongest features.

Exactly what are you trying to do?

--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: d...@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com

jdaw1

unread,
Mar 14, 2010, 6:09:29 PM3/14/10
to
> Exactly what are you trying to do?
Master a simple shading dictionary. With help given here, and some
inspiration of my own, that is now done.
0 new messages