Method and apparatus for creating and performing graphics operations on device-independent bitmaps

Information

  • Patent Grant
  • 6683618
  • Patent Number
    6,683,618
  • Date Filed
    Tuesday, December 13, 1994
    29 years ago
  • Date Issued
    Tuesday, January 27, 2004
    20 years ago
Abstract
Operating system enhancements that enable an application program to create and perform graphics operations on device-independent bitmaps (DIBs) efficiently. The enhancements are in the form of functions that return to the application program a handle to the DIB and a pointer to the location of the DIB in memory. With the handle, the application program can use the capabilities of the operating system to perform graphics operations on the DIB. With the pointer, the application program can use its own drawing capabilities and address the DIB directly. The operating system enhancements also streamline the design and content of graphics drivers such as display drivers by placing basic graphics functions in a graphics engine that communicates with the graphics driver. Simple graphics operations are passed from the graphics driver to the graphics engine, allowing the driver to be limited to more complex operations that utilize special characteristics of graphics hardware associated with the driver.
Description




FIELD OF THE INVENTION




This invention relates generally to computer graphics. More particularly, this invention relates to method and apparatus for enabling an application program to efficiently draw bitmapped images in a standard format that is independent of the device on which the images are created or displayed. Bitmaps of this format are known as device-independent bitmaps, or DIBs. The invention also relates to method and apparatus for simplifying the design of graphics drivers such as display drivers for displaying such bitmaps.




BACKGROUND OF THE INVENTION




In the field of computer graphics, there are two common ways of storing pictorial information: bitmaps and metafiles. A metafile stores an image as a series of instructions that draw the image, such as instructions to draw a circle, add text, etc. A bitmap, on the other hand, is a complete digital representation of an image. Each pixel in the image corresponds to one or more bits in the bitmap. Monochrome bitmaps require only one bit per pixel; color bitmaps require additional bits to indicate the color of each pixel. Bitmaps can exist in a computer's memory or can be stored on a disk or other storage device as files.




Bitmaps have the advantage over metafiles in the time required to generate an image. Copying a bitmap from memory or storage to a video display is much faster than rendering an image using a metafile. However, bitmaps have a number of drawbacks. They are in many respects device dependent, such as for color and spatial resolutions. For example, displaying a color bitmap on a monochrome display device is often unsatisfactory. And where the spatial resolution of the bitmap (i.e., number of pixels in each row and column of the bitmap) differs from the display device, the displayed bitmap is often distorted.




Recognizing the value of bitmaps and their drawbacks, computer operating systems have been designed to support device-independent bitmaps, or DIBs. Because their format is independent of a particular display device's requirements, DIBs have the advantage over other bitmaps (often referred to as device-dependent bitmaps) in that they may easily be used by other application programs and may be displayed on other display devices. The DIB format is well documented in the literature, such as in


Programming Windows


3.1, available from Microsoft Press. Briefly, a DIB file typically includes a structure with a number of information fields that specify the width and height of the bitmap in pixels, the color bits per pixel and other pertinent information. These fields are followed by a color table if the DIB has 8 or fewer bits per pixel. For bitmaps of a certain number of bits per pixel, the table includes entries that specify the intensity of the red, green and blue color for a pixel. A DIB file concludes with an array of bits that define the particular bitmap image, with a number of bits representing each pixel of the image. The bits representing a particular pixel serve as an index into the color table, thereby specifying the color for the pixel.




However, the present process for enabling an application program to use the DIB format is inefficient. Typically, an application program can presently draw onto a DIB in one of two ways. In the first way, the application program includes special code that allows it to create a DIB in memory and then draw onto a DIB. This approach, while taking full advantage of the application program's drawing capability, has drawbacks. It requires that the code perform all of the graphics routines, even such simple routines as drawing a line or rectangle. These routines are expensive to write and duplicate many of the drawing routines offered by the operating system. In the second way, the application program uses the capability of the computer's operating system for working with DlBs. This second approach is simpler from the viewpoint of the application program, but is more time consuming and more limited in capability than the first approach. With respect to time, the application program must make several calls to the operating system. For example, to draw onto a DIB using the Windows operating environment from Microsoft Corp. of Redmond, Wash., the application program calls a function within Windows to draw onto a device-dependent bitmap, or DDB. The application then calls another function to transfer the DDB into the DIB. With respect to drawing capability, operating systems such as Windows typically have only a few functions for drawing figures. To draw more fanciful figures, the application program must use the first approach.




The first approach may combined with the second approach to minimize the complexity of the application program. The application program then handles drawing of the more difficult shapes and the operating system handles drawing of the simpler shapes such as rectangles, circles, etc. But this combined approach requires even more function calls between the application program and the operating system.




