home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / wb / picticon / source / shovecolors.e < prev    next >
Text File  |  1994-12-04  |  4KB  |  206 lines

  1. MODULE 'exec/memory',
  2.              'intuition/intuition','intuition/screens','intuition/gadgetclass',
  3.              'intuition/screens',
  4.              'graphics/rastport','graphics/gfx','graphics/text',
  5.              'graphics/view',
  6.              'libraries/iffparse','iffparse',
  7.              'dos/dos','dos/dosextens','dos/dosasl','exec/tasks'
  8.  
  9.     OBJECT bitmapheader
  10.         w:INT;h:INT;x:INT;y:INT
  11.         depth:CHAR;masking:CHAR
  12.         compression:CHAR;pad1:CHAR;transparentcolor:INT
  13.         xaspect:CHAR;yaspect:CHAR;pagewidth:INT;pageheight:INT
  14.     ENDOBJECT
  15.     DEF source[250]:STRING
  16.     DEF argarray[11]:LIST
  17.     DEF    iff=NIL:PTR TO iffhandle
  18.     DEF cn=NIL:PTR TO contextnode
  19.     DEF    ierror,rlen
  20.     DEF    des=NIL:PTR TO rastport
  21.     DEF bmhd=NIL:PTR TO bitmapheader
  22.     DEF sp=NIL:PTR TO storedproperty
  23.     DEF planedata[10]:LIST
  24.     DEF widthbytes,pokeplane,body,origbody,numbytes
  25.     DEF ditz,dang,dumb,dope
  26.     DEF destrgb[260]:LIST
  27.     DEF vp=NIL:PTR TO viewport
  28.     DEF cm,clipx,clipy
  29.     DEF depth,iffdepth,nc,nci,scratch
  30.     DEF rdarg
  31.     DEF viewport=NIL:PTR TO viewport
  32.     DEF scr=NIL:PTR TO screen
  33.     DEF bitmap=NIL:PTR TO bitmap
  34.     DEF quiet=FALSE
  35.     DEF lock[260]:LIST
  36.     DEF lockmode=0 /* 0 means don't lock unless in palette*/
  37.     DEF force=0    /* 0 means don't override already locked pens! */
  38. PROC main() HANDLE
  39.     IF KickVersion(39)=NIL
  40.         WriteF('\nGet OS3.x (maybe a nice A1200?)\n')
  41.         CleanUp(21)
  42.     ENDIF
  43.  
  44.     iffparsebase:=OpenLibrary('iffparse.library',39)
  45.  
  46.     rdarg:=ReadArgs('FILE/A,QUIET=Q/S,FORCE=F/S,LOCKALL=LA/S',argarray,0)
  47.     IF rdarg>0
  48.         IF argarray[0]<>NIL
  49.             StrCopy(source,argarray[0],ALL)
  50.         ENDIF
  51.         IF argarray[1]<>NIL
  52.             quiet:=TRUE
  53.         ENDIF
  54.         IF argarray[2]<>NIL
  55.             force:=TRUE
  56.         ENDIF
  57.         IF argarray[3]<>NIL
  58.             lockmode:=TRUE
  59.         ENDIF
  60.         FreeArgs(rdarg)
  61.     ELSE
  62.         Raise(1)
  63.     ENDIF
  64.     IF (scr := LockPubScreen(NIL)) = NIL
  65.         Raise(1)
  66.     ELSE
  67.         bitmap:=scr.bitmap
  68.         viewport:=scr.viewport
  69.         depth:=bitmap.depth
  70.         cm:=viewport.colormap
  71.     ENDIF
  72.  
  73.     iff:=AllocIFF()
  74.     
  75.     iff.stream:=Open(source,MODE_OLDFILE)
  76.     IF (iff.stream)
  77.         InitIFFasDOS(iff)
  78.     ELSE
  79.         Raise(1)
  80.     ENDIF
  81.  
  82.     ierror:=OpenIFF(iff,IFFF_READ)
  83.     ierror:=PropChunk(iff,"ILBM","LOCK")
  84.     ierror:=PropChunk(iff,"ILBM","CMAP")
  85.     ierror:=StopOnExit(iff,"ILBM","FORM")
  86.     ierror:=ParseIFF(iff,IFFPARSE_SCAN)
  87.  
  88.     IF(sp:=FindProp(iff,"ILBM","LOCK"))
  89.         body:=sp.data
  90.         FOR scratch:=0 TO (sp.size-1)
  91.             ditz:=Char(body++)
  92.             IF lockmode=0
  93.                 lockpen(scratch,ditz)
  94.             ELSE
  95.                 lockpen(scratch,1)
  96.             ENDIF
  97.         ENDFOR
  98.     ENDIF
  99.     IF(sp:=FindProp(iff,"ILBM","CMAP"))
  100.         body:=sp.data
  101.         FOR scratch:=0 TO (sp.size/3)-1
  102.             ditz:=Char(body++)
  103.             dang:=Char(body++)
  104.             dumb:=Char(body++)
  105.             IF (scratch<(Shl(1,depth)))
  106.                 IF lock[scratch]=FALSE
  107.                     setrgb32(viewport,scratch,ditz,dang,dumb)
  108.                 ENDIF
  109.                 IF force
  110.                     setrgb32(viewport,scratch,ditz,dang,dumb)
  111.                 ENDIF
  112.             ENDIF
  113.         ENDFOR
  114.     ELSE
  115.         Raise(1)
  116.     ENDIF
  117.     Raise(0)
  118. EXCEPT
  119.     IF scr THEN UnlockPubScreen(0,scr)
  120.     IF (iff)
  121.         CloseIFF(iff)
  122.         IF (iff.stream) THEN Close(iff.stream)
  123.         FreeIFF(iff)
  124.     ENDIF
  125.     IF iffparsebase THEN CloseLibrary(iffparsebase)
  126.     IF ((exception) AND (quiet=FALSE)) THEN WriteF('ShoveColors Failed.\n')
  127. ENDPROC
  128.  
  129. PROC getrgb32(cm,fc,nc,tab)
  130.     DEF ret
  131.     MOVE.L cm,A0
  132.     MOVE.L fc,D0
  133.     MOVE.L nc,D1
  134.     MOVE.L tab,A1
  135.     MOVE.L gfxbase,A6
  136.     JSR    -$384(A6)
  137.     MOVE.L D0,ret
  138. ENDPROC ret
  139.  
  140. PROC setrgb32(vp,pen,red,green,blue)
  141.     MOVE.L vp,A0
  142.   MOVE.L pen,D0
  143.   MOVE.L red,D1
  144.   SWAP   D1
  145.   LSL.L  #8,D1
  146.   MOVE.L green,D2
  147.   SWAP   D2
  148.   LSL.L  #8,D2
  149.   MOVE.L blue,D3
  150.   SWAP   D3
  151.   LSL.L  #8,D3
  152.   MOVE.L gfxbase,A6
  153.   JSR    -$354(A6)
  154. ENDPROC
  155.  
  156. PROC obtainpen(cm,n,r,g,b,f)
  157.     DEF ret
  158.     MOVE.L gfxbase,A6
  159.     MOVE.L n,D0
  160.   MOVE.L r,D1
  161.   SWAP   D1
  162.   LSL.L  #8,D1
  163.   MOVE.L g,D2
  164.   SWAP   D2
  165.   LSL.L  #8,D2
  166.   MOVE.L b,D3
  167.   SWAP   D3
  168.   LSL.L  #8,D3
  169.     MOVE.L cm,A0
  170.     MOVE.L f,D4
  171.     JSR    -$3BA(A6)
  172.     MOVE.L D0,ret
  173. ENDPROC ret
  174.  
  175. PROC releasepen(cm,n)
  176.     MOVE.L cm,A0
  177.     MOVE.L n,D0
  178.     MOVE.L gfxbase,A6
  179.     JSR    -$3B4(A6)
  180. ENDPROC
  181.  
  182. PROC lockpen(pn,mode)
  183.  
  184.     DEF cmtable,red,green,blue,dummy
  185.  
  186.     cmtable:=[0,0,0,0,0,0]:LONG
  187.     getrgb32(cm,pn,1,cmtable)
  188.     red:=Char(cmtable)
  189.     green:=Char(cmtable+4)
  190.     blue:=Char(cmtable+8)
  191.  
  192.     dummy:=obtainpen(cm,pn,red,green,blue,0)
  193.  
  194.     IF dummy<0
  195.         lock[pn]:=TRUE /* Pen was unavailable, so DON'T release/change! */
  196.     ELSE
  197.         IF (mode=0) /* Was able to lock, but it needs to be *free* */
  198.             releasepen(cm,pn)
  199.         ENDIF
  200.         lock[pn]:=FALSE
  201.     ENDIF
  202. ENDPROC
  203.  
  204. versionstring:
  205. CHAR '\0$VER: shovecolors 0.3 (4.7.94)\0'
  206.