OSDN Git Service

ソースの文字コードと改行コードを修正
[coroid/inqubus.git] / vhook / framehook.c
index fdb9d2f..99035e4 100644 (file)
-/*\83t\83\8c\81[\83\80\83t\83b\83N\82Ì\91\8a\8eè\82ð\82·\82é\82½\82ß\90ê\97p*/\r
-\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <SDL/SDL.h>\r
-#include "common/framehook_ext.h"\r
-#include "framehook.h"\r
-#include "main.h"\r
-#include "mydef.h"\r
-#include "nicodef.h"\r
-#include "util.h"\r
-\r
-#ifdef _WIN32\r
- #define DLLEXPORT __declspec(dllexport)\r
-#else\r
- #define DLLEXPORT\r
-#endif\r
-\r
-typedef struct ContextInfo{\r
-       FILE* log;\r
-       DATA data;\r
-} ContextInfo;\r
-\r
-/*\r
- * \95K\97v\82È\8aÖ\90\94\82Ð\82Æ\82Â\82ß\81B\8dÅ\8f\89\82É\8cÄ\82Î\82ê\82é\82æ\81I\r
- * \r
- */\r
-int init_setting(FILE*log,const toolbox *tbox,SETTING* setting,int argc, char *argv[]);\r
-\r
-DLLEXPORT int ExtConfigure(void **ctxp,const toolbox *tbox, int argc, char *argv[]){\r
-       int i;\r
-       //\83\8d\83O\r
-       FILE* log = fopen("[log]vhext.txt", "w");\r
-       if(log == NULL){\r
-               puts("[framehook/init]failed to open logfile.\n");\r
-               fflush(log);\r
-               return -1;\r
-       }else{\r
-               fputs("[framehook/init]initializing..\n",log);\r
-               fflush(log);\r
-       }\r
-       //\95K\97v\82È\90Ý\92è\82ª\82 \82é\82©\82Ì\8am\94F\r
-       fprintf(log,"[framehook/init]called with argc = %d\n",argc);\r
-       fflush(log);\r
-       for(i=0;i<argc;i++){\r
-               fprintf(log,"[framehook/init]arg[%2d] = %s\n",i,argv[i]);\r
-               fflush(log);\r
-       }\r
-       //\83Z\83b\83e\83B\83\93\83O\8eæ\93¾\81B\r
-       SETTING setting;\r
-       if(init_setting(log,tbox,&setting,argc,argv)){\r
-               fputs("[framehook/init]initialized settings.\n",log);\r
-               fflush(log);\r
-       }else{\r
-               fputs("[framehook/init]failed to initialize settings.\n",log);\r
-               fflush(log);\r
-               return -2;\r
-       }\r
-       //\83\89\83C\83u\83\89\83\8a\82È\82Ç\82Ì\8f\89\8aú\89»\r
-       if(init(log)){\r
-               fputs("[framehook/init]initialized libs.\n",log);\r
-               fflush(log);\r
-       }else{\r
-               fputs("[framehook/init]failed to initialize libs.\n",log);\r
-               fflush(log);\r
-               return -3;\r
-       }\r
-       /*\83R\83\93\83e\83L\83X\83g\82Ì\90Ý\92è*/\r
-       *ctxp = malloc(sizeof(ContextInfo));\r
-       if(*ctxp == NULL){\r
-               fputs("[framehook/init]initialized to malloc for context.\n",log);\r
-               fflush(log);\r
-       }\r
-       ContextInfo* ci = (ContextInfo*)*ctxp;\r
-       ci->log = log;\r
-       fflush(log);\r
-       if(initData(&ci->data,log,&setting)){\r
-               fputs("[framehook/init]initialized context.\n",log);\r
-               fputs("[framehook/init]initialized.\n",log);\r
-               fflush(log);\r
-               return 0;\r
-       }else{\r
-               fputs("[framehook/init]failed to initialize context.\n",log);\r
-               fflush(log);\r
-               return -4;\r
-       }\r
-}\r
-/*\r
- * \93à\95\94\82Å\82Ì\82Ý\8cÄ\82Î\82ê\82é\81B\r
- */\r
-\r
- /*\r
-       argv[0]:\83v\83\8d\83O\83\89\83\80\r
-       argv[1]:vhook\r
-       argv[2]:\83t\83H\83\93\83g\r
-       argv[3]:\83t\83H\83\93\83g\83C\83\93\83f\83b\83N\83X\r
-       argv[4]:\88ê\89æ\96Ê\r
-       argv[5]:\89e\82Ì\8eí\97Þ\r
-       \88È\8d~\83I\83v\83V\83\87\83\93\r
-       --enable-show-video\81F\95`\89æ\92\86\82É\93®\89æ\82ð\8c©\82¹\82é\81B\r
-       --enable-fontsize-fix\81F\83t\83H\83\93\83g\83T\83C\83Y\82ð\8e©\93®\82Å\92²\90®\82·\82é\81B\r
-*/\r
\r
-int init_setting(FILE*log,const toolbox *tbox,SETTING* setting,int argc, char *argv[]){\r
-       /*video\82Ì\92·\82³*/\r
-       setting->video_length = (tbox->video_length * VPOS_FACTOR);\r
-       /*\88È\8d~\83I\83v\83V\83\87\83\93*/\r
-       \r
-       //\83R\83\81\83\93\83g\82ð\8c©\82¹\82é\82©\94Û\82©\81H\r
-       setting->enable_user_comment = FALSE;\r
-       setting->enable_owner_comment = FALSE;\r
-       setting->data_user_path = NULL;\r
-       setting->data_owner_path = NULL;\r
-       //\88ê\94Ê\93I\82È\90Ý\92è\r
-       setting->font_path = NULL;\r
-       setting->font_index = 0;\r
-       setting->user_slot_max = 30;\r
-       setting->owner_slot_max = 30;\r
-       setting->shadow_kind = 1;//\83f\83t\83H\83\8b\83g\82Í\83j\83R\83j\83R\93®\89æ\95\97\r
-       setting->show_video = FALSE;\r
-       setting->fontsize_fix=FALSE;\r
-       setting->opaque_comment=FALSE;\r
-       int i;\r
-       char* arg;\r
-       for(i=0;i<argc;i++){\r
-               arg = argv[i];\r
-               if(!setting->data_user_path && strncmp(FRAMEHOOK_OPT_DATA_USER,arg,FRAMEHOOK_OPT_DATA_USER_LEN) == 0){\r
-                       char* data_user = arg+FRAMEHOOK_OPT_DATA_USER_LEN;\r
-                       setting->data_user_path = data_user;\r
-                       setting->enable_user_comment = TRUE;\r
-                       fprintf(log,"[framehook/init]User Comment data path:%s\n",setting->data_user_path);\r
-                       fflush(log);\r
-               }else if(!setting->data_owner_path && strncmp(FRAMEHOOK_OPT_DATA_OWNER,arg,FRAMEHOOK_OPT_DATA_OWNER_LEN) == 0){\r
-                       char* data_owner = arg+FRAMEHOOK_OPT_DATA_OWNER_LEN;\r
-                       setting->data_owner_path = data_owner;\r
-                       setting->enable_owner_comment = TRUE;\r
-                       fprintf(log,"[framehook/init]Owner Comment data path:%s\n",setting->data_owner_path);\r
-                       fflush(log);\r
-               }else if(!setting->font_path && strncmp(FRAMEHOOK_OPT_FONT,arg,FRAMEHOOK_OPT_FONT_LEN) == 0){\r
-                       char* font = arg+FRAMEHOOK_OPT_FONT_LEN;\r
-                       setting->font_path = font;\r
-                       fprintf(log,"[framehook/init]Font path:%s\n",setting->font_path);\r
-                       fflush(log);\r
-               }else if(strncmp(FRAMEHOOK_OPT_FONTINDEX,arg,FRAMEHOOK_OPT_FONTINDEX_LEN) == 0){\r
-                       setting->font_index = MAX(0,atoi(arg+FRAMEHOOK_OPT_FONTINDEX_LEN));\r
-                       fprintf(log,"[framehook/init]font index:%d\n",setting->font_index);\r
-                       fflush(log);\r
-               }else if(strncmp(FRAMEHOOK_OPT_SHADOW,arg,FRAMEHOOK_OPT_SHADOW_LEN) == 0){\r
-                       setting->shadow_kind = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHADOW_LEN));\r
-                       fprintf(log,"[framehook/init]shadow kind:%d\n",setting->shadow_kind);\r
-                       fflush(log);\r
-               }else if(strncmp(FRAMEHOOK_OPT_SHOW_USER,arg,FRAMEHOOK_OPT_SHOW_USER_LEN) == 0){\r
-                       setting->user_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_USER_LEN));\r
-                       fprintf(log,"[framehook/init]User Comments on screen:%d\n",setting->user_slot_max);\r
-                       fflush(log);\r
-               }else if(strncmp(FRAMEHOOK_OPT_SHOW_OWNER,arg,FRAMEHOOK_OPT_SHOW_OWNER_LEN) == 0){\r
-                       setting->owner_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_OWNER_LEN));\r
-                       fprintf(log,"[framehook/init]Owner Comments on screen:%d\n",setting->owner_slot_max);\r
-                       fflush(log);\r
-               }else if(!setting->show_video && strcmp(arg,"--enable-show-video") == 0){\r
-                       fputs("[framehook/init]show video while converting.\n",log);\r
-                       fflush(log);\r
-                       setting->show_video=TRUE;\r
-               }else if(!setting->fontsize_fix && strcmp(arg,"--enable-fix-font-size") == 0){\r
-                       fputs("[framehook/init]fix font size automatically.\n",log);\r
-                       fflush(log);\r
-                       setting->fontsize_fix=TRUE;\r
-               }else if(!setting->opaque_comment && strcmp(arg,"--enable-opaque-comment") == 0){\r
-                       fputs("[framehook/init]enable opaque comment.\n",log);\r
-                       fflush(log);\r
-                       setting->opaque_comment=TRUE;\r
-               }\r
-       }\r
-       //\88ø\90\94\82ð\90³\82µ\82­\93ü\97Í\82µ\82½\82©\94Û\82©\82Ì\83`\83F\83b\83N\r
-       //\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
-       if(!setting->font_path){\r
-               fputs("[framehook/init]please set FONT PATH.\n",log);\r
-               fflush(log);\r
-               return FALSE;\r
-       }\r
-       return TRUE;\r
-}\r
-\r
-/*\r
- * \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
- * \r
- */\r
-DLLEXPORT void ExtProcess(void *ctx,const toolbox *tbox,vhext_frame *pict){\r
-    ContextInfo *ci = (ContextInfo *) ctx;\r
-    FILE* log = ci->log;\r
-\r
-       /* Note:\r
-        * 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
-        * \89æ\91\9c\82ª\92ñ\8b\9f\82³\82ê\82Ü\82·\81B\r
-        */\r
-\r
-       //SDL\82Ì\83T\81[\83t\83F\83C\83X\82É\95Ï\8a·\r
-    SDL_Surface* surf = SDL_CreateRGBSurfaceFrom(pict->data,\r
-                                                                                       pict->w,pict->h,24,pict->linesize,\r
-                                                                                               #if SDL_BYTEORDER == SDL_BIG_ENDIAN\r
-                                                                                                   0xff000000,\r
-                                                                                                   0x00ff0000,\r
-                                                                                                   0x0000ff00,\r
-                                                                                               #else\r
-                                                                                                   0x000000ff,\r
-                                                                                                   0x0000ff00,\r
-                                                                                                   0x00ff0000,\r
-                                                                                               #endif\r
-                                                                                                   0x00000000\r
-                                                                                               );\r
-       //\83t\83B\83\8b\83^\r
-       int now_vpos = (pict->pts * VPOS_FACTOR);\r
-       if(!main_process(&ci->data,surf,now_vpos)){\r
-               fputs("[framehook/process]failed to process.\n",log);\r
-               fflush(log);\r
-               exit(1);\r
-       }\r
-       //\83T\81[\83t\83F\83C\83X\8aJ\95ú\r
-       SDL_FreeSurface(surf);\r
-       fflush(log);\r
-}\r
-\r
-/*\r
- * \95K\97v\82È\8aÖ\90\94\8dÅ\8cã\81B\8fI\82í\82Á\82½\82ç\8cÄ\82Î\82ê\82é\82æ\81I\r
- * \r
- */\r
-\r
-DLLEXPORT void ExtRelease(void *ctx,const toolbox *tbox){\r
-    ContextInfo *ci;\r
-    ci = (ContextInfo *) ctx;\r
-    FILE* log = ci->log;\r
-    fputs("[framehook/close]closing...\n",log);\r
-    if (ctx) {\r
-        closeData(&ci->data);\r
-           fputs("[framehook/close]closed.\n",log);\r
-        fclose(log);\r
-           //\83R\83\93\83e\83L\83X\83g\91S\91Ì\r
-        free(ctx);\r
-    }\r
-    //\83\89\83C\83u\83\89\83\8a\82Ì\8fI\97¹\r
-    close();\r
-}\r
-\r
+/*フレームフックの相手をするため専用*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <SDL/SDL.h>
+#include "common/framehook_ext.h"
+#include "framehook.h"
+#include "main.h"
+#include "mydef.h"
+#include "nicodef.h"
+#include "util.h"
+
+#ifdef _WIN32
+ #define DLLEXPORT __declspec(dllexport)
+#else
+ #define DLLEXPORT
+#endif
+
+typedef struct ContextInfo{
+       FILE* log;
+       DATA data;
+} ContextInfo;
+
+/*
+ * 必要な関数ひとつめ。最初に呼ばれるよ!
+ * 
+ */
+int init_setting(FILE*log,const toolbox *tbox,SETTING* setting,int argc, char *argv[]);
+
+DLLEXPORT int ExtConfigure(void **ctxp,const toolbox *tbox, int argc, char *argv[]){
+       int i;
+       //ログ
+       FILE* log = fopen("[log]vhext.txt", "w");
+       if(log == NULL){
+               puts("[framehook/init]failed to open logfile.\n");
+               fflush(log);
+               return -1;
+       }else{
+               fputs("[framehook/init]initializing..\n",log);
+               fflush(log);
+       }
+       //必要な設定があるかの確認
+       fprintf(log,"[framehook/init]called with argc = %d\n",argc);
+       fflush(log);
+       for(i=0;i<argc;i++){
+               fprintf(log,"[framehook/init]arg[%2d] = %s\n",i,argv[i]);
+               fflush(log);
+       }
+       //セッティング取得。
+       SETTING setting;
+       if(init_setting(log,tbox,&setting,argc,argv)){
+               fputs("[framehook/init]initialized settings.\n",log);
+               fflush(log);
+       }else{
+               fputs("[framehook/init]failed to initialize settings.\n",log);
+               fflush(log);
+               return -2;
+       }
+       //ライブラリなどの初期化
+       if(init(log)){
+               fputs("[framehook/init]initialized libs.\n",log);
+               fflush(log);
+       }else{
+               fputs("[framehook/init]failed to initialize libs.\n",log);
+               fflush(log);
+               return -3;
+       }
+       /*コンテキストの設定*/
+       *ctxp = malloc(sizeof(ContextInfo));
+       if(*ctxp == NULL){
+               fputs("[framehook/init]initialized to malloc for context.\n",log);
+               fflush(log);
+       }
+       ContextInfo* ci = (ContextInfo*)*ctxp;
+       ci->log = log;
+       fflush(log);
+       if(initData(&ci->data,log,&setting)){
+               fputs("[framehook/init]initialized context.\n",log);
+               fputs("[framehook/init]initialized.\n",log);
+               fflush(log);
+               return 0;
+       }else{
+               fputs("[framehook/init]failed to initialize context.\n",log);
+               fflush(log);
+               return -4;
+       }
+}
+/*
+ * 内部でのみ呼ばれる。
+ */
+
+ /*
+       argv[0]:プログラム
+       argv[1]:vhook
+       argv[2]:フォント
+       argv[3]:フォントインデックス
+       argv[4]:一画面
+       argv[5]:影の種類
+       以降オプション
+       --enable-show-video:描画中に動画を見せる。
+       --enable-fontsize-fix:フォントサイズを自動で調整する。
+*/
+int init_setting(FILE*log,const toolbox *tbox,SETTING* setting,int argc, char *argv[]){
+       /*videoの長さ*/
+       setting->video_length = (tbox->video_length * VPOS_FACTOR);
+       /*以降オプション*/
+       
+       //コメントを見せるか否か?
+       setting->enable_user_comment = FALSE;
+       setting->enable_owner_comment = FALSE;
+       setting->data_user_path = NULL;
+       setting->data_owner_path = NULL;
+       //一般的な設定
+       setting->font_path = NULL;
+       setting->font_index = 0;
+       setting->user_slot_max = 30;
+       setting->owner_slot_max = 30;
+       setting->shadow_kind = 1;//デフォルトはニコニコ動画風
+       setting->show_video = FALSE;
+       setting->fontsize_fix=FALSE;
+       setting->opaque_comment=FALSE;
+       int i;
+       char* arg;
+       for(i=0;i<argc;i++){
+               arg = argv[i];
+               if(!setting->data_user_path && strncmp(FRAMEHOOK_OPT_DATA_USER,arg,FRAMEHOOK_OPT_DATA_USER_LEN) == 0){
+                       char* data_user = arg+FRAMEHOOK_OPT_DATA_USER_LEN;
+                       setting->data_user_path = data_user;
+                       setting->enable_user_comment = TRUE;
+                       fprintf(log,"[framehook/init]User Comment data path:%s\n",setting->data_user_path);
+                       fflush(log);
+               }else if(!setting->data_owner_path && strncmp(FRAMEHOOK_OPT_DATA_OWNER,arg,FRAMEHOOK_OPT_DATA_OWNER_LEN) == 0){
+                       char* data_owner = arg+FRAMEHOOK_OPT_DATA_OWNER_LEN;
+                       setting->data_owner_path = data_owner;
+                       setting->enable_owner_comment = TRUE;
+                       fprintf(log,"[framehook/init]Owner Comment data path:%s\n",setting->data_owner_path);
+                       fflush(log);
+               }else if(!setting->font_path && strncmp(FRAMEHOOK_OPT_FONT,arg,FRAMEHOOK_OPT_FONT_LEN) == 0){
+                       char* font = arg+FRAMEHOOK_OPT_FONT_LEN;
+                       setting->font_path = font;
+                       fprintf(log,"[framehook/init]Font path:%s\n",setting->font_path);
+                       fflush(log);
+               }else if(strncmp(FRAMEHOOK_OPT_FONTINDEX,arg,FRAMEHOOK_OPT_FONTINDEX_LEN) == 0){
+                       setting->font_index = MAX(0,atoi(arg+FRAMEHOOK_OPT_FONTINDEX_LEN));
+                       fprintf(log,"[framehook/init]font index:%d\n",setting->font_index);
+                       fflush(log);
+               }else if(strncmp(FRAMEHOOK_OPT_SHADOW,arg,FRAMEHOOK_OPT_SHADOW_LEN) == 0){
+                       setting->shadow_kind = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHADOW_LEN));
+                       fprintf(log,"[framehook/init]shadow kind:%d\n",setting->shadow_kind);
+                       fflush(log);
+               }else if(strncmp(FRAMEHOOK_OPT_SHOW_USER,arg,FRAMEHOOK_OPT_SHOW_USER_LEN) == 0){
+                       setting->user_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_USER_LEN));
+                       fprintf(log,"[framehook/init]User Comments on screen:%d\n",setting->user_slot_max);
+                       fflush(log);
+               }else if(strncmp(FRAMEHOOK_OPT_SHOW_OWNER,arg,FRAMEHOOK_OPT_SHOW_OWNER_LEN) == 0){
+                       setting->owner_slot_max = MAX(0,atoi(arg+FRAMEHOOK_OPT_SHOW_OWNER_LEN));
+                       fprintf(log,"[framehook/init]Owner Comments on screen:%d\n",setting->owner_slot_max);
+                       fflush(log);
+               }else if(!setting->show_video && strcmp(arg,"--enable-show-video") == 0){
+                       fputs("[framehook/init]show video while converting.\n",log);
+                       fflush(log);
+                       setting->show_video=TRUE;
+               }else if(!setting->fontsize_fix && strcmp(arg,"--enable-fix-font-size") == 0){
+                       fputs("[framehook/init]fix font size automatically.\n",log);
+                       fflush(log);
+                       setting->fontsize_fix=TRUE;
+               }else if(!setting->opaque_comment && strcmp(arg,"--enable-opaque-comment") == 0){
+                       fputs("[framehook/init]enable opaque comment.\n",log);
+                       fflush(log);
+                       setting->opaque_comment=TRUE;
+               }
+       }
+       //引数を正しく入力したか否かのチェック
+       //ここでチェックしているの以外は、デフォルト設定で逃げる。
+       if(!setting->font_path){
+               fputs("[framehook/init]please set FONT PATH.\n",log);
+               fflush(log);
+               return FALSE;
+       }
+       return TRUE;
+}
+
+/*
+ * 必要な関数二つめ。フレームごとに呼ばれるよ!
+ * 
+ */
+DLLEXPORT void ExtProcess(void *ctx,const toolbox *tbox,vhext_frame *pict){
+    ContextInfo *ci = (ContextInfo *) ctx;
+    FILE* log = ci->log;
+
+       /* Note:
+        * Saccubus 1.22以降の拡張vhookフィルタでは、RGB24フォーマットでのみ
+        * 画像が提供されます。
+        */
+
+       //SDLのサーフェイスに変換
+    SDL_Surface* surf = SDL_CreateRGBSurfaceFrom(pict->data,
+                                                                                       pict->w,pict->h,24,pict->linesize,
+                                                                                               #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+                                                                                                   0xff000000,
+                                                                                                   0x00ff0000,
+                                                                                                   0x0000ff00,
+                                                                                               #else
+                                                                                                   0x000000ff,
+                                                                                                   0x0000ff00,
+                                                                                                   0x00ff0000,
+                                                                                               #endif
+                                                                                                   0x00000000
+                                                                                               );
+       //フィルタ
+       int now_vpos = (pict->pts * VPOS_FACTOR);
+       if(!main_process(&ci->data,surf,now_vpos)){
+               fputs("[framehook/process]failed to process.\n",log);
+               fflush(log);
+               exit(1);
+       }
+       //サーフェイス開放
+       SDL_FreeSurface(surf);
+       fflush(log);
+}
+
+/*
+ * 必要な関数最後。終わったら呼ばれるよ!
+ * 
+ */
+
+DLLEXPORT void ExtRelease(void *ctx,const toolbox *tbox){
+    ContextInfo *ci;
+    ci = (ContextInfo *) ctx;
+    FILE* log = ci->log;
+    fputs("[framehook/close]closing...\n",log);
+    if (ctx) {
+        closeData(&ci->data);
+           fputs("[framehook/close]closed.\n",log);
+        fclose(log);
+           //コンテキスト全体
+        free(ctx);
+    }
+    //ライブラリの終了
+    close();
+}
+