// Path: librestreaming/src/main/java/me/lake/librestreaming/filter/softvideofilter/BaseSoftVideoFilter.java
// public class BaseSoftVideoFilter {
//     protected int SIZE_WIDTH;
//     protected int SIZE_HEIGHT;
//     protected int SIZE_Y;
//     protected int SIZE_TOTAL;
//     protected int SIZE_U;
//     protected int SIZE_UV;
// 
//     public void onInit(int VWidth, int VHeight) {
//         SIZE_WIDTH = VWidth;
//         SIZE_HEIGHT = VHeight;
//         SIZE_Y = SIZE_HEIGHT * SIZE_WIDTH;
//         SIZE_UV = SIZE_HEIGHT * SIZE_WIDTH / 2;
//         SIZE_U = SIZE_UV / 2;
//         SIZE_TOTAL = SIZE_Y * 3 / 2;
//     }
// 
//     /**
//      *
//      * @param orignBuff
//      * @param targetBuff
//      * @param presentationTimeMs
//      * @param sequenceNum
//      * @return false to use orignBuff,true to use targetBuff
//      */
//     public boolean onFrame(byte[] orignBuff, byte[] targetBuff, long presentationTimeMs, int sequenceNum) {
//         return false;
//     }
// 
//     public void onDestroy() {
// 
//     }
// }


import android.graphics.Bitmap;
import me.lake.librestreaming.filter.softvideofilter.BaseSoftVideoFilter;
package me.lake.librestreaming.sample.softfilter;



/**
 * Created by lake on 16-4-1.
 */
public class IconFilterSoft extends BaseSoftVideoFilter {
    byte[] imageByte;
    int iconYSize;
    private int iconW;
    private int iconH;
    private int xPos;

    public void setXPos(int x) {
        xPos = x;
    }

    public IconFilterSoft(Bitmap bitmap) {
        iconW = bitmap.getWidth();
        iconH = bitmap.getHeight();
        imageByte = new byte[iconW * iconH * 3 / 2];
        iconYSize = iconH * iconW;
        int[] tem = new int[iconW * iconH];
        bitmap.getPixels(tem, 0, iconW, 0, 0, iconW, iconH);
        for (int y = 0; y < iconH; y++) {
            for (int x = 0; x < iconW; x++) {
                int color = tem[y * iconW + x];
                if (((color & 0xFF000000) >> 24) == 0) {
                    imageByte[y * iconW + x] = 0;
                    continue;
                }
                int R = (color & 0xff0000) >> 16;
                int G = (color & 0xff00) >> 8;
                int B = (color & 0xff);

                int Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
                int U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
// Path: librestreaming/src/main/java/me/lake/librestreaming/filter/softvideofilter/BaseSoftVideoFilter.java
// public class BaseSoftVideoFilter {
//     protected int SIZE_WIDTH;
//     protected int SIZE_HEIGHT;
//     protected int SIZE_Y;
//     protected int SIZE_TOTAL;
//     protected int SIZE_U;
//     protected int SIZE_UV;
// 
//     public void onInit(int VWidth, int VHeight) {
//         SIZE_WIDTH = VWidth;
//         SIZE_HEIGHT = VHeight;
//         SIZE_Y = SIZE_HEIGHT * SIZE_WIDTH;
//         SIZE_UV = SIZE_HEIGHT * SIZE_WIDTH / 2;
//         SIZE_U = SIZE_UV / 2;
//         SIZE_TOTAL = SIZE_Y * 3 / 2;
//     }
// 
//     /**
//      *
//      * @param orignBuff
//      * @param targetBuff
//      * @param presentationTimeMs
//      * @param sequenceNum
//      * @return false to use orignBuff,true to use targetBuff
//      */
//     public boolean onFrame(byte[] orignBuff, byte[] targetBuff, long presentationTimeMs, int sequenceNum) {
//         return false;
//     }
// 
//     public void onDestroy() {
// 
//     }
// }


// Path: sample/src/main/java/me/lake/librestreaming/sample/softfilter/IconFilterSoft.java
import android.graphics.Bitmap;
import me.lake.librestreaming.filter.softvideofilter.BaseSoftVideoFilter;

package me.lake.librestreaming.sample.softfilter;



/**
 * Created by lake on 16-4-1.
 */
public class IconFilterSoft extends BaseSoftVideoFilter {
    byte[] imageByte;
    int iconYSize;
    private int iconW;
    private int iconH;
    private int xPos;

    public void setXPos(int x) {
        xPos = x;
    }

    public IconFilterSoft(Bitmap bitmap) {
        iconW = bitmap.getWidth();
        iconH = bitmap.getHeight();
        imageByte = new byte[iconW * iconH * 3 / 2];
        iconYSize = iconH * iconW;
        int[] tem = new int[iconW * iconH];
        bitmap.getPixels(tem, 0, iconW, 0, 0, iconW, iconH);
        for (int y = 0; y < iconH; y++) {
            for (int x = 0; x < iconW; x++) {
                int color = tem[y * iconW + x];
                if (((color & 0xFF000000) >> 24) == 0) {
                    imageByte[y * iconW + x] = 0;
                    continue;
                }
                int R = (color & 0xff0000) >> 16;
                int G = (color & 0xff00) >> 8;
                int B = (color & 0xff);

                int Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
                int U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
                int V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;