1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "box/item_property_transform_box.h" 17 18 static const uint8_t ROTATE_NINETY_DEGREES = 90; 19 20 namespace OHOS { 21 namespace ImagePlugin { ParseContent(HeifStreamReader & reader)22heif_error HeifIrotBox::ParseContent(HeifStreamReader &reader) 23 { 24 uint8_t rotation = reader.Read8() & 0x03; // only 2 bits is used 25 rotDegree_ = rotation * ROTATE_NINETY_DEGREES; 26 return reader.GetError(); 27 } 28 Write(HeifStreamWriter & writer) const29heif_error HeifIrotBox::Write(HeifStreamWriter &writer) const 30 { 31 size_t boxStart = ReserveHeader(writer); 32 writer.Write8((uint8_t) (rotDegree_ / ROTATE_NINETY_DEGREES)); 33 WriteCalculatedHeader(writer, boxStart); 34 return heif_error_ok; 35 } 36 ParseContent(HeifStreamReader & reader)37heif_error HeifImirBox::ParseContent(HeifStreamReader &reader) 38 { 39 uint8_t axis = reader.Read8(); 40 direction_ = (axis & 0x01) ? HeifTransformMirrorDirection::HORIZONTAL : HeifTransformMirrorDirection::VERTICAL; 41 return reader.GetError(); 42 } 43 Write(HeifStreamWriter & writer) const44heif_error HeifImirBox::Write(HeifStreamWriter &writer) const 45 { 46 if (direction_ == HeifTransformMirrorDirection::INVALID) { 47 return heif_invalid_mirror_direction; 48 } 49 size_t boxStart = ReserveHeader(writer); 50 writer.Write8(static_cast<uint8_t>(direction_)); 51 WriteCalculatedHeader(writer, boxStart); 52 return heif_error_ok; 53 } 54 } // namespace ImagePlugin 55 } // namespace OHOS 56