blob: ce21def1a3caba6f446650342480e5d4585ec6a8 [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001#include "y2019/image_streamer/flip_image.h"
Tyler Chatowe0241452019-03-08 21:07:50 -08002
Brian Silverman4c7235a2021-11-17 19:04:37 -08003#ifdef __clang__
4// CImg has undefined behavior that Clang warns about. Just suppress the
5// warnings, somebody should evaluate these more carefully if this code is used
6// again.
7#pragma clang diagnostic ignored "-Wvarargs"
8#pragma clang diagnostic ignored "-Wnull-pointer-arithmetic"
9#pragma clang diagnostic ignored "-Wchar-subscripts"
10#pragma clang diagnostic ignored "-Wtautological-unsigned-char-zero-compare"
Adam Snaider13d48d92023-08-03 12:20:15 -070011#pragma clang diagnostic ignored "-Wcast-qual"
12#pragma clang diagnostic ignored "-Wcast-align"
13#pragma clang diagnostic ignored "-Wformat-nonliteral"
Brian Silverman4c7235a2021-11-17 19:04:37 -080014#endif
15
Tyler Chatowe0241452019-03-08 21:07:50 -080016#define cimg_display 0
17#define cimg_use_jpeg
18#define cimg_plugin "plugins/jpeg_buffer.h"
19#include "third_party/cimg/CImg.h"
20
21void flip_image(const char *input, const int input_size, JOCTET *buffer,
Austin Schuh9c03a532019-03-17 18:14:45 -070022 unsigned int *buffer_size, bool flip) {
Tyler Chatowe0241452019-03-08 21:07:50 -080023 ::cimg_library::CImg<unsigned char> image;
24 image.load_jpeg_buffer((JOCTET *)(input), input_size);
Austin Schuh9c03a532019-03-17 18:14:45 -070025 if (flip) {
Tyler Chatowd3384c22019-04-04 16:38:32 -070026 image.rotate(90);
27 } else {
28 image.rotate(270);
Austin Schuh9c03a532019-03-17 18:14:45 -070029 }
Tyler Chatowe0241452019-03-08 21:07:50 -080030
31 image.save_jpeg_buffer(buffer, *buffer_size, 80);
32}