Flexの2つの画像にPixelBenderフィルターを使用します

まだドレ



ピクセルベンダーを使用した場合の簡単な効果を次に示します。



実際、 Andre Michelleでそのような効果を最初に見ましたが、彼はSorsを投稿しませんでした。 当時、私は8番目のプレーヤー(AS2)でそれを書きましたが、新しい機能のリリースに伴い、実験を繰り返すことにしました。 冒険がないわけではありませんが、コードはレーキなしで判明しました。レーキは8つで構築する必要がありました。



こちらをご覧ください 。 (5 mb)





書き込みフィルター



変数:

src-最初の入力画像

src2-2番目の入力画像

白-白い色

黒-黒の色

min-出力画像に白または黒を入れることを決定する値



フィルターロジックは次のとおりです。

-(a1)最初の画像の最初のピクセルの色を取得します

-(a2)2番目の画像の最初のピクセルの色を取得する

-(ss)a1 a2から減算

-各色の差ssがminよりも大きい場合、出力画像では最初のピクセルの代わりに白、そうでない場合は黒になります

<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  1. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  2. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  3. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  4. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  5. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  6. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  7. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  8. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  9. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  10. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  11. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  12. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  13. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  14. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  15. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  16. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  17. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  18. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  19. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  20. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  21. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  22. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



  23. <languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .



<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .







プログラムを書く



コードを読むことで問題が生じることはありません。いくつかのことだけを説明します。



bmp1-最新フレームのビデオクリップのインプリント

bmp2-bmp1のフィンガープリント、つまり最新の前のフレーム

bmp3-PixelBenderフィルターを適用した後の結果の画像

cmf-すべてのピクセルから10ピクセルからアルファを減算するフィルター

out-私たちが見る画像、bmp3はすべてのフレームに重ねられ、cmfとblurフィルターも





  1. パッケージ{
  2. import flash.display.Bitmap;
  3. import flash.display.BitmapData;
  4. import flash.display.Shader;
  5. import flash.display.ShaderJob;
  6. import flash.display.Sprite;
  7. import flash.events.Event;
  8. import flash.filters.BlurFilter;
  9. import flash.filters.ColorMatrixFilter;
  10. import flash.geom.Point;
  11. import flash.media.Video;
  12. import flash.net.NetConnection;
  13. import flash.net.NetStream;
  14. import flash.utils.ByteArray;
  15. [SWF(幅= 376、高さ= 160、backgroundColor = 0x0)]
  16. パブリック クラス SubstractTvはSpriteを拡張します{
  17. [埋め込み(ソース= "../assets/kutu.pbj"、mimeType = "application / octet-stream" )]
  18. private var pbj:クラス。
  19. private var wid: uint = stage.stageWidth;
  20. private var hei: uint = stage.stageHeight;
  21. private var video:ビデオ。
  22. private var nc:NetConnection;
  23. private var ns:NetStream;
  24. private var bmp1:BitmapData;
  25. private var bmp2:BitmapData;
  26. private var bmp3:BitmapData;
  27. private var out :BitmapData;
  28. private var bmp:ビットマップ。
  29. private var shader:シェーダー;
  30. private var shaderJob:ShaderJob;
  31. private var blur:BlurFilter;
  32. private var cmf:ColorMatrixFilter;
  33. パブリック 関数 SubstractTv(){
  34. nc = 新しい NetConnection();
  35. nc.connect( null );
  36. ns = 新しい NetStream(nc);
  37. ns.client = new Object();
  38. ns.play( "video.f4v" );
  39. video = new Video(wid、hei);
  40. video.attachNetStream(ns);
  41. bmp1 = 新しい BitmapData(wid、hei、 true );
  42. bmp2 = bmp1.clone();
  43. bmp3 = bmp1.clone();
  44. out = bmp1.clone();
  45. bmp = new Bitmap( out"auto"true );
  46. addChild(bmp);
  47. shader = new Shader( new pbj() as ByteArray);
  48. shader.data.src.input = bmp1;
  49. shader.data.src2.input = bmp2;
  50. createShaderJob();
  51. addEventListener(Event.ENTER_FRAME、onEnterFrame);
  52. blur = 新しい BlurFilter(3、3、3);
  53. cmf = 新しい ColorMatrixFilter([1、0、0、0、0、0
  54. 0、1、0、0、0、
  55. 0、0、1、0、0、
  56. 0、0、0、1、-10]);
  57. }
  58. プライベート 関数 onEnterFrame(e:Event): void {
  59. if (shaderJob.progress!= 1) return ;
  60. bmp2.draw(bmp1);
  61. {
  62. bmp1.draw(ビデオ);
  63. } catch (e:エラー){}
  64. createShaderJob();
  65. out .applyFilter( outout .rect、 new Point()、blur);
  66. out .applyFilter( outout .rect、 new Point()、cmf);
  67. out .draw(bmp3);
  68. }
  69. プライベート 関数 createShaderJob(): void {
  70. shaderJob = 新しい ShaderJob(shader、bmp3、wid、hei);
  71. shaderJob.start();
  72. }
  73. }
  74. }
*このソースコードは、 ソースコードハイライターで強調表示されました。



All Articles