Related to the use of the operating system to draw onto a bitmap is the role of graphics drivers such as display drivers or printer drivers. A graphics driver is a module of code that operates a graphics device such as a display device or printer and includes within it a collection of graphics functions designed to work with a particular graphics device. The operating system calls these graphics functions to interact with a particular graphics device. Typically each graphics device has its own graphics driver, which is written to take advantage of the particular capabilities of the graphics device. When an operating system receives a function call from an application program to perform a drawing operation, the system makes a similar call to a graphics driver. The graphics driver then carries out the graphics operation on the graphics device.




A drawback of present graphics drivers is their duplication of code. For example, typically there are display drivers for a number of common display devices such as EGA and VGA displays resident in memory at the same time. Each of these drivers contains similar graphics functions, resulting in a substantial duplication of code resident in memory.




Another drawback of graphics drivers is their complexity. Many display devices have special characteristics that require display drivers to be written to take advantage of these characteristics. A true color (24-bit) display card, for example, may require a display driver that is not supplied with the operating system software. The supplier of the card must then provide the required display driver. To do so, the supplier must have intimate knowledge of the operating system that interacts with the display driver. Gaining that knowledge and writing the appropriate code is a time consuming and expensive process.




The objects of the invention are therefore several. One object is to provide an operating system that allows an application program to draw onto device-independent bitmaps in an efficient manner. The application program should not require special code to perform the drawing. If the application program desires to use the drawing capabilities of the operating system to draw onto a DIB, the steps required for doing so should be minimized. A second object is to provide an operating system that can support drawing by the application program onto other bitmaps and output devices without the need for complex and redundant code in the graphics drivers. For example, each display driver should contain only code that takes advantage of its display device's unique characteristics. Redundant code for drawing functions that are common to all display drivers should be removed, and those functions left to the operating system. This change in display driver responsibility reduces the amount of code required to be resident in main memory. This change also simplifies the writing of such graphics drivers.




SUMMARY OF THE INVENTION




A method and apparatus in accordance with the invention is disclosed for enabling an application program to use the operating system to create a device-independent bitmap on which the application may then perform graphics operations. The method includes accessing a data structure describing a desired format for the bitmap. A bitmap is then created according to the desired format. The bitmap is identified to both the operating system and to the application program, enabling the application program to perform graphics operations on the bitmap directly or through the facilities of the operating system.




In one embodiment of the invention, the operating system includes a graphics interface and a graphics engine. The application program calls a first function in the graphics interface to create the DIB. The graphics interface, in turn, calls a second function in the graphics engine to create the DIB. The graphics engine returns to the graphics interface a means for identifying the bitmap to the application program, such as a pointer to the DIB's memory location. The graphics interface then returns to the application program a means for identifying the bitmap to the operating system and the means for identifying the bitmap to the application program.




In another aspect of the invention, the graphics engine carries out drawing operations that previously have been incorporated into graphics drivers. This reduces the tasks of graphics drivers, allowing their code to be limited to handling any special characteristics of the graphics hardware associated with the graphics driver. In the method of the invention, a function call is made to the graphics driver to perform a graphics operation. The graphics driver then determines whether the graphics operation is of a type that the graphics engine may perform. If it is, the graphics driver calls a function in the graphics engine to perform the operation. If it is not, the graphics driver performs the operation.











The foregoing and other objects, features, and advantages of the invention will become more apparent from the following detailed description of a preferred embodiment which proceeds with reference to the accompanying drawings.




BRIEF DESCRIPTION OF THE DRAWINGS





FIG. 1

is a block diagram of a computer system that may be used to implement a method and apparatus embodying the invention.





FIG. 2

is a block diagram of an application program, operating system, graphics driver and graphics device within a computer system such as shown in FIG.


1


.





FIG. 3

is a block diagram of a device-independent bitmap format.





FIG. 4

is a more detailed view of the graphics interface, graphics drivers and graphics engine modules in the diagram of FIG.


2


.





FIG. 5

is a block diagram of a device structure for passing data to a graphics driver or graphics engine.





FIG. 6

is a data flow diagram showing how the operating system in the present embodiment enables an application program to create a device-independent bitmap.





FIG. 7

is a data flow diagram showing how the operating system divides the performance of graphics operations between a graphics driver and a graphics engine.











DETAILED DESCRIPTION OF A PREFERRED EMBODIMENT





FIG. 1

is a block diagram of a computer system


20


which is used to implement a method and apparatus embodying the invention. Computer system


20


includes as its basic elements a computer


22


, input device


24


and output device


26


.




Computer


22


generally includes a central processing unit (CPU)


28


and a memory system


30


that communicate through a bus structure


32


. CPU


28


includes an arithmetic logic unit (ALU)


33


for performing computations, registers


34


for temporary storage of data and instructions and a control unit


36


for controlling the operation of computer system


