Debian Codegraph @

win32/plugins/dfxvideo/winsrc/record.c

raw
1 /***************************************************************************
2 record.c - description
3 -------------------
4 begin : Fri Nov 09 2001
5 copyright : (C) 2001 by Darko Matesic
6 email : [email protected]
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. See also the license.txt file for *
15 * additional informations. *
16 * *
17 ***************************************************************************/
18
19 #include "externals.h"
20 #include "record.h"
21 #include "gpu.h"
22 #include <direct.h>
23
24 extern BOOL RECORD_RECORDING = FALSE;
25 BITMAPINFOHEADER RECORD_BI = {40,0,0,1,16,0,0,2048,2048,0,0};
26 unsigned char RECORD_BUFFER[1600*1200*3];
27 unsigned long RECORD_INDEX;
28 unsigned long RECORD_RECORDING_MODE;
29 unsigned long RECORD_VIDEO_SIZE;
30 unsigned long RECORD_RECORDING_WIDTH;
31 unsigned long RECORD_RECORDING_HEIGHT;
32 unsigned long RECORD_FRAME_RATE_SCALE;
33 unsigned long RECORD_COMPRESSION_MODE;
34 COMPVARS RECORD_COMPRESSION1;
35 unsigned char RECORD_COMPRESSION_STATE1[4096];
36 COMPVARS RECORD_COMPRESSION2;
37 unsigned char RECORD_COMPRESSION_STATE2[4096];
38
39
40 PCOMPVARS pCompression = NULL;
41 AVISTREAMINFO strhdr;
42 PAVIFILE pfile = NULL;
43 PAVISTREAM ps = NULL;
44 PAVISTREAM psCompressed = NULL;
45 AVICOMPRESSOPTIONS opts;
46
47 unsigned long frame;
48 unsigned long skip;
49
50 //--------------------------------------------------------------------
51
52 BOOL RECORD_Start()
53 {
54 static FILE *data;
55 static char filename[255];
56 RECORD_INDEX = 0;
57 if(HIWORD(VideoForWindowsVersion())<0x010a) {MessageBox(NULL,"Video for Windows version is too old !\nAbording Recording.","Error", MB_OK|MB_ICONSTOP);return FALSE;}
58 mkdir("demo");
59 while(TRUE)
60 {
61 sprintf(filename,"demo\\demo%04d.AVI",RECORD_INDEX++);
62 if((data=fopen(filename,"rb"))==NULL) break;
63 fclose(data);
64 if(RECORD_INDEX>9999) goto error;
65 }
66 if((data=fopen(filename,"wb"))==NULL) goto error;
67 if(RECORD_RECORDING_MODE==0)
68 {
69 switch(RECORD_VIDEO_SIZE)
70 {
71 case 0:
72 RECORD_BI.biWidth = iResX;
73 RECORD_BI.biHeight = iResY;
74 break;
75 case 1:
76 RECORD_BI.biWidth = iResX/2;
77 RECORD_BI.biHeight = iResY/2;
78 break;
79 default:
80 RECORD_BI.biWidth = iResX/4;
81 RECORD_BI.biHeight = iResY/4;
82 break;
83 }
84 }
85 else
86 {
87 RECORD_BI.biWidth = RECORD_RECORDING_WIDTH;
88 RECORD_BI.biHeight = RECORD_RECORDING_HEIGHT;
89 }
90 if(RECORD_COMPRESSION_MODE==0)
91 {
92 RECORD_BI.biBitCount = 16;
93 RECORD_BI.biSizeImage = RECORD_BI.biWidth*RECORD_BI.biHeight*2;
94 pCompression = &RECORD_COMPRESSION1;
95 }
96 else
97 {
98 RECORD_BI.biBitCount = 24;
99 RECORD_BI.biSizeImage = RECORD_BI.biWidth*RECORD_BI.biHeight*3;
100 pCompression = &RECORD_COMPRESSION2;
101 }
102 AVIFileInit();
103 if(AVIFileOpen(&pfile,filename,OF_WRITE | OF_CREATE,NULL)!=AVIERR_OK) goto error;
104 memset(&strhdr,0,sizeof(strhdr));
105 strhdr.fccType = streamtypeVIDEO;
106 strhdr.fccHandler = pCompression->fccHandler;
107 strhdr.dwScale = RECORD_FRAME_RATE_SCALE + 1;
108 strhdr.dwRate = (PSXDisplay.PAL)?50:60;// FPS
109 strhdr.dwSuggestedBufferSize = RECORD_BI.biSizeImage;
110 SetRect(&strhdr.rcFrame,0,0,RECORD_BI.biWidth,RECORD_BI.biHeight);
111 if(AVIFileCreateStream(pfile,&ps,&strhdr)!=AVIERR_OK) goto error;
112
113 opts.fccType = pCompression->fccType;
114 opts.fccHandler = pCompression->fccHandler;
115 opts.dwKeyFrameEvery = pCompression->lKey;
116 opts.dwQuality = pCompression->lQ;
117 opts.dwBytesPerSecond = pCompression->lDataRate;
118 opts.dwFlags = AVICOMPRESSF_DATARATE|AVICOMPRESSF_KEYFRAMES|AVICOMPRESSF_VALID;
119 opts.lpFormat = &RECORD_BI;
120 opts.cbFormat = sizeof(RECORD_BI);
121 opts.lpParms = pCompression->lpState;
122 opts.cbParms = pCompression->cbState;
123 opts.dwInterleaveEvery = 0;
124
125 if(AVIMakeCompressedStream(&psCompressed,ps,&opts,NULL)!=AVIERR_OK) goto error;
126
127 //if(AVIStreamSetFormat(psCompressed,0,&RECORD_BI,RECORD_BI.biSizeImage)!=AVIERR_OK) goto error;
128 // fixed:
129 if(AVIStreamSetFormat(psCompressed,0,&RECORD_BI,sizeof(RECORD_BI))!=AVIERR_OK) goto error;
130
131 frame = 0;
132 skip = RECORD_FRAME_RATE_SCALE;
133 return TRUE;
134 error:
135 RECORD_Stop();
136 RECORD_RECORDING = FALSE;
137 return FALSE;
138 }
139
140 //--------------------------------------------------------------------
141
142 void RECORD_Stop()
143 {
144 if(ps) AVIStreamClose(ps);
145 if(psCompressed) AVIStreamClose(psCompressed);
146 if(pfile) AVIFileClose(pfile);
147 AVIFileExit();
148 }
149
150 //--------------------------------------------------------------------
151
152 BOOL RECORD_WriteFrame()
153 {
154 if(skip) {skip--;return TRUE;}
155 skip=RECORD_FRAME_RATE_SCALE;
156 if(!RECORD_GetFrame()) return FALSE;
157 if(FAILED(AVIStreamWrite(psCompressed,frame,1,RECORD_BUFFER,RECORD_BI.biSizeImage,AVIIF_KEYFRAME,NULL,NULL)))
158 {RECORD_Stop();return FALSE;}
159 frame++;
160 return TRUE;
161 }
162
163 //--------------------------------------------------------------------
164
165 BOOL RECORD_GetFrame()
166 {
167 static unsigned short *srcs,*src,*dests,cs;
168 static unsigned char *srcc,*destc;
169 static long x,y,cx,cy,ax,ay;
170 static unsigned long cl;
171
172 if(PSXDisplay.Disabled)
173 {
174 memset(RECORD_BUFFER,0,RECORD_BI.biSizeImage);
175 return TRUE;
176 }
177
178 srcs = (unsigned short*)&psxVuw[PSXDisplay.DisplayPosition.x+(PSXDisplay.DisplayPosition.y<<10)];
179 dests = (unsigned short*)RECORD_BUFFER;
180 destc = (unsigned char*)RECORD_BUFFER;
181 ax = (PSXDisplay.DisplayMode.x*65535L)/RECORD_BI.biWidth;
182 ay = (PSXDisplay.DisplayMode.y*65535L)/RECORD_BI.biHeight;
183 cy = (PSXDisplay.DisplayMode.y-1)<<16;
184 if(RECORD_BI.biBitCount==16)
185 {
186 if(PSXDisplay.RGB24)
187 {
188 for(y=0;y<RECORD_BI.biHeight;y++)
189 {
190 srcc = (unsigned char*)&srcs[(cy&0xffff0000)>>6];
191 cx = 0;
192 for(x=0;x<RECORD_BI.biWidth;x++)
193 {
194 cl = *((unsigned long*)&srcc[(cx>>16)*3]);
195 *(dests++) = (unsigned short)(((cl&0xf8)<<7)|((cl&0xf800)>>6)|((cl&0xf80000)>>19));
196 cx += ax;
197 }
198 cy -= ay;if(cy<0) cy=0;
199 }
200 }
201 else
202 {
203 for(y=0;y<RECORD_BI.biHeight;y++)
204 {
205 src = &srcs[(cy&0xffff0000)>>6];
206 cx = 0;
207 for(x=0;x<RECORD_BI.biWidth;x++)
208 {
209 cs = src[cx>>16];
210 *(dests++) = ((cs&0x7c00)>>10)|(cs&0x03e0)|((cs&0x001f)<<10);
211 cx += ax;
212 }
213 cy -= ay;if(cy<0) cy=0;
214 }
215 }
216 }
217 else if(RECORD_BI.biBitCount==24)
218 {
219 if(PSXDisplay.RGB24)
220 {
221 for(y=0;y<RECORD_BI.biHeight;y++)
222 {
223 srcc = (unsigned char*)&srcs[(cy&0xffff0000)>>6];
224 cx = 0;
225 for(x=0;x<RECORD_BI.biWidth;x++)
226 {
227 cl = *((unsigned long*)&srcc[(cx>>16)*3]);
228 *(destc++) = (unsigned char)((cl&0xff0000)>>16);
229 *(destc++) = (unsigned char)((cl&0xff00)>>8);
230 *(destc++) = (unsigned char)(cl&0xff);
231 cx += ax;
232 }
233 cy -= ay;if(cy<0) cy=0;
234 }
235 }
236 else
237 {
238 for(y=0;y<RECORD_BI.biHeight;y++)
239 {
240 src = &srcs[(cy&0xffff0000)>>6];
241 cx = 0;
242 for(x=0;x<RECORD_BI.biWidth;x++)
243 {
244 cs = src[cx>>16];
245 *(destc++) = (unsigned char)((cs&0x7c00)>>7);
246 *(destc++) = (unsigned char)((cs&0x03e0)>>2);
247 *(destc++) = (unsigned char)((cs&0x001f)<<3);
248 cx += ax;
249 }
250 cy -= ay;if(cy<0) cy=0;
251 }
252 }
253 }
254 else
255 memset(RECORD_BUFFER,0,RECORD_BI.biSizeImage);
256
257 return TRUE;
258 }