Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a jpeg several times in postscripT 1

Status
Not open for further replies.

tparet

Programmer
May 5, 2004
11
FR
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
 
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
Providing PostScript & PDF
Training, Development & Consulting
 
I will have a look at the form.

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

Thanks
Thierry PARET
 
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
Providing PostScript & PDF
Training, Development & Consulting
 
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
 
Just pile them up like beads on a string, or freight cars on a train: one after the other.



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
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
 
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
Providing PostScript & PDF
Training, Development & Consulting
 
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
 
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
Providing PostScript & PDF
Training, Development & Consulting
 
OK

As you said, I will play this.

Thanks very much

Regards
Thierry PARET
 
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
 
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
Providing PostScript & PDF
Training, Development & Consulting
 
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
Providing PostScript & PDF
Training, Development & Consulting
 
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
 
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
Providing PostScript & PDF
Training, Development & Consulting
 
[smarty]Hello
tgreer and tparet

This is bug in ghostscript (parameter "EODCount").
For fix See:
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)
 
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
Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top