home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / blabla / programy / brush2e / brush2e.e next >
Encoding:
Text File  |  1998-06-03  |  7.0 KB  |  172 lines

  1. /*
  2. ** This little program can be used to convert an ILBM brush
  3. ** to something that MUI's Bodychunk class can understand.
  4. ** For easy useage, an emodule-source is generated.
  5. **
  6. ** This tool is written by Jan Hendrik Schulz
  7. ** It is based on brush2c by Stefan Stuntz
  8. **
  9. ** A little changes by Tomasz Korolczuk (Tomash/BLABLA)
  10. ** Now works with big IFF brushes.
  11. */
  12.  
  13. OPT PREPROCESS
  14.  
  15. MODULE 'exec/types'
  16. MODULE 'libraries/iffparse'
  17. MODULE 'datatypes/pictureclass'
  18. MODULE 'graphics/gfx'
  19. MODULE 'iffparse'
  20.  
  21.  
  22. #define to32(c) (Shl(c,24) OR Shl(c,16) OR Shl(c,8) OR c)
  23. #define version '$VER: Brush2E 1.01 (03.06.98)'
  24.  
  25. PROC main()
  26.  
  27.   DEF name[100]:STRING,uname[50]:STRING,c
  28.   DEF iff:PTR TO iffhandle
  29.   DEF cn:PTR TO contextnode, cn2:PTR TO contextnode
  30.   DEF sp:PTR TO storedproperty
  31.   DEF bmhd:PTR TO bitmapheader
  32.   DEF body,size,i,cols
  33.   DEF myargs:PTR TO LONG,rdargs
  34.   DEF buf[200]:STRING,colors=TRUE
  35.   DEF outfile
  36.  
  37.   myargs:=[0,0,0]
  38.   IF (rdargs:=ReadArgs('ILBMFILE/A,EMODSRC/A,NOHEADER/S',myargs,NIL))=NIL
  39.     WriteF('Bad Args!\n')
  40.     RETURN 20
  41.   ENDIF
  42.  
  43.   c:=myargs[0]
  44.   IF (i:=InStr(c,':'))<>-1 THEN c:=c+i+1
  45.   WHILE (i:=InStr(c,'/'))<>-1 DO c:=c+i+1
  46.   StrCopy(name,c)
  47.   IF (c:=InStr(name,'.'))<>-1 
  48.     name[c]:=0
  49.     SetStr(name,StrLen(name))
  50.   ENDIF
  51.   StrCopy(uname,name)
  52.   UpperStr(uname)
  53.   IF (name[]>="a") AND (name[]<="z") THEN name[]:=name[]-32
  54.  
  55.   IF iffparsebase:=OpenLibrary('iffparse.library',36)
  56.     IF outfile:=Open(myargs[1],NEWFILE)
  57.       IF iff:=AllocIFF()
  58.         iff.stream:=Open(myargs[0],OLDFILE)
  59.         IF iff.stream
  60.           InitIFFasDOS(iff)
  61.           IF OpenIFF(iff,IFFF_READ)=0
  62.             IF ParseIFF(iff,IFFPARSE_STEP)=0
  63.               IF (cn:=CurrentChunk(iff)) AND (cn.id=ID_FORM)
  64.                 IF cn.type=ID_ILBM
  65.                   IF (PropChunk(iff,ID_ILBM,ID_BMHD) OR
  66.                       PropChunk(iff,ID_ILBM,ID_CMAP) OR
  67.                       StopChunk(iff,ID_ILBM,ID_BODY) OR
  68.                       StopOnExit(iff,ID_ILBM,ID_FORM) OR
  69.                       ParseIFF(iff,IFFPARSE_SCAN))=0
  70.  
  71.                     Fputs(outfile,'-> EModule with imagedatas for MUI - generated by brush2e.\n\n')
  72.                     Fputs(outfile,'OPT MODULE\nOPT EXPORT\nOPT PREPROCESS\n\n')
  73.                     IF Not(myargs[2])
  74.                       Fputs(outfile,'MODULE \adatatypes/pictureclass\a\n')
  75.                     ENDIF
  76.                     Fputs(outfile,'MODULE \amuimaster\a, \alibraries/mui\a\n')
  77.                     Fputs(outfile,'MODULE \autility/tagitem\a\n\n')
  78.                   
  79.                     IF sp:=FindProp(iff,ID_ILBM,ID_BMHD)
  80.                       bmhd := sp.data
  81.  
  82.                       IF (bmhd.compression=CMPNONE) OR (bmhd.compression=CMPBYTERUN1)
  83.                         cn2:=CurrentChunk(iff)
  84.                         size := cn2.size
  85.  
  86.                         IF body:=New(size)
  87.                           IF ReadChunkBytes(iff,body,size)=size
  88.                             PrintF('Width \d Height \d Depth \d - converting...\n',bmhd.width,bmhd.height,bmhd.depth)
  89.  
  90.                             StringF(buf,'CONST IMG_\s_WIDTH       = \d[3]\n',uname,bmhd.width)
  91.                             Fputs(outfile,buf)
  92.                             StringF(buf,'CONST IMG_\s_HEIGHT      = \d[3]\n',uname,bmhd.height)
  93.                             Fputs(outfile,buf)
  94.                             StringF(buf,'CONST IMG_\s_DEPTH       = \d[3]\n',uname,bmhd.depth)
  95.                             Fputs(outfile,buf)
  96.                             StringF(buf,'CONST IMG_\s_COMPRESSION = \d[3]\n',uname,bmhd.compression)
  97.                             Fputs(outfile,buf)
  98.                             StringF(buf,'CONST IMG_\s_MASKING     = \d[3]\n\n',uname,bmhd.masking)
  99.                             Fputs(outfile,buf)
  100.  
  101.  
  102.                             StringF(buf,'PROC img\sObject()\n  DEF object\n object:=BodychunkObject,\n',name); Fputs(outfile,buf)
  103.                             StringF(buf,'    MUIA_Bodychunk_Body,        {img\sbody},\n',name); Fputs(outfile,buf)
  104.                             StringF(buf,'    MUIA_Bodychunk_Masking,     IMG_\s_MASKING,\n',uname); Fputs(outfile,buf)
  105.                             StringF(buf,'    MUIA_Bodychunk_Compression, IMG_\s_COMPRESSION,\n',uname); Fputs(outfile,buf)
  106.                             StringF(buf,'    MUIA_Bodychunk_Depth,       IMG_\s_DEPTH,\n',uname); Fputs(outfile,buf)
  107.                             StringF(buf,'    MUIA_Bitmap_Height,         IMG_\s_HEIGHT,\n',uname); Fputs(outfile,buf)
  108.                             StringF(buf,'    MUIA_Bitmap_Width,          IMG_\s_WIDTH,\n',uname); Fputs(outfile,buf)
  109.                             StringF(buf,'    MUIA_FixHeight,             IMG_\s_HEIGHT,\n',uname); Fputs(outfile,buf)
  110.                             StringF(buf,'    MUIA_FixWidth,              IMG_\s_WIDTH,\n',uname); Fputs(outfile,buf)
  111.                             IF colors
  112.                               StringF(buf,'    MUIA_Bitmap_SourceColors,   img\sColors(),\n',name); Fputs(outfile,buf)
  113.                             ENDIF
  114.                             Fputs(outfile,'  End\n\n')
  115.                             Fputs(outfile,'ENDPROC object\n\n')
  116.  
  117.  
  118.                             IF Not(myargs[2])
  119.                               StringF(buf,'PROC img\sHeader() IS ',name)
  120.                               Fputs(outfile,buf)
  121.                               StringF(buf,'[\d,\d,\d,\d,\d,\d,\d,0,\d,\d,\d,\d,\d]:bitmapheader\n\n',bmhd.width,bmhd.height,bmhd.left,bmhd.top,bmhd.depth,bmhd.masking,bmhd.compression,bmhd.transparent,bmhd.xaspect,bmhd.yaspect,bmhd.pagewidth,bmhd.pageheight)
  122.                               Fputs(outfile,buf)
  123.                             ENDIF
  124.  
  125.                             StringF(buf,'img\sbody:\nCHAR  ',name)
  126.                             Fputs(outfile,buf)
  127.                             FOR i:=0 TO size-2
  128.                               StringF(buf,'$\z\h[2],',body[i])
  129.                               Fputs(outfile,buf)
  130.                               IF Mod(i+1,15)=0 THEN Fputs(outfile,'\n  ')
  131.                             ENDFOR
  132.                             StringF(buf,'$\z\h[2]\n\n',body[size-1])
  133.                             Fputs(outfile,buf)
  134.                           ENDIF
  135.                           Dispose(body)
  136.                         ENDIF
  137.                       ENDIF
  138.                     ENDIF
  139.  
  140.                     IF sp:=FindProp(iff,ID_ILBM,ID_CMAP)
  141.                       cols := sp.data
  142.  
  143.                       StringF(buf,'PROC img\sColors() IS\n [',name)
  144.                       Fputs(outfile,buf)
  145.                       FOR i:=0 TO sp.size-4 STEP 3
  146.                         StringF(buf,'$\z\h[8],$\z\h[8],$\z\h[8],\n  ',to32(cols[i]),to32(cols[i+1]),to32(cols[i+2]))
  147.                         Fputs(outfile,buf)
  148.                       ENDFOR
  149.                       StringF(buf,'$\z\h[8],$\z\h[8],$\z\h[8]]\n\n',to32(cols[i]),to32(cols[i+1]),to32(cols[i+2]))
  150.                       Fputs(outfile,buf)
  151.                       colors:=TRUE
  152.                     ENDIF
  153.  
  154.                   ENDIF
  155.                 ENDIF
  156.               ENDIF
  157.             ENDIF
  158.             CloseIFF(iff)
  159.           ENDIF
  160.           Close(iff.stream)
  161.         ENDIF
  162.         FreeIFF(iff)
  163.       ENDIF
  164.       Close(outfile)
  165.     ENDIF
  166.     CloseLibrary(iffparsebase)
  167.   ENDIF
  168.   FreeArgs(rdargs)
  169. ENDPROC 0
  170.  
  171. CHAR version
  172.