blob: 506040f5280dfdc223d351be0286d1d4351aeed1 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#include "ImageUtils.hpp"
18
19void convertImgIoInt8(void * data, const size_t sz)
20{
Isabella Gottardi79d41542021-10-20 15:52:32 +010021 uint8_t * tmp_req_data = static_cast<uint8_t *>(data);
22 int8_t * tmp_signed_req_data = static_cast<int8_t *>(data);
alexander3c798932021-03-26 21:42:19 +000023
24 for (size_t i = 0; i < sz; ++i) {
Isabella Gottardi79d41542021-10-20 15:52:32 +010025 tmp_signed_req_data[i] = static_cast<int8_t>(
26 static_cast<int32_t>(tmp_req_data[i]) - 128);
alexander3c798932021-03-26 21:42:19 +000027 }
28}
29
30void convertImgIoGreyscale(const uint8_t * srcPtr, uint8_t * dstPtr, const size_t sz)
31{
32 for (size_t i = 0; i < sz; ++i, srcPtr += 3) {
33 *dstPtr++ = 0.2989 * (*srcPtr) +
34 0.587 * (*(srcPtr+1)) +
35 0.114 * (*(srcPtr+2));
36 }
37}