improve the c++ and python demo apps to conditionally output image formats