今回は前回製作したcvcaptureモジュールを改良し,
追加する機能は,
specファイルを記述する
前回のspecファイルをベースに,
リソースを定義する
まずはリソースです。リソースは<resources>タグ内の<resource>タグで記述します。<resoure>タグではname属性でリソース名,
また,
リスト1 リソース定義
<resources>
<resource name="cvcapture" payload="CvCapture" alloc="no">
<description><?data
Storage for CvCapture.
?></description>
<destruct><?data
cvReleaseCapture(&resource);
?></destruct>
</resource>
</resources>
関数を定義する
次に,
リソースを作成する関数cv_
リスト2 関数定義1
<function name="cv_create_camera_capture">
<proto>resource cvcapture cv_create_camera_capture([int index])</proto>
<summary>Start capturing frames from camera.</summary>
<description>(省略)</description>
<test>
<code><?data
var_dump(cv_create_camera_capture());
?></code>
<result mode="format"><?data
resource(%d) of type (cvcapture)
?></result>
</test>
</function>
<function name="cv_create_file_capture">
<proto>resource cvcapture cv_create_file_capture(string filename)</proto>
<summary>Start capturing frames from video file.</summary>
<description>(省略)</description>
<test>
<skipif><?data
if (!file_exists("sample.3g2")) {
die("skip sample video file does not exist");
}
?></skipif>
<code><?data
var_dump(cv_create_file_capture("sample.3g2"));
?></code>
<result mode="format"><?data
resource(%d) of type (cvcapture)
?></result>
</test>
</function>
cv_
リスト3 関数定義2
<function name="cv_save_capture">
<proto>bool cv_save_capture(resource cvcapture capture, string filename[, array &size])</proto>
<summary>Capture a frame.</summary>
<description>(省略)</description>
<test>
<code><?data
$capture = cv_create_camera_capture();
if ($capture && cv_save_capture($capture, "test_save.jpg", $size)) {
print_r($size);
}
?></code>
<result mode="format"><?data
Array
(
[0] => %d
[1] => %d
)
?></result>
</test>
</function>
ソースコードを生成する
ここまでできたら,
操作1 pecl-genを実行
$ pecl-gen --dir=cvcapture-0.2.0 cvcapture-0.2.0.xml Creating 'cvcapture' extension in './cvcapture-0.2.0' Your extension has been created in directory ./cvcapture. See ./cvcapture-0.2.0/README and/or ./cvcapture-0.2.0/INSTALL for further instructions.