This page explains how Jpegcoll replaces only the retouched part.
The following figure shows the flow of data and process in Jpegcoll.
Jpegcoll internally handles the following four processes. In the figure it is a rectangular square part. Three of them are IJG development tools and some modifications are added.
djpeg (IJG tool , JPEG decoder)
cjpeg (IJG tool , JPEG encoder , patched)
jpegtran (IJG tool , Tool that performs various operations (clipping, rotation, etc.) without loss , patched)
compare (A process of taking a difference between the two BMP images and creating a map)
Each process is explained in the next section.
IJG JPEG decoder without patch. For the convenience of processing it is set to output 24 bit BMP even in black and white JPEG.
IJG JPEG encoder cjpeg that is patched. When compressing images, this patched cjpeg import compression settings (QTable and Sampling factor) available from existing JPEG files. This allows JPEG compression of Retouchd BMP with the same settings as Original JPEG.
This is a process of comparing two BMP images in units of MCU (Minimum Coded Unit: blocks of 8 × 8 to 16 × 16) and storing the number of differences of each MCU in the map. This map is used in the following jpegtran.
Patched "-drop" switch is used. "-drop" is a switch that replaces the data in the specified rectangular area with other JPEG data. This process is patched that reads the difference map created by "compare" process, and applies data replacement by "- drop" only with difference MCU.
Jpegcoll can replace only modified blocks by combining the above process. The points to realize this featureful operation are the following two.
By comparing Original BMP and Retouchd BMP, it is possible to determine exactly which block was retouched.
Since Retouched BMP is JPEG-compressed to create Retouchd JPEG with the same settings as Original JPEG, Original JPEG and Retouchd JPEG can be merged by a MCU unit.