Qbasicnews.com

Full Version: Resizing Images???
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Is there an way to resize your images in your program smoothly.

I'm working on a 2d Space Game project. But wan't to add a 3d like affect by resizing smaller space ships and let them fly beneath your ship or make them bigger and let them fly above you.

Can this be done???
It can be done, but not without some calculus. I haven't learned the technique yet either - you're better off asking Rel or Na_th_an
I made a BMP loader (based on rel's code I think) that could zoom the BMP to almost any size.

Though, the amount of math involved made it very slow =(...
Quote:It can be done, but not without some calculus. I haven't learned the technique yet either - you're better off asking Rel or Na_th_an

??? You can do scaling without calculus!

I belive there is a handy link on gamedev.net.
Hangon...

... has my internet just broken or is gamedev.net just DAMN slow?...


...


.... still waiting...

...

Finally!

Here you go: http://gamedev.net/reference/articles/article362.asp
@dark_prevail: Aaaaaah Pascal... Sorry, try to figure it out from that article.

But if anyone can show me a QB example, that would be great!!!!
Yup, but if you read the tut, it actually explains how to scale. So the language shouldnt matter at all.
[syntax="qbasic"]DEFINT A-Z
'$STATIC
TYPE BMPHeaderType
ID AS STRING * 2
Size AS LONG
RSV1 AS INTEGER
RSV2 AS INTEGER
offset AS LONG
HORZ AS LONG
WID AS LONG
HEI AS LONG
PLANES AS INTEGER
BPP AS INTEGER
COMPRESSION AS LONG
IMAGESIZE AS LONG
xRes AS LONG
yRes AS LONG
CLRUSED AS LONG
CLRIMPORT AS LONG
Pal AS STRING * 1024
END TYPE
DECLARE SUB LoadBMP (DestSeg%, segxRes%, segyRes%, sX%, sY%, File$, SwitchPal%, trans%, scaleX%, scaleY%)
'DestSeg = Destination segment, where to draw, &Ha000 for screen
'segxRes = Segment X resolution, 320 for screen 13
'segyRes = Segment Y resolution, 200 for screen 13
'sX = Start X, image position
'sY = Start Y, image position
'File = The BMP to load, uncompressed 8bit BMP's only.
'SwitchPal = Load palette from file
'trans = If you want a color to be transperant, enter it here
'scaleX = Target width of image, example 64
'scaleY = Target height of image, example 40

CLS : SCREEN 13

LoadBMP &HA000, 320, 200, 0, 0, "bar.bmp", 1, 0, 320, 1000

LoadBMP &HA000, 320, 200, 140, 100, "bar.bmp", 0, 0, 100, 100

LoadBMP &HA000, 320, 200, 50, 70, "bar.bmp", 0, 0, 100, 50

LoadBMP &HA000, 320, 200, 220, 150, "bar.bmp", 0, 0, 20, 150

LoadBMP &HA000, 320, 200, 10, 10, "bar.bmp", 0, 0, 100, 100

t$ = INPUT$(1)

REM $DYNAMIC
SUB LoadBMP (DestSeg%, segxRes%, segyRes%, sX%, sY%, File$, SwitchPal%, trans%, scaleX%, scaleY%)
DIM BMP AS BMPHeaderType

F% = FREEFILE 'Get free filenum
OPEN File$ FOR BINARY AS #F% 'Binary read
GET #F%, , BMP 'Get header
Pall$ = BMP.Pal
IF SwitchPal% THEN
IF LEN(Pall$) = 1024 THEN
OUT &H3C8, 0
FOR i% = 1 TO 1024 STEP 4
B% = ASC(MID$(Pall$, i%, 1)) \ 4
G% = ASC(MID$(Pall$, i% + 1, 1)) \ 4
r% = ASC(MID$(Pall$, i% + 2, 1)) \ 4
OUT &H3C9, r%
OUT &H3C9, G%
OUT &H3C9, B%
NEXT i%
END IF
END IF

Byte$ = SPACE$(BMP.WID)

Wide% = BMP.WID - 1 'Sub 1 since we start at zero
Hite% = BMP.HEI - 1
scaleX! = scaleX * .01
scaleY! = scaleY * .01

sY% = sY% + Hite% * scaleY!

ty = INT(scaleY!)
tx = INT(scaleX!)

DEF SEG = DestSeg%

FOR y% = Hite% TO 0 STEP -1
GET #F%, , Byte$
rXl! = 0
FOR x% = 0 TO Wide%
c% = ASC(MID$(Byte$, x% + 1, 1))
IF c% <> trans% THEN
FOR zy = 0 TO ty
FOR zx = 0 TO tx
xl = sX% + INT(rXl!) + zx
yl = sY% + INT(rYl!) + zy
' IF xl > 0 AND xl < segxRes THEN
' IF yl > 0 AND yl < segyRes THEN
POKE xl + yl * (segxRes + 0&), c%
' END IF
' END IF
NEXT
NEXT
END IF
rXl! = rXl! + scaleX!
NEXT
rYl! = rYl! - scaleY!
NEXT
CLOSE #F
DEF SEG
END SUB[/syntax]

Original BMP loader fom Relsoft
@Z!re: That directly loads a bmp file and scales it. But I use PP256 .put files for my project. How do I scale those files???

@dark_prevail: Tell me if i'm wrong but the article ownly explains how to shrink the images.
Quote:@dark_prevail: Tell me if i'm wrong but the article ownly explains how to shrink the images.

nope. It explains the method which allows you to do both.
PP256 gfx are just GET/PUT compatible data inside arrays. You just need to know how to pset or get a point directly from that data. If you can't figure it out, I'll tell you. (studying right now, too lazy to think in another think appart from Operating Systems and processes fighting for resources :barf: )

I'd suggest you to use a lib for this. There's a fast algo, based on Bresenham integer calculation, but still it will be slow. I can dig for it, it was on the ABC packets.

The non-bresenham way to do it is called "nearest neightbour". You just take the destination size and make two loops to run accross it. For each pixel, you look which pixel in the sprite should be drawn, using simple proportions. The problem is that this uses floating point math thus it's slow.
Pages: 1 2