[alt.sources] [graphics] Format conversion lookup tool written in Prolog -- Request for Data

carlson@lance.tis.llnl.gov (John Carlson) (07/07/90)

Archive-name: rct/05-Jul-90
Original-posting-by: carlson@lance.tis.llnl.gov (John Carlson)
Original-subject: Format conversion lookup tool written in Prolog -- Request for Data
Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)

[Reposted from comp.graphics.
Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]


Here's a start on a Prolog program that looks up how to convert from one format
to another.  I would like to add some more features one of these days.

I have several tools already in my knowledge base.  If you are interested,
let me know, and I will consider publishing the data.

I might turn this into a network/mail service, given demand, etc.

The following is written in SB Prolog v3.1 obtainable via anonymous FTP from
arizona.edu.

John Carlson
carlson@tis.llnl.gov

------------------detach here--------------------------------------------------
/*
Name: RCT
Copyright 1990 University of California Regents

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation.  The University of California makes no
representations about the suitability of this software for any
purpose.  It is provided "as is" without express or implied warranty.

The University of California disclaims all warranties with regard to
this software, including all implied warranties of merchantability and
fitness, in no event shall be the University of California liable for
any special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether in an
action of contract, negligence or other tortious action, arising out of
or in connection with the use or performance of this software.

Author:  John Carlson
E-Mail:  carlson@tis.llnl.gov
*/

/* SB-prolog program to determine list of tools to use to convert from
one format to another. */

/* INSERT */
/*
------------------------------------------------------------------
Usage: fconvert(from_format, to_format, tool).
Purpose: "tool" converts file in "from_format" to "to_format".
Example: fconvert(gif, sunraster, gif2ras).
------------------------------------------------------------------
Usage: toolread(from_format, tool).
Purpose: "tool" converts file in "from_format" to internal structure
Example: toolread(gif, gif2ras).
------------------------------------------------------------------
Usage: toolwrite(to_format, tool).
Purpose: "tool" converts internal structure to "from_format"
Example: toolwrite(sunraster, gif2ras).
*/

/* QUERY */
/*
Usage: conversions(from_format, to_format, convert_tools_lists)
Purpose: Produces a list of lists of tools to apply in order to convert
	from "from_format" to "to_format".
Example: conversions(gif, sunraster, L).
*/

/*
Bugs:
	Should have idea on tool reliability.
	Should be able to query how to get the tool.
	Should encode what harware/OS tool runs on.
*/
/*
Tools and Formats in my knowledge base:

| ?- tools(S).

S = [brushtopbm,cg8gt,cmuwmtopbm,fbm2pod,fbm2tga,fbmtools,fbps,fitstopgm,
fstopgm,g3topbm,gemtopbm,gif2ras,giffer,giftoppm,hipstopgm,icon,icontopbm,
ilbmtoppm,imagestudio,imgtoppm,macptopbm,mgrtopbm,mtvtoppm,pbm2ps,
pbmtoascii,pbmtobbnbg,pbmtocmuwm,pbmtog3,pbmtogo,pbmtoicon,pbmtolj,
pbmtomacp,pbmtomgr,pbmtoptx,pbmtorast,pbmtox10bm,pbmtoxbm,pbmtoxwd,
pcxtopbm,pgmtofits,pgmtopbm,pgmtops,pic2fbm,picio2tiff,picttopbm,pixargt,
ppmtogif,ppmtoilbm,ppmtopgm,ppmtops,ppmtorast,ppmtoxwd,preview,psidtopgm,
pssun,qrt2fbm,qrttoppm,ras2tiff,rasttogif,rasttopbm,rasttoppm,raw2fbm,
rawtopgm,scene,screendump,screenload,sgigt,sgisv,superpaint,targa2fbm,
tgatoppm,tiff2ps,tiff2ras,tifftopgm,xbmtopbm,xgif,ximage,ximtops,ximtorle,
xloadimage,xps,xtoxim,xwd,xwdtopbm,xwdtoppm,xwud,xxim,yap]
yes
| ?- readformats(S).

S = [cmuwm,draw,eps,facesaver,fbm,fits,foto,g3,gem,gif,hdf,hips,ilbm,
imagestudio,imgwhatnot,macpaint,mgr,mtv,nextfb,nextwin,pbm,pcx,pgm,pic,
pict,pixarfb,ppm,ps,qdv,qrt,raw,resid0,riff,scan,sgifb,sunfb,sunicon,
sunraster,superpaint,targa,thunderscan,tiff,xbm,xeroxbrush,xim,xwd,xwin,
yeeface]
yes
| ?- writeformats(S).

S = [ascii,bbnbg,cmuwm,diablo,draw,eps,fbm,fits,g3,gif,graphon,hplj,ilbm,
imagestudio,macpaint,mgr,nextfb,nextwin,pbm,pgm,pict,ppm,printronix,ps,qdv,
resid0,riff,rle,scan,sgifb,sunfb,sunicon,sunraster,superpaint,targa,tiff,
x10bm,xbm,xim,xwd,xwin,yeeface]
yes
| ?- 
*/

/* PBMPLUS */
/*
Jef Poskanzer -- jef@well.sf.ca.us
*/
	
fconvert(gif,ppm,giftoppm).
fconvert(ilbm,ppm,ilbmtoppm).
fconvert(imgwhatnot,ppm,imgtoppm).
fconvert(mtv,ppm,mtvtoppm).
fconvert(qrt,ppm,qrttoppm).
fconvert(sunraster,ppm,rasttoppm).
fconvert(targa,ppm,tgatoppm).
fconvert(xwd,ppm,xwdtoppm).

fconvert(ppm,gif,ppmtogif).
fconvert(ppm,ilbm,ppmtoilbm).
fconvert(ppm,pgm,ppmtopgm).
fconvert(ppm,eps,ppmtops).
fconvert(ppm,sunraster,ppmtorast).
fconvert(ppm,xwd,ppmtoxwd).

/* Pbmplus tools can read "lesser" formats */
fconvert(pbm, X, Y) :- fconvert(pgm, X, Y).
fconvert(pgm, X, Y) :- fconvert(ppm, X, Y).

toolread(gif, gif2ras).
toolwrite(sunraster, gif2ras).

fconvert(X, Y, Z) :-
	X \== Y,
	toolread(X, Z), toolwrite(Y, Z).
conv(X, Y, [Z], W) :-
	X \== Y,
	fconvert(X, Y, Z).
conv(FROM, TO, [TOOL | PROGS], VISITED) :-
	FROM \== TO,
	fconvert(FROM, IF, TOOL),
	not $member2(IF, VISITED),
	conv(IF, TO, PROGS, [ IF | VISITED]),
	not $member2(TOOL, PROGS).
conversions(FROM, TO, CONVS) :- setof(Z,conv(FROM,TO,Z,[FROM]), CONVS).

tools(S) :- setof(Z,[X, Y]^fconvert(X,Y,Z),S).
readformats(S) :- setof(Z,[X, Y]^fconvert(Z,Y,X),S).
writeformats(S) :- setof(Z,[X, Y]^fconvert(X,Z,Y),S).