blob: 184dd56923bdb609aae29b2f67916b9b7cfed5d9 [file] [log] [blame]
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01001/*
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 Sebechlebsky4ce32082024-02-14 16:02:11 +010020#include <optional>
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010021
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010022#include "android/hardware_buffer.h"
23#include "util/Util.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010024
25namespace android {
26namespace companion {
27namespace virtualcamera {
28
29// Jpeg-compress image into the output buffer.
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010030// * 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.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +010032// * quality - 0-100, higher number corresponds to higher quality.
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010033// * 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.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +010036// * 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.
42std::optional<size_t> compressJpeg(int width, int height, int quality,
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010043 std::shared_ptr<AHardwareBuffer> inBuffer,
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +010044 const std::vector<uint8_t>& app1ExifData,
45 size_t outBufferSize, void* outBuffer);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010046
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010047// Round the resolution to the closest higher resolution where width and height
48// are divisible by 2*DCT_SIZE ().
49Resolution roundTo2DctSize(Resolution resolution);
50
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010051} // namespace virtualcamera
52} // namespace companion
53} // namespace android
54
55#endif // ANDROID_COMPANION_VIRTUALCAMERA_JPEGUTIL_H