remove more unportable ASM, obsoleting C_CORE define
[rofl0r-VisualBoyAdvance.git] / src / win32 / AVIWrite.cpp
blob4943224e2a49bf4e2b0334e51d0592b7a929a040
1 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
2 // Copyright (C) 1999-2003 Forgotten
3 // Copyright (C) 2004 Forgotten and the VBA development team
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2, or(at your option)
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include "stdafx.h"
20 #include "AVIWrite.h"
22 AVIWrite::AVIWrite()
24 m_failed = false;
25 m_file = NULL;
26 m_stream = NULL;
27 m_streamCompressed = NULL;
28 m_streamSound = NULL;
29 m_samplesSound = 0;
31 AVIFileInit();
34 AVIWrite::~AVIWrite()
36 if(m_streamSound)
37 AVIStreamClose(m_streamSound);
39 if(m_streamCompressed)
40 AVIStreamClose(m_streamCompressed);
42 if(m_stream)
43 AVIStreamClose(m_stream);
45 if(m_file)
46 AVIFileClose(m_file);
48 AVIFileExit();
51 void AVIWrite::SetVideoFormat(BITMAPINFOHEADER *bh)
53 // force size to 0x28 to avoid extra fields
54 memcpy(&m_bitmap, bh, 0x28);
57 void AVIWrite::SetSoundFormat(WAVEFORMATEX *format)
59 memcpy(&m_soundFormat, format, sizeof(WAVEFORMATEX));
60 ZeroMemory(&m_soundHeader, sizeof(AVISTREAMINFO));
61 // setup the sound stream header
62 m_soundHeader.fccType = streamtypeAUDIO;
63 m_soundHeader.dwQuality = (DWORD)-1;
64 m_soundHeader.dwScale = format->nBlockAlign;
65 m_soundHeader.dwInitialFrames = 1;
66 m_soundHeader.dwRate = format->nAvgBytesPerSec;
67 m_soundHeader.dwSampleSize = format->nBlockAlign;
69 // create the sound stream
70 if(FAILED(AVIFileCreateStream(m_file, &m_streamSound, &m_soundHeader))) {
71 m_failed = true;
72 return;
75 // setup the sound stream format
76 if(FAILED(AVIStreamSetFormat(m_streamSound, 0 , (void *)&m_soundFormat,
77 sizeof(WAVEFORMATEX)))) {
78 m_failed = true;
79 return;
83 bool AVIWrite::Open(const char *filename)
85 // create the AVI file
86 if(FAILED(AVIFileOpen(&m_file,
87 filename,
88 OF_WRITE | OF_CREATE,
89 NULL))) {
90 m_failed = true;
91 return false;
93 // setup the video stream information
94 ZeroMemory(&m_header, sizeof(AVISTREAMINFO));
95 m_header.fccType = streamtypeVIDEO;
96 m_header.dwScale = 1;
97 m_header.dwRate = m_fps;
98 m_header.dwSuggestedBufferSize = m_bitmap.biSizeImage;
100 // create the video stream
101 if(FAILED(AVIFileCreateStream(m_file,
102 &m_stream,
103 &m_header))) {
104 m_failed = true;
105 return false;
108 ZeroMemory(&m_options, sizeof(AVICOMPRESSOPTIONS));
109 m_arrayOptions[0] = &m_options;
111 // call the dialog to setup the compress options to be used
112 if(!AVISaveOptions(AfxGetApp()->m_pMainWnd->GetSafeHwnd(), 0, 1, &m_stream, m_arrayOptions)) {
113 m_failed = true;
114 return false;
117 // create the compressed stream
118 if(FAILED(AVIMakeCompressedStream(&m_streamCompressed, m_stream, &m_options, NULL))) {
119 m_failed = true;
120 return false;
123 // setup the video stream format
124 if(FAILED( AVIStreamSetFormat(m_streamCompressed, 0,
125 &m_bitmap,
126 m_bitmap.biSize +
127 m_bitmap.biClrUsed * sizeof(RGBQUAD)))) {
128 m_failed = true;
129 return false;
132 return true;
135 bool AVIWrite::AddSound(const char *sound, int len)
137 // return if we failed somewhere already
138 if(m_failed)
139 return false;
141 int samples = len / m_soundFormat.nBlockAlign;
143 if(FAILED(AVIStreamWrite(m_streamSound,
144 m_samplesSound,
145 samples,
146 (LPVOID)sound,
147 len,
149 NULL,
150 NULL))) {
151 m_failed = true;
152 return false;
154 m_samplesSound += samples;
156 return true;
159 bool AVIWrite::AddFrame(const int frame, const char *bmp)
161 if (m_failed)
162 return false;
164 // write the frame to the video stream
165 if(FAILED(AVIStreamWrite(m_streamCompressed,
166 frame,
168 (LPVOID)bmp,
169 m_bitmap.biSizeImage,
170 AVIIF_KEYFRAME,
171 NULL,
172 NULL))) {
173 m_failed = true;
174 return false;
176 return true;
179 bool AVIWrite::IsSoundAdded()
181 return m_streamSound != NULL;
184 void AVIWrite::SetFPS(int f)
186 m_fps = f;