Coverage Report

Created: 2025-08-03 06:57

/src/libavif/apps/shared/avifexif.c
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2022 Google LLC
2
// SPDX-License-Identifier: BSD-2-Clause
3
4
#include "avifexif.h"
5
#include "avif/avif.h"
6
7
uint8_t avifImageGetExifOrientationFromIrotImir(const avifImage * image)
8
0
{
9
0
    if ((image->transformFlags & AVIF_TRANSFORM_IROT) && (image->irot.angle == 1)) {
10
0
        if (image->transformFlags & AVIF_TRANSFORM_IMIR) {
11
0
            if (image->imir.axis) {
12
0
                return 7; // 90 degrees anti-clockwise then swap left and right.
13
0
            }
14
0
            return 5; // 90 degrees anti-clockwise then swap top and bottom.
15
0
        }
16
0
        return 8; // 90 degrees anti-clockwise.
17
0
    }
18
0
    if ((image->transformFlags & AVIF_TRANSFORM_IROT) && (image->irot.angle == 2)) {
19
0
        if (image->transformFlags & AVIF_TRANSFORM_IMIR) {
20
0
            if (image->imir.axis) {
21
0
                return 4; // 180 degrees anti-clockwise then swap left and right.
22
0
            }
23
0
            return 2; // 180 degrees anti-clockwise then swap top and bottom.
24
0
        }
25
0
        return 3; // 180 degrees anti-clockwise.
26
0
    }
27
0
    if ((image->transformFlags & AVIF_TRANSFORM_IROT) && (image->irot.angle == 3)) {
28
0
        if (image->transformFlags & AVIF_TRANSFORM_IMIR) {
29
0
            if (image->imir.axis) {
30
0
                return 5; // 270 degrees anti-clockwise then swap left and right.
31
0
            }
32
0
            return 7; // 270 degrees anti-clockwise then swap top and bottom.
33
0
        }
34
0
        return 6; // 270 degrees anti-clockwise.
35
0
    }
36
0
    if (image->transformFlags & AVIF_TRANSFORM_IMIR) {
37
0
        if (image->imir.axis) {
38
0
            return 2; // Swap left and right.
39
0
        }
40
0
        return 4; // Swap top and bottom.
41
0
    }
42
0
    return 1; // Default orientation ("top-left", no-op).
43
0
}
44
45
avifResult avifSetExifOrientation(avifRWData * exif, uint8_t orientation)
46
3
{
47
3
    size_t offset;
48
3
    const avifResult result = avifGetExifOrientationOffset(exif->data, exif->size, &offset);
49
3
    if (result != AVIF_RESULT_OK) {
50
0
        return result;
51
0
    }
52
3
    if (offset < exif->size) {
53
3
        exif->data[offset] = orientation;
54
3
        return AVIF_RESULT_OK;
55
3
    }
56
    // No Exif orientation was found.
57
0
    if (orientation == 1) {
58
        // The default orientation is 1, so if the given orientation is 1 too, do nothing.
59
0
        return AVIF_RESULT_OK;
60
0
    }
61
    // Adding an orientation tag to an Exif payload is involved.
62
0
    return AVIF_RESULT_NOT_IMPLEMENTED;
63
0
}