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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract a jpeg from an eps

Status
Not open for further replies.

gregonthemoon

Programmer
Apr 25, 2005
3
FR
Hi all,

first of all, i'm not a postscript programmer, but i have a problem that involves postscript in some way.


I use huge eps files (~50 Mo), those eps files always are of the same sort :
An emmbedded jpeg + some info on profile + selection...

I need to convert them to jpegs. I currently use ImageMagick, but since the pictures are huge it takes ages (IM even crashes before to finish sometimes).

I then thought that the JPEG must be stored somewhere in the postscript code, so i tried to extract it (searching for the JPEG signature in the binary), but i only managed to extract a thumbnail, the original JPEG seems to be there (between the %%BeginBinary boundaries) but it's encoded into some weird format (at least one i don't know ;-), since it doesn't begin with "FF D8 FF" as JPEG usually do.


Do you know if i can extract the JPEG from the EPS, and if yes in which format is it stored?


thanks for your help
 
seems to be, he is a sample from the code :

...
/ImageType 1 def
/Width cols def
/Height rows def
/ImageMatrix [cols 0 0 rows neg 0 rows] def
/BitsPerComponent 8 def
/Decode [0 1 0 1 0 1 0 1] def
/DataSource currentfile /ASCII85Decode filter
/DCTDecode filter def
currentdict end
%%BeginBinary: 31878013
beginimage
s4IA>!"M;*Ddm8XA,lT0!!*&R!(-_f!WiH*!sAZ,"9eo1"9eu5"U,&6#R:S>#6tMB
#mgnE#mgtI$O[=M$O[@O$k*OQ$k*OQ$k*OQ$k*OQ$k*RE^]5&S*(1[c"9B)7!YGD7
&HDqG!<:jT"9U[a_uS3c!!!6)!<E3%zz"9el/"p"]/#RLhG&-)b4!s8T-!X8l3"9Jc/
Erc=E&Hi(;+VHLq;$I\B,&r/J16J78'sU(M_,A\>1DXHh,]\M,,ssLfP+o6lF2Be&
-^1=32A]>'FMlPd#UY01$5aY6PXS';ZrYXU-lV[:eek:>K/>oOW0!Q)1n-e`HI9G(u<[
[`6n\p,>KCB6T,tVmj^ukP$r,=D2r8R&IO9f]`)Z3D!@fH&7rg\]NOhq'nEt>&&A@
R]<sAg?SP7g&MTc!<<0$!rrH(!'^JU-+k\MdnsG`r.`npMT$K&BF1_e5Dd^X2MtFr
32n-aq.Jmj!$p8mXAV!T+Jh7T_Z_67)@C@tqXE&AlBP]`SCo(nA*"[LJDC`ll%0fa
;DJ?'bm2Wi'X$OuVrHFF6-YH>l)I54V9/Qm'Gtlu3Jo7(S(1<YJoKikGokkm,N:&'
HW3uC3Nu[?+,,%KrS;Lh@%s;nP<i!>'t'&lMLZ1,TZrAl9HBoc2<Zd[Y73X4U7^i4
dFpEU!_MAXW6L(E`j$q7@Rs[N-O`[Xi0PBP[G:ZP_hXC'89k-U6H:tpM?G0_qa-Q-
$'d[^GfRcuACnRpN/A1:<CnZiGi.l!k/#E_@g-E?1c-:/[Kq^`:*c(T,#).P.CL']
>"7O:g#l2F[K;l$ini2?!3@TeW2I<iihkMgJTSX6-RJr6d,N@p\=I/Aq"P$m!'e(R
$%l%GeB]hMM?p-'qI<B]0Zb$KXuM,R%igPOBe$L=3MLPe+,N!gf***hX]@ks$hfY,
K;K-A-m$aU(o4o`ccZdc;-a5T;+Md#,9MJJN5)8-,]PEFH=:n.UsXifd7O.],(gbQ
...


My next question would be : how do you convert this back to a proper JPEG encoding?
 
It's in a proper JPEG encoding, only the binary data is presented in ASCII85, as opposed the HEX or raw binary.

What you have to do is use an ASCII85 decoder. PostScript has one, the /ASCII85Decode filter. I don't know if there are 3rd party tools or not.

Everything between the "beginimage" and the terminal "~>" mark, is the binary data.

You can modify the existing program a bit to decode your jpeg, if you like.

Let's see, thinking off the top of my head:

Code:
%!PS
/decodeJPEG
{
  /input currentfile /ASCII85Decode filter def
  /output (c:\\myImage.jpg) (w) file def
  {
    ouput input read 3 -1 roll write not {exit} if
  } loop
} bind def

decodeJPEG
s4IA>!"M;*Ddm8XA,lT0!!*&R!(-_f!WiH*!sAZ,"9eo1"9eu5"U,&6#R:S>#6tMB
#mgnE#mgtI$O[=M$O[@O$k*OQ$k*OQ$k*OQ$k*OQ$k*RE^]5&S*(1[c"9B)7!YGD7
&HDqG!<:jT"9U[a_uS3c!!!6)!<E3%zz"9el/"p"]/#RLhG&-)b4!s8T-!X8l3"9Jc/
Erc=E&Hi(;+VHLq;$I\B,&r/J16J78'sU(M_,A\>1DXHh,]\M,,ssLfP+o6lF2Be&
-^1=32A]>'FMlPd#UY01$5aY6PXS';ZrYXU-lV[:o>K/>oOW0!Q)1n-e`HI9G(u<[
[`6n\p,>KCB6T,tVmj^ukP$r,=D2r8R&IO9f]`)Z3D!@fH&7rg\]NOhq'nEt>&&A@
R]<sAg?SP7g&MTc!<<0$!rrH(!'^JU-+k\MdnsG`r.`npMT$K&BF1_e5Dd^X2MtFr
32n-aq.Jmj!$p8mXAV!T+Jh7T_Z_67)@C@tqXE&AlBP]`SCo(nA*"[LJDC`ll%0fa
;DJ?'bm2Wi'X$OuVrHFF6-YH>l)I54V9/Qm'Gtlu3Jo7(S(1<YJoKikGokkm,N:&'
HW3uC3Nu[?+,,%KrS;Lh@%s;nP<i!>'t'&lMLZ1,TZrAl9HBoc2<Zd[Y73X4U7^i4
dFpEU!_MAXW6L(E`j$q7@Rs[N-O`[Xi0PBP[G:ZP_hXC'89k-U6H:tpM?G0_qa-Q-
$'d[^GfRcuACnRpN/A1:<CnZiGi.l!k/#E_@g-E?1c-:/[Kq^`:*c(T,#).P.CL']
>"7O:g#l2F[K;l$ini2?!3@TeW2I<iihkMgJTSX6-RJr6d,N@p\=I/Aq"P$m!'e(R
$%l%GeB]hMM?p-'qI<B]0Zb$KXuM,R%igPOBe$L=3MLPe+,N!gf***hX]@ks$hfY,
K;K-A-m$aU(o4o`ccZdc;-a5T;+Md#,9MJJN5)8-,]PEFH=:n.UsXifd7O.],(gbQ
...

I haven't tested any of that. It looks correct, but I might be missing something or the "3 -1 roll" might need to be "3 1 roll", I always mess that up.

The general idea is to read the "binary" data through the ASCII85Decode filter, writing the "decoded" byte to an output file.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top