×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

a jpeg several times in postscripT

a jpeg several times in postscripT

a jpeg several times in postscripT

(OP)
Hello,

I can put a jpeg file into my postscript document. But I will like to put this image in each pages. So I would like to insert only once the image code.

How could I make a procedure to store the image into the printer for my current document?

Here is my current ps code :

0.240000 0.240000 scale
gsave 1067.00 1529.00 translate
save
/RawData currentfile /ASCIIHexDecode filter def
/Data RawData << >> /DCTDecode filter def
20 20 translate
572.00 586.11 scale
/DeviceRGB setcolorspace
{ << /ImageType 1
     /Width 527
     /Height 540
     /BitsPerComponent 8
     /ImageMatrix [ 527 0 0 -540 0 540 ]
     /DataSource Data
     /Decode [0 1 0 1 0 1]
  >> image
  Data closefile
  RawData flushfile
  restore
} exec
%%here is the image data
>grestore

Thanks for your help
Thierry PARET

RE: a jpeg several times in postscripT

Search this forum for keyword: form

There are several posts/threads on the PostScript Form dictionary, which is the mechanism you need to use.

More info on my website.

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

RE: a jpeg several times in postscripT

(OP)
I will have a look at the form.

Don't you think a procedure will be possible too?

Thanks
Thierry PARET

RE: a jpeg several times in postscripT

No. A procedure is tokenized, so can't contain inline image data.

1. Create a data acquisition procedure that reads your image data. You're close in the code you posted.

2. Create a form dictionary for image caching/resuse.

3. The form dictionary's PaintProc should use the data acquisition procedure you defined in step 1.

All of this is detailed in various threads in this forum. If you have more questions, just ask!

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

RE: a jpeg several times in postscripT

(OP)
Hello,

I have one more question :

/ImageData
currentfile
<< /Filter /ASCIIHexDecode >>
/ReusableStreamDecode filter
...

how can I use ASCIIHexDecode and the DCTDecode filter with the ResuableStreamDecode?

regards
Thierry PARET

RE: a jpeg several times in postscripT

Just pile them up like beads on a string, or freight cars on a train: one after the other.

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

RE: a jpeg several times in postscripT

(OP)
My direct image command :
/RawData currentfile /ASCIIHexDecode filter def
/Data RawData << >> /DCTDecode filter def
...
/DataSource Data

for the data source is working.

As you wrote, I tried now the following ReusableDecodeStream :

/ImageData1
currentfile
<< /Filter /ASCIIHexDecode /DCTDecode
>> /ReusableStreamDecode filter
%%Imagedata bytes
def

But it is not correct.
May be I'm not good for beads or cars.

I think I have to change something in the Filter but All my changes are unsuccessfull.

I can use an EPS with my jpeg image, I would like to improve my postscript code.

Regards
Thierry PARET

RE: a jpeg several times in postscripT

Yeah, lots of filter stuff here.

Add this to the very top of your program:

CODE

/ImageData
currentfile
<< /Filter /SubFileDecode
   /DecodeParms << /EODCount 0 /EODString (*EOD*) >>
>> /ReusableStreamDecode filter

You can change "ImageData" to whatever name you want. These two filters work together. SubFileDecode creates a "sub file" up to the EODstring. It's a way to break off a chunk of PostScript code into its own file in memory.

ReusableStreamDecode creates a file that is "resuable"... you can roll it back up to the top, do random access on it, and it stays in memory.

Notice that we're doing this to currentfile, and that we've started a definition, /ImageData.

So directly after this code block, put your working JPEG stuff:

CODE

/RawData currentfile /ASCIIHexDecode filter def
/Data RawData << >> /DCTDecode filter def
...
/DataSource Data

Right after THAT, place the *EOD* expected by SubFileDecode. Then complete the /ImageData definition with "def".

Here's what we have so far, then:

CODE

/ImageData
currentfile
<< /Filter /SubFileDecode
   /DecodeParms << /EODCount 0 /EODString (*EOD*) >>
>> /ReusableStreamDecode filter

/RawData currentfile /ASCIIHexDecode filter def
/Data RawData << >> /DCTDecode filter def
...
/DataSource Data
*EOD*
def

