ID Number: Q42600
5.00 5.10 6.00 6.00a 6.00ax 7.00
MS-DOS
docerr
Summary:
The formula given for _imagesize in the "Microsoft C Run-Time Library
Reference" for Microsoft C versions 5.0 and 5.1, in the "Microsoft C
Reference" in versions 6.0, 6.0a, and 6.0ax, and on page 133 of the
"Microsoft QuickC 2.0 Graphics Library Reference" is incorrect for
most color EGA and VGA video modes. This formula was not documented in
C/C++ 7.0. The formula given is as follows:
xwid = abs(x1-x2)+1;
ywid = abs(y1-y2)+1;
size = 4+((long) ((xwid*bits_per_pixel+7)/8)*(long)ywid);
This formula is accurate only for the following modes:
_MRES4COLOR
_MRESNOCOLOR
_HRESBW
_VRES2COLOR
_MRES256COLOR
_HERCMONO
_ORESCOLOR
For most EGA and VGA color graphics modes, the correct formula is as
follows:
xwid = abs(x1-x2)+1;
ywid = abs(y1-y2)+1;
size = 4 + ((bits_per_pixel * (long) ((xwid+7)/8)) * ywid);
This formula should be used exclusively for modes that use bit planes.
These modes are as follows:
_MRES16COLOR
_HRES16COLOR
_ERESCOLOR
_VRES16COLOR
Either formula is accurate for the following modes:
_HRESBW
_VRES2COLOR
_HERCMONO
_ORESCOLOR
A call to _getvideoconfig will determine the current video mode. This
call is also necessary to determine the bits_per_pixel value.
Note that for all cases, _imagesize does return the correct value.
Only the formula given in the reference manuals is incorrect.
More Information:
The formula used internally by the _imagesize function is as follows:
xwid = abs(x1-x2)+1;
ywid = abs(y1-y2)+1;
size = 4+(bits_per_plane*(long) ((xwid*linear_bits_per_pixel+7)/8)*ywid);
This formula is useful only for lending understanding of how the two
prior formulas are derived. It cannot be used in a C program for the
following reasons:
- In this formula, linear_bits_per_pixel is the actual number of
linear bits required to store a pixel. In the color EGA and VGA
modes listed, this is not equivalent to the bitsperpixel field of
the videoconfig structure. In fact, the bitsperpixel field is
vc.bitsperpixel = linear_bits_per_pixel * bits_per_plane;
There is no way to determine linear_bits_per_pixel within C.
- There is no way to determine the bits_per_plane value within C.
The formula given in the run-time library reference is correct for CGA,
single-color, and _MRES256COLOR modes because bit planes are not
used in storing graphic images. That is, bits_per_plane is equal
to 1; therefore, this factor may be simplified out of the equation.
The formula fails in the case where bits_per_plan is greater than 1.
For more information on bit planes and pixel maps, refer to the
"Programmer's Guide to PC & PS/2 Video Systems" by Richard Wilton,
Pages 87-91.
Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax 7.00