1

我已经为饱和度编写了以下矩阵,但它没有给出正确的结果。有人可以告诉我这里有什么问题吗?

   ColorMatrix colorMatrix = new ColorMatrix(saturationFilter(0.3f));
   ColorMatrixColorFilter matrix = new ColorMatrixColorFilter(colorMatrix);

    public static float[] saturationFilter(float x){

    float lumR = 0.3086f;
    float lumG = 0.6094f;
    float lumB = 0.0820f;
    float matrix[] = {lumR*(1-x)+x,lumG*(1-x),lumB*(1-x), 0, 0, 0,0,
                      lumR*(1-x)+x,lumG*(1-x),lumB*(1-x), 0, 0, 0,0,
                      lumR*(1-x)+x,lumG*(1-x),lumB*(1-x), 0, 0, 0,0,
                      0f, 0f, 0f, 1f, 0f,
                      0f ,0f, 0f, 0f ,1f};

    return matrix;
}
4

1 回答 1

1

我已经通过正确编写矩阵来纠正上述函数,因为在所有错误的情况下我都在增加红色通道。这工作正常。

   public static float[] saturationFilter(float saturation){

    float p_val = cleanValue(saturation,100);
    float x = 1+((p_val > 0) ? 3*p_val/100 : p_val/100);
    float lumR = 0.3086f;
    float lumG = 0.6094f;
    float lumB = 0.0820f;
    float matrix[] = {lumR*(1-x)+x, lumG*(1-x),  lumB*(1-x), 0, 0, 
                      lumR*(1-x),   lumG*(1-x)+x, lumB*(1-x), 0, 0,
                      lumR*(1-x),   lumG*(1-x),   lumB*(1-x)+x, 0, 0,
                      0f, 0f, 0f, 1f, 0f,
                      0f ,0f, 0f, 0f ,1f};

    return matrix;
   }

     private static float cleanValue(float p_val, float p_limit){
         return Math.min(p_limit, Math.max(-p_limit, p_val));
}
于 2012-09-25T12:06:03.387 回答