And the reason is that according JPEG standard you can only store 12-bit images in JPEG Extended Baseline 12-bit Lossy mode.
We do not truncate image data in UIC demo applications andtake more straightforward approach instead. The application logic only allow you to store image in format which will not cause bits truncation. For 16-bit images it is PNM, JPEG lossless or JPEG2000 formats. For 12-bit images it is PNM, JPEG Extended Baseline 12-bit Lossy, JPEG lossless and JPEG2000 formats. And for 8-bit images you additionally can store images in BMP and DDS formats.