20


in response to instructions from a computer program such as an application or an operating system. Illustrative examples of a CPU are the X86 family of microprocessors available from Intel Corporation of Santa Clara, Calif.




Memory system


30


generally includes high-speed main memory


38


in the form of a medium such as random access memory (RAM) and read only memory (ROM) semiconductor devices and secondary storage


40


in the form of a medium such as floppy disks, hard disks, tape, CD-ROM, etc. and other devices that use optical or magnetic recording material. Main memory


38


stores programs such as a computer's operating system and currently running application programs. Main memory


38


also includes video display memory for displaying images through a display device.




Input device


24


and output device


26


are typically peripheral devices connected by bus structure


32


to computer


22


. Input device


24


may be a keyboard, modem, pointing device, pen, or other device for providing input data to the computer. Output device


26


may be a display device, printer, sound device or other device for providing output data from the computer.




It should be understood that

FIG. 1

is a block diagram illustrating the basic elements of a computer system; the figure is not intended to illustrate a specific architecture for a computer system


20


. For example, no particular bus structure is shown because various bus structures known in the field of computer design may be used to interconnect the elements of the computer system in a number of ways, as desired. CPU


28


may be comprised of a discrete ALU


33


, registers


34


and control unit


36


or may be a single device in which these parts of the CPU are integrated together, such as in a microprocessor. Moreover, the number and arrangement of the elements of the computer system may be varied from what is shown and described in ways known in the art (i.e., multiple CPUs, client-server systems, computer networking, etc.).





FIG. 2

is a block diagram of a portion of an operating system


42


in communication with an application program


44


and a graphics driver


46


. Operating system


42


and application program


44


may be written to run on a variety of computer systems, including systems based on Intel microprocessors. These elements are preferably resident in main memory


38


, but they may also reside in secondary storage


40


and be swapped in and out of the main memory as needed. Operating system


42


further communicates with a graphics device


48


, memory bitmaps


50


and device-independent bitmaps


52


. Graphics device


48


includes devices such as a graphics adapter that includes display screen memory or a printer that includes a memory buffer. Within the illustrated portion of operating system


42


are a graphics interface


54


and a graphics engine


56


. Each of the blocks in

FIG. 2

except for graphics device


48


and bitmaps


50


,


52


is typically implemented as a module of code containing a set of related functions.




This, of course, is only a description of the preferred embodiment. Graphics engine


56


or its equivalent may also be contained in the graphics interface or other parts of operating system


42


.




For drawing onto a display screen (the display memory surface, or frame buffer, for the graphics device), graphics interface


54


interacts with a graphics device


48


(

FIG. 1

) through a graphics driver


46


. A graphics driver such as a display driver is a module containing a set of functions designed for accommodating a particular graphics display device, such as a true color display adapter, a display accelerator, etc. A display driver also contains device-specific code needed to carry out particular graphics operations on the device. Function calls from an application program


44


to functions in graphics interface


54


are translated by the graphics interface into corresponding calls to functions in a graphics driver


46


for the particular device


48


. These graphics driver functions then execute instructions for drawing graphics or performing other graphics operations on the display screen. Depending on the capabilities of the display device, graphics interface


54


may generate many calls to a graphics driver


46


from a single call from an application program


44


.




In the preferred embodiment of the invention, graphics interface


54


may also interact with a graphics device


48


through graphics engine


56


. This interaction occurs both directly through the graphics engine and indirectly through a graphics driver


46


, depending on the purpose for which the graphics engine is invoked. The interaction is direct if graphics interface


54


is called by an application program


44


to create or draw onto a memory surface defining a device-independent bitmap (DIB)


52


. In this case, graphics interface


54


calls a function in graphics engine


56


. The graphics engine in turn creates or draws directly onto a DIB


52


in main memory


38


. As part of its execution of the function for creating a DIB, graphics engine


56


returns a means for identifying the DIB to graphics interface


54


such as a pointer to the memory location for the DIB's bits. The graphics interface in turn passes this pointer in a “pointer to a pointer” to application program


44


to enable the program to draw directly onto the DIB without the involvement and inherent drawing limitations of operating system


42


. This direct communication between DIB


52


and application program


44


is indicated in

FIG. 2

by a long arrow on the right side of the figure.




The interaction between graphics interface


54


and graphics engine


56


is indirect if the graphics interface is asked by an application program


44


to draw onto the memory surface defining the display screen. This interaction is described generally above wherein graphics interface


54


calls a function in graphics driver


46


to draw onto the display screen of graphics device


48


. Graphics driver


46


examines the function call to determine if the requested function may be performed by the graphics engine. If executing the function requires access to unusual or unique features of the graphics device such as color conversion, then the graphics driver carries out the function's operation. However, if executing the function does not require such access, then graphics driver


46


