Coverage Report

Created: 2026-10-17 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavif/apps/shared/avifexif.c
Line
Count
Source
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
235
{
47
235
    size_t offset;
48
235
    const avifResult result = avifGetExifOrientationOffset(exif->data, exif->size, &offset);
49
235
    if (result != AVIF_RESULT_OK) {
50
133
        return result;
51
133
    }
52
102
    if (offset < exif->size) {
53
59
        exif->data[offset] = orientation;
54
59
        return AVIF_RESULT_OK;
55
59
    }
56
    // No Exif orientation was found.
57
43
    if (orientation == 1) {
58
        // The default orientation is 1, so if the given orientation is 1 too, do nothing.
59
43
        return AVIF_RESULT_OK;
60
43
    }
61
    // Adding an orientation tag to an Exif payload is involved.
62
0
    return AVIF_RESULT_NOT_IMPLEMENTED;
63
43
}