Try to optimize the image layer by avoiding unnecessary image conversions

In ImageUtils, I've removed the test on the internal format, which seems irrelevant here, since we are doing work on CPU side

In ImageLayer, I've changed the test logic before converting images to avoid a lot of unnecessary image conversions.