什么是pixmap

什么是pixmap(像素图)

pixmap存储并显示了一张图像(image), 存储和显示的方式是一个以像素颜色值为元素的矩形阵列。(术语“pixmap”是“像素(pixel)“和”图”(map)的缩写。)

当pixmap仅使用单色来表示每个像素的颜色(产生单色图像)时,通常称为位图。 位图有时也用于指代任何像素图。

虽然术语“pixmap”通常用于描述实际的像素阵列或它们创建的图像,但 Common Graphics 现在使用该术语来描述用于管理像素图图像的一类对象。

总结起来,pixmap狭义上可以表示屏幕上显示的图像,因为屏幕上的图像就是由一个个不同颜色的像素组成的。广义上pixmap表示管理像素图的对象,其有颜色、长宽高、纹理等属性,用来程序中进行各种各样的变换和处理。

 

应用程序可以使用 Common Graphics pixmap objects(称为像素图)来管理其图像。 可以通过使用 load-pixmap 从 .bmp 文件加载像素图或通过使用 make-instance 形式以编程方式定义它来创建像素图。 定义后,可以通过使用复制到流将其复制到窗口或打印机流来直接使用像素图,也可以通过将其与静态图片、图片按钮或多图片按钮控件关联来间接使用。 (请注意,虽然位图窗格有时被称为具有后备存储像素图或位图,但这实际上是内部对象而不是像素图。)

 

Pixmap Properties

像素图具有以下属性。 虽然可以随时修改像素图属性,但它们通常在创建时指定,因为各种属性必须相互兼容,并且像素图通常是静态对象。 (要使用不同的图像,最好创建一个单独的像素图)

bits-per-pixel Specifies the number of bits that are used to denote each pixel value. Must be either 1, 4, 8, 16, or 24. Must be large enough for the largest pixel value used by the pixmap.
  • 1-bit-per-pixel values are 0 and 1
  • 4-bits-per-pixel values are 0 through 15
  • 8-bits-per-pixel values are 0 through 255
  • 16-bits-per-pixel values are 0 through 65535
  • 24-bits-per-pixel (true color) values are not a single index into a colormap, but instead uses one byte for each of the red, green, and blue components of the color.
colors A vector of RGB color structures that determines the color that will be used for each pixel value. Pixels with the value 0 will use the first color in the color vector, and in general pixels with the value N will use the Nth member of the color vector. The colors vector should contain at least (one more than) as many members as the largest pixel value in the contents list.
contents A list of lists containing the individual pixel values of the pixmap. Each inner list contains the pixels for one row of the pixmap from left to right, and the outer list contains the rows from top to bottom. When pretty-printed, the contents list is oriented as the image will appear, giving a rough idea of what the real thing will look like.
mask-contents An optional property to define part of the pixmap as transparent. If supplied, it is a list of lists that corresponds to the contents list. Each member of the inner lists is either a 1 to indicate that the pixel at that location should be transparent, or a 0 to indicate that the pixel should be the color in the corresponding contents list (or in the texture, if a texture is supplied rather than a contents list).

When a mask is used, the main contents list (or texture) should have a zero for each transparent pixel. Therefore, the first entry in the colors vector of a pixmap that uses a mask will normally be a dummy color that never appears in the image, since index zero is reserved for transparent pixels.

Also note that if a pixmap uses a mask then it should not also use a pixmap-handle, because the "device-dependent bitmap" that the handle points to will not incorporate the mask. This restriction may be removed in the future.

height The height in pixels of the pixmap's texture. Normally this need not be specified, as it is computed automatically from the contents property.
invert-p A flag indicating whether the rows of the contents list are specified from top to bottom or from bottom to top.
  • If invert-p is nil, then the rows of the contents list will be pretty-printed so as to look right-side-up.
  • If invert-p is non-nil, then the pretty-printed contents will look upside down.

Note, though, that the operating system specifies pixmaps from bottom to top, so when invert-p is non-nil, this is actually the most natural orientation from the operating system's point of view, and an "inverted" pixmap will actually be somewhat faster. In addition, pixmaps created by calling load-pixmap will be "inverted" because that is the way that the data is read from the .bmp file most efficiently.

name An arbitrary symbol used for finding the pixmap programmatically. A pixmap may be associated with a control by specifying its name as the pixmap-name property of the control (assuming that the pixmap has been cached).

See Also cache-pixmap

