Solved

Postscript and bitmaps revisited

Posted on 2004-10-08
14
796 Views
Last Modified: 2013-12-03
Hi all,

Finally I have returned to attempt to get back to sorting this problem (which I began to look at in January but was side tracked by other projects) and could do with some pointers. I have a JPEG image of our company logo. As part of a new quoting system, I need to be able to output this to postscript in several places on a page and on potentially multiple pages. By hook or by crook (actually using jpeg2ps) I've got some code that I can use to generate the logo and I can incorporate it into some postscript code and the logo will print. The code for the logo is:

/RawData currentfile /ASCII85Decode filter def
/Data RawData << >> /DCTDecode filter def
200 200 translate
50 50 scale
/DeviceGray setcolorspace
{ << /ImageType 1
     /Width 71
     /Height 88
     /ImageMatrix [ 71 0 0 -88 0 88 ]
     /DataSource Data
     /BitsPerComponent 8
     /Decode [0 1]
  >> image
  Data closefile
  RawData flushfile
  /NimbusSanL-Regu findfont 10 scalefont setfont  
  3 inch 3 inch (TEST TEXT) centre_show
  showpage
  restore
} exec
s4IA0!"_al8O`[\!<E1.!+5d,s4[N@!!<9(!s/N+!s8W.!s8Z0#R(A7"9f,;#6kG
B$4I=N$4@4N%MB<^%M90Y$P4'b&JGin'bq,f(Dmo%(_RMt'`YrK$O?`7!(R%j&HM

.... data omitted

r]\qt!QGb%I<3\V_BJKTOu5p4dJ&)!Gfj7\E2!/8oR!:c-D5P@9'R!at.rr=-JlM
Su8H%3?q2u`lXq([d!%2Zmm?\c$0G5hP<[JN,D[s5CYKU^Z-l.4]1E;1]4rRJP2K
u!L?N06rD'Nb=f~>
%%EOF

The problem is, I cannot see anyway to put this as a subroutine within the postscript code. I'd like this to be a subroutine so I can print it in several places at different size and onto multiple pages.

At the moment, if I try to enclose this in a subroutine and the call the routine it simply doesn't work. This is what I tried:

/layout_logo {
/RawData currentfile /ASCII85Decode filter def
/Data RawData << >> /DCTDecode filter def
200 200 translate

... rest of code

r]\qt!QGb%I<3\V_BJKTOu5p4dJ&)!Gfj7\E2!/8oR!:c-D5P@9'R!at.rr=-JlM
Su8H%3?q2u`lXq([d!%2Zmm?\c$0G5hP<[JN,D[s5CYKU^Z-l.4]1E;1]4rRJP2K
u!L?N06rD'Nb=f~>
%%EOF
} def

....

then in main code:

/logo_layout

Also, if I include it into the main body of the program I only appear to be able to use it once and anything that I put after it (e.g. more text) is just ignored. I thought it was the showpage. But if I take this out, again it just doesn't work at all.

I'm no expert on postscript and so I'm scratching my head a bit here to work out how to get this to work.

Any help appreciated,

Thanks,

Trevor.

0
Comment
Question by:trevorb
  • 8
  • 6
14 Comments
 
LVL 8

Expert Comment

by:RLGSC
ID: 12260022
Trevor.

If I am reading your posting, you are on the correct track.

In file preamble, define a macro for the Logo. Depending on your applications need, you may also want to define some different ordinal positions (one macro for general placement, and additional macros for different placements--upper left, lower right, upper right, etc.).

When you want to put the logo in a specific point, the code fragment looks somewhat like (assmiing GenLogo is the name of the Logo generating macro):

   xxx yyy moveto GenLogo

You can get more complicated, for example specifying logo sizes, etc., but this is the basics.

You can also make your application less sensitive to company reorganizations by writing the code generically and using different include files to redefine the logo. This trick is also useful in internationalization contexts. (I have done this type of thing more than a few times).

I hope that the above is helpful. If I have been unclear, or incomplete, please let me know.

- Bob (aka RLGSC)
0
 

Author Comment

by:trevorb
ID: 12261196
Hi Bob,

Thanks for the prompt reply.

Basically, I have tried what you suggested. This is in fact the way I thought it should be done also. But I use GSView to check the file (eventually we wil go Ghostscript to PDF) and it just errors and won't read the file.

This is what I have:

%!
%%IncludeFeature: colormodel (cmyk)
%%IncludeFeature: header (off)
%%IncludeFeature: colorseparation(off)
%%IncludeFeature: collate (on)
%%IncludeFeature: emulation (postscript)
%%IncludeFeature: orientation (landscape)
%!PS-Adobe-3.0
%%Title: QUOTE PRE TEST
%%Creator: TREVOR
%%CreationDate: Fri, 08 October 2004
%%BoundingBox: 8 8 588 835
%%Pages: (atend)
%%PageOrder: Special
%%Requirements:
%%DocumentNeededFonts:
%%DocumentSuppliedFonts:
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
%%EndComments

/inch { 72 mul } def

/graphic_layout {

/RawData currentfile /ASCIIHexDecode filter def
/Data RawData << >> /DCTDecode filter def
572.00 708.96 scale
/DeviceRGB setcolorspace
{ << /ImageType 1
     /Width 71
     /Height 88
     /ImageMatrix [ 71 0 0 -88 0 88 ]
     /DataSource Data
     /BitsPerComponent 8
     /Decode [0 1 0 1 0 1]
  >> image
  Data closefile
  RawData flushfile
  showpage
  restore
} exec
FFD8FFE000104A46494600010101004800480000FFDB00430001010101010101
0101010101010101010101010101010101010101010101010101010101010101

.. data ommited

C32F83FF000EBC33FD99E1DB6D234797FE11DFED99F4F97C41ABEBBAAEA65140
1E814514500145145007FFD9>
%%EOF

} def

1 inch 1 inch moveto graphic_layout

showpage
%%EndOfDocument

But it just doesn't work :-(

I thought it might be the spurious looking %%EOF that I've left in the example above. But taking this out it still doesn't work.

I can find examples of graphics in postscript code (e.g. in the book you pointed me to when you helped me before) but these are onlt snippets and it's hard to see how the whole postscript file comes together.

Trevor.
0
 

Author Comment

by:trevorb
ID: 12261211
BTW as you can see I set JPEG2PS to output hex data which looks more like examples in the 'red' book.

Trevor.
0
 
LVL 8

Expert Comment

by:RLGSC
ID: 12263376
Trevor,

I have to run for a meeting, but a quick glance shows a common error.

Look carefully at your code (and what it does when it executes). Remember, PostScript is a programming language. If you execute the code operation by operation, you will see that the code you entered does not do what you want.

I am sorry for being cryptic,  but I have to run for a meeting. I will try to be less cryptic later or tomorrow.

- Bob (aka RLGSC)
0
 

Author Comment

by:trevorb
ID: 12266737
Bob,

Hope you meeting went well.

I've sat here all day and tried various things that I think are wrong but just cannot see the wood for the trees unfortunately.

Also, I've left my 'red book' at work (I'm at home) and do not pocess enough knowledge of postscript to know what are built in commands and what are not.

