beetlebug▾
/

Photo operations

ztk::photo (src/photo_ops.zig) follows these sources. The code is ztk's own; no library is used.

Exif 2.3

The Exif specification (JEITA CP-3451, Exif version 2.3) places the Exif data of a JPEG file in an APP1 segment that starts with Exif and two zero bytes, and gives the data the structure of TIFF: the byte order II or MM, the number 42, and the first directory of 12-byte entries. Tag 274 (Orientation), a SHORT, gives 1 to 8: the place of row 0 and of column 0 of the stored image. ztk::photo orientation reads that tag, and ztk::photo orient maps each value to its turn and mirror.

PNG and eXIf

The PNG specification gives the chunk layout: length, type, data, and CRC after the 8-byte signature. The extension "Extensions to the PNG 1.2 Specification", version 1.5.0, adds the chunk eXIf, whose data is the same TIFF structure as in Exif, before the first IDAT.

The methods

The resize averages the area under each new pixel along a side that gets smaller (a box filter), and blends the 2 nearest pixels along a side that gets larger (linear interpolation), one side at a time. The turn by an angle that is no multiple of 90 samples the source at the middle of each new pixel turned back, with bilinear interpolation. Both blend colors times alpha (premultiplied alpha), so a clear pixel adds no color. These are textbook methods of image processing, with no code from another project.