blob: a882223ead65e7dd7b975c55af554d79de5f0738 [file] [log] [blame]
Tyler Chatowe0241452019-03-08 21:07:50 -08001#include "flip_image.h"
2
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"
11#endif
12
Tyler Chatowe0241452019-03-08 21:07:50 -080013#define cimg_display 0
14#define cimg_use_jpeg
15#define cimg_plugin "plugins/jpeg_buffer.h"
16#include "third_party/cimg/CImg.h"
17
18void flip_image(const char *input, const int input_size, JOCTET *buffer,
Austin Schuh9c03a532019-03-17 18:14:45 -070019 unsigned int *buffer_size, bool flip) {
Tyler Chatowe0241452019-03-08 21:07:50 -080020 ::cimg_library::CImg<unsigned char> image;
21 image.load_jpeg_buffer((JOCTET *)(input), input_size);
Austin Schuh9c03a532019-03-17 18:14:45 -070022 if (flip) {
Tyler Chatowd3384c22019-04-04 16:38:32 -070023 image.rotate(90);
24 } else {
25 image.rotate(270);
Austin Schuh9c03a532019-03-17 18:14:45 -070026 }
Tyler Chatowe0241452019-03-08 21:07:50 -080027
28 image.save_jpeg_buffer(buffer, *buffer_size, 80);
29}