blob: e64fb4fb61edb0fb5826f4373009e882fa1241af [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
20#include <memory>
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +010021#include <optional>
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010022
23#include "android/hardware_buffer.h"
24#include "system/graphics.h"
25
26namespace android {
27namespace companion {
28namespace virtualcamera {
29
30// Jpeg-compress image into the output buffer.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +010031// * width - width of the image
32// * heigh - height of the image
33// * quality - 0-100, higher number corresponds to higher quality.
34// * ycbr - android_ycbr structure describing layout of input YUV420 image.
35// * app1ExifData - vector containing data to be included in APP1
36// segment. Can be empty.
37// * outBufferSize - capacity of the output buffer.
38// * outBuffer - output buffer to write compressed data into.
39// Returns size of compressed data if the compression was successful,
40// empty optional otherwise.
41std::optional<size_t> compressJpeg(int width, int height, int quality,
42 const android_ycbcr& ycbcr,
43 const std::vector<uint8_t>& app1ExifData,
44 size_t outBufferSize, void* outBuffer);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010045
Jan Sebechlebsky9ae496f2023-12-05 15:56:28 +010046// Jpeg-compress all-black image into the output buffer.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +010047// * width - width of the image
48// * heigh - height of the image
49// * quality - 0-100, higher number corresponds to higher quality.
50// * app1ExifData - vector containing data to be included in APP1
51// segment. Can be empty.
52// * outBufferSize - capacity of the output buffer.
53// * outBuffer - output buffer to write compressed data into.
54// Returns size of compressed data if the compression was successful,
55// empty optional otherwise.
56std::optional<size_t> compressBlackJpeg(int width, int height, int quality,
57 const std::vector<uint8_t>& app1ExifData,
58 size_t outBufferSize, void* outBuffer);
Jan Sebechlebsky9ae496f2023-12-05 15:56:28 +010059
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010060} // namespace virtualcamera
61} // namespace companion
62} // namespace android
63
64#endif // ANDROID_COMPANION_VIRTUALCAMERA_JPEGUTIL_H