XPMReader.st
changeset 24 6bc436eb4c4a
parent 22 24b4aff428c0
child 28 8daff0234d2e
equal deleted inserted replaced
23:11c422f6d825 24:6bc436eb4c4a
    18 !
    18 !
    19 
    19 
    20 XPMReader comment:'
    20 XPMReader comment:'
    21 COPYRIGHT (c) 1994 by Claus Gittinger
    21 COPYRIGHT (c) 1994 by Claus Gittinger
    22               All Rights Reserved
    22               All Rights Reserved
       
    23 
       
    24 $Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.2 1994-08-05 01:16:30 claus Exp $
    23 '!
    25 '!
    24 
    26 
    25 !XPMReader class methodsFor:'documentation'!
    27 !XPMReader class methodsFor:'documentation'!
    26 
    28 
    27 copyright
    29 copyright
    38 "
    40 "
    39 !
    41 !
    40 
    42 
    41 version
    43 version
    42 "
    44 "
    43 $Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.1 1994-06-03 00:54:13 claus Exp $
    45 $Header: /cvs/stx/stx/libview2/XPMReader.st,v 1.2 1994-08-05 01:16:30 claus Exp $
    44 "
    46 "
    45 !
    47 !
    46 
    48 
    47 documentation
    49 documentation
    48 "
    50 "
    49     this class provides methods for loading x-pixmap-file (xpm) images.
    51     this class provides methods for loading x-pixmap-file (xpm) images.
    50     These images are used (in X) for palette images (see ctwm or hp-vue for a lot of them).
    52     These images are used (in X) for palette images (see ctwm or hp-vue for a lot
    51     The code here is a hack - it may not work for all images (it works for the testfiles
    53     of them). The code here is a hack - it may not work for all images (it works
    52     I got here).
    54     for the testfiles I got here).
    53     Limitations: only reads the full-color specification, ignoring monochrome
    55     Limitations: 
    54     and greyscale info.
    56         only reads the full-color specification, ignoring monochrome
    55     Can only handle single-character index.
    57         and greyscale info.
    56     Does not (currently) handle none-colors (i.e. for image-masks).
    58 
       
    59         Can only handle single-character index.
       
    60 
       
    61         Does not (currently) handle none-colors (i.e. for image-masks).
       
    62 
       
    63         Save not supported
    57 
    64 
    58     Suggestions: adapt & use the XPM library here.
    65     Suggestions: adapt & use the XPM library here.
    59 "
    66 "
    60 ! !
    67 ! !
    61 
    68 
    91     |s|
    98     |s|
    92 
    99 
    93     aStream peek == $# ifTrue:[
   100     aStream peek == $# ifTrue:[
    94         aStream next.
   101         aStream next.
    95         s := '#'.
   102         s := '#'.
    96         [aStream peek isAlphaNumeric] whileTrue:[
   103     ] ifFalse:[
    97             s := s copyWith:aStream next
   104         s := ''.
    98         ].
   105     ].
    99         ^ s
   106     [aStream peek isAlphaNumeric] whileTrue:[
   100     ].
   107         s := s copyWith:aStream next
   101     ^ aStream upTo:$"
   108     ].
       
   109     ^ s
   102 !
   110 !
   103 
   111 
   104 fromFile:aFileName
   112 fromFile:aFileName
   105     "read an XPM-image from aFileName. return the receiver (with all
   113     "read an XPM-image from aFileName. return the receiver (with all
   106      relevant instance variables set for the image) or nil on error"
   114      relevant instance variables set for the image) or nil on error"
   169         (line notNil and:[line startsWith:'"']) ifFalse:[
   177         (line notNil and:[line startsWith:'"']) ifFalse:[
   170             'XPM: format error (expected color spec)' errorPrintNL.
   178             'XPM: format error (expected color spec)' errorPrintNL.
   171             inStream close.
   179             inStream close.
   172             ^ nil
   180             ^ nil
   173         ].
   181         ].
       
   182 
   174         s := ReadStream on:line.
   183         s := ReadStream on:line.
   175         s next. "skip quote"
   184         s next. "skip quote"
   176         index := s next asciiValue.
   185         index := s next asciiValue.
   177         xlation at:index put:colorIndex - 1.
   186         xlation at:index put:colorIndex - 1.
   178 
   187 
   218                                 s next.
   227                                 s next.
   219                                 s skipSeparators.
   228                                 s skipSeparators.
   220                                 colorName := self colorNameFrom:s.
   229                                 colorName := self colorNameFrom:s.
   221                                 s skipSeparators.
   230                                 s skipSeparators.
   222                             ] ifFalse:[
   231                             ] ifFalse:[
   223                                 'XPM: expected ''c'',''m'',''g'' or ''s''' errorPrintNL.
   232                                 'XPM: format error (expected ''c'',''m'',''g'' or ''s'')' errorPrintNL.
   224                                 s next.
   233                                 inStream close.
       
   234                                 ^ nil
   225                             ].
   235                             ].
   226                         ]
   236                         ]
   227                     ]
   237                     ]
   228                 ]
   238                 ]
   229             ].
   239             ].
   271 
   281 
   272     photometric := #palette.
   282     photometric := #palette.
   273     samplesPerPixel := 1.
   283     samplesPerPixel := 1.
   274     bitsPerSample := Array with:bitsPerPixel.
   284     bitsPerSample := Array with:bitsPerPixel.
   275 
   285 
   276     "XPMReader fromFile:'bitmaps/magtape.xpm'" 
   286     "
   277     "XPMReader fromFile:'bitmaps/pixmap.xpm'" 
   287      XPMReader fromFile:'../fileIn/bitmaps/magtape.xpm' 
   278     "XPMReader fromFile:'bitmaps/ljet.xpm'" 
   288      XPMReader fromFile:'../fileIn/bitmaps/pixmap.xpm' 
       
   289      XPMReader fromFile:'../fileIn/bitmaps/ljet.xpm'
       
   290     " 
   279 ! !
   291 ! !