[ARM Stable Update] 2023-07-08 - Kernels, KDE Frameworks, systemd, LibreOffice, Pipewire, (Community to Extra Migration)

Since this update, Megapixels on the original PinePhone produces black&white JPEGs with a Moiré-type pattern (probably a Bayer pattern) instead of colored JPEGs. Looks like debayering is not being done.

In the Megapixels preview, everything looks nice and colored (even the small preview of the taken picture in the button in the bottom row), but when I open the JPEG in anything, it shows as Bayer.

And I can confirm it is a Bayer pattern, G’MIC-Qt’s Bayer filter with starting pattern Green-Blue reconstructs the colors, sorta. (It neither smoothes out the Bayer pattern nor applies a color correction matrix, so the result is suboptimal, but it proves that it is definitely a Bayer pattern that is stored in the JPEG instead of a decoded image.)

The issue seems to be with the metadata in the DNG because both dcraw and dcraw_emu on the computer also fail to debayer those DNGs whereas they debayer DNGs from before the update just fine.

Looking at the exiftool output, the CFA (color filter array) information is missing from the metadata:

-CFA Repeat Pattern Dim          : 2 2
-CFA Pattern 2                   : 2 1 1 0
-CFA Pattern                     : [Blue,Green][Green,Red]

This script works as a workaround, both on the computer and (after installing perl-image-exiftool that was not installed) on the PinePhone itself (the postprocessing commands are adapted and simplified from /usr/share/megapixels/postprocess.sh, e.g., no need to check whether exiftool is installed because the script needs it anyway to fix the DNG):

#!/bin/bash
if [ "$#" -ne 1 ]; then
 echo "Usage: $0 target[.dng]"
 exit 1
fi
TARGET="$1"
TARGET="${TARGET%.dng}"
echo "fixing $TARGET.dng..."
exiftool "-CFARepeatPatternDim=2 2" "-CFAPattern=[Blue,Green][Green,Red]" "-CFAPattern2=2 1 1 0" -P -overwrite_original "$TARGET.dng" || exit $?
echo "redoing the postprocessing..."
dcraw_emu +M -H 4 -o 1 -q 3 -T -fbdd 1 "$TARGET.dng" || exit $?
convert "$TARGET.dng.tiff" -sharpen 0x1.0 -sigmoidal-contrast 6,50% "$TARGET.jpg" || exit $?
exiftool -tagsFromfile "$TARGET.dng.tiff" -software="Megapixels" -overwrite_original "$TARGET.jpg" || exit $?
rm -f "$TARGET.dng.tiff"
echo "wrote $TARGET.jpg"
exit 0

Since those tags are unconditionally written to the DNG by the Megapixels source code, and since Megapixels was not updated, I suspect the libtiff 4.5.1 upgrade (upgraded from 4.5.0 in this update set) as the likely culprit. (It seems to be losing or incorrectly setting these tags.)