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 ANDROID_COMPANION_VIRTUALCAMERA_JPEGUTIL_H 18 #define ANDROID_COMPANION_VIRTUALCAMERA_JPEGUTIL_H 19 20 #include <optional> 21 22 #include "android/hardware_buffer.h" 23 #include "util/Util.h" 24 25 namespace android { 26 namespace companion { 27 namespace virtualcamera { 28 29 // Jpeg-compress image into the output buffer. 30 // * width - width of the image, can be less than width of inBuffer. 31 // * heigh - height of the image, can be less than height of inBuffer. 32 // * quality - 0-100, higher number corresponds to higher quality. 33 // * inBuffer - Input buffer, the dimensions of the buffer must be aligned to 34 // 2*DCT_SIZE (16) to include necessary padding in case width and height of 35 // image is not aligned with 2*DCT_SIZE. 36 // * app1ExifData - vector containing data to be included in APP1 37 // segment. Can be empty. 38 // * outBufferSize - capacity of the output buffer. 39 // * outBuffer - output buffer to write compressed data into. 40 // Returns size of compressed data if the compression was successful, 41 // empty optional otherwise. 42 std::optional<size_t> compressJpeg(int width, int height, int quality, 43 std::shared_ptr<AHardwareBuffer> inBuffer, 44 const std::vector<uint8_t>& app1ExifData, 45 size_t outBufferSize, void* outBuffer); 46 47 // Round the resolution to the closest higher resolution where width and height 48 // are divisible by 2*DCT_SIZE (). 49 Resolution roundTo2DctSize(Resolution resolution); 50 51 } // namespace virtualcamera 52 } // namespace companion 53 } // namespace android 54 55 #endif // ANDROID_COMPANION_VIRTUALCAMERA_JPEGUTIL_H 56