Java 类android.media.effect.Effect 实例源码

项目:PhotoPhase    文件:GLESUtil.java   
private static int applyEffect(int[] textureHandles, int n, Effect effect, Rect dimen) {
    // Apply the border (we need a thread-safe call here)
    synchronized (SYNC) {
        // No more than 1024 (the minimum supported by all the gles20 devices)
        effect.apply(textureHandles[n], dimen.width(), dimen.height(), textureHandles[n + 1]);
    }

    // Delete the unused texture
    if (GLESUtil.DEBUG_GL_MEMOBJS) {
        Log.d(GLESUtil.DEBUG_GL_MEMOBJS_DEL_TAG, "glDeleteTextures: ["
                + textureHandles[n] + "]");
    }
    GLES20.glDeleteTextures(1, textureHandles, n);
    GLESUtil.glesCheckError("glDeleteTextures");
    return textureHandles[n + 1];
}
项目:WiCamera3D    文件:Filter.java   
/**
 * Filter context should be released before the current GL context is lost.
 */
public static void releaseContext() {
    if (context != null) {
        // Release all effects created with the releasing context.
        for (Effect effect : effects.values()) {
            effect.release();
        }
        effects.clear();
        context.release();
        context = null;
    }
}
项目:WiCamera3D    文件:Filter.java   
protected Effect getEffect(String name) {
       Effect effect = null;
        if (context == null) {
            context = EffectContext.createWithCurrentGlContext();
        }
        effect = context.getFactory().createEffect(name);
        effect.setParameter("tile_size", DEFAULT_TILE_SIZE);
        effects.put(this, effect);
    return effect;
}
项目:WiCamera3D    文件:RedEyeFilter.java   
@Override
public void process(Photo src, Photo dst) {
    Effect effect = getEffect(EffectFactory.EFFECT_REDEYE);
    float[] centers = new float[redeyes.size() * 2];
    int i = 0;
    for (PointF eye : redeyes) {
        centers[i++] = eye.x;
        centers[i++] = eye.y;
    }
    effect.setParameter("centers", centers);
    effect.apply(src.texture(), src.width(), src.height(), dst.texture());
}
项目:PhotoPhase    文件:SimpleTextureManager.java   
public SimpleTextureManager(Context context, Effect effect, Border border, boolean singleTexture) {
    // Pre-calculate the window size for the PhotoPhaseTextureManager. In onSurfaceChanged
    // the best fixed size will be set. The disposition size is simple for a better
    // performance of the internal arrays
    final Configuration conf = context.getResources().getConfiguration();
    int w = (int) AndroidHelper.convertDpToPixel(context, conf.screenWidthDp);
    int h = (int) AndroidHelper.convertDpToPixel(context, conf.screenHeightDp);
    mDimensions = new Rect(0, 0, w, h);
    mEffect = effect;
    mBorder = border;
    mContext = context;
    mSingleTexture = singleTexture;
}
项目:PhotoPhase    文件:Effects.java   
/**
 * Method that that release the cached data
 */
public void release() {
    for (Effect effect : mCachedEffects.values()) {
        try {
            effect.release();
        } catch (NoSuchElementException ex) {
            // Catching a runtime exception is not ideally, but releasing
            // the effect causes a fc it the effect is not a valid state.
            // Since we are releasing the effect we can ignore it to avoid
            // crash the app
        }
    }
    mCachedEffects.clear();
}
项目:PhotoPhase    文件:Effects.java   
/**
 * Method that return the next effect to use with the picture.
 *
 * @return Effect The next effect to use or null if no need to apply any effect
 */
