Support unrar64.dll
[xy_vsfilter.git] / src / subtitles / VobSubFile.h
blob4c3836d1cad2251cbd6768c958c62ece9738af6e
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
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 GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #pragma once
24 #include <atlcoll.h>
25 #include "VobSubImage.h"
26 #include "..\SubPic\ISubPic.h"
28 #define VOBSUBIDXVER 7
30 extern CString FindLangFromId(WORD id);
32 class CVobSubSettings
34 protected:
35 HRESULT Render(SubPicDesc& spd, RECT& bbox);
37 public:
38 CSize m_size;
39 int m_x, m_y;
40 CPoint m_org;
41 int m_scale_x, m_scale_y; // % (don't set it to unsigned because as a side effect it will mess up negative coordinates in GetDestrect())
42 int m_alpha; // %
43 int m_fSmooth; // 0: OFF, 1: ON, 2: OLD (means no filtering at all)
44 int m_fadein, m_fadeout; // ms
45 bool m_fAlign;
46 int m_alignhor, m_alignver; // 0: left/top, 1: center, 2: right/bottom
47 unsigned int m_toff; // ms
48 bool m_fOnlyShowForcedSubs;
49 bool m_fCustomPal;
50 int m_tridx;
51 RGBQUAD m_orgpal[16], m_cuspal[4];
53 CVobSubImage m_img;
55 CVobSubSettings() {InitSettings();}
56 void InitSettings();
58 bool GetCustomPal(RGBQUAD* cuspal, int& tridx);
59 void SetCustomPal(RGBQUAD* cuspal, int tridx);
61 void GetDestrect(CRect& r); // destrect of m_img, considering the current alignment mode
62 void GetDestrect(CRect& r, int w, int h); // this will scale it to the frame size of (w, h)
64 void SetAlignment(bool fAlign, int x, int y, int hor, int ver);
67 [uuid("998D4C9A-460F-4de6-BDCD-35AB24F94ADF")]
68 class CVobSubFile : public CVobSubSettings, public ISubStream, public CSubPicProviderImpl
70 protected:
71 CString m_title;
73 void TrimExtension(CString& fn);
74 bool ReadIdx(CString fn, int& ver), ReadSub(CString fn), ReadRar(CString fn), ReadIfo(CString fn);
75 bool WriteIdx(CString fn), WriteSub(CString fn);
77 CMemFile m_sub;
79 BYTE* GetPacket(int idx, int& packetsize, int& datasize, int iLang = -1);
80 bool GetFrame(int idx, int iLang = -1);
81 bool GetFrameByTimeStamp(__int64 time);
82 int GetFrameIdxByTimeStamp(__int64 time);
84 bool SaveVobSub(CString fn);
85 bool SaveWinSubMux(CString fn);
86 bool SaveScenarist(CString fn);
87 bool SaveMaestro(CString fn);
89 public:
90 typedef struct
92 __int64 filepos;
93 __int64 start, stop;
94 bool fForced;
95 char vobid, cellid;
96 __int64 celltimestamp;
97 bool fValid;
98 } SubPos;
100 typedef struct
102 int id;
103 CString name, alt;
104 CAtlArray<SubPos> subpos;
105 } SubLang;
107 int m_iLang;
108 SubLang m_langs[32];
110 public:
111 CVobSubFile(CCritSec* pLock);
112 virtual ~CVobSubFile();
114 bool Copy(CVobSubFile& vsf);
116 typedef enum {None,VobSub,WinSubMux,Scenarist,Maestro} SubFormat;
118 bool Open(CString fn);
119 bool Save(CString fn, SubFormat sf = VobSub);
120 void Close();
122 CString GetTitle() {return(m_title);}
124 DECLARE_IUNKNOWN
125 STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
127 // ISubPicProvider
128 STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps);
129 STDMETHODIMP_(POSITION) GetNext(POSITION pos);
130 STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps);
131 STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps);
132 STDMETHODIMP_(bool) IsAnimated(POSITION pos);
133 STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox);
135 // IPersist
136 STDMETHODIMP GetClassID(CLSID* pClassID);
138 // ISubStream
139 STDMETHODIMP_(int) GetStreamCount();
140 STDMETHODIMP GetStreamInfo(int i, WCHAR** ppName, LCID* pLCID);
141 STDMETHODIMP_(int) GetStream();
142 STDMETHODIMP SetStream(int iStream);
143 STDMETHODIMP Reload();
146 [uuid("D7FBFB45-2D13-494F-9B3D-FFC9557D5C45")]
147 class CVobSubStream : public CVobSubSettings, public ISubStream, public CSubPicProviderImpl
149 CString m_name;
151 CCritSec m_csSubPics;
152 struct SubPic {REFERENCE_TIME tStart, tStop; CAtlArray<BYTE> pData;};
153 CAutoPtrList<SubPic> m_subpics;
155 public:
156 CVobSubStream(CCritSec* pLock);
157 virtual ~CVobSubStream();
159 void Open(CString name, BYTE* pData, int len);
161 void Add(REFERENCE_TIME tStart, REFERENCE_TIME tStop, BYTE* pData, int len);
162 void RemoveAll();
164 DECLARE_IUNKNOWN
165 STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
167 // ISubPicProvider
168 STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps);
169 STDMETHODIMP_(POSITION) GetNext(POSITION pos);
170 STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps);
171 STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps);
172 STDMETHODIMP_(bool) IsAnimated(POSITION pos);
173 STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox);
175 // IPersist
176 STDMETHODIMP GetClassID(CLSID* pClassID);
178 // ISubStream
179 STDMETHODIMP_(int) GetStreamCount();
180 STDMETHODIMP GetStreamInfo(int i, WCHAR** ppName, LCID* pLCID);
181 STDMETHODIMP_(int) GetStream();
182 STDMETHODIMP SetStream(int iStream);
183 STDMETHODIMP Reload() {return E_NOTIMPL;}