
;---------------------------------------------------------------------------
;
; This program demonstrates the use of vlab.library. It scans a full-frame
; YUV-picture with a size of 640*512. Then this picture is converted to RGB.
;
;---------------------------------------------------------------------------

               incdir    ASI:
               include   "exec/exec_lib.i"
               include   "exec/memory.i"

               include   "vlab.i"
               include   "vlab_lib.i"
;---------------------------------------------------------------------------
; position and size of the picture you want to scan

LEFT           equ       40
TOP            equ       50
WIDTH          equ       640
HEIGHT         equ       512
;---------------------------------------------------------------------------
CALLEXEC:    MACRO
               movea.l    4,a6
               jsr       _LVO\1(a6)
             ENDM

CALLVLAB:    MACRO
               movea.l   VLabBase,a6
               jsr       _LVO\1(a6)
             ENDM
;---------------------------------------------------------------------------

;---- open vlab.library

               moveq     #VLAB_LIB_VERSION,d0       ;version
               lea       VLabName(pc),a1    ;name = 'vlab.library'
               CALLEXEC  OpenLibrary        ;open the library
               move.l    d0,VLabBase        ;store the pointer to its base
               beq       .NoLib             ;open failed

;---- select a CVBS-input

               moveq     #VLREG_INPUT,d0    ;select input
               moveq     #0,d1              ;input 0, the lower one
               CALLVLAB  VLab_Custom        ;do it

;---- select full-frame

               moveq     #VLREG_FULLFRAME,d0 ;select desired frame(s)
               moveq     #1,d1              ;1 = full-frame (lace)
               CALLVLAB  VLab_Custom        ;do it

;---- get memory for Y-data

               move.l    #WIDTH*HEIGHT,d0   ;the amount of memory needed
               move.l    d0,d4              ;store it for FreeMem()
               move.l    #MEMF_PUBLIC,d1    ;prefer FAST-memory
               CALLEXEC  AllocMem           ;allocate the memory
               move.l    d0,BufferY         ;store pointer
               beq       .NoMemY            ;no

;---- get memory for U-data

               movea.l   VLabBase,a0
               move.l    #WIDTH,d0          ;the width if the picture
               divu.w    vlb_RatioYUV(a0),d0 ;calculate number of U-pixels
               mulu.w    #HEIGHT,d0         ;the amount of memory needed
               move.l    d0,d5              ;store it
               move.l    #MEMF_PUBLIC,d1    ;prefer FAST-memory
               CALLEXEC  AllocMem           ;allocate the memory
               move.l    d0,BufferU         ;store pointer
               beq       .NoMemU            ;no

;---- get memory for V-data

               move.l    d5,d0              ;the amount of memory needed
               move.l    #MEMF_PUBLIC,d1    ;prefer FAST-memory
               CALLEXEC  AllocMem           ;allocate the memory
               move.l    d0,BufferV         ;store pointer
               beq       .NoMemV            ;no

;---- scan the picture

               movea.l   BufferY,a0         ;BufferY
               movea.l   BufferU,a1         ;BufferU
               movea.l   BufferV,a2         ;BufferV
               move.w    #LEFT,d0           ;LeftEdge
               move.w    #TOP,d1            ;TopEdge
               move.w    #WIDTH,d2          ;Width
               move.w    #HEIGHT,d3         ;Height
               CALLVLAB  VLab_Scan          ;get the picture
               tst.l     d0
               beq       .ScanError

;---- get memory for RGB-data

               move.l    #WIDTH*HEIGHT*3,d0 ;the amount of memory needed
               move.l    d0,d6              ;store it for FreeMem()
               move.l    #MEMF_PUBLIC,d1    ;prefer FAST-memory
               CALLEXEC  AllocMem           ;allocate the memory
               move.l    d0,BufferRGB       ;store pointer
               beq       .NoMemRGB          ;no

;---- convert picture to RGB

               movea.l   BufferY,a0         ;BufferY
               movea.l   BufferU,a1         ;BufferU
               movea.l   BufferV,a2         ;BufferV
               movea.l   BufferRGB,a3       ;BufferRGB
               move.l    d4,d0              ;Size (number of Y-pixels)
               moveq     #RGB_HIRES,d1
               CALLVLAB  VLab_YUVtoRGB

;---- now do anything with the RGB-picture

;              ...

;---- free the RGB memory

               movea.l   BufferRGB,a1       ;pointer to V-data
               move.l    d6,d0              ;the amount of memory to free
               CALLEXEC  FreeMem            ;free the memory
.NoMemRGB:
.ScanError:

;---- free the pictures memory

               movea.l   BufferV,a1         ;pointer to V-data
               move.l    d5,d0              ;the amount of memory to free
               CALLEXEC  FreeMem            ;free the memory
.NoMemV:
               movea.l   BufferU,a1         ;pointer to U-data
               move.l    d5,d0              ;the amount of memory to free
               CALLEXEC  FreeMem            ;free the memory
.NoMemU:
               movea.l   BufferY,a1         ;pointer to Y-data
               move.l    d4,d0              ;the amount of memory to free
               CALLEXEC  FreeMem            ;free the memory
.NoClip:
.NoMemY:
;---- close vlab.library

               movea.l   VLabBase,a1        ;the pointer to VLabBase
               CALLEXEC  CloseLibrary       ;close the library
.NoLib:
;---- the end

               moveq     #0,d0              ;no errors (I hope)
               rts                          ;return to the shell
;---------------------------------------------------------------------------
VLabName:      dc.b      'vlab.library',0
               even
;###################################################################
               section   bss,BSS
;###################################################################

VLabBase:      ds.l      1
BufferY:       ds.l      1
BufferU:       ds.l      1
BufferV:       ds.l      1
BufferRGB:     ds.l      1

;---------------------------------------------------------------------------
               end
