home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / timwin.zip / TIMWIN2.EXE / pak / COLUNIV.CMD < prev    next >
OS/2 REXX Batch file  |  1992-08-05  |  3KB  |  120 lines

  1. ;coluniv  --  universal colour image
  2. ; Usage:
  3. ;        *coluniv <dest.im> <basename> #red #green #blue
  4. ; dest.im.   image to put the result in
  5. ; basename   basename of colour image on disk, e.g. baboo
  6. ; #red, etc. number of levels per colour (e.g. 6, 7, 6)
  7. ;
  8. ; Expects: 
  9. ;   3 images on disk: <basename>r, <basename>g and <basename>b
  10. ;
  11. #define DITHER    1
  12. parms
  13.   file destim         ;1st. param: destination image
  14.   string target       ;2nd. param: basename of colour image (e.g. baboon)
  15.   int nred            ;number of levels for red
  16.   int ngreen          ;idem green
  17.   int nblue           ;idem blue
  18. endparms
  19. char tmp[100]         ;character array to assemble file names
  20. file img              ;image variable
  21. file klad = "a"       ;klad-image
  22. int colmode = PIX8    ;default colour mode
  23.  
  24. if (nred*ngreen*nblue) > 256
  25.   if ((((improp destim) & PIXMASK) == PIX12) || (((improp destim) & PIXMASK) == PIX16))
  26.     colmode = PIX12
  27.   else
  28.      print "Product of colour levels must be < 256"
  29.      stop 1
  30.   endif
  31. endif
  32.  
  33. if (nred == 1) || (ngreen == 1) || (nblue == 1)
  34.  colmode = DITHER
  35. endif
  36.  
  37. if ((improp destim) & DIS_BIT) == DIS_BIT
  38.   switch colmode
  39.     case DITHER
  40.       lut 2 6 5 6
  41.     case PIX12
  42.       lut 2 1 110 16 16 16
  43.     case PIX8
  44.       lut 2 6 10 nred ngreen nblue 
  45.   endsw
  46. elseif ((improp destim) & WIN_BIT) == WIN_BIT
  47.   switch colmode
  48.     case DITHER
  49.       lut 3 1 5 6
  50.     case PIX8
  51.       lut 3 1 10 nred ngreen nblue
  52.     default
  53.       call error
  54.   endsw
  55. else
  56.   print "ILLEGAL IMAGE SPECIFIED"
  57.   beep
  58.   stop 1
  59. endif
  60.  
  61. dest klad                         ;tmp
  62. fprint tmp 0 "%s%s" target, "b"
  63. img = tmp
  64.  
  65. switch colmode       ;BLUE
  66.   case DITHER
  67.     dot img 
  68.     keep 8           ;keep the most significant bitplane
  69.   case PIX8
  70.     mul img nblue    ;get blue img, scale to 'nblue' levels
  71.   case PIX12
  72.     shr img 4        ;shifting down the 4 upper bitplanes into the lower
  73. endsw
  74. copy klad destim     ;the blue image is the lowest
  75.  
  76. fprint tmp 0 "%s%s" target, "g"
  77. img = tmp
  78.  
  79. switch colmode        ;GREEN
  80.   case DITHER
  81.     dot img
  82.     keep 7
  83.   case PIX8
  84.     mul img ngreen       ;get green img, scale to 'ngreen' levels
  85.     mul (nblue*256)      ;green is on to of blue
  86.   case PIX12
  87.     and img 0xf0         ;keep the 4 upper biplanes
  88. endsw
  89. ;add klad destim >destim
  90. add klad destim
  91. save destim
  92.  
  93. fprint tmp 0 "%s%s" target, "r"
  94. img = tmp
  95.  
  96. switch colmode            ;RED
  97.   case DITHER
  98.     dot img
  99.     keep 6
  100.     dest destim
  101.     add klad destim
  102.   case PIX8
  103.     mul img nred         ;get red img, scale to 'nred' levels
  104.     mul (nblue*ngreen*256) ;red is on top of blue and green
  105.     dest destim
  106.     add klad destim
  107.   case PIX12
  108.     shr img 4
  109.     ovl destim 2
  110.     save destim
  111.     ovl destim 0    
  112. endsw
  113.  
  114. stop 0
  115.  
  116. error:
  117.    beep
  118.    print "Illegal parameter combination"
  119. return
  120.