OSDN Git Service

16:9(HD動画)用コマンドを追加し、フォントサイズを調整する
[coroid/inqubus.git] / vhook / main.c
1
2 #include <SDL/SDL.h>
3 #include <SDL/SDL_ttf.h>
4 #include <stdio.h>
5 #include "main.h"
6 #include "mydef.h"
7 #include "nicodef.h"
8 #include "process.h"
9 /**
10  * ライブラリ初期化
11  */
12 int init(FILE* log){
13         fputs("[main/init]initializing libs...\n",log);
14         //SDL
15         if(SDL_Init(SDL_INIT_VIDEO)>=0){
16                 fputs("[main/init]initialized SDL.\n",log);
17         }else{
18                 fputs("[main/init]failed to initialize SDL.\n",log);
19             return FALSE;
20         }
21         //SDL_ttf
22         if(TTF_Init() >= 0){
23                 fputs("[main/init]initialized SDL_ttf.\n",log);
24         }else{
25                 fputs("[main/init]failed to initialize SDL_ttf.\n",log);
26             return FALSE;
27         }
28         fputs("[main/init]initialized libs.\n",log);
29         return TRUE;
30 }
31 /*
32  * データの初期化
33  */
34 int initData(DATA* data,FILE* log,const SETTING* setting){
35         int i;
36     data->user_comment.common = data;
37     data->owner_comment.common = data;
38         data->user_comment.enable = setting->enable_user_comment;
39         data->owner_comment.enable = setting->enable_owner_comment;
40         data->user_comment.opaque_comment = setting->opaque_comment;
41     data->owner_comment.opaque_comment = 1; // オーナコメントは常に不透明
42         data->log = log;
43         data->fontsize_fix = setting->fontsize_fix;
44         data->show_video = setting->show_video;
45         data->shadow_kind = setting->shadow_kind;
46         data->process_first_called=FALSE;
47         data->video_length = setting->video_length;
48     data->aspect_mode = setting->aspect_mode;
49         fputs("[main/init]initializing context...\n",log);
50         //フォント
51         TTF_Font** font = data->font;
52         const char* font_path = setting->font_path;
53         const int font_index = setting->font_index;
54         for(i=0;i<CMD_FONT_MAX;i++){
55                 int fontsize = COMMENT_FONT_SIZE[i];
56                 if(setting->fontsize_fix){
57                         fontsize <<= 1;
58                 }
59                 font[i] = TTF_OpenFontIndex(font_path,fontsize,font_index);
60                 if(font[i] == NULL){
61                     fprintf(log,"[main/init]failed to load font:%s index:[%d].\n",font_path,font_index);
62                     //0でも試してみる。
63                     fputs("[main/init]retrying to open font at index:0...",log);
64                     font[i] = TTF_OpenFontIndex(font_path,fontsize,0);
65                     if(font[i] == NULL){
66                             fputs("failed.\n",log);
67                             return FALSE;
68                     }else{
69                             fputs("success.\n",log);
70                     }
71                 }
72                 TTF_SetFontStyle(font[i],TTF_STYLE_BOLD);
73         }
74         fputs("[main/init]initialized font.\n",log);
75         /*
76          * ユーザコメント
77          */
78         if(data->user_comment.enable){
79                 fputs("[main/init]User Comment is enabled.\n",log);
80                 //コメントデータ
81                 if(initChat(log,&data->user_comment.chat,setting->data_user_path,&data->user_comment.slot,data->video_length)){
82                         fputs("[main/init]initialized comment.\n",log);
83                 }else{
84                         fputs("[main/init]failed to initialize comment.",log);
85                         return FALSE;
86                 }
87                 //コメントスロット
88                 if(initChatSlot(log,&data->user_comment.slot,setting->user_slot_max,&data->user_comment.chat)){
89                         fputs("[main/init]initialized comment slot.\n",log);
90                 }else{
91                         fputs("[main/init]failed to initialize comment slot.",log);
92                         return FALSE;
93                 }
94         }
95         /*
96          * オーナコメント
97          */
98         if(data->owner_comment.enable){
99                 fputs("[main/init]Owner Comment is enabled.\n",log);
100                 //コメントデータ
101                 if(initChat(log,&data->owner_comment.chat,setting->data_owner_path,&data->owner_comment.slot,data->video_length)){
102                         fputs("[main/init]initialized comment.\n",log);
103                 }else{
104                         fputs("[main/init]failed to initialize comment.",log);
105                         return FALSE;
106                 }
107                 //コメントスロット
108         // TODO とりあえず最大数は1024にしておくが...
109                 if(initChatSlot(log,&data->owner_comment.slot,1024,&data->owner_comment.chat)){
110                         fputs("[main/init]initialized comment slot.\n",log);
111                 }else{
112                         fputs("[main/init]failed to initialize comment slot.",log);
113                         return FALSE;
114                 }
115         }
116         
117         //終わり。
118         fputs("[main/init]initialized context.\n",log);
119         return TRUE;
120 }
121 /*
122  * 映像の変換
123  */
124 int main_process(DATA* data,SDL_Surface* surf,const int now_vpos){
125         FILE* log = data->log;
126         if(!data->process_first_called){
127                 fprintf(log,"[main/process]screen size is %dx%d.\n",surf->w,surf->h);
128                 fflush(log);
129         }
130         /*フィルタをかける*/
131         if(process(data,surf,now_vpos)){
132         }
133         fflush(log);
134         /*変換した画像を見せる。*/
135         if(data->show_video){
136                 if(!data->process_first_called){
137                         data->screen = SDL_SetVideoMode(surf->w, surf->h, 24, SDL_HWSURFACE | SDL_DOUBLEBUF);
138                         if(data->screen == NULL){
139                                 fputs("[main/process]failed to initialize screen.\n",log);
140                                 fflush(log);
141                                 return FALSE;
142                         }
143                 }
144                 SDL_BlitSurface(surf,NULL,data->screen,NULL);
145                 SDL_Flip(data->screen);
146                 SDL_Event event;
147                 while(SDL_PollEvent(&event)){}
148         }
149         //一回目以降はTRUEになる。
150         data->process_first_called=TRUE;
151         fflush(log);
152         return TRUE;
153 }
154 /*
155  * データのクローズ
156  */
157 int closeData(DATA* data){
158         int i;
159         //ユーザコメントが有効なら開放
160         if(data->user_comment.enable){
161                 closeChat(&data->user_comment.chat);
162                 closeChatSlot(&data->user_comment.slot);
163         }
164         //オーナコメントが有効なら開放
165         if(data->owner_comment.enable){
166                 closeChat(&data->owner_comment.chat);
167                 closeChatSlot(&data->owner_comment.slot);
168         }
169     //フォント開放
170         for(i=0;i<CMD_FONT_MAX;i++){
171                 TTF_CloseFont(data->font[i]);
172         }
173         return TRUE;
174 }
175
176 /*
177  * ライブラリシャットダウン
178  */
179 int close(){
180     //SDLをシャットダウン
181     SDL_Quit();
182         //同じくTTFをシャットダウン
183     TTF_Quit();
184         return TRUE;
185 }