I will have another look on Monday and see if I can spot my mistake.

Thanks again,

Trevor.
0
 
LVL 8

Expert Comment

by:RLGSC
ID: 12273218
Trevor,

Sorry for the delay, a few urgent items came up yesterday and this morning and prevented  my writing you. After all, I must give paying clients a higher priority than my "public service".

The problem is that the code that you have is reading from the input stream. If you execute it multiple times, it will expect multiple copies of the graphic, which is clearly unacceptable. What must be done is eliminate the read from input, or alternatively, read the input into a variable which is then referenced later on in the PostScript program.I have done this many times, albeit each time ends up somewhat different, due to differences in the client's situation.

In effect, what you need to do is to create the same king of mechanism as is used to input a downloadable font, but without the machinery peculiar to a font.

Does the above help?

- Bob



0
 

Author Comment

by:trevorb
ID: 12276203
Hi Bob,

Don't worry, I appreciate fully that your paying customers come first. We all have to make a living!

I've spent all morning trying different things in different places. I'm assuming from your last e-mail that I somehow have to make the graphic data 'in-line' in the postscript code?

I've been trying to find ways to do this and examples to point me in the right direction, but I just cannot get this to work as I want.

I have to admit, although my knowledge of postscript is okay (several of our internal programs produce postscript output including some complex CAM packages!), it's not brilliant. I know just the fundamentals, mostly picked up from leaning from examples.

But this has got me stumped. Anymore hints to get me going with this?

I'm beginning to get a bit frustrated, I keep having brainwaves which consequently don't work. I think soon I will have to think of a completely different way to achieve what I want to do.

Your help is very much appreciated,

Thanks again Bob,

Trevor.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 8

Expert Comment

by:RLGSC
ID: 12276757
Trevor,

