NvJpeg Encoder in CudaSamples failed with a simple picture

If you can only use 12.0, the errors that I encountered on that versions were solved by rounding up the pitch t 4 or 8 (like you did in your code example). However, it was also necessary to set the memory outside the image (but inside this pitch) to zero, to get consistent results. Even then, it could be the case that a horizontal green and purple line would appear at the bottom of the image, after encoding, which I found no fix for (other than updating to 12.1).