blob: 0a8df909b910005571845fce4d53475eef480da1 [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>
Yabin Cui1a8b3f82024-07-23 12:16:23 -070021#include <vector>
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010022
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010023#include "android/hardware_buffer.h"
24#include "util/Util.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010025
26namespace android {
27namespace companion {
28namespace virtualcamera {
29
30// Jpeg-compress image into the output buffer.
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010031// * 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 Sebechlebsky4ce32082024-02-14 16:02:11 +010033// * quality - 0-100, higher number corresponds to higher quality.
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010034// * 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 Sebechlebsky4ce32082024-02-14 16:02:11 +010037// * 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.
43std::optional<size_t> compressJpeg(int width, int height, int quality,
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010044 std::shared_ptr<AHardwareBuffer> inBuffer,
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +010045 const std::vector<uint8_t>& app1ExifData,
46 size_t outBufferSize, void* outBuffer);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010047
Jan Sebechlebskyb3771312024-03-15 10:38:02 +010048// Round the resolution to the closest higher resolution where width and height
49// are divisible by 2*DCT_SIZE ().
50Resolution roundTo2DctSize(Resolution resolution);
51
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010052} // namespace virtualcamera
53} // namespace companion
54} // namespace android
55
56#endif // ANDROID_COMPANION_VIRTUALCAMERA_JPEGUTIL_H