×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Graphics array and Bsave query

Graphics array and Bsave query

Graphics array and Bsave query

(OP)
     Hello I recently viewed an old post here about dimensioning graphics arrays and bsaving.  I have some working code although I do not fully understand why it works so.  I understand with a graphics array (scrn 13) we get 2 bytes per integer.  But in my code I must use L x W /2 + 1, I don't know what the +1 is for but it works.  Also using bsave I calculate the amount of bytes and have to add 4 for the entire picture to be loaded.  Can anyone enlighten me? I know a few people have given different answers to this question in the past I'm just wondering what the De Facto rule is for it, i.e. actual equation. here's the code I use just to test this.

It make a 320x200 picture of random pixels, gets its in array bsaves it, then clears the screen and then finally bloads it. check it out

------------------------------------------------------------
CLS
DIM scrn(32001) AS INTEGER
DIM scrn2(32001) AS INTEGER 'one integer = 2 bytes
RANDOMIZE TIMER
SCREEN 13
  FOR y = 0 TO 199
   FOR x = 0 TO 319
    PSET (x, y), RND * 7
   NEXT
  NEXT
 
  GET (0, 0)-(319, 199), scrn
  a$ = INPUT$(1)
  CLS
  PUT (0, 0), scrn, PSET
DEF SEG = VARSEG(scrn(0))
INPUT "Filename: ", file$
BSAVE file$, VARPTR(scrn(0)),64004
DEF SEG
CLS
a$ = INPUT$(1)
DEF SEG = VARSEG(scrn2(0))
BLOAD file$, VARPTR(scrn2(0))
DEF SEG
PUT (0, 0), scrn2(0), PSET
SLEEP 3

'((totalx x totaly) / BytesPerInteger) - 1forZero
'((320 x 200) / 2) - 1 = 31999
'then add 2 bytes for the height and width
'31999 + 2 = 32001


RE: Graphics array and Bsave query

What exactly is your question?

If you are asking what the +1 is for, it is for this:

320 * 200 = 64000 Bytes...

1 Integer = 2 Bytes
32000 Integers = 64000 Bytes

Dim X(31999) = 64000 Bytes
X(0) = byte 1 & 2
X(1) = byte 3 & 4
...
X(31999) = byte 63999 & 64000

So now the formula looks like: (320 X 200) - 1

Then the 2 extra integers added to the begining are used by Get/Put to store the Width & Height of the image...

Which, it's been a while, but I believe it is something like:

X(0) = width
y(1) = height * 2

Though, to do a BSAVE you don't have to even use Get / Put...

I made a tutorial a while back that is on my website that explains how to use BSAVE to capture screen shots...
http://cubee101.topcities.com/rawtutorial.html

You might find it interesting...

Let me know if you would like any of this explaing in more detail...
-Josh

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.

RE: Graphics array and Bsave query

(OP)
Thanks I knew about the little formula in the help but I got really confused as to which one to use, because I found one in the qbasic bible (book), one or two online and the one in the help, I didn't know which was the right one as they all were different from each other.  Some worked some didn't, thanks though It crossed my mind that the graphics array held the Height and width just wasn't sure where the numbers were coming from... I assum the extra bytes in addition to the image size in bytes is the Header?

Thanks though

RE: Graphics array and Bsave query

>>I assum the extra bytes in addition to the image size in bytes is the Header?

For BSAVE... yeah... The header is 7 bytes...

Such AS:
FD 00 A0 00 00 00 FA

Where...
Byte 1 (FD): ID Byte
  Alway &HFD, This is to verify that the file is a QBASIC BSAVE file

Byte 2-3 (00 A0): Segment
  Stores segment of BSAVE, in this case A000 (video memory)

Byte 4-5 (00 00): Address
  Stores offset of BSAVE, in this case 0 (also in little endian format... low byte first)

Byte 6-7 (00 FA): Length
  Stores the length of the data, in this case FA00 or 64000.
  Use this if you want to dimension an array ahead of
time to hold the BLOAD data.

Hope this helps...
-Josh

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.

RE: Graphics array and Bsave query

(OP)
Hmmm I checked and that can't explain why when bsaving I add +4 to the L*W (total image bytes scr13) and not 7 for the header.  Am I saving part of the header and it works because i'm missing something it doesn't use?

Rob

RE: Graphics array and Bsave query

there are 2 headers...

BSAVE Header (if you open the file in binary mode)
GET/PUT Header...

The BSAVE Header is 7 bytes
The GET/PUT Header is 4 Bytes

you don't have to use GET To save a Screen Shot...
  Thus the File will have a 7 Byte Header...

If you do use GET, the File Header will be 11 total (but 4 bytes are actually included in the Data)

For the Get Header...
A value such as 320 or 640 takes 2 Bytes, Since 255 is the max value of a Byte, the Value needs a Word (2 Bytes) so the Integer can be stored...
2 Integer = 4 Bytes, thats where those 4 Bytes come from...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

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.

Join Us             Close