support grayscale and bug fix.