package com.gh.gamecenter.core.utils

import android.graphics.Bitmap
import com.facebook.common.references.CloseableReference
import com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory
import com.facebook.imagepipeline.request.BasePostprocessor

class TopCutProcess(private val cutRatio: Float) : BasePostprocessor() {

    override fun process(sourceBitmap: Bitmap, bitmapFactory: PlatformBitmapFactory): CloseableReference<Bitmap>? {
        val viewWidth = sourceBitmap.width
        val viewHeight = sourceBitmap.height.toFloat()
        var newHeight = viewWidth / cutRatio
        if (newHeight > viewHeight) {
            newHeight = viewHeight
        }
        val bitmapRef = bitmapFactory.createBitmap(sourceBitmap, 0, 0, viewWidth, (newHeight).toInt())
        return CloseableReference.cloneOrNull(bitmapRef)
    }
}