calls an appropriate function in the graphics engine, which carries out the requested graphics operation. In this way, each of the graphics drivers


46


does not have to include code for common drawing operations such as creating rectangles, lines, etc., but can be limited to code necessary to utilize unique features of their respective unique graphics devices. By placing the code for carrying out common graphics operations in graphics engine


56


rather than in all of the graphics drivers, a substantial duplication of code is avoided and the display drivers may be much simpler in design.




This indirect interaction through graphics driver


46


also occurs when the function call from graphics interface


54


to the graphics driver involves performing graphics operations on a memory surface defining a memory bitmap


50


that is not created specifically as a DIB, but generally has the format of a DIB. These bitmaps are created and stored in main memory


38


for various purposes, such as for transferring a bitmapped image to a display screen. Graphics engine


56


may be used for creating and drawing onto these memory bitmaps.




The device-independent format of a DIB


52


is shown in

FIG. 3. A

typical file format for a DIB includes a header structure


52




a


that provides information about the bitmap. This information includes the height and width of the desired bitmap in pixels, such as 100 by 200 pixels. Header


52




a


also indicates the number of color bits per pixels, such as eight or 16, and other attributes of the DIB. Color table


52




b


, if present, provides a color for each of the possible bit combinations for a pixel. For example, if the DIB specifies eight bits per pixel, then the color table has 256 entries, with each possible bit combination being a separate index into the color table. The entries in the color table, in turn, may represent indices into a color palette or represent colors directly. Bitmap


52




c


consists of an array of the bits for each pixel of the bitmap. For example, a 100 by 200 bitmap with a color depth of eight bits per pixel would have an array of 100*200*8=160,000 bits. For the purposes of the invention, these are the pertinent portions of the format DIB. A more detailed description of a DIB file format may be found in a number of references, including


Programming Windows


3.1 noted above.





FIG. 4

is a more detailed view of the contents of graphics interface


54


, graphics drivers


46


, and graphics engine


56


in the preferred embodiment. A set of functions defining the graphics interface are collected in a module of operating system


42


. This module is a self-contained unit whose code is physically separate from the code of other modules of the operating system. Within graphics interface


54


are functions for creating bitmaps, drawing onto these bitmaps and onto the screen display, and copying bitmaps from one memory surface to another (blt functions). Also included are functions unique to the present invention for enabling an application program to draw directly or indirectly onto DIBs, as generally explained above. An example of a function for enabling an application program to create a DIB is defined in Table I:












TABLE I









CreateDIBSection























hBITMAP CreateDIBSection (hdc, lpInfo, dwUsage, lplpBits, hSection,






dwOffset)












hdc;




//handle of device context






BITMAPINFO *lpInfo;




//address of bitmap size and format data






dwUsage;




//color data usage






**lplpBits;




//address of buffer that receives the







address of the bitmap bits






hSection;




//handle of a memory mapped object






dwOffset;




//offset to the bitmap bits














The parameters to the function are several. The parameter hdc is the handle of a device context for the newly created DIB and is a word length data type such as an integer. The parameter Ipinfo is a pointer from application program


44


to a data structure that includes the BitMapInfo header structure and color table (

FIG. 3

,


52




a


and


52




b


) and is a double word length data type such as a long. This data structure describes a desired format of the device-independent bitmap to be created. The parameter dwUsage specifies whether the entries in the color table represent palette indices or actual colors and is a word data type. The parameter IpIpBits is a “pointer to a pointer” to a memory location for the bitmap bits (

FIG. 3

,


52




c


) and is a double word data type. The parameter hSection is a double word length data type. The parameter dwOffset is a double word length data type. The parameter returned by the function is hBITMAP, a word length data type, that is a handle to the newly created bitmap. The handle hBitmap identifies the device-independent bitmap being created to operating system


42


. Within the definition of the function is also a call to a memory allocator, such as to a function in graphics engine


56


, which allocates memory for the bitmap bits. After execution, the function returns the bitmap bits pointer and the bitmap handle to the application program. A more complete explanation of the function CreateDIBSection appears in Appendix A.




This is, of course, only a preferred form of a function for creating a DIB. Equivalent function definitions with parameters, data structures, and global may also be used. For example, the pointer Ipinfo may be viewed conceptually as one form of a means for accessing a desired format of a device-independent bitmap to be created. Other equivalent forms include but are not limited to a data structure as a function parameter or a global variable to identify the bitmap format. The pointer IpIpBits is just one form of a means for identifying the bitmap to the application program. Other equivalent forms include but are not limited to a data structure as a function parameter or a global variable to identify the bitmap. The handle hbitmap is only one form of a means for identifying the bitmap to the operating system. Data structures, global variables and other techniques known in the art may also be used as noted above. The function call to graphics engine


56