The next step: turn all of that into a Form:

CODE

/IDForm
<< /FormType 1
   /BBox [154 321 441 521]
   /Matrix [ 1 0 0 1 0 0]
   /PaintProc
   { pop
       /ostate save def
         /showpage {} def
         /setpagedevice /pop load def
         ImageData 0 setfileposition ImageData cvx exec
       ostate restore
   } bind
>> def

Of course, adjust the BBox to match your image. Then, when you want the image drawn:

CODE

%do a translate, scale, if you need.
IDForm execform

That should work.

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

RE: a jpeg several times in postscripT

(OP)
Sorry but it doesn't work. I copy your code but I have the following error:

Error: /undefined in FFD8FFE000104A46494600010100000100010000FFDB004300

Here is my code :

CODE

/ImageData1
currentfile
<< /Filter /SubFileDecode
   /DecodeParms << /EODCount 0 /EODString (*EOD*) >>
>> /ReusableStreamDecode filter
/RawData currentfile /ASCIIHexDecode filter def
/Data RawData << >> /DCTDecode filter def
%Image data
/DataSource Data
*EOD*
def

/ImageForm1
<< /FormType 1
   /BBox [0 0 284 263]
   /Matrix [ 1 0 0 1 0 0]
   /PaintProc
   { pop
       /ostate save def
       /showpage {} def
       /setpagedevice /pop load def
       ImageData1 0 setfileposition ImageData1 cvx exec
       ostate restore
   } bind
>> def

gsave
200 500 translate
ImageForm1 execform
grestore

RE: a jpeg several times in postscripT

Something looks wrong with your /DataSource... I never see it actually defined anywhere.

Try passing all of your filters to the ReusableStreamDecode filter, and removing your DataSource definition.

CODE

/ImageData1
currentfile
<<
  /Filter %% an array of filters to use in order
  [/SubFileDecode /ASCIIHexDecode /DCTDecode]
  /DecodeParms %% an array or parameters for filters
  [<< /EODCount 0 /EODString (*EOD*) >> null null]
>> /ReusableStreamDecode filter
%Image data
*EOD*
def   %% ImageData1 is now pure JPEG bytes

Let me know if this is making sense. Your image data needs to be in a "random access file" in memory.

So we're trying to say:

SubFileDecode: here's a chunk of stuff, break it off into a "file".

ASCIIHexDecode: It's in HEX Pairs. Decode that to binary.

DCTDecode: that binary stream is JPEG data. Decode it.

ReusableStreamDecode: put that jpeg data into a random access, resuable stream

/ImageData1: define that stream as something named "ImageData1".

You next have to create a Data Acquisition Procedure. This is something that can return the entire ImageData1 stream of bytes from start to finish. It should look like:

ImageData 0 setfileposition ImageData cvx

play with this, I haven't tested the DAP part. You'll wrap that into a procedure.

Then you create form. That form's PaintProc will need to contain your image dictionary. BitsPerComponent, all that stuff. The image dictionary requires a DataSource entry. The DataSource should be the DAP you created above.

This is very complex, I know. But it's very logical, and you just need to work through it step by step.

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

RE: a jpeg several times in postscripT

(OP)
OK

As you said, I will play this.

Thanks very much

Regards
Thierry PARET

RE: a jpeg several times in postscripT

(OP)
Thomas,

For the moment, I'm trying to load several times my jpeg using a form containg a EPS file.

But If I call several times my form, I have an ioerror for the setfileposition command.

Do you have any idea

CODE


gsave
0 10 translate
ImageForm1 execform
grestore

gsave
200 200 translate
ImageForm1 execform
grestore

RE: a jpeg several times in postscripT

That means (perhaps) that your ImageForm1 definition isn't correct.

You're welcome to send me your code for debugging, if you like. You can find my email address on my website.

You have to agree to let me post portions back into the forum, if necessary, so that this thread provides some value to the Tek-Tips community!

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

RE: a jpeg several times in postscripT

I got your email, but your server rejected my replies.

So I'll reply here:

