Author Topic: Draw Image Rectangle Sub  (Read 6467 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Draw Image Rectangle Sub
« on: July 13, 2006 »
The following snippet is kinda Psuedo code, as I've not included the entire source which is pretty lengthy.
However, this portion of the code isn't right, and I wondered if anybody could spot what I'm calculating wrongly.
I've based it off, from the Blitz Basic "DrawImageRect" command. All that is contained in the Images(x,y) is the image colour data.

If you know what I've buggered up, I'd love to know what the correction is.

Code: [Select]
Sub DrawImageRect ( ByVal PosX, Byval PosY, ByVal rect_x, ByVal rect_y, ByVal rect_width, ByVal rect_height)

    Dim x,y, Col
   
    For y=rect_y to rect_height-1
        For x=rect_x To rect_width-1
           
            Col=Images(x,y)
           
            FeedPixels( x+PosX, y+PosY, Col )
           
        Next
    Next
   
End Sub

Cheers for taking a look and many thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Draw Image Rectangle Sub
« Reply #1 on: July 13, 2006 »
what is it actually doing wrong as from that code, assuming that your not running out of the images arrays x & y size, looks like it would work ?

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Draw Image Rectangle Sub
« Reply #2 on: July 13, 2006 »
Not sure what all you inputs mean, so I got rid of rect_x and rect_y
Dunno if this is what you are looking for.

Code: [Select]
Sub DrawImageRect ( ByVal PosX, Byval PosY, ByVal rect_width, ByVal rect_height )

  Â  Dim x,y, Col
  Â  
  Â  For y=0 to rect_height-1
  Â  Â  Â  For x=0 To rect_width-1
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  Col=Images(x, y)
  Â  Â  Â  Â  Â  
  Â  Â  Â  Â  Â  FeedPixels( x + PosX, y + PosY, Col )
  Â  Â  Â  Â  Â  
  Â  Â  Â  Next
  Â  Next
  Â  
End Sub

But for it to be similar to blitz, you would usually get the rect_width and height from the actual image.
« Last Edit: July 13, 2006 by Tetra »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Draw Image Rectangle Sub
« Reply #3 on: July 13, 2006 »
@TinDragon: It doesnt display anything.

@Tetra: Want to aim for the Blitz approach, Im thinking maybe I need to add rect_x and rect_Y at the start of the x,y loop and also to the end rect_height / width. Will have a play.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Draw Image Rectangle Sub
« Reply #4 on: July 13, 2006 »
Hmmm, I can't phathom this one. I've tried doing the following:

Code: [Select]
Sub DrawImageRect( ByVal PosX, Byval PosY, ByVal rect_x, Byval rect_y, ByVal rect_width, ByVal rect_height )


    Dim x,y, Col
   
    Col=Images( rect_x, rect_y )

    For y=0 to rect_height-1
        For x=0 To rect_width-1
           
           FeedPixels( x + PosX, y + PosY, Col )
           
        Next
    Next
End Sub

And still no joy. :(
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Draw Image Rectangle Sub
« Reply #5 on: July 13, 2006 »
Cool, i've fixed it!! Hurray :D

Code: [Select]
Sub DrawImageRect( ByVal PosX, Byval PosY, ByVal rect_x, Byval rect_y, ByVal rect_width, ByVal rect_height )

    Dim x,y, Col
   

    For y=0 to rect_height-1
        For x=0 To rect_width-1
           
            Col=Images( x+rect_x, y+rect_y )

            if x+PosX>0 and x+PosY<XRES-1 and y+PosY>0 and y+PosY<YRES-1 then
           
                FeedPixels( x + PosX, y + PosY, Col )
           
           End if
           
        Next
    Next
   
End Sub

Feel free to use.

Cheers - Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Draw Image Rectangle Sub
« Reply #6 on: July 13, 2006 »
Hehehe, I must be drunk. I started trying to fix this problem before I realised that there were more posts underneath Doh!  ;D Never mind and glad you got it fixed mate.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Draw Image Rectangle Sub
« Reply #7 on: July 13, 2006 »
Cheers, this opens alot of doors for me porting over some effects.
Hope it's of use to others too.

Thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Draw Image Rectangle Sub
« Reply #8 on: July 13, 2006 »
Drawimagerect is a handy function for all sine scrollers :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Draw Image Rectangle Sub
« Reply #9 on: July 13, 2006 »
I've now also managed to do a very famous Jeff Minter Atari effect too. Which I hope to put to use in the next GVY release.
There's a ton of cool stuff to be had with DIR.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

thrawn89

  • Guest
Re: Draw Image Rectangle Sub
« Reply #10 on: July 15, 2006 »
Can you please give us a short example with this function in action? Im having difficulty understanding as to its purpose...thanks :-)

Thrawn

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Draw Image Rectangle Sub
« Reply #11 on: July 15, 2006 »
The main thing with this function is that for example, you could load in a whole picture, say a screen with a font on it and cut the bits out of it that you want to draw.
Being able to draw slices out of the image makes it very easy to simulate Amiga copper wobble effects and also to make sine scrolls with ease as you can then just step through the letter with a simple for next loop varying the sine wave as you go.
Shockwave ^ Codigos
Challenge Trophies Won:

thrawn89

  • Guest
Re: Draw Image Rectangle Sub
« Reply #12 on: July 16, 2006 »
Ahh...you know, I can code a png decoder, I can even write my own render from scratch...yet...that just went right over my head XD

Ok, ok, I understood some of it...how would you use it as you say to cycle through a font pic [cause if you resource and load one png it will drastcally cut down on load times for a font set]?

Also...could you use it for say...sound resampling?

Thrawn


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Draw Image Rectangle Sub
« Reply #13 on: July 16, 2006 »
No problem, you'd have a strip of the letters, I've attached a strip of sprites from a game I made because I can't find a suitable font at the minute but it will give you the idea.

You'd set your font out in a similar fashion to this, as one long image all in ascii order, you can load in your image as this one strip and then just use the ascii offset to calculate mathematically the position in the strip.
for example, if you wanted to draw the exclamation mark and your letters are 32*32, being as the first character is space and the second one is exclamation mark you could do;

STRING="!"

Code: [Select]
         offset = (ASC(MID(STRING,POINTER,1)) - 31) * 32
         draw_image_rect ( FONT_SCREEN , XPOS , YPOS , OFFSET , 0 , OFFSET+31 , 31 )

To cut the letter out of the font strip that you wanted to draw.
I guess that you could use the technique to get different notes from a sound sample, if you sampled a sound at a very low C for instance and stepped through the sound data to increase the speed you play the note you'd notice a rise in pitch so I guess that you could make a simple tracker program in that way, dunno I've never really thought about doing anything like that.
All I know is that it's a pain in the ass to have to load each letter of a font seperately and it would be nice to be able to load gfx strips like this.


 
« Last Edit: July 16, 2006 by Shockwave »
Shockwave ^ Codigos
Challenge Trophies Won:

thrawn89

  • Guest
Re: Draw Image Rectangle Sub
« Reply #14 on: July 16, 2006 »
Ok, I understand fully now...Im sure you dont need all those variables in the parameter list though, when I get back and start making mine, I'll post the code....

Thrawn

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Draw Image Rectangle Sub
« Reply #15 on: July 16, 2006 »
Cool, But I'm sure you'd need to have at least these parameters;

SCREENX , SCREENY , STARTX , STARTY , WIDTH , HEIGHT
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Draw Image Rectangle Sub
« Reply #16 on: July 16, 2006 »
[quote = "Blitz Basic Syntax" ]
DrawImageRect:  image,x,y,rect_x,rect_y,rect_width,rect_height,[frame]

Parameters:
image = variable holding the image handle
x = x location on the screen to draw the image
y = y location on the screen to draw the image
rect_x = starting x location within the image to draw
rect_y = starting y location within the image to draw
rect_width = the height of the area to draw
rect_height = the width of the area to draw
frame = optional frame number of image to draw
Quote

If you've got or used BB in the past, then you'd know how pretty usefull this command is.

All I've done is omit the Image, as Im not using sprites as you'll see by my first few posts. All my data is loaded / made into a Dim Image( Width, Height ) as I find it much easier to manipulate the colour data with.

I'll post up some code if I've still got Internet and I remember, when I get home of a few example a bit later in seperate topics.

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: