Created
September 21, 2023 02:10
-
-
Save zhuker/3c47a9700e6f18542bd41a9a679191ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#ifdef __ARM_NEON | |
#include <arm_neon.h> | |
#endif | |
#include <fstream> | |
void gray2RgbRow(const uint8_t *gray, uint8_t *rgb, int n) { | |
int i = 0; | |
#ifdef __ARM_NEON | |
const int vsize = 16; | |
for (; i <= n - vsize; i += vsize, gray += vsize, rgb += vsize * 3) { | |
uint8x16_t g = vld1q_u8(gray); | |
uint8x16x3_t v{g, g, g}; | |
vst3q_u8(rgb, v); | |
} | |
#endif | |
for (; i < n; i++, gray++, rgb += 3) { | |
rgb[0] = rgb[1] = rgb[2] = gray[0]; | |
} | |
} | |
int YToRGB24(const uint8_t *src_y, | |
int src_stride_y, | |
const uint8_t *src_vu, | |
int src_stride_vu, | |
uint8_t *dst_rgb24, | |
int dst_stride_rgb24, | |
int width, | |
int height) { | |
for (int y = 0; y < height; ++y) { | |
gray2RgbRow(src_y, dst_rgb24, width); | |
dst_rgb24 += dst_stride_rgb24; | |
src_y += src_stride_y; | |
} | |
return 0; | |
} | |
int main() { | |
//created with | |
// # ffmpeg -i headshot1024.jpg -pix_fmt yuv420p -f rawvideo headshot1024.yuv420p | |
const std::string inputFile = "headshot1024.yuv420p"; | |
std::ifstream infile(inputFile, std::ios_base::binary); | |
std::vector<uint8_t> buffer{std::istreambuf_iterator<char>(infile), | |
std::istreambuf_iterator<char>()}; | |
int w = 1024; | |
int h = 790; | |
uint8_t rgb[1024 * 790 * 3] = {}; | |
YToRGB24(buffer.data(), w, nullptr, 0, rgb, w * 3, w, h); | |
std::ofstream out("headshot1024.rgb", std::ios::binary); | |
out.write((char *) &rgb[0], sizeof(rgb)); | |
out.close(); | |
// to open image use | |
// # ffmpeg -s 1024x790 -f rawvideo -pix_fmt rgb24 -i headshot1024.rgb -vframes 1 headshot1024.rgb.png | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment