A Microsoft® DirectX® surface object, DXSurface, is an abstract image whose pixel data is obtainable in 32-bit ARGB color format, regardless of the underlying pixel representation. Microsoft DirectX Transform uses this data object for both input and output images. DXSurfaces enable you to concentrate on the logical aspects of designing the transform, while letting the supporting software take care of numerous details, such as alpha blending, dithering, and converting among different pixel formats.
You can use DXSurfaces as transform inputs or outputs. However, the power of DXSurfaces and their supporting tools can be used in any Microsoft Windows® graphics application that you create. In many ways, DXSurfaces are easier to use than DirectDrawSurfaces because they always have a known pixel format to use for image manipulation. DXSurfaces enable all the standard, pixel-level access of images, while also exposing generic graphics tools, such as lookup tables and image filters.
The most common ways to construct DXSurfaces are by creating them from image files or by initializing them from DirectDrawSurface objects. A DXSurface also can be a procedural surface, where the sample values are calculated on demand, rather than being stored statically in an array. Because you can represent compressed images as DXSurfaces, they introduce new image compression techniques into the architecture.
This article contains the following sections.
In addition to the advantages of supporting per-pixel alpha, procedural surfaces, and any pixel format and depth, DXSurfaces are the recommended surface for DirectX Transform operations for a number of other reasons.
As previously mentioned, DXSurfaces need to be wrapped on DirectDrawSurfaces before they're passed as parameters to DirectX Transform objects. This occurs so that a DXSurface is always passed to a transform. This means that supplying DXSurfaces directly to DirectX Transform objects will be slightly more efficient than supplying other types of surfaces because the aggregation step is not necessary. Furthermore, if the DXSurface is already in one of two standard pixel formats (ARGB32 or PMARGB32), read and read/write pointers can be obtained to directly access the surface's samples, saving a copy to a buffer.
DXSurfaces also provide additional functionality beyond that of DirectDrawSurfaces by supporting transforms on surfaces containing an alpha channel or a color key.
DXSurface objects are created with the IDXSurfaceFactory interface. This interface exists as a service of the IDXTransformFactory interface, which must be created with the Component Object Model (COM) method CoCreateInstance. Transform users often create the DXTransformFactory (Transform Factory) and use it to obtain a pointer to the DXSurfaceFactory (Surface Factory) and any transform interfaces they need. DXSurface users only need the Surface Factory pointer, which can be obtained by using the following statement.
hr = CoCreateInstance( CLSID_DXTransformFactory, NULL, CLSCTX_INPROC, IID_IDXSurfaceFactory, (void **)&g_pSurfFact );
Multiple DXSurfaces can be created with the IDXSurfaceFactory::CreateSurface method. You can also create DXSurfaces from image files by using the IDXSurfaceFactory::LoadImage method, as shown in the following:
hr = g_pSurfFact->LoadImage( pwcsFileName, NULL, NULL, &DDPF_PMARGB32, IID_IDXSurface, (void**)g_pSurf );
You can use the IDXARGBReadPtr and IDXARGBReadWritePtr interfaces to read or to modify the samples of the surfaces. The helper functions contain routines to combine arrays of samples and to allocate working buffers.
Top of Page
© 2000 Microsoft and/or its suppliers. All rights reserved. Terms of Use.