Qbasicnews.com
May 26, 2020, 04:39:20 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: Sprite loading read/data statements vs image files  (Read 5401 times)
annunaki10
New Member

Posts: 23



« Reply #15 on: June 04, 2004, 03:54:21 PM »

As far as i know yes. This is a snapshot that came with the program i'm using.
Another thing i noticed is that after i run my version and i exit out of QB, windows gives me an error about something failing and frozen. :x  
[/list]
Logged
annunaki10
New Member

Posts: 23



« Reply #16 on: June 04, 2004, 04:11:50 PM »

Quote
I think this was actually for a BSAVEd file with the palette included. Try it without that bit, and see what you get. If you do get an image, but the colours are wrong, then you may want to think about making your own palette file. You would do this by saving each of the colours from 0 to 255 into a file. The colours would be saved using the R G and B components.


i noticed that the program bsvbabel has a file called QBPAL.pal. Without it, nothing works. i read the tutorial about palettes and how they work.  How would i incorporate this palette file into whatever it is i need?-
Logged
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #17 on: June 04, 2004, 04:27:08 PM »

BLECH. I hate BSVs, so what I would recommend for your personal health is for you to create your own file types. Then you know for sure EXACTLY how they are saved. Thats what I do. For example, I have something called IPF. It stands for "Included palette format". It has the palette r g b components from 0 to 255, then the dimensions of the image, then just commences with the raw image data. I suggest you use that. Much easier.
Logged
Spotted Cheetah
Ancient QBer
****
Posts: 400



WWW
« Reply #18 on: June 04, 2004, 07:27:02 PM »

The solution: QBPDraw Smiley (If you are using 16 colors)

I do not want to advertise myself here since it is not only my program, but it was designed exactly to do what you want. Try it! It is at QB4All, at the Graphic section.
Logged

fter 60 million years a civilization will search for a meteorite destroying most of the living creatures around this age...

There must be a better future for the Cheetahs!

http://rcs.fateback.com/
annunaki10
New Member

Posts: 23



« Reply #19 on: June 04, 2004, 07:43:19 PM »

i actually found the solution for this. i will post the code snippet next time i'm at work. Thanks for everyone's help.
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #20 on: June 04, 2004, 07:57:22 PM »

I don't know if this has been solved, I'm too lazy to review the whole topic Tongue

To store several sprites in one single array, in GET/PUT format you have two choices.

Before, let's remember that you will need to DIM with a value of size% = (width * height)\2+1 in SCREEN 13.

1.- Two dimmensions:

Code:
DIM Sprites%(size%, numberOfSprites% - 1)


You get/put the sprite number "n%" this way:

Code:
GET (x0%, y0%)-(x1%, y1%), Sprites%(0, n%)

PUT (x%, y%), Sprites%(0, n%)


2.- One dimmension:

Code:
DIM Sprites%(size% * (numberOfSprites%))


You get/put the sprite number "n%" this way:

Code:
GET (x0%, y0%)-(x1%, y1%), Sprites%( (n%-1) * size% )

PUT (x%, y%), Sprites%( (n%-1) * size%)


Personally I use option #1.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #21 on: June 05, 2004, 08:04:20 AM »

But nath, how does it actually physically hold the picture if you only dimension half the subscripts needed?

And how come that only works with some progs? I find when using rellib that I have to dimension the full x*y, I think.


EDIT: oh and well, there ya go. Nath just proved me wrong on the sprite array problem. =P Well, you learn something new everyday.
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #22 on: June 05, 2004, 10:10:25 AM »

Dark:  Call me Oz in PMs and stuff, but in the general forum ppl only know me as Alex~

I suppose i could ask if i could change my username to Oz....

Alex~
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #23 on: June 05, 2004, 10:33:22 AM »

Quote from: "dark_prevail"
But nath, how does it actually physically hold the picture if you only dimension half the subscripts needed?

And how come that only works with some progs? I find when using rellib that I have to dimension the full x*y, I think.


EDIT: oh and well, there ya go. Nath just proved me wrong on the sprite array problem. =P Well, you learn something new everyday.


1 byte per pixel.

width * height pixels, then width * height bytes.

The array is made of integers. 1 integer = 2 bytes.

So you need (width * height) \ 2 integers.

You also need 1 integer to store the width an 1 integer to store the height, so (width * height) \ 2 + 2 integers.

But QB arrays begin in "0", so you have to DIM a size% = (width% * height%) \ 2 + 1

The above works if width * height gives an even number. If the result is odd, you will to add 1 more 'cause  width*height\2 will leave out "half an integer". But if you work with 16x16, 16x24, 24x32 and those "normal" sizes the formula always work.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
annunaki10
New Member

Posts: 23



« Reply #24 on: June 07, 2004, 12:14:33 AM »

Thanks nath for explaining how to figure out how much space is needed for the GETed array.

As for my other problem with loading an image onto the screen, here's what i came up with. i figured i'd post the snippet i came up with by checking several different sources.

Code:
DEFINT A-Z
'$DYNAMIC

DECLARE SUB BloadImage (infile$, a())
DECLARE SUB BSVPut (i(), ix, iy)
SCREEN 13

DIM imageFile(1)
file$ = "sprite.bsv"

CALL BloadImage(file$, imageFile())
CALL BSVPut(imageFile(), 1, 1)

'##################################################################
SUB BloadImage (file$, a())

    'get amount of memory needed for a():
    bsvNum = FREEFILE
    OPEN file$ FOR RANDOM AS #bsvNum LEN = 1

    'redimension a() exactly:
    REDIM a((LOF(bsvNum) - 7) \ 2)
    CLOSE #bsvNum

    'BLoad the image:
    DEF SEG = VARSEG(a(0))
    BLOAD file$, VARPTR(a(0))

END SUB

'##################################################################
SUB BSVPut (i(), ix, iy)

    DEF SEG = VARSEG(i(2))
    o& = VARPTR(i(2))

    maxx = ix + i(0) \ 8 - 1 '(optimize calc upper x loop)
    FOR y = iy TO iy + i(1) - 1
        FOR x = ix TO maxx
            IF (x >= 0 AND x <= 319) AND (y >= 0 AND y <= 199) THEN PSET (x, y), PEEK(o&)
        o& = o& + 1
    NEXT x, y

END SUB

Logged
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #25 on: June 07, 2004, 07:46:01 AM »

Quote from: "na_th_an"
1 byte per pixel.

width * height pixels, then width * height bytes.

The array is made of integers. 1 integer = 2 bytes.

So you need (width * height) \ 2 integers.

You also need 1 integer to store the width an 1 integer to store the height, so (width * height) \ 2 + 2 integers.

But QB arrays begin in "0", so you have to DIM a size% = (width% * height%) \ 2 + 1

The above works if width * height gives an even number. If the result is odd, you will to add 1 more 'cause  width*height\2 will leave out "half an integer". But if you work with 16x16, 16x24, 24x32 and those "normal" sizes the formula always work.


ok thats cool. It would have been good if qb had a "Tiny integer" with only 8 bits/1 byte.
Or it would be good if it let you make your own data types! I mean like specify how many bits the type supported. that would make memory management more effiecent, wouldnt it. I mean, if you were storing thousands of 1s and 0s, you could make your own 1 bit data type. Then you could dimension room for 10000s more records.
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #26 on: June 07, 2004, 09:33:56 AM »

And that would make QB even slower Tongue
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #27 on: June 07, 2004, 01:09:16 PM »

hmm.... well I suppose it only be slower for custom data types, yes? So then just normal proggies would be the same speed =)
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!