Fix a crash bug when bitsPerSample > 8