home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 2 / agavol2.iso / software / utilities / icon_tools / iconian296 / sources / mwb2ni.e < prev    next >
Text File  |  1995-07-11  |  10KB  |  360 lines

  1. /*
  2.  
  3. mwb2ni -- Converts an old icon (8-color magicwb) to the "newicon" format
  4.  
  5. Written by Chad Randall -- Broken Spork Technologies, mbissaymssiK Software
  6.  
  7.   INTERNET:crandall@garnet.msen.com
  8.     USNAIL:229 S.Washington St
  9.            Manchester, Michigan  48158-9680
  10.  
  11. Check out Iconian 3, Picticon, PlayKiSS, and randomcopy for other of my works.
  12.  
  13.  
  14. We are the damned of all the world
  15. With sadness in our hearts
  16. The wounded of the wars
  17. We've been hung out to dry
  18. You didn't want us anyway
  19. And now we're making up our minds
  20. You tell us how to run our lives
  21. We run for Youthanasia        -- Mustaine
  22. */
  23.  
  24. MODULE 'dos/dos','dos/dosextens','dos/dosasl','exec/tasks'
  25. MODULE 'newicon','libraries/newicon'
  26. MODULE 'exec/nodes','exec/ports','exec/types','exec/memory',
  27.        'intuition/intuition','intuition/screens','intuition/gadgetclass',
  28.        'intuition/screens',
  29.              'graphics/rastport','graphics/gfx','graphics/text',
  30.        'graphics/view','graphics/gfxbase','workbench/workbench',
  31.        'wb','icon','graphics/clip'
  32.  
  33. DEF noisy=TRUE
  34. DEF ctrlc=FALSE
  35. DEF rdarg
  36. DEF argarray[11]:LIST
  37. DEF source[500]:STRING
  38. DEF array[25]:LIST
  39. DEF    filename[750]:STRING,filestart,pathlen
  40. DEF fh1,fh2,fh3,res,t,names:PTR TO LONG
  41. DEF re[18]:LIST,gr[18]:LIST,bl[18]:LIST,lc=0,toomany=0
  42. DEF red,grn,blu
  43. DEF buffer
  44. DEF scr=NIL:PTR TO screen
  45. DEF x,y,w,h,nw
  46. DEF long
  47. DEF offset=4
  48. DEF r1,g1,b1,r2,g2,b2
  49. DEF res1,res2
  50. DEF apath=NIL:PTR TO anchorpath
  51. DEF backup=FALSE
  52. DEF bitmap=NIL:PTR TO bitmap,rast=NIL:PTR TO rastport
  53. DEF makedot=FALSE
  54. DEF force=FALSE
  55. DEF default=FALSE
  56.  
  57. PROC dosearch(str)
  58.     DEF fileinfo=NIL:PTR TO fileinfoblock
  59.     DEF    achain=NIL:PTR TO achain
  60.     DEF err=0,pathlen,filestart,first=0,chance=1
  61.     DEF    newdate=NIL:PTR TO datestamp
  62.     DEF dirlist[1000]:LIST,ctr=0
  63.     DEF ii
  64.     DEF lock=0
  65.  
  66.  
  67.     FOR ii:=0 TO 999
  68.         dirlist[ii]:=0
  69.     ENDFOR
  70.     apath:=New(SIZEOF anchorpath)
  71.  
  72.     WHILE err=NIL
  73.         IF first=FALSE
  74.             err:=MatchFirst(str,apath)
  75.             first:=TRUE
  76.         ELSE
  77.             err:=MatchNext(apath)
  78.         ENDIF
  79.         IF err=NIL
  80.             achain:=apath.last
  81.             IF (achain)
  82.                 fileinfo:=achain.info
  83.                 IF (fileinfo)
  84.                     IF (fileinfo.direntrytype)<0
  85.                         filestart:=FilePart(str)
  86.                         pathlen:=filestart-str
  87.                         IF (pathlen)
  88.                             StrCopy(filename,str,pathlen)
  89.                         ELSE
  90.                             StrCopy(filename,'',ALL)
  91.                         ENDIF
  92.                         AddPart(filename,fileinfo.filename,740)
  93.                         IF ctr<950
  94.                             dirlist[ctr]:=String(StrLen(filename)+7)
  95.                             StrCopy(dirlist[ctr],filename,ALL)
  96.                             ctr:=ctr+1
  97.                         ENDIF
  98.                     ENDIF
  99.                 ENDIF
  100.             ENDIF
  101.         ENDIF
  102.     ENDWHILE
  103.     IF apath THEN MatchEnd(apath)
  104.     IF apath THEN Dispose(apath);apath:=NIL
  105.  
  106.     FOR ii:=0 TO 999
  107.         IF (dirlist[ii]>0)
  108.             doconvert(dirlist[ii])
  109.             IF CtrlC();ii:=505;ctrlc:=TRUE;ENDIF
  110.         ENDIF
  111.     ENDFOR
  112.     FOR ii:=0 TO 999
  113.         IF (dirlist[ii])
  114.             DisposeLink(dirlist[ii])
  115.             dirlist[ii]:=0
  116.         ENDIF
  117.     ENDFOR
  118. ENDPROC
  119.  
  120. PROC doconvert(file)
  121.     DEF string[500]:STRING
  122.     DEF diskobj=NIL:PTR TO diskobject
  123.     DEF newdiskobj=NIL:PTR TO newdiskobject
  124.     DEF ci1=NIL:PTR TO chunkyimage
  125.     DEF ci2=NIL:PTR TO chunkyimage
  126.     DEF cd1=NIL
  127.     DEF cd2=NIL
  128.     DEF col=NIL
  129.     DEF vp=0:PTR TO viewport,colormap=0,depth=2
  130.     DEF red0,grn0,blu0
  131.     DEF red1,grn1,blu1
  132.     DEF red2,grn2,blu2
  133.     DEF red3,grn3,blu3
  134.     DEF red4,grn4,blu4
  135.     DEF red5,grn5,blu5
  136.     DEF red6,grn6,blu6
  137.     DEF red7,grn7,blu7
  138.     DEF oldi1=0,oldi2=0,oldni1=0,oldni2=0,oldw=1,oldh=1
  139.     DEF offs,w,h,i,t,rpix
  140.     DEF gad:PTR TO gadget
  141.     NEW ci1,ci2,rast
  142.     col:=New(1024)
  143.  
  144.     stripinfo(file)
  145.     StrAdd(file,'.info',ALL)
  146.     StrCopy(string,file,ALL)
  147.     UpperStr(string)
  148.     IF InStr(string,'.INFO')>0
  149.         PutChar(file+InStr(string,'.INFO'),0)
  150.         IF (noisy) THEN WriteF('\nConverting "\s"...',file)
  151.         newdiskobj:=GetNewDiskObject(file)
  152.         IF (newdiskobj)
  153.             diskobj:=newdiskobj.ndo_stdobject
  154.             oldni1:=newdiskobj.ndo_normalimage
  155.             oldni2:=newdiskobj.ndo_selectedimage
  156.             IF (((newdiskobj.ndo_normalimage) OR (newdiskobj.ndo_selectedimage)) AND (force=0))
  157.                 IF (noisy) THEN WriteF('already a newicon!')
  158.             ELSE
  159.               gad:=diskobj.gadget::gadget
  160.                 oldi1:=gad.gadgetrender
  161.                 oldi2:=gad.selectrender
  162.               w:=gad.gadgetrender::image.width
  163.               h:=gad.gadgetrender::image.height
  164.               oldw:=w;oldh:=h
  165.               w:=limit(w,1,92)
  166.               h:=limit(h,1,92)
  167.                 bitmap:=AllocBitMap(w+64,h+32,8,BMF_STANDARD OR BMF_CLEAR,NIL)
  168.                 InitRastPort(rast);rast.bitmap:=bitmap
  169.                 IF (bitmap)
  170.                       vp:=scr.viewport;colormap:=vp.colormap
  171.                       depth:=scr.bitmap::bitmap.depth
  172.                       IF (default=0)
  173.                           red0,grn0,blu0:=getrgb(colormap,0)
  174.                           red1,grn1,blu1:=getrgb(colormap,1)
  175.                           red2,grn2,blu2:=getrgb(colormap,2)
  176.                           red3,grn3,blu3:=getrgb(colormap,3)
  177.                           red4,grn4,blu4:=getrgb(colormap,offset+0)
  178.                           red5,grn5,blu5:=getrgb(colormap,offset+1)
  179.                           red6,grn6,blu6:=getrgb(colormap,offset+2)
  180.                           red7,grn7,blu7:=getrgb(colormap,offset+3)
  181.                       ELSE
  182.                             red0:=149;grn0:=149;blu0:=149
  183.                             red1:=000;grn1:=000;blu1:=000
  184.                             red2:=255;grn2:=255;blu2:=255
  185.                             red3:=059;grn3:=103;blu3:=162
  186.                             red4:=123;grn4:=123;blu4:=123
  187.                             red5:=175;grn5:=175;blu5:=175
  188.                             red6:=170;grn6:=144;blu6:=124
  189.                             red7:=255;grn7:=169;blu7:=151
  190.                       ENDIF
  191.                       PutChar(col+0,red0)
  192.                          PutChar(col+1,grn0)
  193.                       PutChar(col+2,blu0)
  194.                       PutChar(col+3,red1)
  195.                       PutChar(col+4,grn1)
  196.                       PutChar(col+5,blu1)
  197.                       PutChar(col+6,red2)
  198.                       PutChar(col+7,grn2)
  199.                       PutChar(col+8,blu2)
  200.                       PutChar(col+9,red3)
  201.                       PutChar(col+10,grn3)
  202.                       PutChar(col+11,blu3)
  203.                       PutChar(col+12,red4)
  204.                       PutChar(col+13,grn4)
  205.                       PutChar(col+14,blu4)
  206.                       PutChar(col+15,red5)
  207.                       PutChar(col+16,grn5)
  208.                       PutChar(col+17,blu5)
  209.                       PutChar(col+18,red6)
  210.                       PutChar(col+19,grn6)
  211.                       PutChar(col+20,blu6)
  212.                       PutChar(col+21,red7)
  213.                       PutChar(col+22,grn7)
  214.                       PutChar(col+23,blu7)
  215.  
  216.                       newdiskobj.ndo_normalimage:=ci1
  217.                       DrawImage(rast,diskobj.gadget::gadget.gadgetrender,0,0)
  218.                       cd1:=New(w*h)
  219.                       FOR t:=0 TO h-1
  220.                           FOR i:=0 TO w-1
  221.                               rpix:=ReadPixel(rast,i,t)
  222.                               IF rpix>3
  223.                                   rpix:=limit(rpix-offset+4,4,7)
  224.                               ENDIF
  225.                               PutChar(cd1+i+(t*w),rpix)
  226.                           ENDFOR
  227.                       ENDFOR
  228.                       IF (diskobj.gadget::gadget.selectrender)
  229.                           newdiskobj.ndo_selectedimage:=ci2
  230.                           DrawImage(rast,diskobj.gadget::gadget.selectrender,0,0)
  231.                           cd2:=New(w*h)
  232.                           FOR t:=0 TO h-1
  233.                               FOR i:=0 TO w-1
  234.                                   rpix:=ReadPixel(rast,i,t)
  235.                                   IF rpix>3
  236.                                       rpix:=limit(rpix-offset+4,4,7)
  237.                                   ENDIF
  238.                                   PutChar(cd2+i+(t*w),rpix)
  239.                               ENDFOR
  240.                           ENDFOR
  241.                       ENDIF
  242.                       ci1.width:=w
  243.                       ci1.height:=h
  244.                       ci1.numcolors:=8
  245.                       ci1.flags:=0
  246.                       ci1.palette:=col
  247.                       ci1.chunkydata:=cd1
  248.                       ci2.width:=w
  249.                       ci2.height:=h
  250.                       ci2.numcolors:=8
  251.                       ci2.flags:=0
  252.                       ci2.palette:=col
  253.                       ci2.chunkydata:=cd2
  254.                         IF (makedot)
  255.                             PutLong({fillim},{image})
  256.                             gad.gadgetrender:={oldimage}
  257.                             gad.selectrender:=0
  258.                             gad.width:=1
  259.                             gad.height:=1
  260.                         ENDIF
  261.                       IF (PutNewDiskObject(file,newdiskobj))=0;IF (noisy) THEN WriteF('Failed!');ELSE;IF (noisy) THEN WriteF('Saved.');ENDIF
  262.                         Delay(5)
  263.                       IF cd1 THEN Dispose(cd1)
  264.                       IF cd2 THEN Dispose(cd2)
  265.                   FreeBitMap(bitmap)
  266.                 ELSE
  267.                     IF (noisy) THEN WriteF('couldn\at allocate bitmap!')
  268.                 ENDIF
  269.                 gad.gadgetrender:=oldi1
  270.                 gad.selectrender:=oldi2
  271.                 gad.width:=oldw
  272.                 gad.height:=oldh
  273.             ENDIF
  274.             newdiskobj.ndo_normalimage:=oldni1
  275.             newdiskobj.ndo_selectedimage:=oldni2
  276.             FreeNewDiskObject(newdiskobj)
  277.         ELSE
  278.             IF (noisy) THEN WriteF('couldn\at open diskobj!')
  279.         ENDIF
  280.     ENDIF
  281.     END ci1,ci2,rast
  282.     Dispose(col)
  283. ENDPROC
  284.  
  285. PROC getrgb(cm,pn)
  286.     DEF buf
  287.     buf:=[0,0,0,0,0,0,0,0]
  288.     GetRGB32(cm,pn,1,buf)
  289.     RETURN Long(buf),Long(buf+4),Long(buf+8)
  290. ENDPROC
  291.  
  292. PROC main() HANDLE
  293.     newiconbase:=OpenLibrary('newicon.library',37)
  294.     IF (newiconbase)
  295.       IF ((scr:=LockPubScreen('Workbench')))
  296.             argarray[0]:=0
  297.             argarray[1]:=0
  298.             argarray[2]:=0
  299.             argarray[3]:=0
  300.             argarray[4]:=0
  301.             argarray[5]:=0
  302.             argarray[6]:=0
  303.             rdarg:=ReadArgs('FROM/A/M,O=OFFSET/N/K,BAK=BACKUP/S,DOT=CLEAROLD/S,REDO/S,D=DEFAULT/S,Q=QUIET/S',argarray,0)
  304.             IF argarray[0]=NIL THEN Raise("HELP")
  305.             IF argarray[2] THEN backup:=TRUE
  306.             IF argarray[3] THEN makedot:=TRUE
  307.             IF argarray[4] THEN force:=TRUE
  308.             IF argarray[5] THEN default:=TRUE
  309.             IF argarray[6];noisy:=FALSE;ENDIF
  310.             IF argarray[1];offset:=argarray[1];offset:=limit(^offset,0,252);ENDIF
  311.             IF (rdarg<>0)
  312.                 names:=argarray[0]
  313.                 WHILE ((names[0]))
  314.                     IF (noisy) THEN WriteF('\nScanning "\s"',names[0])
  315.                     dosearch(names[]++)
  316.                     IF CtrlC();ctrlc:=TRUE;ENDIF
  317.                 EXIT (ctrlc<>0)
  318.                 ENDWHILE
  319.             ENDIF
  320.             UnlockPubScreen(0,scr);scr:=0
  321.       ELSE
  322.           IF (noisy) THEN WriteF('couldn\at lock Workbench!')
  323.         ENDIF
  324.     ENDIF
  325. EXCEPT DO
  326.     IF (noisy) THEN WriteF('\n')
  327.     IF (scr) THEN UnlockPubScreen(0,scr)
  328.     IF apath THEN MatchEnd(apath)
  329.     IF apath THEN Dispose(apath);apath:=NIL
  330.     IF buffer THEN Dispose(buffer)
  331.     IF exception="HELP" THEN IF (noisy) THEN WriteF('Usage: mwb2ni FROM/A/M,O=OFFSET/N/K,BAK=BACKUP/S,DOT=CLEAROLD/S,REDO/S,D=DEFAULT/S\n')
  332.     IF exception="DOS" THEN IF (noisy) THEN WriteF('An error occured.\n\n')
  333. ENDPROC
  334.  
  335. PROC bigger(a,max) IS IF (a<max) THEN max ELSE a
  336. PROC smaller(a,min) IS IF (a>min) THEN min ELSE a
  337. PROC limit(a,min,max) IS smaller(bigger(a,min),max)
  338. PROC stripinfo(name)
  339.     DEF comp1[6]:STRING,comp2[6]:STRING
  340.     StrCopy(comp1,'.INFO',ALL)
  341.     MidStr(comp2,name,StrLen(name)-5,5)
  342.     UpperStr(comp2)
  343.     IF StrCmp(comp1,comp2,5)
  344.         MidStr(name,name,0,(StrLen(name)-5))
  345.     ENDIF
  346. ENDPROC
  347.  
  348. oldimage:
  349.     INT 0,0,1,1,1
  350. fillim:
  351.     LONG 0    ->FILL ME
  352.     CHAR 1,0
  353.     LONG 0
  354.  
  355. image:
  356.     LONG $FFFF
  357.  
  358. version:
  359.     CHAR    '\0$VER: mwb2ni 0.004 (10.7.95) \tWritten by Chad Randall INTERNET:(crandall@garnet.msen.com)\0'
  360.