VDI vr_trnfm() example

GFA BASIC-related articles in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2252
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

VDI vr_trnfm() example

Postby lp » Fri Nov 14, 2014 7:03 pm

This is a quick example I threw together of how to use the VDI to transform a bitmap.

This example draws a test block on the screen and then transforms it to VDI standard format and writes it to disk with a simple header. It then reads the file back and converts it back to device format and draws the image at two new screen locations using two different methods. It then falls into a loop and you can draw the image at the mouse location.

The PUT command in GFA has a poorly documented feature. It can render the image via the VDI if bit 4 of the mode is set. However, if you ever managed to figure this out from the vague manual it don't work, it's terribly broken. It might even crash. This example however works with GBE + runonly. :wink:

This could for example be used to write a game that runs under GEM in any mode on any gfx card. You can make all the game images for all the modes you wish to support and convert them to VDI standard format. Then use the VDI to transform them at load time to the current mode. If it happens to be running on a gfx card then it should work, because the VDI driver knows the internal format of its own screen layout and the image is correctly transformed.

Code: Select all

' this test assumes a few things:
'   the console is open to catch text output
'   o:\ is mapped to u:\ram\ on my system, good for writing temporary files
'   requires updated interpreter, otherwise put command with vdi option is broken
' note: block width must to be evenly divisible by 16
'
' define test block size
bx&=20
by&=20
bw&=16
bh&=16
'
' render test block on the screen
@draw_test_block(bx&,by&,bw&,bh&)
'
bp&=WORD{LONG{GB+4}+20} !bit planes via gem
s%=((bw&*bp&)\8)*bh&    !calc bitmap size in bytes
PRINT "planes: ";bp&
PRINT "bitmap size: ";s%;" bytes"
'
' convert device format to vdi standard format
s$=SPACE$(s%)              !src buf
d$=SPACE$(s%)              !dst buf
@vro_cpyfm(FALSE,_X,_Y,bx&,by&,bw&,bh&,V:s$,bw&,bh&,0,0,bw&,bh&) !cpy scrn to buf
@vr_trnfm(V:s$,0,bp&,bw&,bh&,V:d$,1,bp&)                         !transform
' save image to disk in vdi standard format
OPEN "o",#1,"o:\image.vdi"
OUT& #1,bw&,bh&,bp&        !header width,height,planes
BPUT #1,V:d$,s%            !bitmap
CLOSE #1
'
' load image from disk in vdi standard format
s$=SPACE$(s%)              !src buf
d$=SPACE$(s%)              !dst buf
OPEN "i",#1,"o:\image.vdi"
iw&=INP&(#1)               !width
ih&=INP&(#1)               !height
ip&=INP&(#1)               !planes
BGET #1,V:s$,s%            !bitmap
CLOSE #1
' convert vdi standard format to device format
PRINT "width=";iw&;" height=";ih&;" planes=";ip&
@vr_trnfm(V:s$,1,ip&,iw&,ih&,V:d$,0,ip&)         !transform
'
' test #1 - render block on the screen
@vro_cpyfm(V:d$,iw&,ih&,0,0,iw&,ih&,FALSE,_X,_Y,40,40,iw&,ih&) !cpy buf to scrn
'
' test #2 - build a gfa gfx put block
g$=MKI$(iw&-1)+MKI$(ih&-1)+MKI$(ip&)+d$ !required 6 byte header + bitmap
PUT 60,60,g$,BSET(3,4)                  !set bit 4 of mode for a vdi blit
'
DO
  ~GRAF_MKSTATE(mx&,my&,mk&,sk&)
  IF mk&=1                      !button 1?
    DEFMOUSE 256                !hidem
    PUT mx&,my&,g$,BSET(3,4)    !vdi blit at mouse x/y
    DEFMOUSE 257                !showm
  ENDIF
LOOP UNTIL mk&=2                !button 2?
~FORM_DIAL(3,0,0,0,0,0,0,_X,_Y) !force desktop redraw
'
EDIT
PROCEDURE draw_test_block(bx&,by&,bw&,bh&)
  LOCAL c&,x&,y&
  CLR c&
  FOR y&=by& TO by&+bh&-1
    FOR x&=bx& TO bx&+bw&-1
      COLOR c&
      PLOT x&,y&
      INC c&
      IF c&>_C-1
        c&=0
      ENDIF
    NEXT x&
  NEXT y&
  COLOR 1
  BOX bx&,by&,bx&+bw&-1,by&+bh&-1
RETURN
PROCEDURE vro_cpyfm(sa%,sw.&,sh.&,sx&,sy&,sw&,sh&,da%,dw.&,dh.&,dx&,dy&,dw&,dh&)
  LOCAL src%,dst%
  INLINE src%,24
  INLINE dst%,24
  CONTRL(0)=109
  CONTRL(1)=4
  CONTRL(3)=1
  CONTRL(6)=V~H
  INTIN(0)=3
  LONG{CONTRL+14}=src%
  LONG{CONTRL+18}=dst%
  PTSIN(0)=sx&
  PTSIN(1)=sy&
  PTSIN(2)=sx&+sw&-1
  PTSIN(3)=sy&+sh&-1
  PTSIN(4)=dx&
  PTSIN(5)=dy&
  PTSIN(6)=dx&+dw&-1
  PTSIN(7)=dy&+dh&-1
  LONG{src%}=sa%
  WORD{src%+4}=sw.&
  WORD{src%+6}=sh.&
  WORD{src%+8}=(sw.&+15)\16
  WORD{src%+10}=0
  WORD{src%+12}=WORD{LONG{GB+4}+20}
  LONG{dst%}=da%
  WORD{dst%+4}=dw.&
  WORD{dst%+6}=dh.&
  WORD{dst%+8}=(dw.&+15)\16
  WORD{dst%+10}=0
  WORD{dst%+12}=WORD{LONG{GB+4}+20}
  VDISYS
RETURN
PROCEDURE vr_trnfm(sa%,sf&,sp&,w&,h&,da%,df&,dp&)
  LOCAL src%,dst%
  INLINE src%,24
  INLINE dst%,24
  CONTRL(0)=110
  CONTRL(1)=0
  CONTRL(3)=0
  CONTRL(6)=V~H
  LONG{CONTRL+14}=src%
  LONG{CONTRL+18}=dst%
  LONG{src%}=sa%
  WORD{src%+4}=w&
  WORD{src%+6}=h&
  WORD{src%+8}=(w&+15)\16
  WORD{src%+10}=sf&
  WORD{src%+12}=sp&
  LONG{dst%}=da%
  WORD{dst%+4}=w&
  WORD{dst%+6}=h&
  WORD{dst%+8}=(w&+15)\16
  WORD{dst%+10}=df&
  WORD{dst%+12}=dp&
  VDISYS
RETURN
Last edited by lp on Sat Jan 10, 2015 4:23 am, edited 1 time in total.

User avatar
Cyprian
Atari God
Atari God
Posts: 1404
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: VDI vr_trnfm() example

Postby Cyprian » Fri Nov 14, 2014 10:09 pm

can we use that method for converting e.g. 4-bitplane image into hi-color (Falcon's mode) to true-color image (VME video card)?
Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Aranym / Steem / Saint
http://260ste.appspot.com/

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2252
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: VDI vr_trnfm() example

Postby lp » Sat Nov 15, 2014 3:44 pm

I am not sure sure if vr_trnfm() will do that. The documentation is not really clear on that point. I wondered the same thing, might have to make a test.

The book 'COMPUTE!'s Technical Reference Guide - Volume One - VDI' (page 129) mentions the use of one image for all modes and using vr_trnfm() to transform it. However it suggests the opposite, supplying the image in the highest mode you plan to support, and let vr_trnfm() convert it down.

vido
Atari Super Hero
Atari Super Hero
Posts: 536
Joined: Mon Jan 31, 2011 7:39 pm

Re: VDI vr_trnfm() example

Postby vido » Sat Nov 15, 2014 5:31 pm

Thank you Lonny!
I guess this is your answer to my question to you the other day?
Just from the look I think this will hekp me a lot :)

I will try to use this as soon as I will find time. I tried new GBE and now I use it :)
Thanks again ...

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2252
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: VDI vr_trnfm() example

Postby lp » Sat Nov 15, 2014 6:03 pm

Yes, our discussion about GEM prompted me to write that example. :wink:

I'm not sure if the VDI will transform a lower bit plane image to a higher one. Either way the results are not going to be very good. A set of images for all the modes is going to yield the best visual results for any project. The book even goes on to suggests this, because it will just drop the unneeded planes when converting down.

The Falcon has high-color so there really should be no problems with that, unless some video card driver that supports the same mode doesn't follow the same rules as the Falcon VDI. I don't know what layout the Falcon VDI uses when converting a high-color image to standard format.

Also true-color is somewhat of a gray area. When you get into 24-bit and 32-bit true-color who knows since Atari dev stopped at high-color.

vido
Atari Super Hero
Atari Super Hero
Posts: 536
Joined: Mon Jan 31, 2011 7:39 pm

Re: VDI vr_trnfm() example

Postby vido » Sat Nov 15, 2014 9:03 pm

This will help anyway. I have resolutions with 32, 24, 16 and maybe 256 bit graphics modes in mind.
And if this wont work (I doubt) I will make separate gfx for different color depths.

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: VDI vr_trnfm() example

Postby Mikefulton » Wed Jan 13, 2016 7:41 am

Cyprian wrote:can we use that method for converting e.g. 4-bitplane image into hi-color (Falcon's mode) to true-color image (VME video card)?


No, it won't do that. What vr_trnfm does convert a raster form between having bitplanes interleaved a word at a time (aka how the video shifter wants it) and having all the data for a single bitplane followed by all the data for the next bitplane, etc. (aka standard format).

Theoretically, for different video hardware, that first format could be different. Like pixel-packed instead of bitplanes. However, it'd always be converting between two different arrangements of the same kind of pixels, not between two completely different pixel formats (like 4-plane to true-color).

User avatar
Rajah Lone
Captain Atari
Captain Atari
Posts: 371
Joined: Wed Aug 07, 2002 12:27 pm
Location: Lyon / France
Contact:

Re: VDI vr_trnfm() example

Postby Rajah Lone » Sat Mar 05, 2016 5:03 pm

lp wrote:You can make all the game images for all the modes you wish to support and convert them to VDI standard format.

This is what I do in my games.
Images are file-stored in a custom format : header that is used finaly as a MFDB and bitmaps in standard format: n*16 pixels width, separate planes.
Usualy, graphics are 16 colors.
- for 16c screenmode: vr_trnfm() is used directly to convert standard to atari planar format.
- for 256c screenmode: vr_trnfm() is also used, but 4 planes are added to the orignal 4 planes, so indexes are shifted to higher than 16 to keep the original GEM colors untouched.
- for TC15 to TC 32: vr_trnfm() is not used. Each color of the palette is converted to a pixel array (16 pixels, LONG values), v_scrninfo() gave all information about screen structure to build these pixels. Each bitmap is read, each index palette is read, so the corresponding pixel is written by hand into the final bitmap.

If you are interested, see my GFA sources. Teenage Queen Reloaded, load_image procedure. I have written an util to convert GIF to the custom vdi image format (2VDI.PRG or 2DGX.PRG), also available in my sources.


Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 2 guests