@SuppressWarnings("boxing")
public Effect getNextEffect() {
    // Get an effect based on the user preference
    EFFECTS[] effects = Preferences.General.Effects.toEFFECTS(
            Preferences.General.Effects.getSelectedEffects(mContext));
    EFFECTS nextEffect = null;
    if (effects.length > 0) {
        int low = 0;
        int high = effects.length - 1;
        int pos = Utils.getNextRandom(low, high);
        nextEffect = effects[pos];
    }
    return getEffect(nextEffect);
}
项目:WiCamera3D    文件:Filter.java   
public void release() {
    Effect effect = effects.remove(this);
    if (effect != null) {
        effect.release();
    }
}
项目:PhotoPhase    文件:Effects.java   
private void updateParameters(EFFECTS type, Effect effect) {
    Settings settings = type.mSettings;
    if (settings == null) {
        return;
    }
    int val = Preferences.General.Effects.getEffectSettings(mContext, type.mId, settings.mDef);

    // Update the parameters
    if (type.compareTo(EFFECTS.AUTOFIX) == 0) {
        effect.setParameter("scale", (val * 0.05f));
    } else if (type.compareTo(EFFECTS.BLUR) == 0) {
        effect.setParameter(BlurEffect.STRENGTH_PARAMETER, (val * 0.2f) + 1.0f);
    } else if (type.compareTo(EFFECTS.FROSTED) == 0) {
        effect.setParameter(FrostedEffect.STRENGTH_PARAMETER, (val * 0.005f) + 0.005f);
    } else if (type.compareTo(EFFECTS.GRAIN) == 0) {
        effect.setParameter("strength", (val * 0.075f) + 0.075f);
    } else if (type.compareTo(EFFECTS.DOF) == 0) {
        effect.setParameter(DoFEffect.STRENGTH_PARAMETER, (val * 0.05f));
    } else if (type.compareTo(EFFECTS.SCANLINES) == 0) {
        effect.setParameter(ScanlinesEffect.STRENGTH_PARAMETER, (val * 0.3f) + 3f);
    } else if (type.compareTo(EFFECTS.HALFTONE) == 0) {
        effect.setParameter(HalftoneEffect.STRENGTH_PARAMETER, (val * 4f) + 40f);
    } else if (type.compareTo(EFFECTS.NOISE) == 0) {
        effect.setParameter(NoiseEffect.STRENGTH_PARAMETER, (val * 0.00175) + 0.00175);
    } else if (type.compareTo(EFFECTS.PIXELATE) == 0) {
        effect.setParameter(PixelateEffect.STRENGTH_PARAMETER, (val * 0.075) + 0.5);
    } else if (type.compareTo(EFFECTS.SATURATE) == 0) {
        effect.setParameter("scale", (val * 0.04f) + 0.1f);
    } else if (type.compareTo(EFFECTS.TEMPERATURE) == 0) {
        effect.setParameter("scale", (val * 0.04f) + 0.1f);
    } else if (type.compareTo(EFFECTS.VIGNETTE) == 0) {
        effect.setParameter("scale", (val * 0.04f) + 0.1f);
    } else if (type.compareTo(EFFECTS.SWIRL) == 0) {
        effect.setParameter(SwirlEffect.STRENGTH_PARAMETER, (val * 0.15f) + 1.0f);
    } else if (type.compareTo(EFFECTS.DUOTONE) == 0) {
        final String[] firstColors = {"#ff4a61c6", "#ffc64a50", "#ff4ac65b"};
        final int[] secondColors = {Color.WHITE, Color.BLACK, Color.LTGRAY};
        effect.setParameter("first_color", Color.parseColor(firstColors[val % firstColors.length]));
        effect.setParameter("second_color", secondColors[(val / secondColors.length)]);
    }  else if (type.compareTo(EFFECTS.TINT) == 0) {
        final int[] colors = {
                Color.WHITE, Color.BLACK, Color.LTGRAY, Color.LTGRAY, Color.DKGRAY,
                Color.parseColor("#ff4a61c6"), Color.parseColor("#ffc64a50"),
                Color.parseColor("#ff4ac65b"), Color.parseColor("#ffc64ab6"),
                Color.parseColor("#ffc6c54a"), Color.parseColor("#ffc69f4a"),
                Color.parseColor("#ff934ac6"), Color.parseColor("#ffffa500")};
        effect.setParameter("tint", colors[val]);
    }
}