palette-size Normally this is computed automatically from the colors property, but may be specified for backward compatibility as an alternative to the bits-per-pixel property.
  • If specified directly, it should be the maximum number of colors allowed, either 2, 16, 256, or 65536.
  • If computed automatically from the colors property, it is the actual number of colors in the color vector, which may be less than the maximum possible for the bits-per-pixel of the pixmap.

The maximum number of colors allowed is determined by (expt 2 bits-per-pixel). 24-bit (true color) pixmaps do not use a color vector at all.

pixmap-handle The handle to an optional more efficient version of the pixmap which is managed inside the operating system. This property should not be set directly by an application, but instead is set indirectly by calling open-pixmap-handle on the pixmap to create the handle. The handle can be destroyed later by calling close-pixmap-handle on the pixmap.

This property is optional because there is a trade-off to using a pixmap handle. While they draw faster, they essentially double the amount of memory required for the pixmap since the operating system is making its own copy of the pixels that are defined in Lisp for the pixmap. It is a good idea to close pixmap handles that are no longer being used by calling close-pixmap-handle on the pixmaps that had used them.

Sometimes Common Graphics automatically opens a pixmap handle for a pixmap, in particular if it is used by a control (since controls tend to be small enough that we can assume that the extra space is not very significant). A multi-picture-button button-info MUST use a pixmap handle, since its implementation currently depends on that, so the handle should not be removed from a pixmap that is used in a multi-picture-button.

source If this pixmap was created by calling load-pixmap on a .bmp file, then the path namestring will be preserved as the value of the source property. If the pixmap was defined programmatically instead, then the source property will be nil.
texture A texture object that describes each pixel in the pixmap. Typically the pixels are specified with the contents property, but alternatively a texture object may first be created and then specified here. This is most useful for backward compatibility with version 3.0.2, where textures and texture-infos are used individually.
mask An optional second texture object that describes whether or not the pixmap is transparent at each pixel. Typically the mask pixels are specified with the mask-contents property, but alternately a texture object may first be created and then specified here. If supplied, the mask texture's bits-per-pixel must be 1, and the texture should have a 1 for each transparent pixel and a 0 for each non-transparent pixel.
texture-info A structure that internally contains the colorsbits-per-pixelwidth, and height properties of the pixmap.

Provided as a property that is redundant with these other properties, primarily for backward compatibility with version 3.0.2 applications that have created texture-info structures, so that these structures can be specified directly as the texture-info property of a pixmap as an alternative to specifying the other properties separately.

width The width in pixels of the texture-info's texture. Normally this need not be specified, as it is computed automatically from the contents property.

 

Creating a Pixmap Programmatically

An example of a programmatically created pixmap:

(make-instance 'pixmap
  :name :find-debug-prompt
  :bits-per-pixel 4
  :colors (vector black dark-red dark-green
             dark-yellow dark-blue dark-magenta
             dark-cyan light-gray gray red green
             yellow blue magenta cyan white)
  :contents
  '((7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7)
    (7 0 0 7 7 7 7 7 7 7 7 7 7 7 7 7)
    (7 0 0 0 7 7 7 7 7 7 7 7 7 7 7 7)
    (7 7 0 0 0 7 7 7 7 7 7 7 7 7 7 7)
    (7 7 7 0 0 0 7 7 7 7 7 7 7 7 7 7)
    (7 7 7 7 0 0 0 7 7 7 7 7 7 7 7 7)
    (7 7 7 7 7 0 0 0 7 7 7 7 7 7 7 7)
    (7 7 7 7 7 7 0 0 0 7 7 7 7 7 7 7)
    (7 7 7 7 7 0 0 0 7 7 7 7 7 7 7 7)
    (7 7 7 7 0 0 0 7 7 7 7 7 7 7 7 7)
    (7 7 7 0 0 0 7 7 7 7 7 7 7 7 7 7)
    (7 7 0 0 0 7 7 7 7 7 7 7 7 7 7 7)
    (7 0 0 0 7 7 7 7 7 0 0 0 0 0 7 7)
    (7 0 0 7 7 7 7 7 7 0 0 0 0 0 7 7)
    (7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7)
    (7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7)))

 

参考链接

http://ai.eecs.umich.edu/people/dreeves/misc/lispdoc/cg/pixmaps/pixmap.htm

posted @ 2024-02-18 10:57  青山牧云人  阅读(121)  评论(0编辑  收藏  举报