The process is two stage:

 1- Load the data into a variable (in this, the code snippet you posted is erroneous, the data cannot be placed into the macro definition.

 2- To put the graphic onto the page, you need a separate operation to place it on the page, using the information that you loaded into your program state in Step 1.

If your PostScript familiarity is thin, start with the fundamentals. Print a copy of the code out, get out your Red Book, and check what every operation is doing and how it affects the PostScript context. In the example that you originally posted, you will see that plaing the data into the /xxx {  ... } def sequence will not work, the operators that you are invoking read from the standard input stream, not the lexical tokens stored by "def".

However, you can run that code segment in such a way that you are able to save the graphic image in a PostScript variable. Then you can place it on a page. In effect, you are creating a very simple (1 character) raster font (but without a lot of the baggage that a font definition has; ceomceptually speaking, if it were a font, all you would need to do is use the "show" command to place it at any point on the page.

For an introduction to PostScript, I will try to locate my DECUS presentation, and place it on my www site (http://www.rlgsc.com/presentations.html). I have to go rooting some archives to locate it, I haven't given it in a few years.

I hope that my comments are helpful.

- Bob (aka RLGSC)
0
 

Author Comment

by:trevorb
ID: 12277474
Bob,

Thanks again, and yes your comments are helpful.

I will go away and have another look at what I'm doing wrong.

Please bear with me though, this is a complete new learning curve for me. And for something that I thought was going to be relatively easy too.

I had thought of saying to my boss that he'll have to do without the logo on the quote although I can't see him being too happy about that.

Once again, I really appreciate the help you've given.

Trevor.
0
 
LVL 8

Expert Comment

by:RLGSC
ID: 12278699
Trevor,

I have done a fair bit of consulting on PostScript-related matters. Your problems are not uncommon, and I am sure that they can be surmounted.

I will try to locate that intro session in my archives.

- Bob
0
 

Author Comment

by:trevorb
ID: 12285988
Hi Bob,

I'm slowly making some progress thanks to your help and encouragement. I've finally created a cope snippet that works having found out how to store the image data to a variable. This is what I come up with:

%!

/inch { 72 mul } def

/bw_logo_graphic <
ffffffffffffffffffffffffffffffffffffffffffffffffffff
ff000000000000000000000000000000000000ffffffffffffff

... data omitted

ff000000000000000000000000000000000000000000000000ff
ffffffffffffffffffffffffffffffffffffffffffffffffffff
> def

/logo_graphic <
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

... data omitted

ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffff
> def

/draw_bw_logo {
save
1 inch 1 inch scale
26 34 8 [26 0 0 -34 0 34]
{bw_logo_graphic}
image
restore
} def

/draw_colour_logo {
save
1 inch 1 inch scale
100 100 8
[100 0 0 -100 0 100]
{logo_graphic}
false 3 colorimage
restore
} def

save
3 inch 1 inch translate
draw_bw_logo
restore

save
1 inch 3 inch translate
draw_colour_logo
restore

showpage

How does that look? Anyway I could improve it or can you see anything that may cause me problems?

But having got this far I now have another problem. The graphics I found above are from examples I found that read from the input stream and I used these examples (because the images are fairly simple) to help me eventually reach the code above that appears to work.

But now I have the problem of using my own company's logo. I used JPEG2EPS to generate a EPS file that seems to contain the image data that I require. I cut the data and pasted it into the logo_graphic variable and changed the image details to represent this, the image was 71 px x 88 px so had:

71 88 8
[71 0 0 -88 0 88]

But the image just comes out all corrupt. But at least it has no errors. I've tried changing the parameters slightly but to no avail. I've also studied the EPS file produced to see if I can see any clues and have tried the various options in the JPEG2PS program. But no joy at the moment.

So near, yet so far...........

Trevor.
0
 
LVL 8

Accepted Solution

by:
RLGSC earned 250 total points
ID: 12312712
Trevor,

I found my "Introduction to PostScript" presentation. You can get a copy of it at http://www.rlgsc.com/decus/usf95/index.html.

- Bob
0
 

Author Comment

by:trevorb
ID: 12317129
Bob,

Thanks for that, very much appreciated. I will print that off and have a read over my coffee this morning.

The graphics thing is still bugging me though. I'm fine with black and white bitmaps (which luckily I'm able to use temporarily), I can get those to work and understand the postscript reasoning.

But it's the colour ones that are still causing me problems. I understand what postscript requires (I think so anyway), but when I supply the data from software like ImageMagik or JPEG2PS, I get an error. It's not like it even displays a corrupt image, in simply errors when read into Ghostscript for viewing. Have to have a think about it over the weekend when I can sit down and have a look without the pressures of the office.

Will let you know how I get on.

Do you know of any easy way to convert the binary JPEG data into hex that can easily be pasted into the postscript file?

I think with all the help you've given me, I will have to up your points entitlement.

Thanks again,

Trevor.
0
 

Author Comment

by:trevorb
ID: 12356518
Hi Bob,

Had every success with BW bitmaps and logos thanks to your help. But still unable to sort out the colour versions.

But luckily the reports I'm working on only need BW logos for now. And I'm under pressure to get version 1 working so I'm having little time to investigate why the colour version is causing me a problem.

I will have to finish these current reports and then revisit the colour version later.

Thanks again for your help, it really was appreciated.

Trevor.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now