eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'XPMReader':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: XPMReader


Inheritance:

   Object
   |
   +--ImageReader
      |
      +--XPMReader

Package:
stx:libview2
Category:
Graphics-Images-Readers
Version:
rev: 1.70 date: 2017/06/19 17:49:17
user: mawalch
file: XPMReader.st directory: libview2
module: stx stc-classLibrary: libview2

Description:


This class provides methods for loading x-pixmap-file (xpm) images.

These images are used (in X) for palette images 
(see ctwm or hp-vue for a lot of them).
The format is actually a piece of C-code, which can be compiled by the C-compiler
into a constant image data structure.

The code here is a hack - it may not work for all images 
(it works for the testfiles I got here).

Limitations: 
    only reads the full-color specification, ignoring monochrome
    and greyscale info.

    Can only handle single-character index.

    Only understands single-word color names (i.e. names with spaces 
    are not supported)

    Image writing is only supported for images with less than about 200
    colors (single byte encoding). 
    If present, the mask must be a single bit mask (i.e. no alpha channel).
    Due to the algorithm, writing may be slow for big images

Suggestions: adapt & use the XPM library here.


Related information:

    Image
    Form
    Icon
    BlitImageReader
    FaceReader
    GIFReader
    JPEGReader
    PBMReader
    PCXReader
    ST80FormReader
    SunRasterReader
    TargaReader
    TIFFReader
    WindowsIconReader
    XBMReader
    XWDReader

Class protocol:

initialization
o  initialize
tell Image-class, that a new fileReader is present
for the '.xpm' and '.pm' extensions.

testing
o  canRepresent: anImage
return true, if anImage can be represented in my file format.
Currently only images with less than 80 colors are supported.

o  isValidImageFile: aFileName
return true, if aFileName contains an x-bitmap-file image
usage example(s):
     XPMReader isValidImageFile:'fooBar'    
     XPMReader isValidImageFile:'../../goodies/bitmaps/xpmBitmaps/device_images/ljet.xpm'      
     XPMReader isValidImageFile:'bitmaps/gifImages/garfield.gif' 


Instance protocol:

private-reading
o  colorNameFrom: aStream
read either a color-name or value specified in X-notation
(#rrggbb where rr, gg and bb are 2-digit hex numbers)

o  readColorMap: colorMapSize
skip quote

private-writing
o  colorNameOf: aColor
generate a name for a color. If it's a standard color,
return its name; otherwise return the hex representation.

reading
o  readImage
read an XPM-image from my inStream. Return the receiver
(with all relevant instance variables set for the image)

writing
o  save: image onFile: aFileName
save image as XPM file on aFileName.
Caveat: currently, only a maximum of roughly 50 colors is handled
(i.e. very simple images)

o  save: image onStream: aStream
save image as XPM file on aStream.
Caveat: currently, only a maximum of 256 colors is handled
(i.e. very simple images)


Examples:


Reading from a file:
  |image|

  image := Image fromFile:('../../goodies/bitmaps/xpmBitmaps/INFO.xpm').
  image inspect
Saving to a file:
  |image|

  image := Image fromScreen:(0@0 corner:30@30).
  image usedColors size > 256 ifTrue:[
      image := image asDitheredImageUsing:(Color standardDitherColorsForDepth8) depth:8.
  ].
  XPMReader save:image onFile:'/tmp/test.xpm'.
  '/tmp/test.xpm' asFilename contents asString inspect
Or directly into a stream:
  |image stream|

  image := Image fromScreen:(0@0 corner:30@30).
  image usedColors size > 256 ifTrue:[
      image := image asDitheredImageUsing:(Color standardDitherColorsForDepth8) depth:8.
  ].
  stream := WriteStream on:(String new).
  XPMReader save:image onStream:stream.
  stream contents inspect


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Thu, 21 Mar 2019 00:12:02 GMT