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