×
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

large array size

large array size

large array size

(OP)
Hi everyone
I'd like to do some image processing of a 301K
image (an array of 640 * 480 pixels with 256
graylevels) How can I do it? Right now I have:

SCREEN 13
DIM a%(23000)
a$ = "image.bmp"
OPEN a$ FOR BINARY AS #1
FOR j% = 1 TO 21000 STEP 2
   GET #1, j%, a%(j%)
NEXT
CLOSE

It seems I am limited to about 20000-30000
probably because DIM is not large enough
How can I read the whole image?

RE: large array size

U need to dynamically dim the array.
On command-line, there is a switch for it.
For after compile, put a '$DYNAMIC before the DIM.

Cheers
 Erez Sh.

RE: large array size

QB array sizes aren't limited to 64K, if you dynamically allocate it, but the range of indices is still limited to 32768.  To overcome this, allocate a DOUBLE array. One DOUBLE is 8 bytes long, so
'You may need to load QB using QB/AH
'$DYNAMIC
DIM a#(0 TO 32767)
will give you a 256KB array.  You would manipulate it by POKEing into the array (pretend it's a byte array). Unfortunately, 640x480x1byte/pixel=300KB for a 640x480 screen.  So even a DOUBLE array isn't large enough.  There are three ways around this.
1) You can load directly to the screen, in scanline increments (or larger).
2) You can load into two (or more) arrays, and make two FOR loops that load the first
   half and the second half of the bitmap.
3) You can have DOS allocate a huge chunk of memory using interrupts, after you release some using SETMEM.

Since you are doing image processing, I think 2) is the best way.  By the way, you can load more than 8 bytes at a time using GET.  You can do something like DIM a as string*1024: GET #1,, a.  Then you can DEF SEG=VARSEG(a):ofs=0: POKE (SADD(a)+ofs),newval.  If you use BLOAD, you can load close to 64K at a time.  Using INTERRUPT, you can load at least 64K at a time.


RE: large array size

It is a waste to use an integer or a double to contain single bytes.
use :
DIM a(size) AS STRING * 1
But why load an entire file to memory???

Cheers
 Erez Sh.

RE: large array size

Erez,
  I'm not sure if you understood what I meant.  I allocated a DOUBLE array for the sole purpose of allocating more than 64K at a time.  I still treat it as if it were a BYTE array when I POKE into it.  But you reminded me of a point I missed.  When you poke into the array, you need to change segments (using DEF SEG), if the array is greater than 64KB.  

RE: large array size

I'm talking about using the GET statement.
I don't think it will load 4 btes to each array element.
I will probably load 1 byte to each.

besides, DIM a(100000) as string*1 works for me
Why shouldn't it work 4 u?

Cheers
 Erez Sh.

RE: large array size

Hmmm... I assume it won't work for us because Qbasic doesn't allow us to dimension an array with 100000 elements(?). Tell me is I'm getting close....

RE: large array size

U can dim an array of 100000 elements!

Cheers
 Erez Sh.

RE: large array size

Please give me an example with a one-dimensional array. QB45 help tells me that "The maximum range between array subscript values is 32,767."

I'd be interested in a way around this. Thanks.

RE: large array size

Ditto!!!  Please provide an example if you will.

--MiggyD

RE: large array size

Basically, it is limited to 32767 elements, per dimension.
When I said qbasic support 100000 elements, i ment like this:
DIM a(25000,4) as string*1
I works for any size, except for when it's out of memory.
But that's something else.

Cheers
 Erez Sh.

RE: large array size

Erezsh,
   You're right.  I think I forgot that because I was purposely working in QB without the /AH parameter for speed.  So Eduardo can just do
REM $DYNAMIC
DIM image(0 TO 639,0 TO 479)
and then load the image, and process it.

RE: large array size

(OP)
I have seen 11 responses to my msg about arrays
but I have tried different things, nothing works.
QBASIC/AH does not work (A not allowed)
DIM image (0 to 639, 0 to 479) also fails. I can
only go up to DIM image (0 to 639, 0 to 24)
My version is Q1.0 maybe it's not the latest
Would it help to upgrade? Where can I get it?

In fact how about is I just read the memory with
a loop containing some PEEK and DEFSEG
and write the processed pixels somewhere else with POKE
How can I know where my image lies in the memory of my
Dell PC?
How can I know where to write (dangerous, I do
not want to cover anything?)
I used to have an Oric Atmos in 1985 where I know
exactly what's the address of the hires screen
but on today's PC how can I know where exactly the
files occupy the memory?
Please explain well to me any idea or write the code
because I am not very computer litterate

Edouardo

RE: large array size

Oh. Old version.
Qb 1.0 probably doesn't support it.
U should upgrade to at least QB 4.0 (4.5 recommended).
Go to:
http://www.qbasicnews.com/features/compilers.html

Using peek and poke can be useful sometimes, but in your case it can cause harm. Unless knowing exactly where to write in memory, u can cause some errors by writing on reserved memory peices (either DOS's or for Qbasic's).
If u want to use peek and poke, u must allocate it first using a variable (for big areas use an array) but then we're back to the first issue.

Cheers
 Erez Sh.

RE: large array size

EDOUARDO:

I have this question for you.  Why are you using a STEP through in your loop?

> FOR j% = 1 TO 21000 STEP 2
>    GET #1, j%, a%(j%)
> NEXT
> CLOSE

Wouldn't it be easier to actually fill in the array as a sequential/linear string like:
(array) - chr/byte
    (1) - 21,
    (2) - 22,
    (3) - 23,
    (4) - 24,
    (5) - 25, ...etc.

Instead of skipping some indicies:
    (1) - 21,
    (2) - null,
    (3) - 22,
    (4) - null,
    (5) - 23, ...etc.

I'm hopeful that is a precurser to an answer for you, although, I've made plenty of apps for businesses, I've never realy had to deal with graphics in QB.  So forgive my ignorance in this matter.

-MiggyD

"The world is shrinking with every new user online."

RE: large array size

(OP)
Miggy
Don't worry about the step 2 I don't remember well why
but I know I could see my small image.


My question remains unanswered. Again when I have
a file called image.bmp on my computer how can I know
where it is in the memory (the hex address of where I
can start a for next loop of peek, no more GET #1,blabla

RE: large array size

Well, sorry I asked.  

If you read Toshi's first response...last paragraph...he mentions several memory statements that you'll have to look up in you help files.

-MiggyD

"The world shrinks more and more with every new user online."

RE: large array size

Well folks, it is pretty simple.
The integer in QB is made of 2 bytes.
The file is read byte-by-byte.
So if u read two bytes, you proceed 2 bytes, and not one.

Cheers
 Erez Sh.

RE: large array size

edouardo,

If you want to do image processing in a QB-like language, I recommend Visual Basic. Not only does it simplify visualization of the effect being calculated (if that is desired), but it allows you to have absolutely massive arrays. For instance, the following code would let you process a 1024x768 image:

Dim image(0 To 1023, 0 To 767) As Byte
fileNumber% = FreeFile
Open "image.dat" For Binary As fileNumber%
Get fileNumber%, , image()
Close #fileNumber%
'now image() can be processed directly

You'll note also my use of the 'Byte' data type, also available in VB but not in QB. While Visual Basic is not quite as fast as QB, for image processing, which is typically not a realtime type of application, it is clearly superior.

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