I most often see this with compressed video, but I've also seen it often enough with JPEG images. Many times blacks, reds, and other generally dark colors seem to be especially prone to compression artifacts, even if you're just opening a file and saving a copy of it. What causes this, and what countermeasures can be taken to prevent it?
The problem with most image compression methods is that computers see brightness linear. your eyes and brain see light logarithmic. What this means is that a small difference in brightness in dark colours is very noticeable but a small change in brightness in bright colours is hardly noticeable at all. A solution would be to use a format that compresses images based on logarithmic brightness. I am however not aware of any such compression method. This will of course come with its own downsides. but should be a significant improvement for darker images.
My first guess, specifically with JPEG, is that the colour palette doesn't include the colours your seeing as missing. From my understanding, compression algorithms generally try to remove visual or audio bits that a user can't see or hear--at least this is the way it works with MP3.
Another possible reason would be changing the bit level between the original and the compressed version.
Just work in any lossless format (PSD, TIFF, etc. Even PNG if it's for a very basic operation) and save as JPG only in the final export(if you actually need to use JPG), as the final file to be published on the web. Also, there are many ways to export a JPG, some tools allow disabling jpg color artifacts, some even do partial compression per areas of the canvas, etc.