Jdatestamp Technical Info
This section describes the working of some of the Jdatestamp features.
Lossless Date Stamp
If the entire jpeg image is decompressed and re-compressed after writing
the date there is bound to be a slight reduction in image quality due to
loss of information since JPEG is a lossy compression algorithm.
Jdatestamp uses the following steps to imprint the date:
Thus the slight quality reduction is only for the small area used by the
Uses jhead to
get the picture Date/Time.
Uses Jpegtran from IJG
for lossless crop and drop, to crop out the rectangular area required for the date text.
This step is lossless.
Decompresses the cropped image to internal memory.
Writes the date text on the decompressed image using the
Freetype2 Library API.
Compresses back the cropped section.
Losslessly drops back the cropped out image using jpegtran.
Scaling of Pointsize and text position
If in a jdatestamp command the pointsize or x/y coordinate is followed by
x then the value is multiplied by the scaling factor to scale the value
according to the image size.
The scaling factor is calculated using the below formula:
scaling factor = Closer to 1.0 between
(pixels in longer image side)/1600
(pixels in shorter image side)/1200
The transparency of the date text can be specified in the range 0-100 using
the -trans option. This option is implemented as follows.
while setting a pixel a simple alpha composite is done between the
text color (fgRed:fgBlue:fgGreen) and the image pixel (bgRed:bgBlue:bgGreen).
The effective pixel value is calculated as:
textRed = (fgRed*(100-transparency) + bgRed*transparency)/100;
textGreen = (fgGreen*(100-transparency) + bgGreen*transparency)/100;
textBlue = (fgBlue*(100-transparency) + bgBlue*transparency)/100;
Auto Color Selection
For each color in autocolors.txt a color Factor is calculated and multiplied
by the priority factor if any present next to the color in autocolors.txt.
The color with the maximum resulting color Factor is chosen. The priority
factor is to give more priority to colors which are seldom picked up otherwise
and to give lesser priority to overly selected colors like cyan to have a more
uniform distribution of colors.
To calculate the color factor the cropped image is divided into more or less
equal square boxes each of around 20*(image scale factor) pixels width.
For each box the average background Color (avgBgRed:avgBgGreen:avgBgBlue)
is calculated by averaging the red, green and blue color components of the
pixels in the box. For each auto color (fgRed:fgGreen:fgBlue) considered the
color difference is calculated as:
color difference = abs(fgRed-avgBgRed) + abs(fgGreen-avgBgGreen) +
The colorFactor of a color is the minimum color difference among all the boxes
in the cropped image.