|
Class: XPMReader
Object
|
+--ImageReader
|
+--XPMReader
- Package:
- stx:libview2
- Category:
- Graphics-Images-Readers
- Version:
- rev:
1.79
date: 2023/05/03 16:26:51
- user: stefan
- file: XPMReader.st directory: libview2
- module: stx stc-classLibrary: libview2
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.
copyrightCOPYRIGHT (c) 1994 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
class initialization
-
initialize
-
tell Image-class, that a new fileReader is present
for the '.xpm' and '.pm' extensions.
testing
-
canRepresent: anImage
-
return true, if anImage can be represented in my file format.
Currently only images with less than 80 colors are supported.
-
isValidImageStream: inStream
-
return true, if inStream possibly contains a XPM image.
The stream is left open and position undefined afterwards
private-reading
-
colorNameFrom: aStream
-
read either a color-name or value specified in X-notation
(#rrggbb where rr, gg and bb are 2-digit hex numbers)
-
readColorMap: colorMapSize
-
skip quote
private-writing
-
colorNameOf: aColor
-
generate a name for a color. If it's a standard color,
return its name; otherwise return the hex representation.
reading
-
readImage
-
read an XPM-image from my inStream. Return the receiver
(with all relevant instance variables set for the image)
writing
-
save: image onFile: aFilenameOrFilenameString
-
save image as XPM file on aFileName.
Caveat: currently, only a maximum of roughly 50 colors is handled
(i.e. very simple images)
-
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)
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
|
|