What you are asking, essentially, is whether the decode process for a JPEG image can be reversed. This is a very different intent from that of a conventional JPEG encoder, and I am not aware of any software which accomplishes this. Mathematically this is possible* so long as the image has not had a transform or other modification applied after it was encoded, but programatically how difficult could it be?
The first problem is colour space - JPEG uses subsampled (the colour sampled over a group of pixels) yCbCr whereas a bitmap is RGB. Inevitable losses converting between these colour-spaces (and also in any gamma adjustment) introduce noise. The second problem to solve is JPEG records the image data as macroblocks (NxN sized sub-images), which must be inferred from the decoder's output image. A more in-depth explanation of the JPEG format and encoding process can be found here http://www.guillermito2.net/stegano/jsteg/
'un-decoding' a JPEG:
To create an approximation of the original JPEG data, we need to find the subsampling, size and alignment of macroblocks, and Discrete Cosine Transform (DCT) coefficients that were used to encode them. The rest is identical to a normal JPEG encoding process. One naive implementation that comes to mind is "educated guess and check": assume some common JPEG implementations were used to create the image, and try applying them until one is found that has 'JPEG-like' results from the DCT (typically zeros for high frequencies).
After that, fine-tune the coefficients for minimum error compared to the original (i.e. bitmap of the compressed image). This process will still result in tradeoff between error and filesize, but it should get close enough for practical purposes.
Source: Previous employment verifying DNx and ProRes video codecs, which apply JPEG-like coding to each individual frame (software reversing decoded frames would have been a very interesting and potentially useful side project).
* A set of input data exists that will produce identical output when passed through the original JPEG decoder, however it is highly improbable for any reconstruction to be a byte-wise copy (ignoring metadata) of the original file because information was lost during the decoding process.
Is this actually just about your understanding or do you want to do this (and if so, why)? – Dave – 2017-06-22T08:21:43.720
1I still don't get your problem - but as a rule of thumb, any (further) lossy encoding reduces the quality - it's only a best-case-scenario that can't be achieved without much effort (manually fine-tuning parameters, using "the best" tools,...) to get the same quality out of a lossy compression. And since JPEG doesn't offer much fine-tuning...
So the answer is: no. However, it's possible that the further loss of quality won't be visible - but that's something you have to try out because it really depends on the used formats (encoders), the picture in question and the use-case. – flolilo – 2017-06-22T11:43:12.030