OSDN Git Service

Linuxビルド対応
[coroid/inqubus.git] / vhook / framehook.c
1 /*\83t\83\8c\81[\83\80\83t\83b\83N\82Ì\91\8a\8eè\82ð\82·\82é\82½\82ß\90ê\97p*/\r
2 \r
3 #include <stdlib.h>\r
4 #include <stdio.h>\r
5 #include <string.h>\r
6 #include <SDL/SDL.h>\r
7 #include "common/framehook_ext.h"\r
8 #include "framehook.h"\r
9 #include "main.h"\r
10 #include "mydef.h"\r
11 #include "nicodef.h"\r
12 #include "util.h"\r
13 \r
14 #ifdef _WIN32\r
15  #define DLLEXPORT __declspec(dllexport)\r
16 #else\r
17  #define DLLEXPORT\r
18 #endif\r
19 \r
20 typedef struct ContextInfo{\r
21         FILE* log;\r
22         DATA data;\r
23 } ContextInfo;\r
24 \r
25 /*\r
26  * \95K\97v\82È\8aÖ\90\94\82Ð\82Æ\82Â\82ß\81B\8dÅ\8f\89\82É\8cÄ\82Î\82ê\82é\82æ\81I\r
27  * \r
28  */\r
29 int init_setting(FILE*log,const toolbox *tbox,SETTING* setting,int argc, char *argv[]);\r
30 \r
31 DLLEXPORT int ExtConfigure(void **ctxp,const toolbox *tbox, int argc, char *argv[]){\r
32         int i;\r
33         //\83\8d\83O\r
34         FILE* log = fopen("[log]vhext.txt", "w");\r
35         if(log == NULL){\r
36                 puts("[framehook/init]failed to open logfile.\n");\r
37                 fflush(log);\r
38                 return -1;\r
39         }else{\r
40                 fputs("[framehook/init]initializing..\n",log);\r
41                 fflush(log);\r
42         }\r
43         //\95K\97v\82È\90Ý\92è\82ª\82 \82é\82©\82Ì\8am\94F\r
44         fprintf(log,"[framehook/init]called with argc = %d\n",argc);\r
45         fflush(log);\r
46         for(i=0;i<argc;i++){\r
47                 fprintf(log,"[framehook/init]arg[%2d] = %s\n",i,argv[i]);\r
48                 fflush(log);\r
49         }\r
50         //\83Z\83b\83e\83B\83\93\83O\8eæ\93¾\81B\r
51         SETTING setting;\r
52         if(init_setting(log,tbox,&setting,argc,argv)){\r
53                 fputs("[framehook/init]initialized settings.\n",log);\r
54                 fflush(log);\r
55         }else{\r
56                 fputs("[framehook/init]failed to initialize settings.\n",log);\r
57                 fflush(log);\r
58                 return -2;\r
59         }\r
60         //\83\89\83C\83u\83\89\83\8a\82È\82Ç\82Ì\8f\89\8aú\89»\r
61         if(init(log)){\r
62                 fputs("[framehook/init]initialized libs.\n",log);\r
63                 fflush(log);\r
64         }else{\r
65                 fputs("[framehook/init]failed to initialize libs.\n",log);\r
66                 fflush(log);\r
67                 return -3;\r
68         }\r
69         /*\83R\83\93\83e\83L\83X\83g\82Ì\90Ý\92è*/\r
70         *ctxp = malloc(sizeof(ContextInfo));\r
71         if(*ctxp == NULL){\r
72                 fputs("[framehook/init]initialized to malloc for context.\n",log);\r
73                 fflush(log);\r
74         }\r
75         ContextInfo* ci = (ContextInfo*)*ctxp;\r
76         ci->log = log;\r
77         fflush(log);\r
78         if(initData(&ci->data,log,&setting)){\r
79                 fputs("[framehook/init]initialized context.\n",log);\r
80                 fputs("[framehook/init]initialized.\n",log);\r
81                 fflush(log);\r
82                 return 0;\r
83         }else{\r
84                 fputs("[framehook/init]failed to initialize context.\n",log);\r
85                 fflush(log);\r
86                 return -4;\r
87         }\r
88 }\r
89 /*\r
90  * \93à\95\94\82Å\82Ì\82Ý\8cÄ\82Î\82ê\82é\81B\r
91  */\r
92 \r
93  /*\r
94         argv[0]:\83v\83\8d\83O\83\89\83\80\r
95         argv[1]:vhook\r
96         argv[2]:\83t\83H\83\93\83g\r
97         argv[3]:\83t\83H\83\93\83g\83C\83\93\83f\83b\83N\83X\r
98         argv[4]:\88ê\89æ\96Ê\r
99         argv[5]:\89e\82Ì\8eí\97Þ\r
100         \88È\8d~\83I\83v\83V\83\87\83\93\r
101         --enable-show-video\81F\95`\89æ\92\86\82É\93®\89æ\82ð\8c©\82¹\82é\81B\r
102         --enable-fontsize-fix\81F\83t\83H\83\93\83g\83T\83C\83Y\82ð\8e©\93®\82Å\92²\90®\82·\82é\81B\r
103 */\r
104  \r
105 int init_setting(FILE*log,const toolbox *tbox,SETTING* setting,int argc, char *argv[]){\r
106         /*video\82Ì\92·\82³*/\r
107         setting->video_length = (tbox->video_length * VPOS_FACTOR);\r
108         /*\88È\8d~\83I\83v\83V\83\87\83\93*/\r
109         \r
110         //\83R\83\81\83\93\83g\82ð\8c©\82¹\82é\82©\94Û\82©\81H\r
111         setting->enable_user_comment = FALSE;\r
112         setting->enable_owner_comment = FALSE;\r
113         setting->data_user_path = NULL;\r
114         setting->data_owner_path = NULL;\r
115         //\88ê\94Ê\93I\82È\90Ý\92è\r
116         setting->font_path = NULL;\r
117         setting->font_index = 0;\r
118         setting->user_slot_max = 30;\r
119         setting->owner_slot_max = 30;\r
120         setting->shadow_kind = 1;//\83f\83t\83H\83\8b\83g\82Í\83j\83R\83j\83R\93®\89æ\95\97\r
121         setting->show_video = FALSE;\r
122         setting->fontsize_fix=FALSE;\r
123         setting->opaque_comment=FALSE;\r
124         int i;\r
125         char* arg;\r
126         for(i=0;i<argc;i++){\r
127                 arg = argv[i];\r
128                 if(!setting->data_user_path && strncmp(FRAMEHOOK_OPT_DATA_USER,arg,FRAMEHOOK_OPT_DATA_USER_LEN) == 0){\r
129                         char* data_user = arg+FRAMEHOOK_OPT_DATA_USER_LEN;\r
130                         setting->data_user_path = data_user;\r
131                         setting->enable_user_comment = TRUE;\r
132                         fprintf(log,"[framehook/init]User Comment data path:%s\n",setting->data_user_path);\r
133                         fflush(log);\r
134                 }else if(!setting->data_owner_path && strncmp(FRAMEHOOK_OPT_DATA_OWNER,arg,FRAMEHOOK_OPT_DATA_OWNER_LEN) == 0){\r
135                         char* data_owner = arg+FRAMEHOOK_OPT_DATA_OWNER_LEN;\r
136                         setting->data_owner_path = data_owner;\r
137                         setting->enable_owner_comment = TRUE;\r
138                         fprintf(log,"[framehook/init]Owner Comment data path:%s\n",setting->data_owner_path);\r
139                         fflush(log);\r
140                 }else if(!setting->font_path && strncmp(FRAMEHOOK_OPT_FONT,arg,FRAMEHOOK_OPT_FONT_LEN) == 0){\r
141                         char* font = arg+FRAMEHOOK_OPT_FONT_LEN;\r
142                         setting->font_path = font;\r
143                         fprintf(log,"[framehook/init]Font path:%s\n",setting->font_path);\r
144                         fflush(log);\r
145                 }else if(strncmp(FRAMEHOOK_OPT_FONTINDEX,arg,FRAMEHOOK_OPT_FONTINDEX_LEN) == 0){\r
146                         setting->font_index = MAX(0,atoi(arg+FRAMEHOOK_OPT_FONTINDEX_LEN));\r
147                         fprintf(log,"[framehook/init]font index:%d\n",setting->font_index);\r
148                         fflush(log);\r
149                 }else if(strncmp(FRAMEHOOK_OPT_SHADOW,arg,FRAMEHOOK_OPT_SHADOW_LEN) == 0){\r
150                         setting->shadow_kind = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHADOW_LEN));\r
151                         fprintf(log,"[framehook/init]shadow kind:%d\n",setting->shadow_kind);\r
152                         fflush(log);\r
153                 }else if(strncmp(FRAMEHOOK_OPT_SHOW_USER,arg,FRAMEHOOK_OPT_SHOW_USER_LEN) == 0){\r
154                         setting->user_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_USER_LEN));\r
155                         fprintf(log,"[framehook/init]User Comments on screen:%d\n",setting->user_slot_max);\r
156                         fflush(log);\r
157                 }else if(strncmp(FRAMEHOOK_OPT_SHOW_OWNER,arg,FRAMEHOOK_OPT_SHOW_OWNER_LEN) == 0){\r
158                         setting->owner_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_OWNER_LEN));\r
159                         fprintf(log,"[framehook/init]Owner Comments on screen:%d\n",setting->owner_slot_max);\r
160                         fflush(log);\r
161                 }else if(!setting->show_video && strcmp(arg,"--enable-show-video") == 0){\r
162                         fputs("[framehook/init]show video while converting.\n",log);\r
163                         fflush(log);\r
164                         setting->show_video=TRUE;\r
165                 }else if(!setting->fontsize_fix && strcmp(arg,"--enable-fix-font-size") == 0){\r
166                         fputs("[framehook/init]fix font size automatically.\n",log);\r
167                         fflush(log);\r
168                         setting->fontsize_fix=TRUE;\r
169                 }else if(!setting->opaque_comment && strcmp(arg,"--enable-opaque-comment") == 0){\r
170                         fputs("[framehook/init]enable opaque comment.\n",log);\r
171                         fflush(log);\r
172                         setting->opaque_comment=TRUE;\r
173                 }\r
174         }\r
175         //\88ø\90\94\82ð\90³\82µ\82­\93ü\97Í\82µ\82½\82©\94Û\82©\82Ì\83`\83F\83b\83N\r
176         //\82±\82±\82Å\83`\83F\83b\83N\82µ\82Ä\82¢\82é\82Ì\88È\8aO\82Í\81A\83f\83t\83H\83\8b\83g\90Ý\92è\82Å\93¦\82°\82é\81B\r
177         if(!setting->font_path){\r
178                 fputs("[framehook/init]please set FONT PATH.\n",log);\r
179                 fflush(log);\r
180                 return FALSE;\r
181         }\r
182         return TRUE;\r
183 }\r
184 \r
185 /*\r
186  * \95K\97v\82È\8aÖ\90\94\93ñ\82Â\82ß\81B\83t\83\8c\81[\83\80\82²\82Æ\82É\8cÄ\82Î\82ê\82é\82æ\81I\r
187  * \r
188  */\r
189 DLLEXPORT void ExtProcess(void *ctx,const toolbox *tbox,vhext_frame *pict){\r
190     ContextInfo *ci = (ContextInfo *) ctx;\r
191     FILE* log = ci->log;\r
192 \r
193         /* Note:\r
194          * Saccubus 1.22\88È\8d~\82Ì\8ag\92£vhook\83t\83B\83\8b\83^\82Å\82Í\81ARGB24\83t\83H\81[\83}\83b\83g\82Å\82Ì\82Ý\r
195          * \89æ\91\9c\82ª\92ñ\8b\9f\82³\82ê\82Ü\82·\81B\r
196          */\r
197 \r
198         //SDL\82Ì\83T\81[\83t\83F\83C\83X\82É\95Ï\8a·\r
199     SDL_Surface* surf = SDL_CreateRGBSurfaceFrom(pict->data,\r
200                                                                                         pict->w,pict->h,24,pict->linesize,\r
201                                                                                                 #if SDL_BYTEORDER == SDL_BIG_ENDIAN\r
202                                                                                                     0xff000000,\r
203                                                                                                     0x00ff0000,\r
204                                                                                                     0x0000ff00,\r
205                                                                                                 #else\r
206                                                                                                     0x000000ff,\r
207                                                                                                     0x0000ff00,\r
208                                                                                                     0x00ff0000,\r
209                                                                                                 #endif\r
210                                                                                                     0x00000000\r
211                                                                                                 );\r
212         //\83t\83B\83\8b\83^\r
213         int now_vpos = (pict->pts * VPOS_FACTOR);\r
214         if(!main_process(&ci->data,surf,now_vpos)){\r
215                 fputs("[framehook/process]failed to process.\n",log);\r
216                 fflush(log);\r
217                 exit(1);\r
218         }\r
219         //\83T\81[\83t\83F\83C\83X\8aJ\95ú\r
220         SDL_FreeSurface(surf);\r
221         fflush(log);\r
222 }\r
223 \r
224 /*\r
225  * \95K\97v\82È\8aÖ\90\94\8dÅ\8cã\81B\8fI\82í\82Á\82½\82ç\8cÄ\82Î\82ê\82é\82æ\81I\r
226  * \r
227  */\r
228 \r
229 DLLEXPORT void ExtRelease(void *ctx,const toolbox *tbox){\r
230     ContextInfo *ci;\r
231     ci = (ContextInfo *) ctx;\r
232     FILE* log = ci->log;\r
233     fputs("[framehook/close]closing...\n",log);\r
234     if (ctx) {\r
235         closeData(&ci->data);\r
236             fputs("[framehook/close]closed.\n",log);\r
237         fclose(log);\r
238             //\83R\83\93\83e\83L\83X\83g\91S\91Ì\r
239         free(ctx);\r
240     }\r
241     //\83\89\83C\83u\83\89\83\8a\82Ì\8fI\97¹\r
242     close();\r
243 }\r
244 \r