home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1556 < prev    next >
Text File  |  1990-12-28  |  6KB  |  168 lines

  1. Newsgroups: alt.sources
  2. From: carlson@lance.tis.llnl.gov (John Carlson)
  3. Subject: [graphics] Format conversion lookup tool written in Prolog -- Request for Data
  4. Message-ID: <1990Jul7.024349.26616@math.lsa.umich.edu>
  5. Date: Sat, 7 Jul 90 02:43:49 GMT
  6.  
  7. Archive-name: rct/05-Jul-90
  8. Original-posting-by: carlson@lance.tis.llnl.gov (John Carlson)
  9. Original-subject: Format conversion lookup tool written in Prolog -- Request for Data
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.graphics.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15.  
  16. Here's a start on a Prolog program that looks up how to convert from one format
  17. to another.  I would like to add some more features one of these days.
  18.  
  19. I have several tools already in my knowledge base.  If you are interested,
  20. let me know, and I will consider publishing the data.
  21.  
  22. I might turn this into a network/mail service, given demand, etc.
  23.  
  24. The following is written in SB Prolog v3.1 obtainable via anonymous FTP from
  25. arizona.edu.
  26.  
  27. John Carlson
  28. carlson@tis.llnl.gov
  29.  
  30. ------------------detach here--------------------------------------------------
  31. /*
  32. Name: RCT
  33. Copyright 1990 University of California Regents
  34.  
  35. Permission to use, copy, modify, and distribute this software and its
  36. documentation for any purpose and without fee is hereby granted,
  37. provided that the above copyright notice appear in all copies and that
  38. both that copyright notice and this permission notice appear in
  39. supporting documentation.  The University of California makes no
  40. representations about the suitability of this software for any
  41. purpose.  It is provided "as is" without express or implied warranty.
  42.  
  43. The University of California disclaims all warranties with regard to
  44. this software, including all implied warranties of merchantability and
  45. fitness, in no event shall be the University of California liable for
  46. any special, indirect or consequential damages or any damages
  47. whatsoever resulting from loss of use, data or profits, whether in an
  48. action of contract, negligence or other tortious action, arising out of
  49. or in connection with the use or performance of this software.
  50.  
  51. Author:  John Carlson
  52. E-Mail:  carlson@tis.llnl.gov
  53. */
  54.  
  55. /* SB-prolog program to determine list of tools to use to convert from
  56. one format to another. */
  57.  
  58. /* INSERT */
  59. /*
  60. ------------------------------------------------------------------
  61. Usage: fconvert(from_format, to_format, tool).
  62. Purpose: "tool" converts file in "from_format" to "to_format".
  63. Example: fconvert(gif, sunraster, gif2ras).
  64. ------------------------------------------------------------------
  65. Usage: toolread(from_format, tool).
  66. Purpose: "tool" converts file in "from_format" to internal structure
  67. Example: toolread(gif, gif2ras).
  68. ------------------------------------------------------------------
  69. Usage: toolwrite(to_format, tool).
  70. Purpose: "tool" converts internal structure to "from_format"
  71. Example: toolwrite(sunraster, gif2ras).
  72. */
  73.  
  74. /* QUERY */
  75. /*
  76. Usage: conversions(from_format, to_format, convert_tools_lists)
  77. Purpose: Produces a list of lists of tools to apply in order to convert
  78.     from "from_format" to "to_format".
  79. Example: conversions(gif, sunraster, L).
  80. */
  81.  
  82. /*
  83. Bugs:
  84.     Should have idea on tool reliability.
  85.     Should be able to query how to get the tool.
  86.     Should encode what harware/OS tool runs on.
  87. */
  88. /*
  89. Tools and Formats in my knowledge base:
  90.  
  91. | ?- tools(S).
  92.  
  93. S = [brushtopbm,cg8gt,cmuwmtopbm,fbm2pod,fbm2tga,fbmtools,fbps,fitstopgm,
  94. fstopgm,g3topbm,gemtopbm,gif2ras,giffer,giftoppm,hipstopgm,icon,icontopbm,
  95. ilbmtoppm,imagestudio,imgtoppm,macptopbm,mgrtopbm,mtvtoppm,pbm2ps,
  96. pbmtoascii,pbmtobbnbg,pbmtocmuwm,pbmtog3,pbmtogo,pbmtoicon,pbmtolj,
  97. pbmtomacp,pbmtomgr,pbmtoptx,pbmtorast,pbmtox10bm,pbmtoxbm,pbmtoxwd,
  98. pcxtopbm,pgmtofits,pgmtopbm,pgmtops,pic2fbm,picio2tiff,picttopbm,pixargt,
  99. ppmtogif,ppmtoilbm,ppmtopgm,ppmtops,ppmtorast,ppmtoxwd,preview,psidtopgm,
  100. pssun,qrt2fbm,qrttoppm,ras2tiff,rasttogif,rasttopbm,rasttoppm,raw2fbm,
  101. rawtopgm,scene,screendump,screenload,sgigt,sgisv,superpaint,targa2fbm,
  102. tgatoppm,tiff2ps,tiff2ras,tifftopgm,xbmtopbm,xgif,ximage,ximtops,ximtorle,
  103. xloadimage,xps,xtoxim,xwd,xwdtopbm,xwdtoppm,xwud,xxim,yap]
  104. yes
  105. | ?- readformats(S).
  106.  
  107. S = [cmuwm,draw,eps,facesaver,fbm,fits,foto,g3,gem,gif,hdf,hips,ilbm,
  108. imagestudio,imgwhatnot,macpaint,mgr,mtv,nextfb,nextwin,pbm,pcx,pgm,pic,
  109. pict,pixarfb,ppm,ps,qdv,qrt,raw,resid0,riff,scan,sgifb,sunfb,sunicon,
  110. sunraster,superpaint,targa,thunderscan,tiff,xbm,xeroxbrush,xim,xwd,xwin,
  111. yeeface]
  112. yes
  113. | ?- writeformats(S).
  114.  
  115. S = [ascii,bbnbg,cmuwm,diablo,draw,eps,fbm,fits,g3,gif,graphon,hplj,ilbm,
  116. imagestudio,macpaint,mgr,nextfb,nextwin,pbm,pgm,pict,ppm,printronix,ps,qdv,
  117. resid0,riff,rle,scan,sgifb,sunfb,sunicon,sunraster,superpaint,targa,tiff,
  118. x10bm,xbm,xim,xwd,xwin,yeeface]
  119. yes
  120. | ?- 
  121. */
  122.  
  123. /* PBMPLUS */
  124. /*
  125. Jef Poskanzer -- jef@well.sf.ca.us
  126. */
  127.     
  128. fconvert(gif,ppm,giftoppm).
  129. fconvert(ilbm,ppm,ilbmtoppm).
  130. fconvert(imgwhatnot,ppm,imgtoppm).
  131. fconvert(mtv,ppm,mtvtoppm).
  132. fconvert(qrt,ppm,qrttoppm).
  133. fconvert(sunraster,ppm,rasttoppm).
  134. fconvert(targa,ppm,tgatoppm).
  135. fconvert(xwd,ppm,xwdtoppm).
  136.  
  137. fconvert(ppm,gif,ppmtogif).
  138. fconvert(ppm,ilbm,ppmtoilbm).
  139. fconvert(ppm,pgm,ppmtopgm).
  140. fconvert(ppm,eps,ppmtops).
  141. fconvert(ppm,sunraster,ppmtorast).
  142. fconvert(ppm,xwd,ppmtoxwd).
  143.  
  144. /* Pbmplus tools can read "lesser" formats */
  145. fconvert(pbm, X, Y) :- fconvert(pgm, X, Y).
  146. fconvert(pgm, X, Y) :- fconvert(ppm, X, Y).
  147.  
  148. toolread(gif, gif2ras).
  149. toolwrite(sunraster, gif2ras).
  150.  
  151. fconvert(X, Y, Z) :-
  152.     X \== Y,
  153.     toolread(X, Z), toolwrite(Y, Z).
  154. conv(X, Y, [Z], W) :-
  155.     X \== Y,
  156.     fconvert(X, Y, Z).
  157. conv(FROM, TO, [TOOL | PROGS], VISITED) :-
  158.     FROM \== TO,
  159.     fconvert(FROM, IF, TOOL),
  160.     not $member2(IF, VISITED),
  161.     conv(IF, TO, PROGS, [ IF | VISITED]),
  162.     not $member2(TOOL, PROGS).
  163. conversions(FROM, TO, CONVS) :- setof(Z,conv(FROM,TO,Z,[FROM]), CONVS).
  164.  
  165. tools(S) :- setof(Z,[X, Y]^fconvert(X,Y,Z),S).
  166. readformats(S) :- setof(Z,[X, Y]^fconvert(Z,Y,X),S).
  167. writeformats(S) :- setof(Z,[X, Y]^fconvert(X,Z,Y),S).
  168.