is just one form of a means for creating a device-independent bitmap of the desired format. Graphics interface itself may contain the necessary code, or it may make calls to other modules in addition or instead of to the graphics engine.





FIG. 4

also shows a preferred form of graphics engine


56


. The graphics engine is also a module that contains a set of functions for creating a DIB and for performing graphics operations on DIBs, other bitmaps and physical devices. These functions include drawing and copying functions (known as “blitting”). They also contain a function for creating a DIB in response to a function call from graphics interface


54


, such as the following function in Table II below:












TABLE II









CreateDIBPDevice























CreateDIBPDevice (CDP_DibInfo, CDP_Pdevice, CDP_lpBits, CDS_Flags)













Converts a BITMAPINFO structure into a DIB PDevice structure.














CDP_DibInfo




//pointer to the Info structure.







CDP_PDevice




//buffer to hold DIB PDevice structure







CDP_lpBits




//pointer to bits.













If this is 0, the function will fill in the offset













part of deBits assuming that the caller will allocate a 0 based







buffer and fill in the selector for the buffer later.














CDS_Flags




//used to initialize the deFlags field.







Exit:













eax = size of the bits buffer, if successful.







eax = 0 if failure.















The parameters passed from graphics interface


54


in this function call are several. The parameter DibInfo, a double word length data type such as a long, is a pointer to the BitMapInfo structure described above and derived from the pointer IpInfo. The parameter Pdevice, a double word length data type, is a pointer to a block of memory that contains a DIB pdevice structure, to be described. The parameter IpBits, a double word length data type, points to the location of the bitmap bits. The parameter Flags is a word length data type such as an integer. The function returns a parameter of a double word length data type which provides the bit size of the buffer. These parameters are more fully described in Appendix B, which gives a detailed description of a preferred form of this function, CreateDIBPDevice. As with the graphics interface functions, these are only preferred forms of means for accessing and identifying data. Data structures, global variables and other techniques may also be used in a function as noted above. Equivalent functions and other techniques may also be used. Upon execution of this function, graphics engine


56


fills in the contents of a pdevice structure buffer allocated by graphics interface


54


and pointed to by the pointer IpBits.




Several other functions, GetDIBColorTable and SetDIBColorTable are also believed to be unique to the present invention. They appear in Appendices C and D, respectively. The function GetDIBColorTable retrieves color values from a range of entries in the color table of the DIB that is currently selected into a specified device context. The function's parameters include hdc, a handle to a device context into which a DIB is selected. The parameter hdc is a word length data type such as an integer. The parameter uStartIndex, a word length data type, specifies an index (starting at 0) from the beginning of the color table. The function GetDIBColorTable retrieves entries from the color table beginning with the entry at the specified index. The parameter uNumIndices, a word length data type, specifies the number of color table entries to retrieve. The parameter IpColors, a double word length data type such as a long, is a pointer to a buffer that receives an array of RGBQUAD structures containing color information from the DIB's color table. The function returns a parameter of a word length data type. The return value, if the function succeeds, is the number of entries retrieved from the color table.




The function SetDIBColorTable sets RGB (red, green, blue) color values in a range of entries in the color table of the DIB that is currently selected into a specified device context. The function's parameters include hdc, a handle to a device context into which a DIB is selected. The parameter hdc is a word length data type. The parameter uStartIndex, a word length data type, specifies an index (starting at 0) from the beginning of the color table. The function SetDIBColorTable sets the entries from the color table beginning with the entry at the specified index. The parameter uNumIndices, a word length data type, specifies the number of color table entries to set. The parameter IpColors, a double word length data type, is a pointer to an array of RGBQUAD structures containing new color information for the DIB's color table. The function returns a parameter of a word length data type. The return value, if the function succeeds, is the number of entries set in the color table.




A DIB pdevice structure


60


is shown in the block diagram of FIG.


5


. The pdevice structure is passed as a parameter to graphics engine


56


and describes the format of a DIB to be created. The structure includes a number of fields whose data is derived from the parameters passed by graphics interface


54


. Of particular relevance are BitsPerPixel field


60




a


, Bits field


60




b


and BitMapInfo field


60




c


. BitsPerPixel field


60




a


indicates the number of bits for each pixel in the DIB to be created. Bits field


60




b


identifies the drawing surface for the DIB, that is, the memory location where the DIB will reside. BitMapInfo field


60




c


points to a data structure that describes the format of the DIB, the pixel characteristics and the color table.





FIG. 4

further shows a preferred form of a graphics driver


46


. The graphics driver include drawing functions that may be called by graphics interface


54


to draw onto non-DIB bitmaps, such as the screen display of graphics device


48


and memory bitmaps


50


. However, these drawing and blitting functions pass the drawing or copying tasks through to graphics engine


56


