1 /*
2  * This software is copyrighted as noted below.  It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is".  Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * vfr.c - interface with SGI's Video FRamer.
20  *
21  * Author:      Raul Rivero
22  *              Mathematics Dept.
23  *              University of Oviedo
24  * Date:        Thu Jan 16 1992
25  * Copyright (c) 1992, Raul Rivero
26  *
27  */
28 
29 #include <lug.h>
30 #include <lugfnts.h>
31 
32 
33 /*
34  * Look here !!!
35  * =============
36  *
37  * This code is valid only if we have defined the iVFR
38  * macro ( read the root Makefile for more information ).
39  *
40  */
41 
42 
43 #ifdef iVFR
44 
45 #include "image.h"
46 #include "vframer.h"
47 
48 #define VIDEO_BUFFER_NAME		"r_y_625"
49 #define VFRLINESIZE             	1024
50 
write_vfr(bitmap,resetVFR,VFRbuffer)51 write_vfr( bitmap, resetVFR, VFRbuffer )
52 bitmap_hdr *bitmap;
53 int resetVFR;
54 char *VFRbuffer;
55 {
56   register int y, x;
57   VFR_DEV *vfr;
58   byte *ptr;
59   int totalsize = bitmap->ysize * bitmap->xsize;
60   byte *r, *g, *b;
61   int offset;
62   int flag;
63   char *videomode;
64 
65   /* An image ? */
66   if ( bitmap->magic != LUGUSED )
67     error( 19 );
68 
69   /* We need a RGB image */
70   if ( bitmap->depth < 24 )
71     error( 7 );
72 
73   /*
74    * Open the Video FRamer.
75    */
76   flag = ( resetVFR ? VFR_CUSTOM_SETUP : -VFR_CUSTOM_SETUP );
77   videomode = ( VFRbuffer ? VFRbuffer : VIDEO_BUFFER_NAME );
78   if ( !(vfr = vfr_open( DEFAULT_VFR_ADDR, flag, videomode )) )
79     error( 16 );
80 
81   /*
82    * Pointers to VF's shadow memory and
83    * image components.
84    */
85   ptr =  (byte *) VFR_DEVICE_PSHADOW( *vfr );
86   r = bitmap->r;
87   g = bitmap->g;
88   b = bitmap->b;
89   offset = 4 * ( VFRLINESIZE - bitmap->xsize );
90 
91   for ( y = 0; y < bitmap->ysize; y += 2 ) {
92     /*
93      * Odd lines.
94      */
95     for ( x = 0; x < bitmap->xsize; x++ ) {
96       *ptr++ = 0;
97       *ptr++ = *b++;
98       *ptr++ = *g++;
99       *ptr++ = *r++;
100     }
101     /*
102      * Fill unused line with 0's.
103      */
104     bzero( ptr, offset );
105     ptr += offset;
106 
107     /*
108      * Non odd lines.
109      */
110     for ( x = 0; x < bitmap->xsize; x++ ) {
111       *ptr++ = 0;
112       *ptr++ = *b++;
113       *ptr++ = *g++;
114       *ptr++ = *r++;
115     }
116     bzero( ptr, offset );
117     ptr += offset;
118   }
119 
120   /*
121    * Now we have the image into shadow memory, so write
122    * it to VFR.
123    */
124   if ( !vfr_convert_from_rgb( vfr, bitmap->xsize ) )
125     error( 10 );
126 }
127 
128 
129 #endif  /* iVFR */
130