What is formula for a graphics array
What is formula for a graphics array
(OP)
Does anyone know the correct forumula for dimensioning a graphics array in a given screen mode? and how to calculate the amount of bytes needed for bsaving?
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS Contact USThanks. We have received your request and will respond promptly. Come Join Us!Are you a
Computer / IT professional? Join Tek-Tips Forums!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting Guidelines |
What is formula for a graphics array
|
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Register now while it's still free!
Already a member? Close this window and log in.
RE: What is formula for a graphics array
It's in QB's help file under Screen Modes...
http://qbasicnews.com/qboho/qckadvr.screensr.shtml
Are you using QBasic, or QuickBasic 4.5 (w/ compiler)
Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
RE: What is formula for a graphics array
I meant under Get (graphics) Statment here:
Click here
Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
RE: What is formula for a graphics array
After you have created an onscreen image you need to calculate the x and y co-ordinates of a rectangle large enough to hold the entire image.You then use GET to capture the image.
DIM Arrayname(SomeSize)
GET [[STEP]](x1,y1)-[[STEP]](x2,y2),Arrayname
The size specified in the DIM statement depends on these 3
* The height + width of the rectangle enclosing the image
* The screen mode chosen for graphics output
* The type of array (integer,long interger,single or double precision)
The formula for calculating the size in BYTES of Arrayname is
size-in-bytes=4 + height * planes * INT((width * bits-per-pixel/planes + 7))/8
Where height + width are pixel dimentions of the rectangle.
The value of bits-per-pixel depends on the number of colors available in the given screen mode.
This list shows the value of planes for each screen mode
SCREEN MODE Number of BIT PLANES
========= ===============
1,1,11,13...............................1
9(64k vid mem),10.......................2
7,8,9 (more than 64k vid mem),12........4
To get the number of elements that should be in the array , divide the size-in-bytes by the number of bytes for 1 element of the array. This is where the type of array comes into play. If an INT array then each element takes 2 bytes of memory(the size of INT=2), so size-in-bytes should be divided by 2 to get the actual size of the array.Similary , a long INT array size-in-bytes should be divided by 4 (1 Long INT = 4 bytes).If single precision then divide by 4 , if double precision then divide by 8.
This example shows how to calculate the size of an integer array to hold a rectangle in SCREEN 1 with co-ordinates (10,40) upper left , (90,80) lower right.
1] Calculate the height and width
RectangleHeight = ABS (y2-y1)+1 = 80-40 +1 = 40
RectangleWidth = ABS (x2-x1)=1 = 90-10 +1 = 81
Remember to add 1 after subtracting y1 from y2 and x1 from x2
2] Calculate the size in bytes of the integer array
ByteSize = 4 + RectangleHeight * INT((RectangleWidth * BitsPerPixel + 7) / 8)
= 4 + 41 * INT((81 * 2 +7) / 8
= 4 + 41 * INT(169 / 8)
= 4 + 41 * 21
=865
3]Divide the size in bytes by the bytes per element(2 for integers) and round the result up to nearest whole number
865 / 2 = 433
DIM Arrayname (1 to 433) AS INTEGER
Composed from reading the original QuickBasic 4.5 official MSDos manual page 195 in Vol 2.
RE: What is formula for a graphics array
Did you visit the link I posted?
It is the page from QB 4.5
It says...
CODE
Syntax
GET [STEP](x1,y1)-[STEP](x2,y2),arrayname[(indices)]
Argument Description
x1,y1,x2,y2 Coordinates marking a rectangular area on the screen.
The placeholders x1, y1, x2, and y2 are numeric
expressions that are the coordinates of diagonally
opposite corners of the rectangle.
STEP Keyword indicating that coordinates are relative to
the most recently plotted point. For example, if the
last point plotted were (10,10), then the actual
coordinates referred to by STEP (5,10) would be
(5+10,10+10) or (15,20). If the second coordinate pair
in a GET statement has a STEP argument, it is relative
to the first coordinate pair in the statement.
arrayname Name assigned to the array that holds the image. This
array can be of any numeric type; its dimensions must
be large enough to hold the entire image.
indices Numeric constants or variables indicating the element
of the array where the saved image starts.
The GET statement transfers a screen image into the array specified
by arrayname. The PUT statement, associated with GET, transfers the
image stored in the array onto the screen.
The following formula gives the required size of the array in bytes:
4 + INT(((x2 - x1 + 1) * (bits-per-pixel-per-plane) + 7)/8)
* planes * ((y2 - y1) + 1)
The bits-per-pixel-per-plane and planes values depend on the
specification set in the SCREEN statement. The table below shows the
number of bits per pixel per plane and the number of planes for each
screen mode.
Values for Bits per Pixel per Plane and for Planes
Bits per Pixel
Screen Mode per Plane Planes
1 2 1
2 1 1
7 1 4
8 1 4
9 1 2 (if 64K of EGA memory)
4 (if > 64K of EGA memory)
10 1 2
11 1 1
12 1 4
13 8 1
The bytes per element of an array are as follows:
? Two bytes for an integer array element
? Four bytes for a long-integer array element
? Four bytes for a single-precision array element
? Eight bytes for a double-precision array element
For example, suppose you wanted to use the GET statement to store an
image in high resolution (SCREEN 2). If the coordinates of the upper-
left corner of the image are (0,0), and the coordinates of the lower-
right corner are (32,32), then the required size of the array in bytes
is 4 + INT((33 * 1 + 7)/8) * 1 * (33), or 169. This means an integer
array with 85 elements would be large enough to hold the image.
Unless the array type is integer or long, the contents of an array
after a GET appear meaningless when inspected directly. Examining
or manipulating noninteger arrays containing graphics images may cause
run-time errors.
One of the most useful things that can be done with GET and
PUT is animation.
Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
RE: What is formula for a graphics array
RE: What is formula for a graphics array
Yes i did and decided to post what the manual said anyway. Lol , at least both forms of help agree!. Also now we have 2 "official" examples in 2 differing screen modes. You adequately answered his question with that link , but i saw no harm in adding to the post. What do you think ?
RE: What is formula for a graphics array
No problem, I was just curious...
Beholder2,
Yes, there is a 3D example that I made on my site, called Ghost-Cube
The source is included...
(It is wireframe, but you can use it to get the basics of 3D)
There are several other cool effects as well...
For further discussion on this, you may want to start a new thread...
Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.