whenever possible. Only specialized drawing functions that require manipulation of the display hardware remain fully in the display driver. Drawing is thus centralized to a degree within graphics engine


56


, reducing the duplication of code among the modules.




The details of the interaction of graphics interface


54


with graphics engine


56


in the preferred embodiment will now be described with reference to

FIGS. 4-6

. When an application program


44


desires to create a DIB, it makes a function call to graphics interface


54


, passing the interface a pointer to a memory location where the format of the DIB is stored. In the preferred embodiment, this function call is to the function CreateDIBSection, and the pointer passed is IpInfo. The application program may also pass pointers to an existing DIB, hSection and dwOffset, if it is desired to modify an existing DIB. Other parameters passed by the application program may indicate the nature of the color table (dwUsage) and a device handle (hdc). This is summarized in

FIG. 6

as a call to a DIB creation function.




Graphics interface


54


responds to this function call by executing the corresponding function. As part of that execution, the graphics interface computes values, calls a second function within graphics engine


56


and passes these values as parameters to the second function. In the preferred embodiment, the corresponding function is CreateDIBPDevice. The parameters passed include a pointer to the DIB format (DibInfo) and a pointer to DIB pdevice structure


60


that indicates the memory location for the DIB (Pdevice). This is illustrated in

FIG. 6

as a call to a DIB creation function within graphics engine


56


. The graphics engine then allocates the memory for the DIB required for the format specified.




These two functions return values to their calling environments. Graphics engine


56


returns to graphics interface


54


a pointer to the memory location for the DIB bits. The pointer is the parameter IpBits in the CreateDlBPDevice function. Graphics interface


54


, in turn, returns to application program


44


a pointer to a buffer that contains the memory for the DIB bits and a handle identifying the DIB to the operating system. The handle is an index into a table in graphics interface


54


whose entries identify the nature and location of objects such as bitmaps. The handle is hBitmap and the “pointer to a pointer” is the parameter IpIpBits in the CreateDIBSection function.




Application program


44


may now draw or copy onto the DIB directly using its own facilities and the pointer IpIpBits or indirectly through the facilities of operating system


42


and the handle hBitmap. How the drawing is handled varies by operating system. In the Windows environment, for example, the graphics interface is called by the application program to create a memory device context and then to select the bitmap into the memory device context. The bitmap may then be drawn or otherwise manipulated in the memory device context.




The details of the interaction of graphics interface


54


, graphics driver


46


and graphics engine


56


in the preferred embodiment for drawing onto memory surfaces supporting other bitmaps will now be described with reference to

FIGS. 4

,


5


and


7


. As a preliminary to drawing or other graphics functions, a bitmap must be created as described. A memory device context must also be created, and then the bitmap associated with the memory device context. The handle of the memory device context is then communicated to the application program for its use in utilizing the operating system to draw onto bitmaps.




When the application program desires to draw onto a memory bitmap or onto a physical device itself such as the screen display of graphics device


48


, it calls an appropriate function within graphics interface


54


. This is indicated in FIG.


7


. These functions include drawing functions, blitting functions and others. Graphics interface


54


, in turn, calls an appropriate function in a graphics driver


46


. The graphics driver in response determines if it is capable of performing the graphics operation represented by the function. If it is a function that does not require resort to the special characteristics of the display hardware, then display driver passes the function to graphics engine


56


, which carries out the operation. If the function does require manipulation of the display hardware, the display driver carries out the function.




The above description of the functions that may be employed in the preferred embodiment sets forth the required information for writing the associated function definitions. Any detailed programming connected therewith is well within the skill of the art.




In view of the many possible embodiments to which the principles of our invention may be applied, it should be recognized that the illustrated embodiment is only a preferred example of the invention and should not be taken as a limitation on the scope of the invention. For example, the module definitions may be changed so that the various functions of the graphics engine and graphics drivers are incorporated into one another or into the graphics interface. Parameters for functions maybe pointers, data structures or other equivalent means. Global variables may be used to communicate among functions. The invention should therefore be considered limited only by the following claims. We claim as our invention all that comes within the scope and spirit of these claims.

















CreateDIBSection






hBITMAP CreateDIBSection (hdc, lpInfo, dwUsage, lplpBits, hSection,






dwOffset)












hdc;




//handle of device context






BITMAPINFO *lpInfo;




//address of bitmap size and format data














dwUsage;




//color data usage












**lplpBits;




//address of buffer that receives the address of the







bitmap bits






hSection;




//handle of a memory mapped object






dwOffset;




//offset to the bitmap bits













The CreateDIBSection function creates a device-independent bitmap to







which both the graphics interface and applications can directly write.











parameters hdc













Handle of a device context (DC) for providing objects.













lpInfo













Points to a BITMAPINFO structure that describes the desired format of













