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