Attached is my version. From what you describe, however, the programming isn't the problem - your version works. However, we are definitely using PostScript Level 3 filters, so if your document works in GhostScript and/or Acrobat Distiller, but doesn't PRINT, then likely your printer is not PostScript Level 3 compatible.
 
There is another approach, which uses only PostScript Level 2. It involves turning your image data into an array of strings, and creating a DAP to put each string on the stack, change it to executable, and execute it.
 
Let me know if you want to try that route, I can send you the code this evening.

CODE

%!PS-Adobe-3.0

/ImageData
currentfile
<< /Filter [/SubFileDecode /ASCIIHexDecode /DCTDecode]
   /DecodeParms [<< /EODCount 0 /EODString (*EOD*) >> null null]
>> /ReusableStreamDecode filter
%% EXCLUDED ALL THE HEXPAIR DATA
*EOD*
def
/readdata { ImageData 0 setfileposition ImageData} def

/JumpForm    
<< /FormType 1
   /BBox [0 0 284 263]
   /Matrix [ 1 0 0 1 0 0]
   /PaintProc
   { pop
     save
     284.00 263.00 scale
     /DeviceRGB setcolorspace
     << /ImageType 1
        /Width 284
        /Height 263
        /BitsPerComponent 8
        /ImageMatrix [ 284 0 0 -263 0 263 ]
        /DataSource readdata
        /Decode [0 1 0 1 0 1]
     >> image
     restore
   } bind
>> def

JumpForm execform
0 300 translate
JumpForm execform

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

RE: a jpeg several times in postscripT

(OP)
Thomas,

Thanks a lot for your help.

Now the file is correctly printed but not view in GhostView.

I have the error:
 
Displaying page 1
Error: /undefined in --filter--

What should I do to see correctly my file in a viewer?

Regards
Thierry PARET

RE: a jpeg several times in postscripT

GhostView/GhostScript is open-source, and so may or may not properly support all filters or combination of filters. All I can do is give my opinion on whether the code is valid PostScript or not. If it prints, then I would say it's "working code".

Another good product for working with PostScript is Adobe's Acrobat Distiller. Unfortunately, it cannot be purchased separately, but only with Acrobat 6.0 Standard or Professional.

For general PostScript debugging (Level 2 only) I use PSAlter 1.6 from Quite Software.

For server-based PostScript processing, I use activePDF Server. It is very good, but I occasionally run into problems (which they have always addressed).

I know how frustrating this kind of problem can be.

If you want to try moving to a pure Level 2 only method, look at thread Thread280-797297. Maybe GhostScript will like that approach better.

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

RE: a jpeg several times in postscripT

Hello
tgreer and tparet

This is bug in ghostscript (parameter "EODCount").
For fix See:wwwghostscriptcom/pipermail/gs-code-review/2004-January/004353.html

My sugestion to put jpeg data to poscript:

%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 20 20 200 200
%%Page: 1 1

/ImageData
currentfile
<< /Filter [ /ASCIIHexDecode /DCTDecode ]>>
/ReusableStreamDecode filter
%IMAGE HEXPAIR DATA, J use "jpeg2ps -h"
def

/JumpForm  << /FormType 1
   /BBox [ 0 0 20 19 ]
   /Matrix [ 1 0 0 1 0 0]
   /PaintProc
    {
        pop
        ImageData 0 setfileposition
        /DeviceGray setcolorspace
        20  19 scale
            <<
            /ImageType 1
            /Width 20
            /Height 19
            /BitsPerComponent 8
            /ImageMatrix [ 20 0 0 -19 0 19 ]
            /DataSource ImageData
            /Decode [0 1]
            >> image
    } bind                                                   
>> def  
     
020 030 translate JumpForm execform
020 030 translate JumpForm execform
020 030 translate JumpForm execform
%%EOF

This work with ghostscript (Tested only in Linux)

RE: a jpeg several times in postscripT

It's not actually a bug in GhostScript. The documentation for subfiledecode indicates that EODCount is required. However, Distiller provides this entry for you if you leave it out. GhostScript isn't so forgiving.

Thomas D. Greer
http://www.tgreer.com
Providing PostScript & PDF
Training, Development & Consulting

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close