-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathgray2rgba.cc
More file actions
79 lines (62 loc) · 2.17 KB
/
Copy pathgray2rgba.cc
File metadata and controls
79 lines (62 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//===- gray2rgba.cc -------------------------------------------*- C++ -*-===//
//
// Copyright (C) 2022 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#define NOCPP
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define REL_WRITE 0
#define REL_READ 1
#include <aie_api/aie.hpp>
::aie::vector<uint8, 64> vector_broadcast(::aie::vector<uint8, 16> e) {
v64uint8 lli = e.template grow<64>();
lli = shuffle(lli, lli, T8_2x64_lo);
lli = shuffle(lli, lli, T8_2x64_lo);
return ::aie::vector<uint8, 64>(lli);
}
void gray2rgba_aie(uint8_t *y_in, uint8_t *rgba_out, const int32_t height,
const int32_t width) {
// Initialize alpha vector
::aie::vector<uint8, 64> alpha255 = ::aie::zeros<uint8, 64>();
for (int i = 0; i < 16; i++) {
alpha255[i * 4 + 3] = 255;
}
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j += 16) {
::aie::vector<uint8, 16> data_buf = ::aie::load_v<16>(y_in);
y_in += 16;
// vector shuffle
::aie::vector<uint8, 64> out = vector_broadcast(data_buf);
// bitwise OR with alpha value
v64uint8 fout = bor(out, alpha255);
::aie::store_v(rgba_out, ::aie::vector<uint8, 64>(fout));
rgba_out += 64;
}
return;
;
}
void gray2rgba_aie_scalar(uint8_t *y_in, uint8_t *rgba_out,
const int32_t height, const int32_t width) {
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++) {
uint8_t value = y_in[i * width + j];
rgba_out[i * width * 4 + j * 4] = value;
rgba_out[i * width * 4 + j * 4 + 1] = value;
rgba_out[i * width * 4 + j * 4 + 2] = value;
rgba_out[i * width * 4 + j * 4 + 3] = 255;
}
return;
;
}
extern "C" {
void gray2rgbaLine(uint8_t *in, uint8_t *out, int32_t lineWidth) {
gray2rgba_aie(in, out, 1, lineWidth);
}
void gray2rgbaTile(uint8_t *in, uint8_t *out, int32_t tileHeight,
int32_t tileWidth) {
gray2rgba_aie(in, out, tileHeight, tileWidth);
}
} // extern "C"