/src/skia/include/private/SkExif.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2023 Google Inc. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license that can be |
5 | | * found in the LICENSE file. |
6 | | */ |
7 | | |
8 | | #ifndef SkExif_DEFINED |
9 | | #define SkExif_DEFINED |
10 | | |
11 | | #include "include/codec/SkEncodedOrigin.h" |
12 | | #include "include/core/SkData.h" |
13 | | #include "include/core/SkRefCnt.h" |
14 | | #include "include/private/base/SkAPI.h" |
15 | | |
16 | | #include <cstdint> |
17 | | |
18 | | class SK_API SkExifMetadata { |
19 | | public: |
20 | | /* |
21 | | * Parse the metadata specified in |data|. |
22 | | */ |
23 | | SkExifMetadata(const sk_sp<SkData> data); |
24 | | |
25 | | /* |
26 | | * If the image encoded origin is specified, populate |out| and return true. Otherwise return |
27 | | * false. |
28 | | */ |
29 | 1.56k | bool getOrigin(SkEncodedOrigin* out) const { |
30 | 1.56k | if (fOriginPresent && out) *out = fOriginValue; |
31 | 1.56k | return fOriginPresent; |
32 | 1.56k | } |
33 | | |
34 | | /* |
35 | | * If the HDR headroom is specified, populate |out| and return true. Otherwise return false. |
36 | | */ |
37 | 3.40k | bool getHdrHeadroom(float* out) const { |
38 | 3.40k | if (fHdrHeadroomPresent && out) *out = fHdrHeadroomValue; |
39 | 3.40k | return fHdrHeadroomPresent; |
40 | 3.40k | } |
41 | | |
42 | | /* |
43 | | * If resolution unit, x, or y is specified, populate |out| and return true. Otherwise return |
44 | | * false. |
45 | | */ |
46 | 0 | bool getResolutionUnit(uint16_t* out) const { |
47 | 0 | if (fResolutionUnitPresent && out) *out = fResolutionUnitValue; |
48 | 0 | return fResolutionUnitPresent; |
49 | 0 | } |
50 | 0 | bool getXResolution(float* out) const { |
51 | 0 | if (fXResolutionPresent && out) *out = fXResolutionValue; |
52 | 0 | return fXResolutionPresent; |
53 | 0 | } |
54 | 0 | bool getYResolution(float* out) const { |
55 | 0 | if (fYResolutionPresent && out) *out = fYResolutionValue; |
56 | 0 | return fYResolutionPresent; |
57 | 0 | } |
58 | | |
59 | | /* |
60 | | * If pixel dimension x or y is specified, populate |out| and return true. Otherwise return |
61 | | * false. |
62 | | */ |
63 | 0 | bool getPixelXDimension(uint32_t* out) const { |
64 | 0 | if (fPixelXDimensionPresent && out) *out = fPixelXDimensionValue; |
65 | 0 | return fPixelXDimensionPresent; |
66 | 0 | } |
67 | 0 | bool getPixelYDimension(uint32_t* out) const { |
68 | 0 | if (fPixelYDimensionPresent && out) *out = fPixelYDimensionValue; |
69 | 0 | return fPixelYDimensionPresent; |
70 | 0 | } |
71 | | |
72 | | private: |
73 | | // Helper functions and constants for parsing the data. |
74 | | void parseIfd(uint32_t ifdOffset, bool littleEndian, bool isRoot); |
75 | | |
76 | | // The input data. |
77 | | const sk_sp<SkData> fData; |
78 | | |
79 | | // The origin property. |
80 | | bool fOriginPresent = false; |
81 | | SkEncodedOrigin fOriginValue = kTopLeft_SkEncodedOrigin; |
82 | | |
83 | | // The HDR headroom property. |
84 | | bool fHdrHeadroomPresent = false; |
85 | | float fHdrHeadroomValue = 1.f; |
86 | | |
87 | | // Resolution. |
88 | | bool fResolutionUnitPresent = false; |
89 | | uint16_t fResolutionUnitValue = 0; |
90 | | bool fXResolutionPresent = false; |
91 | | float fXResolutionValue = 0; |
92 | | bool fYResolutionPresent = false; |
93 | | float fYResolutionValue = 0; |
94 | | |
95 | | // Size in pixels. |
96 | | bool fPixelXDimensionPresent = false; |
97 | | uint32_t fPixelXDimensionValue = 0; |
98 | | bool fPixelYDimensionPresent = false; |
99 | | uint32_t fPixelYDimensionValue = 0; |
100 | | }; |
101 | | |
102 | | #endif |