the bitmap to create including the pixel width, pixel height, color depth,







and color table for the bitmap.













The BITMAPINFO structure has the following form:













typedef struct tagBITMAPINFO { // bml







BITMAPINFOHEADER bmiHeader;














RGBQUAD




bmiColors[1];













} BITMAPINFO;













Usage













Specifies whether the bmiColors member of the BITMAPINFO







structure contains explicit red, green, and blue (RGB) values or







palette indices. The dwUsage parameter must be one of the







following values:














Value




Meaning







DIB_PAL_COLORS




The color table consists of an








array of 16-bit indices into the








logical palette of the DC into








which the bitmap is to be








selected.







DIB_RGB_COLORS




The color table contains literal








RGB values.













lplpBits













Points to a buffer that receives the address of the bitmap bits.













This field can be NULL in which case the address of the bitmap bits is







not returned to the caller on this call.







hSection













Identifies a memory mapped object from which the bitmap should







be created.







If hSection is NULL, the graphics interface allocates the memory







mapped object for the application and ignores the dwOffset







parameter.













dwOffset







The byte offset from the base memory location given by hSection











APPENDIX A











CreateDIBPDevice






CreateDIBPDevice (CDP_DibInfo, CDP_Pdevice, CDP_lpBits, CDS_Flags)






 Converts a BITMAPINFO structure into a DIB PDevice structure.












CDP_DibInfo




//pointer to the Info structure.






CDP_PDevice




//buffer to DIB PDevice structure






CDP_lpBits




//pointer to bits.













 If this is 0, the function will fill in the offset part of deBits







assuming that the caller will allocate a 0 based buffer and fill in







the selector for the buffer later.












CDS_Flags




//used to initialize the deFlags field.






Exit:













eax = size of the bits buffer, if successful.







eax = 0 if failure.











The above function is called by the graphics interface while creating a DIB via






CreateDIBSection.






The purpose of CreateDIBPDevice is the following:












1.




Validate the DIB Header pointed to by the CDP_DIBInfo far pointer. The







graphics engine knows what DIB formats it supports and if the DIB







information passed by the graphics interface does not conform to one of







those formats, the CreateDIBPDevice will return failure.






2.




Once the DIB has been validated, the graphics interface expects the







graphics engine to fill in the buffer pointed to by the CDP_PDevice far







pointer with a DIB PDEVICE structure that will be used as a PDEVICE







when drawing on the DIB. The graphics engine then does this. Most of







the information that it needs to fill in the PDevice structure comes from







the CDP_DIBInfo structure (width, height, format etc.). However,







CDP_DIBInfo does not specify how to fill in the deFlags (attributes of the







surface) and the deBits (pointer to the bits for the surface) fields. The







graphics interface passes these parameters explicitly. CDP_lpBits is the







pointer to the bits. The graphics interface passes this in as a NULL>







This is because the graphics interface does not know yet what the size







of the bits buffer will be.







CDP_Flags is used to build deFlags. The flag value will indicate that the







drawing surface is a DIB (as opposed to a DDB or the screen).






3.




The graphics engine returns the size needed for the DIB buffer in the







eax.











The graphics interface uses the value in eax to allocate a buffer for the bits






buffer. Once it has done this, it will patch up the deBits field of the PDevice






with the address of the buffer.






The above CreateDIBPDevice is used by display drivers to construct a pdevice






for their surface. In this case, the CDP_lpBits will be non null and will point to






the memory address of the screen.






The above CreateDIBPDevice is also used internally in the graphics engine






while constructing PDevices for DDBs.











APPENDIX B











GetDIBColorTable






UINT GetDIBColorTable(hdc, uStartIndex, uNumIndices, lpColors)












HDC hdc;




// handle of the device context






UINT uStartIndex;




// starting index in color table






UINT uNumIndices;




// number of color table entries to retrieve






RGBQUAD *pColors;




// address of buffer to receive color entries











The GetDIBColorTable function retrieves color values from a range of entries






in the color table of the device-independent bitmap (DIB) that is currently






selected into a specified device context.






Parameters hdc













Identifies a device context into which a DIB section bitmap is selected.











uStartIndex













Specifies an index (starting at 0) from the beginning of the color table.







The function retrieves entries from the color table beginning with the







entry at the specified index.











uNumIndices













Specifies the number of color table entries to retrieve.











lpColors













Points to a buffer that receives an array of RGBQUAD structures







containing color information from the DIB's color table. The buffer must







be large enough to contain as many RGBQUAD structures as the value







of cEntries. The RGBQUAD structure has the following form:













typedef struct tagRGBQUAD {













BYTE rgbBlue;







BYTE rgbGreen;







BYTE rgbRed;







BYTE rgbReserved;













} RGBQUAD;







typedef RGBQUAD FAR* LPRGBQUAD;











