package com.sheep.gamegroup.util.glide;

import android.graphics.Bitmap;
import android.support.annotation.NonNull;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.sheep.gamegroup.module.find.util.IFilter;

import org.wysaid.nativePort.CGENativeLibrary;

import java.security.MessageDigest;

/**
 * Created by realicing on 2018/12/4.
 * realicing@sina.com
 * 图片滤镜转化
 */
public class FilterTransform extends BitmapTransformation {

    private IFilter filter;

    public FilterTransform(IFilter filter) {
        super();
        this.filter = filter;
    }

    @Override
    protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
//        Bitmap dstImage = CGENativeLibrary.filterImage_MultipleEffects(toTransform, filter.getConfig(), 1.0f);
        return CGENativeLibrary.filterImage_MultipleEffects(toTransform, filter.getConfig(), 1.0f);
    }

    @Override
    public void updateDiskCacheKey(MessageDigest messageDigest) {
        messageDigest.update((filter.getConfig().hashCode() + filter.getName()).getBytes(CHARSET));
    }
}
