The Separation of Pixmap and Image

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Separation of Pixmap and Image

Runar Jordahl
I always find the separation of Smalltalk.Graphics.Image and
Smalltalk.Graphics.Pixmap a bit strange. I guess images are to be used
for storing graphic obtained from external sources, while pixmaps are
what you "paint" at. I usually create a pixmap to draw on, use its
graphics context to make basic shapes and copy images into it. Finally
the pixmap is displayed to the user.

One difference between Image and Pixmap is that only Pixmap can answer
a graphics context, so it is only on a Pixmap you can draw basic
shapes like lines and circles. As far as I can see, you basically have
to use pixmaps for drawing on. It becomes impractical to only use
images.

Another difference is that a Pixmap seems to always have the depth of
the graphics card. This is not the case for Image. Even on a 256 color
display I can create and manipulate a true color Image:
(Image extent: (10@10) depth: 32 palette: FixedPalette rgb8Bit)

But if I try to convert the Image to a Pixmap using the statement
below, and then look at its depth, the depth is changed to whatever my
screen has:
(Image extent: (10@10) depth: 32 palette: FixedPalette rgb8Bit)
asRetainedMedium depth

From what I can understand, this means that if you spit out Pixmaps
from a web server image, you need to ensure the graphic card is
properly set up in order to get true color images. Shouldn't I be able
to draw graphical objects (like lines and boxes) in whatever color
system I want, regardless of the graphic card on the PC?

Another annoyance is reading and storing a single pixel value (or a
color value) on a Pixmap. Below is an example where the first line
creates a Pixmap, and the second line reads the value for pixel 0@0.
It should not need to involve this amount of work!

(((Pixmap extent: 10@10)
        contentsOfArea: (0@0 extent: 1@1)) at: 1) atPoint: 0@0



I guess what I really want is a GraphicsContext for
Smalltalk.Graphics.Image. Then I could draw shapes on a bitmap of the
depth I specify. I could access individual pixels, and at the end send
the result to the screen or a file.

Runar Jordahl