expand8bit.pro 961 Bytes
FUNCTION expand8bit,str,method=method

;Transform given Hexadecimal string from base 16=2^4 to base 256=2^8
;used to transform postcript images from 4 to 8 bits/pixels
;used by fix_ps4ill10.pro
;Note: method=1 is a bit inefficient since string 'afbc10f' is in fact
;converted into 'aaffbbcc1100ff'
;Created JPB 22/12/02

mmethod=1
IF keyword_set(method) THEN mmethod=method

CASE mmethod OF
  1: BEGIN
    hexa=[strtrim(string([0,1,2,3,4,5,6,7,8,9]),2),['a','b','c','d','e','f']]
    base=16
    bbase=256
    len=strlen(str)
    strout=''
    FOR i=0L,len-1 DO BEGIN
      sstr='v=byte('+"'"+strmid(str,i,1)+"'"+'X)'
      toto=execute(sstr)
      vv=(1.*v)/(base-1)*(bbase-1)
      vv1=vv/base
      vv2=vv mod base
      strout=strout+hexa(vv1)+hexa(vv2)
  ;    print,'v=',v,'vv=',vv
    ENDFOR
  END
  2: BEGIN
    strout=''
    FOR i=0L,strlen(str)-1 DO BEGIN
      cc=strmid(str,i,1)
      strout=strout+cc+cc
    ENDFOR
  END
ENDCASE

RETURN,strout

END