1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef HEIF_CLEAN_APERTURE_H_ 18 #define HEIF_CLEAN_APERTURE_H_ 19 20 #include <stdint.h> 21 22 namespace android { 23 namespace heif { 24 25 struct Fraction { 26 Fraction() = default; 27 Fraction(int32_t n, int32_t d); 28 29 void simplify(); 30 bool commonDenominator(Fraction* f); 31 bool add(Fraction f); 32 bool subtract(Fraction f); isIntegerFraction33 bool isInteger() const { return n % d == 0; } getInt32Fraction34 int32_t getInt32() const { return n / d; } 35 int32_t n; 36 int32_t d; 37 }; 38 39 struct CleanAperture { 40 Fraction width; 41 Fraction height; 42 Fraction horizOff; 43 Fraction vertOff; 44 }; 45 46 // Converts the CleanAperture value into a rectangle with bounds left, top, right and bottom. 47 // Returns true on success, false otherwise. 48 bool convertCleanApertureToRect(uint32_t imageW, uint32_t imageH, const CleanAperture& image, 49 int32_t* left, int32_t* top, int32_t* right, int32_t* bottom); 50 51 } // namespace heif 52 } // namespace android 53 54 #endif // HEIF_CLEAN_APERTURE_H_ 55