Return Value   If the function succeeds, the return value is the number of






entries retrieved from the color table; otherwise, it is zero. To get extended






error information, use the GetLastError function.






Comments  This function retrieves the color table for a DIB that has 1, 4 or 8






bits per pixel. A DIB that has more than 8 bits per pixel does not have a color






table. Instead, it has a color mask that you can retrieve by using the GetObject






function.






The GetDIBColorTable function should be called to retrieve the color table for






device-independent bitmaps that use 1, 4, or 8 bits per pixel. The biBitCount






member of a bitmap's associated BITMAPINFOHEADER structure specifies






the number of bits per pixel. Device-independent bitmaps with a biBitCount






value greater than 8 do not have a color table, but they do have associated






color masks. Call the GetObject function to retrieve those color masks.











APPENDIX C











SetDIBColorTable






UINT SetDIBColorTable(hdc, uStartIndex, uNumIndices, IpColors)












HDC hdc;




// handle of the device context






UINT uStartIndex;




// starting index in color table






UINT uNumIndices;




// number of color table entries to set






RGBQUAD *pColors;




// address of the new color table











The SetDIBColorTable function sets RGB (red, green, blue) color values in a






range of entries in the color table of the device-independent bitmap (DIB) that






is currently selected into a specified device context.






Parameters hdc













Identifies a device context into which a DIB is selected.











uStartIndex













Specifies an index (starting at 0) from the beginning of the color table.







The function sets the entries in the color table beginning with the entry







at the specified index.











uNumIndices













Specifies the number of color table entries to set.











IpColors













Points to an array of RGBQUAD structures containing new color







information for the DIB's color table. The RGBQUAD structure has the







following form:







typedef struct tagRGBQUAD {













BYTE rgbBlue;







BYTE rgbGreen;







BYTE rgbRed;







BYTE rgbReserved;













} RGBQUAD;







typedef RGBQUAD FAR* LPRGBQUAD;











Return Value  If the function succeeds, the return value is the number of






entries set in the color table; otherwise, it is zero.






Comments  The function increases the size of the color table if more entries






are added than exist in the current color table. This function sets the color






table for a DIB that has 1, 4 or 8 bits per pixel. A DIB that has more than 8 bits






per pixel does not have a color table. Instead, it has a color mask that you can






retrieve by using the GetObject function.











APPENDIX D













Claims
  • 1. A method of invoking an operating system function from an application program comprising:making a function call of the form CreateDIBSection (a, b, c, d, e, f), wherein a through f are parameters and: a represents a handle to a device context; b represents a pointer to a data structure that describes the format of a bitmap to create; c represents a value that specifies whether members of the data structure contain explicit color values or palette indices; d represents a pointer to a buffer that receives the address of the bitmap bits; e represents an identifier of a memory mapped object from which the bitmap may be created; f represents a value that specifies an offset; and passing the parameters to the called operating system function.
  • 2. The method of claim 1 wherein:a is named hdc; b is named IpIpinfo; c is named dwUsage; d is named IpIpBits; e is named hSection; and f is named dwOffset.
  • 3. The method of claim 1 including returning a value g to the calling environment, g representing a handle to the bitmap if the function succeeds.
  • 4. An operating system stored in memory comprising a plurality of functions which may be called by an application program, the operating system including a function CreateDIBSection, which accepts six parameters from a calling program and returns a value that is a handle to a created bitmap.
  • 5. The operating system of claim 4 wherein the six parameters comprise:a handle to a device context; a pointer to a data structure that describes the format of a bitmap to create; a value that specifies whether members of the data structure contain explicit color values or palette indices; a pointer to a buffer that receives the address of the bitmap bits; an identifier of a memory mapped object from which the bitmap may be created; and a value that specifies an offset.
  • 6. The operating system of claim 5 wherein:the handle to a device context is named hdc; the pointer to a data structure that describes the format of a bitmap to create is named IpIpinfo; the value that specifies whether members of the data structure contain explicit color values or palette indices is named dwUsage; the pointer to a buffer that receives the address of the bitmap bits is named IpIpBits; the identifier of a memory mapped object from which the bitmap may be created is named hsection; and the value that specifies an offset is named dwOffset.
RELATED APPLICATION DATA

This application is a continuation-in-part of U.S. application Ser. No. 08/328,349, filed Oct. 24, 1994. Now U.S. Pat. No. 5,734,387.

US Referenced Citations (1)
Number Name Date Kind
5434913 Tung et al. Jul 1995 A
Non-Patent Literature Citations (1)
Entry
“Device Driver Adaption Guide” Microsoft Corporation, 1992; Chapters 1, 2 & 10.
Continuation in Parts (1)
Number Date Country
Parent 08/328349 Oct 1994 US
Child 08/355406 US